Skip to content

Commit

Permalink
Merge pull request #3372 from autonomys/domain_block_state_pruning
Browse files Browse the repository at this point in the history
Finalize domain blocks and default domain block and state pruning
  • Loading branch information
vedhavyas authored Feb 10, 2025
2 parents c67d141 + d368a8a commit 8dcc0fd
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 84 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use subspace_runtime::RuntimeApi as CRuntimeApi;
use subspace_runtime_primitives::opaque::Block as CBlock;
use subspace_runtime_primitives::AccountId;
use subspace_runtime_primitives::{AccountId, DOMAINS_BLOCK_PRUNING_DEPTH};
use subspace_service::FullClient as CFullClient;

/// `DomainInstanceStarter` used to start a domain instance node based on the given
Expand Down Expand Up @@ -166,6 +166,7 @@ impl DomainInstanceStarter {
consensus_chain_sync_params: None::<
ConsensusChainSyncParams<_, Arc<dyn NetworkRequest + Sync + Send>>,
>,
challenge_period: DOMAINS_BLOCK_PRUNING_DEPTH,
};

let mut domain_node = domain_service::new_full::<
Expand Down Expand Up @@ -228,6 +229,7 @@ impl DomainInstanceStarter {
consensus_chain_sync_params: None::<
ConsensusChainSyncParams<_, Arc<dyn NetworkRequest + Sync + Send>>,
>,
challenge_period: DOMAINS_BLOCK_PRUNING_DEPTH,
};

let mut domain_node = domain_service::new_full::<
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ sc-network = { git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a814
sc-proof-of-time = { version = "0.1.0", path = "../sc-proof-of-time" }
sc-subspace-chain-specs = { version = "0.1.0", path = "../sc-subspace-chain-specs" }
sc-service = { git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305", default-features = false }
sc-state-db = { git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305"}
sc-storage-monitor = { git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305", default-features = false }
sc-telemetry = { git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }
sc-transaction-pool-api = { git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }
Expand Down
64 changes: 62 additions & 2 deletions crates/subspace-node/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use futures::stream::StreamExt;
use futures::FutureExt;
use sc_cli::Signals;
use sc_consensus_slots::SlotProportion;
use sc_service::{BlocksPruning, Configuration, PruningMode};
use sc_state_db::Constraints;
use sc_storage_monitor::StorageMonitorService;
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sc_utils::mpsc::tracing_unbounded;
Expand All @@ -30,6 +32,7 @@ use std::sync::Arc;
use subspace_logging::init_logger;
use subspace_metrics::{start_prometheus_metrics_server, RegistryAdapter};
use subspace_runtime::{Block, RuntimeApi};
use subspace_runtime_primitives::{DOMAINS_BLOCK_PRUNING_DEPTH, DOMAINS_PRUNING_DEPTH_MULTIPLIER};
use subspace_service::config::ChainSyncMode;
use tracing::{debug, error, info, info_span, warn};

Expand Down Expand Up @@ -88,7 +91,7 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {

let ConsensusChainConfiguration {
maybe_tmp_dir: _maybe_tmp_dir,
subspace_configuration,
mut subspace_configuration,
dev,
pot_external_entropy,
storage_monitor,
Expand Down Expand Up @@ -128,6 +131,15 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
None
};

if maybe_domain_configuration.is_some() {
// TODO: currently, we set consensus block and state pruning to challenge period
// when the node is running a domain node.
// But is there a situation when challenge period is not enough?
// If we do such a scenario, we would rather keep the consensus block and state pruning
// to archive-canonical
ensure_block_and_state_pruning_params(&mut subspace_configuration.base)
}

let mut task_manager = {
let subspace_link;
let consensus_chain_node = {
Expand Down Expand Up @@ -182,7 +194,8 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
})?;

// Run a domain
if let Some(domain_configuration) = maybe_domain_configuration {
if let Some(mut domain_configuration) = maybe_domain_configuration {
ensure_block_and_state_pruning_params(&mut domain_configuration.domain_config);
let mut xdm_gossip_worker_builder = GossipWorkerBuilder::new();
let gossip_message_sink = xdm_gossip_worker_builder.gossip_msg_sink();
let (domain_message_sink, domain_message_receiver) =
Expand Down Expand Up @@ -372,3 +385,50 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
.await
.map_err(Into::into)
}

pub fn ensure_block_and_state_pruning_params(config: &mut Configuration) {
let blocks_to_prune =
DOMAINS_BLOCK_PRUNING_DEPTH.saturating_mul(DOMAINS_PRUNING_DEPTH_MULTIPLIER);

if let BlocksPruning::Some(blocks) = config.blocks_pruning {
config.blocks_pruning = BlocksPruning::Some(if blocks >= blocks_to_prune {
blocks
} else {
warn!(
"Blocks pruning config needs to be at least {:?}",
blocks_to_prune
);
blocks_to_prune
});
}

match &config.state_pruning {
None => {
config.state_pruning = Some(PruningMode::Constrained(Constraints {
max_blocks: Some(blocks_to_prune),
}))
}
Some(pruning_mode) => {
if let PruningMode::Constrained(constraints) = pruning_mode {
let blocks_to_prune = match constraints.max_blocks {
None => blocks_to_prune,
Some(blocks) => {
if blocks >= blocks_to_prune {
blocks
} else {
warn!(
"State pruning config needs to be at least {:?}",
blocks_to_prune
);
blocks_to_prune
}
}
};

config.state_pruning = Some(PruningMode::Constrained(Constraints {
max_blocks: Some(blocks_to_prune),
}))
}
}
}
}
3 changes: 3 additions & 0 deletions crates/subspace-node/src/commands/run/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use std::net::SocketAddr;
use std::sync::Arc;
use subspace_runtime::RuntimeApi as CRuntimeApi;
use subspace_runtime_primitives::opaque::Block as CBlock;
use subspace_runtime_primitives::DOMAINS_BLOCK_PRUNING_DEPTH;
use subspace_service::FullClient as CFullClient;
use tokio::sync::broadcast::Receiver;
use tokio_stream::wrappers::errors::BroadcastStreamRecvError;
Expand Down Expand Up @@ -513,6 +514,7 @@ where
maybe_operator_id: operator_id,
confirmation_depth_k: chain_constants.confirmation_depth_k(),
consensus_chain_sync_params,
challenge_period: DOMAINS_BLOCK_PRUNING_DEPTH,
};

let mut domain_node = domain_service::new_full::<
Expand Down Expand Up @@ -553,6 +555,7 @@ where
maybe_operator_id: operator_id,
confirmation_depth_k: chain_constants.confirmation_depth_k(),
consensus_chain_sync_params,
challenge_period: DOMAINS_BLOCK_PRUNING_DEPTH,
};

let mut domain_node = domain_service::new_full::<
Expand Down
6 changes: 6 additions & 0 deletions crates/subspace-runtime-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub const BLOCK_WEIGHT_FOR_2_SEC: Weight =
/// Maximum block length for non-`Normal` extrinsic is 5 MiB.
pub const MAX_BLOCK_LENGTH: u32 = 5 * 1024 * 1024;

/// Pruning depth multiplier for state and blocks pruning.
pub const DOMAINS_PRUNING_DEPTH_MULTIPLIER: u32 = 2;

/// Domains Block pruning depth.
pub const DOMAINS_BLOCK_PRUNING_DEPTH: u32 = 14_400;

/// We allow for 3.75 MiB for `Normal` extrinsic with 5 MiB maximum block length.
pub fn maximum_normal_block_length() -> BlockLength {
BlockLength::max_with_normal_ratio(MAX_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO)
Expand Down
6 changes: 3 additions & 3 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ use subspace_runtime_primitives::utility::MaybeIntoUtilityCall;
use subspace_runtime_primitives::{
maximum_normal_block_length, AccountId, Balance, BlockNumber, FindBlockRewardAddress, Hash,
HoldIdentifier, Moment, Nonce, Signature, SlowAdjustingFeeUpdate, BLOCK_WEIGHT_FOR_2_SEC,
MAX_BLOCK_LENGTH, MIN_REPLICATION_FACTOR, NORMAL_DISPATCH_RATIO, SHANNON, SLOT_PROBABILITY,
SSC,
DOMAINS_BLOCK_PRUNING_DEPTH, MAX_BLOCK_LENGTH, MIN_REPLICATION_FACTOR, NORMAL_DISPATCH_RATIO,
SHANNON, SLOT_PROBABILITY, SSC,
};

sp_runtime::impl_opaque_keys! {
Expand Down Expand Up @@ -742,7 +742,7 @@ parameter_types! {
pub MaxDomainBlockWeight: Weight = maximum_domain_block_weight();
pub const DomainInstantiationDeposit: Balance = 100 * SSC;
pub const MaxDomainNameLength: u32 = 32;
pub const BlockTreePruningDepth: u32 = 14_400;
pub const BlockTreePruningDepth: u32 = DOMAINS_BLOCK_PRUNING_DEPTH;
pub const StakeWithdrawalLockingPeriod: DomainNumber = 14_400;
// TODO: revisit these. For now epoch every 10 mins for a 6 second block and only 100 number of staking
// operations allowed within each epoch.
Expand Down
Loading

0 comments on commit 8dcc0fd

Please sign in to comment.