Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the minimum mapping block 1, not genesis #3247

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 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 @@ -377,11 +383,14 @@ pub enum CreateObjectMappings {
}

impl CreateObjectMappings {
/// The minimum mapping block number.
pub const MIN_BLOCK: CreateObjectMappings = CreateObjectMappings::Block(NonZeroU32::MIN);
teor2345 marked this conversation as resolved.
Show resolved Hide resolved

/// The fixed block number to start creating object mappings from.
/// 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::MIN_BLOCK,
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
subspace_networking: SubspaceNetworking::Create { config: dsn_config },
dsn_piece_getter: None,
sync: Default::default(),
Expand Down
28 changes: 21 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 All @@ -354,6 +362,12 @@ impl fmt::Display for CreateObjectMappingConfig {
}
}

impl CreateObjectMappingConfig {
/// The minimum mapping block number.
pub const MIN_BLOCK: CreateObjectMappingConfig =
CreateObjectMappingConfig::Block(NonZeroU32::MIN);
}

/// Options for running a node
#[derive(Debug, Parser)]
pub(super) struct ConsensusChainOptions {
Expand Down Expand Up @@ -443,10 +457,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 +548,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::MIN_BLOCK);
}

if sync.is_none() {
Expand Down
Loading