Skip to content

Commit

Permalink
Merge pull request #2319 from subspace/3g-cleanups
Browse files Browse the repository at this point in the history
Gemini 3g cleanups
  • Loading branch information
nazar-pc authored Dec 13, 2023
2 parents 104c250 + e3c98d0 commit 5ad43be
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 301 deletions.
179 changes: 0 additions & 179 deletions crates/sc-subspace-chain-specs/res/chain-spec-raw-gemini-3g.json

This file was deleted.

2 changes: 0 additions & 2 deletions crates/sc-subspace-chain-specs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use sc_chain_spec::NoExtension;

/// Devnet chain spec
pub const DEVNET_CHAIN_SPEC: &str = include_str!("../res/chain-spec-raw-devnet.json");
/// Gemini 3g chain spec
pub const GEMINI_3G_CHAIN_SPEC: &str = include_str!("../res/chain-spec-raw-gemini-3g.json");

/// Specialized `ChainSpec` for the consensus runtime.
pub type ConsensusChainSpec<GenesisConfig> = SerializableChainSpec<GenesisConfig>;
Expand Down
121 changes: 32 additions & 89 deletions crates/sp-consensus-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,31 +403,12 @@ impl Default for SolutionRanges {
}
}

// TODO: Remove V0 when we break the protocol
/// Subspace blockchain constants.
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, Copy, TypeInfo)]
pub enum ChainConstants {
/// V0 of the chain constants.
#[codec(index = 0)]
V0 {
/// Depth `K` after which a block enters the recorded history.
confirmation_depth_k: BlockNumber,
/// Number of slots between slot arrival and when corresponding block can be produced.
block_authoring_delay: Slot,
/// Era duration in blocks.
era_duration: BlockNumber,
/// Slot probability.
slot_probability: (u64, u64),
/// Number of latest archived segments that are considered "recent history".
recent_segments: HistorySize,
/// Fraction of pieces from the "recent history" (`recent_segments`) in each sector.
recent_history_fraction: (HistorySize, HistorySize),
/// Minimum lifetime of a plotted sector, measured in archived segment.
min_sector_lifetime: HistorySize,
},
/// V0 of the chain constants.
#[codec(index = 1)]
V1 {
/// Depth `K` after which a block enters the recorded history.
confirmation_depth_k: BlockNumber,
/// Number of slots between slot arrival and when corresponding block can be produced.
Expand All @@ -450,100 +431,66 @@ pub enum ChainConstants {
impl ChainConstants {
/// Depth `K` after which a block enters the recorded history.
pub fn confirmation_depth_k(&self) -> BlockNumber {
match self {
Self::V0 {
confirmation_depth_k,
..
}
| Self::V1 {
confirmation_depth_k,
..
} => *confirmation_depth_k,
}
let Self::V0 {
confirmation_depth_k,
..
} = self;
*confirmation_depth_k
}

/// Era duration in blocks.
pub fn era_duration(&self) -> BlockNumber {
match self {
Self::V0 { era_duration, .. } | Self::V1 { era_duration, .. } => *era_duration,
}
let Self::V0 { era_duration, .. } = self;
*era_duration
}

/// Number of slots between slot arrival and when corresponding block can be produced.
pub fn block_authoring_delay(&self) -> Slot {
match self {
Self::V0 {
block_authoring_delay,
..
}
| Self::V1 {
block_authoring_delay,
..
} => *block_authoring_delay,
}
let Self::V0 {
block_authoring_delay,
..
} = self;
*block_authoring_delay
}

/// Slot probability.
pub fn slot_probability(&self) -> (u64, u64) {
match self {
Self::V0 {
slot_probability, ..
}
| Self::V1 {
slot_probability, ..
} => *slot_probability,
}
let Self::V0 {
slot_probability, ..
} = self;
*slot_probability
}

/// The slot duration in milliseconds.
pub fn slot_duration(&self) -> SlotDuration {
match self {
Self::V0 { .. } => {
// 1000ms is used on most networks, so it is a safe default
SlotDuration::from_millis(1000)
}
Self::V1 { slot_duration, .. } => *slot_duration,
}
let Self::V0 { slot_duration, .. } = self;
*slot_duration
}

/// Number of latest archived segments that are considered "recent history".
pub fn recent_segments(&self) -> HistorySize {
match self {
Self::V0 {
recent_segments, ..
}
| Self::V1 {
recent_segments, ..
} => *recent_segments,
}
let Self::V0 {
recent_segments, ..
} = self;
*recent_segments
}

/// Fraction of pieces from the "recent history" (`recent_segments`) in each sector.
pub fn recent_history_fraction(&self) -> (HistorySize, HistorySize) {
match self {
Self::V0 {
recent_history_fraction,
..
}
| Self::V1 {
recent_history_fraction,
..
} => *recent_history_fraction,
}
let Self::V0 {
recent_history_fraction,
..
} = self;
*recent_history_fraction
}

/// Minimum lifetime of a plotted sector, measured in archived segment.
pub fn min_sector_lifetime(&self) -> HistorySize {
match self {
Self::V0 {
min_sector_lifetime,
..
}
| Self::V1 {
min_sector_lifetime,
..
} => *min_sector_lifetime,
}
let Self::V0 {
min_sector_lifetime,
..
} = self;
*min_sector_lifetime
}
}

Expand Down Expand Up @@ -747,10 +694,6 @@ impl PotParameters {
sp_api::decl_runtime_apis! {
/// API necessary for block authorship with Subspace.
pub trait SubspaceApi<RewardAddress: Encode + Decode> {
/// The slot duration in milliseconds for Subspace.
#[deprecated(note = "Use chain constants instead")]
fn slot_duration() -> SlotDuration;

/// Proof of time parameters
fn pot_parameters() -> PotParameters;

Expand Down
21 changes: 2 additions & 19 deletions crates/subspace-networking/src/protocols/peer_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,11 @@ pub struct Notification;
/// Defines a subscription to a peer-info notification.
pub type NotificationHandler = Arc<dyn Fn(&Notification) + Send + Sync + 'static>;

//TODO: remove on the next networking breaking change
/// Backward compatibility placeholder for the obsolete CuckooFilterDTO -
/// "Cuckoo filter data transfer object".
#[derive(Clone, Encode, Decode, Default, Debug)]
pub struct PlaceHolder {
/// A placeholder for: "Exported cuckoo filter values" field of the CuckooFilterDTO.
pub field1: Vec<u8>,
/// Cuckoo filter items.
/// A placeholder for: "Cuckoo filter items." field of the CuckooFilterDTO.
pub field2: u64,
}

#[derive(Clone, Encode, Decode, Default, Debug)]
/// Peer info data
pub enum PeerInfo {
/// DSN farmer.
Farmer {
/// Backward compatibility placeholder.
placeholder: PlaceHolder,
},
Farmer,
/// DSN node.
Node,
/// DSN bootstrap node.
Expand Down Expand Up @@ -125,9 +110,7 @@ impl PeerInfoProvider {
PeerInfoProvider::Node => PeerInfo::Node,
PeerInfoProvider::BootstrapNode => PeerInfo::BootstrapNode,
PeerInfoProvider::Client => PeerInfo::Client,
PeerInfoProvider::Farmer => PeerInfo::Farmer {
placeholder: Default::default(),
},
PeerInfoProvider::Farmer => PeerInfo::Farmer,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ fn main() -> Result<(), Error> {
"subspace_gemini_3d",
"subspace_gemini_3e",
"subspace_gemini_3f",
"subspace_gemini_3g",
] {
let _ = std::fs::remove_dir_all(
base_dir.join("subspace-node").join("chains").join(chain),
Expand Down
4 changes: 2 additions & 2 deletions crates/subspace-node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::domain::evm_chain_spec::{self, SpecId};
use hex_literal::hex;
use parity_scale_codec::Encode;
use sc_service::{ChainType, NoExtension};
use sc_subspace_chain_specs::{ConsensusChainSpec, DEVNET_CHAIN_SPEC, GEMINI_3G_CHAIN_SPEC};
use sc_subspace_chain_specs::{ConsensusChainSpec, DEVNET_CHAIN_SPEC};
use sc_telemetry::TelemetryEndpoints;
use sp_consensus_subspace::FarmerPublicKey;
use sp_core::crypto::{Ss58Codec, UncheckedFrom};
Expand Down Expand Up @@ -206,7 +206,7 @@ pub fn gemini_3g_compiled() -> Result<ConsensusChainSpec<RuntimeGenesisConfig>,
}

pub fn gemini_3g_config() -> Result<ConsensusChainSpec<RuntimeGenesisConfig>, String> {
ConsensusChainSpec::from_json_bytes(GEMINI_3G_CHAIN_SPEC.as_bytes())
unimplemented!("Please use release prefixed with gemini-3g")
}

pub fn devnet_config() -> Result<ConsensusChainSpec<RuntimeGenesisConfig>, String> {
Expand Down
6 changes: 1 addition & 5 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,6 @@ impl_runtime_apis! {
}

impl sp_consensus_subspace::SubspaceApi<Block, FarmerPublicKey> for Runtime {
fn slot_duration() -> SlotDuration {
SlotDuration::from_millis(SLOT_DURATION)
}

fn pot_parameters() -> PotParameters {
Subspace::pot_parameters()
}
Expand Down Expand Up @@ -959,7 +955,7 @@ impl_runtime_apis! {
}

fn chain_constants() -> ChainConstants {
ChainConstants::V1 {
ChainConstants::V0 {
confirmation_depth_k: ConfirmationDepthK::get(),
block_authoring_delay: Slot::from(BlockAuthoringDelay::get()),
era_duration: EraDuration::get(),
Expand Down
6 changes: 1 addition & 5 deletions test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,10 +1068,6 @@ impl_runtime_apis! {
}

impl sp_consensus_subspace::SubspaceApi<Block, FarmerPublicKey> for Runtime {
fn slot_duration() -> SlotDuration {
SlotDuration::from_millis(SLOT_DURATION)
}

fn pot_parameters() -> PotParameters {
Subspace::pot_parameters()
}
Expand Down Expand Up @@ -1151,7 +1147,7 @@ impl_runtime_apis! {
}

fn chain_constants() -> ChainConstants {
ChainConstants::V1 {
ChainConstants::V0 {
confirmation_depth_k: ConfirmationDepthK::get(),
block_authoring_delay: Slot::from(BlockAuthoringDelay::get()),
era_duration: EraDuration::get(),
Expand Down

0 comments on commit 5ad43be

Please sign in to comment.