Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 0 additions & 19 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ members = [
"toolkit/sidechain/sidechain-mc-hash",
"toolkit/sidechain/pallet",
"toolkit/sidechain/rpc",
"toolkit/sidechain/sidechain-slots",
"toolkit/sidechain/primitives",
"toolkit/committee-selection/primitives",
"toolkit/committee-selection/query",
Expand Down Expand Up @@ -286,7 +285,6 @@ pallet-address-associations = { path = "toolkit/address-associations/pallet", de

# sidechain core
sidechain-domain = { path = "toolkit/sidechain/domain", default-features = false }
sidechain-slots = { path = "toolkit/sidechain/sidechain-slots", default-features = false }
sidechain-mc-hash = { path = "toolkit/sidechain/sidechain-mc-hash", default-features = false }
sp-sidechain = { path = "toolkit/sidechain/primitives", default-features = false }
pallet-sidechain = { path = "toolkit/sidechain/pallet", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Existing chains must add the `LegacyToV1Migration` migration to their runtime be
* `sidechain-block-search` crate has been removed. All logic used by `sp-session-validator-management-query` has been
moved to that crate directly.
* `ScSlotNumber` type has been removed from `sidechain_domain` crate as its been obsolete after other changes
* `sidechain-slots` crate bas been removed after all other components have been decoupled from the notion of slots.
Legacy chains whose nodes used the `SlotApi` runtime API and the `sidechain_slots::runtime_api_client::slot_config`
function to read slot duration from the runtime should instead use their respective consensus algorithm's runtime API
(eg. `AuraApi` and `BabeApi`) or local environment.

## Fixed

Expand Down
1 change: 0 additions & 1 deletion demo/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ authority-selection-inherents = { workspace = true }
frame-system = { workspace = true }
pallet-transaction-payment = { workspace = true }
sidechain-domain = { workspace = true }
sidechain-slots = { workspace = true, features = ["std", "serde"] }
sp-sidechain = { workspace = true }
pallet-sidechain-rpc = { workspace = true, features = ["legacy-slotapi-compat"] }
pallet-session-validator-management = { workspace = true }
Expand Down
12 changes: 10 additions & 2 deletions demo/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use partner_chains_demo_runtime::{
};
use sc_service::ChainType;
use sidechain_domain::ScEpochDuration;
use sidechain_slots::SlotsPerEpoch;
use sp_core::{Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

Expand Down Expand Up @@ -37,6 +36,8 @@ pub fn runtime_wasm() -> &'static [u8] {
WASM_BINARY.expect("Runtime wasm not available")
}

pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 60;

/// Creates chain-spec according to the config obtained by wizards.
/// [serde_json::Value] is returned instead of [sc_service::GenericChainSpec] in order to avoid
/// GPL code in the toolkit.
Expand All @@ -63,7 +64,7 @@ pub fn pc_create_chain_spec(config: &CreateChainSpecConfig<SessionKeys>) -> serd
non_authority_keys: vec![],
},
sidechain: config.pallet_sidechain_config(ScEpochDuration::from_millis(
SLOT_DURATION * u64::from(SlotsPerEpoch::default().0),
SLOT_DURATION * DEFAULT_SLOTS_PER_EPOCH,
)),
session_committee_management: config.pallet_session_validator_management_config(),
governed_map: config.governed_map_config(),
Expand All @@ -86,3 +87,10 @@ pub fn pc_create_chain_spec(config: &CreateChainSpecConfig<SessionKeys>) -> serd
let chain_spec_str = chain_spec.as_json(raw).expect("Chain spec serialization can not fail");
serde_json::from_str(&chain_spec_str).unwrap()
}

pub(crate) fn read_slots_per_epoch_from_env() -> u64 {
std::env::var("SLOTS_PER_EPOCH")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(DEFAULT_SLOTS_PER_EPOCH)
}
34 changes: 14 additions & 20 deletions demo/node/src/inherent_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use sidechain_domain::{
DelegatorKey, McBlockHash, ScEpochNumber, mainchain_epoch::MainchainEpochConfig,
};
use sidechain_mc_hash::{McHashDataSource, McHashInherentDataProvider as McHashIDP};
use sidechain_slots::ScSlotConfig;
use sp_api::ProvideRuntimeApi;
use sp_block_participation::{
BlockParticipationApi,
Expand Down Expand Up @@ -81,16 +80,14 @@ where
governed_map_data_source,
bridge_data_source,
} = self;
let CreateInherentDataConfig { mc_epoch_config, sc_slot_config, time_source } = config;
let CreateInherentDataConfig { mc_epoch_config, slot_duration, time_source, .. } = config;

let (slot, timestamp) =
timestamp_and_slot_cidp(sc_slot_config.slot_duration, time_source.clone());
let (slot, timestamp) = timestamp_and_slot_cidp(*slot_duration, time_source.clone());
let parent_header = client.expect_header(parent_hash)?;

// note: We pass slot start time to `McHashIDP` instead of timestamp for backward compatibility
// with the old `McHashIDP` version that was slot-based.
let slot_start_timestamp =
Timestamp::new(sc_slot_config.slot_start_time(*slot).unix_millis());
let slot_start_timestamp = config.slot_start_time(*slot);
let mc_hash = McHashIDP::new_proposal(
parent_header,
mc_hash_data_source.as_ref(),
Expand All @@ -100,7 +97,7 @@ where

let ariadne_data_provider = AriadneIDP::new(
client.as_ref(),
sc_slot_config.epoch_duration().as_millis() as u64,
config.sc_epoch_duration_millis,
mc_epoch_config,
parent_hash,
(*timestamp).as_millis(),
Expand Down Expand Up @@ -152,7 +149,7 @@ pub struct VerifierCIDP<T> {

impl<T: Send + Sync> CurrentSlotProvider for VerifierCIDP<T> {
fn slot(&self) -> Slot {
*timestamp_and_slot_cidp(self.config.slot_duration(), self.config.time_source.clone()).0
*timestamp_and_slot_cidp(self.config.slot_duration, self.config.time_source.clone()).0
}
}

Expand Down Expand Up @@ -187,19 +184,16 @@ where
governed_map_data_source,
bridge_data_source,
} = self;
let CreateInherentDataConfig { mc_epoch_config, sc_slot_config, .. } = config;
let CreateInherentDataConfig { mc_epoch_config, .. } = config;

// note: Because it's not exposed during block verification, we are approximating the block
// timestamp by the starting timestamp of the slots. This is also needed for backward compatibility
// of [McHashIDP] for chains that used the old slot-based version of it.
let timestamp = TimestampIDP::new(Timestamp::new(
sc_slot_config.slot_start_time(verified_block_slot).unix_millis(),
));
let timestamp = TimestampIDP::new(config.slot_start_time(verified_block_slot));

let parent_header = client.expect_header(parent_hash)?;
let parent_slot = slot_from_predigest(&parent_header)?;
let parent_slot_timestamp = parent_slot
.map(|slot| Timestamp::new(sc_slot_config.slot_start_time(slot).unix_millis()));
let parent_slot_timestamp = parent_slot.map(|slot| config.slot_start_time(slot));

let mc_state_reference = McHashIDP::new_verification(
parent_header,
Expand All @@ -212,7 +206,7 @@ where

let ariadne_data_provider = AriadneIDP::new(
client.as_ref(),
sc_slot_config.epoch_duration().as_millis() as u64,
config.sc_epoch_duration_millis,
mc_epoch_config,
parent_hash,
(*timestamp).as_millis(),
Expand Down Expand Up @@ -263,16 +257,16 @@ pub fn slot_from_predigest(
}

#[derive(new, Clone)]
pub(crate) struct CreateInherentDataConfig {
pub struct CreateInherentDataConfig {
pub mc_epoch_config: MainchainEpochConfig,
// TODO ETCM-4079 make sure that this struct can be instantiated only if sidechain epoch duration is divisible by slot_duration
pub sc_slot_config: ScSlotConfig,
pub slot_duration: SlotDuration,
pub sc_epoch_duration_millis: u64,
pub time_source: Arc<dyn TimeSource + Send + Sync>,
}

impl CreateInherentDataConfig {
pub fn slot_duration(&self) -> SlotDuration {
self.sc_slot_config.slot_duration
pub fn slot_start_time(&self, slot: Slot) -> Timestamp {
Timestamp::new(self.slot_duration.as_millis() * u64::from(slot))
}
}

Expand Down
1 change: 0 additions & 1 deletion demo/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ where
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
C::Api: sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>,
C::Api: sidechain_slots::SlotApi<Block>,
C::Api: sp_sidechain::GetGenesisUtxo<Block>,
C::Api: sp_sidechain::GetSidechainStatus<Block>,
C::Api: sp_block_producer_fees::BlockProducerFeesApi<Block, AccountId>,
Expand Down
44 changes: 30 additions & 14 deletions demo/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ use sc_telemetry::{Telemetry, TelemetryWorker};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sidechain_domain::mainchain_epoch::MainchainEpochConfig;
use sidechain_mc_hash::McHashInherentDigest;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_consensus_aura::AuraApi;
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use sp_partner_chains_consensus_aura::block_proposal::PartnerChainsProposerFactory;
use sp_runtime::traits::Block as BlockT;
use sp_sidechain::GetEpochDurationApi;
use std::{sync::Arc, time::Duration};
use time_source::SystemTimeSource;
use tokio::task;
Expand Down Expand Up @@ -76,6 +80,7 @@ pub fn new_partial(
Option<Telemetry>,
DataSources,
Option<McFollowerMetrics>,
CreateInherentDataConfig,
),
>,
ServiceError,
Expand Down Expand Up @@ -134,13 +139,24 @@ pub fn new_partial(
telemetry.as_ref().map(|x| x.handle()),
)?;

let sc_slot_config = sidechain_slots::runtime_api_client::slot_config(&*client)
.map_err(sp_blockchain::Error::from)?;
let slot_duration = client
.runtime_api()
.slot_duration(client.info().best_hash)
.expect("Aura slot duration must be configured in the runtime");
let sc_epoch_duration_millis = client
.runtime_api()
.get_epoch_duration_millis(client.info().best_hash)
.expect("Epoch duration must be configured in the runtime");

let time_source = Arc::new(SystemTimeSource);
let epoch_config = MainchainEpochConfig::read_from_env()
.map_err(|err| ServiceError::Application(err.into()))?;
let inherent_config = CreateInherentDataConfig::new(epoch_config, sc_slot_config, time_source);
let inherent_config = CreateInherentDataConfig::new(
epoch_config,
slot_duration,
sc_epoch_duration_millis,
time_source,
);

let import_queue = partner_chains_aura_import_queue::import_queue::<
AuraPair,
Expand All @@ -155,7 +171,7 @@ pub fn new_partial(
justification_import: Some(Box::new(grandpa_block_import.clone())),
client: client.clone(),
create_inherent_data_providers: VerifierCIDP::new(
inherent_config,
inherent_config.clone(),
client.clone(),
data_sources.mc_hash.clone(),
data_sources.authority_selection.clone(),
Expand All @@ -178,7 +194,14 @@ pub fn new_partial(
keystore_container,
select_chain,
transaction_pool,
other: (grandpa_block_import, grandpa_link, telemetry, data_sources, mc_follower_metrics),
other: (
grandpa_block_import,
grandpa_link,
telemetry,
data_sources,
mc_follower_metrics,
inherent_config,
),
})
}

Expand Down Expand Up @@ -210,7 +233,7 @@ pub async fn new_full_base<Network: sc_network::NetworkBackend<Block, <Block as
keystore_container,
select_chain,
transaction_pool,
other: (block_import, grandpa_link, mut telemetry, data_sources, _),
other: (block_import, grandpa_link, mut telemetry, data_sources, _, inherent_config),
} = new_partial(&config)?;

let metrics = Network::register_notification_metrics(config.prometheus_registry());
Expand Down Expand Up @@ -317,13 +340,6 @@ pub async fn new_full_base<Network: sc_network::NetworkBackend<Block, <Block as
let proposer_factory: PartnerChainsProposerFactory<_, _, McHashInherentDigest> =
PartnerChainsProposerFactory::new(basic_authorship_proposer_factory);

let sc_slot_config = sidechain_slots::runtime_api_client::slot_config(&*client)
.map_err(sp_blockchain::Error::from)?;
let time_source = Arc::new(SystemTimeSource);
let mc_epoch_config = MainchainEpochConfig::read_from_env()
.map_err(|err| ServiceError::Application(err.into()))?;
let inherent_config =
CreateInherentDataConfig::new(mc_epoch_config, sc_slot_config.clone(), time_source);
let aura = sc_partner_chains_consensus_aura::start_aura::<
AuraPair,
_,
Expand All @@ -338,7 +354,7 @@ pub async fn new_full_base<Network: sc_network::NetworkBackend<Block, <Block as
_,
McHashInherentDigest,
>(StartAuraParams {
slot_duration: sc_slot_config.slot_duration,
slot_duration: inherent_config.slot_duration,
client: client.clone(),
select_chain,
block_import,
Expand Down
3 changes: 1 addition & 2 deletions demo/node/src/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ pub fn staging_genesis(
sidechain: SidechainConfig {
genesis_utxo,
epoch_duration: ScEpochDuration::from_millis(
SLOT_DURATION
* u64::from(sidechain_slots::SlotsPerEpoch::read_from_env().unwrap().0),
SLOT_DURATION * read_slots_per_epoch_from_env(),
),
..Default::default()
},
Expand Down
3 changes: 1 addition & 2 deletions demo/node/src/template_chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ pub fn chain_spec() -> Result<ChainSpec, envy::Error> {
sidechain: SidechainConfig {
genesis_utxo,
epoch_duration: ScEpochDuration::from_millis(
SLOT_DURATION
* u64::from(sidechain_slots::SlotsPerEpoch::read_from_env().unwrap().0),
SLOT_DURATION * read_slots_per_epoch_from_env(),
),
..Default::default()
},
Expand Down
3 changes: 1 addition & 2 deletions demo/node/src/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ pub fn testnet_genesis(
sidechain: SidechainConfig {
genesis_utxo,
epoch_duration: ScEpochDuration::from_millis(
SLOT_DURATION
* u64::from(sidechain_slots::SlotsPerEpoch::read_from_env().unwrap().0),
SLOT_DURATION * read_slots_per_epoch_from_env(),
),
..Default::default()
},
Expand Down
Loading
Loading