Skip to content

Commit

Permalink
Merge pull request #3247 from autonomys/fix-map-sync
Browse files Browse the repository at this point in the history
Make the minimum mapping block 1, not genesis
  • Loading branch information
teor2345 authored Nov 22, 2024
2 parents 1a47759 + 7b4bfb3 commit 92cd589
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
12 changes: 9 additions & 3 deletions crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ use sp_runtime::traits::{
use sp_runtime::Justifications;
use std::error::Error;
use std::future::Future;
use std::num::NonZeroU32;
use std::slice;
use std::sync::atomic::{AtomicU16, Ordering};
use std::sync::Arc;
Expand Down Expand Up @@ -365,8 +366,13 @@ pub struct ObjectMappingNotification {
pub enum CreateObjectMappings {
/// Start creating object mappings from this block number.
///
/// This can be lower than the latest archived block.
Block(BlockNumber),
/// This can be lower than the latest archived block, but must be greater than genesis.
///
/// The genesis block doesn't have mappings, so starting mappings at genesis is pointless.
/// The archiver will fail if it can't get the data for this block, but snap sync doesn't store
/// the genesis data on disk. So avoiding genesis also avoids this error.
/// <https://github.com/paritytech/polkadot-sdk/issues/5366>
Block(NonZeroU32),

/// Create object mappings as archiving is happening.
Yes,
Expand All @@ -381,7 +387,7 @@ impl CreateObjectMappings {
/// If there is no fixed block number, or mappings are disabled, returns None.
fn block(&self) -> Option<BlockNumber> {
match self {
CreateObjectMappings::Block(block) => Some(*block),
CreateObjectMappings::Block(block) => Some(block.get()),
CreateObjectMappings::Yes => None,
CreateObjectMappings::No => None,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn main() -> Result<(), Error> {
base: consensus_chain_config,
// Domain node needs slots notifications for bundle production.
force_new_slot_notifications: true,
create_object_mappings: CreateObjectMappings::Block(0),
create_object_mappings: CreateObjectMappings::No,
subspace_networking: SubspaceNetworking::Create { config: dsn_config },
dsn_piece_getter: None,
sync: Default::default(),
Expand Down
22 changes: 15 additions & 7 deletions crates/subspace-node/src/commands/run/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use sc_telemetry::TelemetryEndpoints;
use std::collections::HashSet;
use std::fmt;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::num::NonZeroU32;
use std::path::PathBuf;
use std::str::FromStr;
use subspace_core_primitives::BlockNumber;
Expand Down Expand Up @@ -308,10 +309,17 @@ struct TimekeeperOptions {
pub enum CreateObjectMappingConfig {
/// Start creating object mappings from this block number.
///
/// This can be lower than the latest archived block.
Block(BlockNumber),
/// This can be lower than the latest archived block, but must be greater than genesis.
///
/// The genesis block doesn't have mappings, so starting mappings at genesis is pointless.
/// The archiver will fail if it can't get the data for this block, and snap sync doesn't store
/// the genesis data on disk. So avoiding genesis also avoids this error.
/// <https://github.com/paritytech/polkadot-sdk/issues/5366>
Block(NonZeroU32),

/// Create object mappings as archiving is happening.
/// This continues from the last archived segment, but mappings that were in the channel or RPC
/// segment when the node shut down can be lost.
Yes,

/// Don't create object mappings.
Expand All @@ -337,7 +345,7 @@ impl FromStr for CreateObjectMappingConfig {
"no" => Ok(Self::No),
"yes" => Ok(Self::Yes),
block => block.parse().map(Self::Block).map_err(|_| {
"Unsupported create object mappings setting: use `yes`, `no` or a block number"
"Unsupported create object mappings setting: use `yes`, `no` or a non-zero block number"
.to_string()
}),
}
Expand Down Expand Up @@ -443,10 +451,10 @@ pub(super) struct ConsensusChainOptions {

/// Create object mappings during archiving.
///
/// Can be set to `no` (default), `yes` (creates object mappings as archiving is happening) or
/// block number from which to continue creating object mappings.
/// Can be set to `no` (default), `yes` (creates object mappings as archiving is happening), or
/// a non-zero block number where the node starts creating object mappings.
///
/// --dev mode enables mappings from genesis automatically, unless the value is supplied
/// --dev mode enables mappings from the first block automatically, unless a value is supplied
/// explicitly.
/// Use `no` to disable mappings in --dev mode.
#[arg(long)]
Expand Down Expand Up @@ -534,7 +542,7 @@ pub(super) fn create_consensus_chain_configuration(
timekeeper_options.timekeeper = true;

if create_object_mappings.is_none() {
create_object_mappings = Some(CreateObjectMappingConfig::Block(0));
create_object_mappings = Some(CreateObjectMappingConfig::Block(NonZeroU32::MIN));
}

if sync.is_none() {
Expand Down

0 comments on commit 92cd589

Please sign in to comment.