Skip to content

Commit 2c4a5b9

Browse files
authored
remove: ETCM-12417 sidechain-slots crate and its usages (#1121)
1 parent 47de356 commit 2c4a5b9

File tree

20 files changed

+72
-329
lines changed

20 files changed

+72
-329
lines changed

Cargo.lock

Lines changed: 0 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ members = [
3131
"toolkit/sidechain/sidechain-mc-hash",
3232
"toolkit/sidechain/pallet",
3333
"toolkit/sidechain/rpc",
34-
"toolkit/sidechain/sidechain-slots",
3534
"toolkit/sidechain/primitives",
3635
"toolkit/committee-selection/primitives",
3736
"toolkit/committee-selection/query",
@@ -286,7 +285,6 @@ pallet-address-associations = { path = "toolkit/address-associations/pallet", de
286285

287286
# sidechain core
288287
sidechain-domain = { path = "toolkit/sidechain/domain", default-features = false }
289-
sidechain-slots = { path = "toolkit/sidechain/sidechain-slots", default-features = false }
290288
sidechain-mc-hash = { path = "toolkit/sidechain/sidechain-mc-hash", default-features = false }
291289
sp-sidechain = { path = "toolkit/sidechain/primitives", default-features = false }
292290
pallet-sidechain = { path = "toolkit/sidechain/pallet", default-features = false }

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Existing chains must add the `LegacyToV1Migration` migration to their runtime be
6262
* `sidechain-block-search` crate has been removed. All logic used by `sp-session-validator-management-query` has been
6363
moved to that crate directly.
6464
* `ScSlotNumber` type has been removed from `sidechain_domain` crate as its been obsolete after other changes
65+
* `sidechain-slots` crate bas been removed after all other components have been decoupled from the notion of slots.
66+
Legacy chains whose nodes used the `SlotApi` runtime API and the `sidechain_slots::runtime_api_client::slot_config`
67+
function to read slot duration from the runtime should instead use their respective consensus algorithm's runtime API
68+
(eg. `AuraApi` and `BabeApi`) or local environment.
6569

6670
## Fixed
6771

demo/node/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ authority-selection-inherents = { workspace = true }
5353
frame-system = { workspace = true }
5454
pallet-transaction-payment = { workspace = true }
5555
sidechain-domain = { workspace = true }
56-
sidechain-slots = { workspace = true, features = ["std", "serde"] }
5756
sp-sidechain = { workspace = true }
5857
pallet-sidechain-rpc = { workspace = true, features = ["legacy-slotapi-compat"] }
5958
pallet-session-validator-management = { workspace = true }

demo/node/src/chain_spec.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use partner_chains_demo_runtime::{
55
};
66
use sc_service::ChainType;
77
use sidechain_domain::ScEpochDuration;
8-
use sidechain_slots::SlotsPerEpoch;
98
use sp_core::{Pair, Public};
109
use sp_runtime::traits::{IdentifyAccount, Verify};
1110

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

39+
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 60;
40+
4041
/// Creates chain-spec according to the config obtained by wizards.
4142
/// [serde_json::Value] is returned instead of [sc_service::GenericChainSpec] in order to avoid
4243
/// GPL code in the toolkit.
@@ -63,7 +64,7 @@ pub fn pc_create_chain_spec(config: &CreateChainSpecConfig<SessionKeys>) -> serd
6364
non_authority_keys: vec![],
6465
},
6566
sidechain: config.pallet_sidechain_config(ScEpochDuration::from_millis(
66-
SLOT_DURATION * u64::from(SlotsPerEpoch::default().0),
67+
SLOT_DURATION * DEFAULT_SLOTS_PER_EPOCH,
6768
)),
6869
session_committee_management: config.pallet_session_validator_management_config(),
6970
governed_map: config.governed_map_config(),
@@ -86,3 +87,10 @@ pub fn pc_create_chain_spec(config: &CreateChainSpecConfig<SessionKeys>) -> serd
8687
let chain_spec_str = chain_spec.as_json(raw).expect("Chain spec serialization can not fail");
8788
serde_json::from_str(&chain_spec_str).unwrap()
8889
}
90+
91+
pub(crate) fn read_slots_per_epoch_from_env() -> u64 {
92+
std::env::var("SLOTS_PER_EPOCH")
93+
.ok()
94+
.and_then(|s| s.parse().ok())
95+
.unwrap_or(DEFAULT_SLOTS_PER_EPOCH)
96+
}

demo/node/src/inherent_data.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use sidechain_domain::{
1313
DelegatorKey, McBlockHash, ScEpochNumber, mainchain_epoch::MainchainEpochConfig,
1414
};
1515
use sidechain_mc_hash::{McHashDataSource, McHashInherentDataProvider as McHashIDP};
16-
use sidechain_slots::ScSlotConfig;
1716
use sp_api::ProvideRuntimeApi;
1817
use sp_block_participation::{
1918
BlockParticipationApi,
@@ -81,16 +80,14 @@ where
8180
governed_map_data_source,
8281
bridge_data_source,
8382
} = self;
84-
let CreateInherentDataConfig { mc_epoch_config, sc_slot_config, time_source } = config;
83+
let CreateInherentDataConfig { mc_epoch_config, slot_duration, time_source, .. } = config;
8584

86-
let (slot, timestamp) =
87-
timestamp_and_slot_cidp(sc_slot_config.slot_duration, time_source.clone());
85+
let (slot, timestamp) = timestamp_and_slot_cidp(*slot_duration, time_source.clone());
8886
let parent_header = client.expect_header(parent_hash)?;
8987

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

10198
let ariadne_data_provider = AriadneIDP::new(
10299
client.as_ref(),
103-
sc_slot_config.epoch_duration().as_millis() as u64,
100+
config.sc_epoch_duration_millis,
104101
mc_epoch_config,
105102
parent_hash,
106103
(*timestamp).as_millis(),
@@ -152,7 +149,7 @@ pub struct VerifierCIDP<T> {
152149

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

@@ -187,19 +184,16 @@ where
187184
governed_map_data_source,
188185
bridge_data_source,
189186
} = self;
190-
let CreateInherentDataConfig { mc_epoch_config, sc_slot_config, .. } = config;
187+
let CreateInherentDataConfig { mc_epoch_config, .. } = config;
191188

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

199194
let parent_header = client.expect_header(parent_hash)?;
200195
let parent_slot = slot_from_predigest(&parent_header)?;
201-
let parent_slot_timestamp = parent_slot
202-
.map(|slot| Timestamp::new(sc_slot_config.slot_start_time(slot).unix_millis()));
196+
let parent_slot_timestamp = parent_slot.map(|slot| config.slot_start_time(slot));
203197

204198
let mc_state_reference = McHashIDP::new_verification(
205199
parent_header,
@@ -212,7 +206,7 @@ where
212206

213207
let ariadne_data_provider = AriadneIDP::new(
214208
client.as_ref(),
215-
sc_slot_config.epoch_duration().as_millis() as u64,
209+
config.sc_epoch_duration_millis,
216210
mc_epoch_config,
217211
parent_hash,
218212
(*timestamp).as_millis(),
@@ -263,16 +257,16 @@ pub fn slot_from_predigest(
263257
}
264258

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

273267
impl CreateInherentDataConfig {
274-
pub fn slot_duration(&self) -> SlotDuration {
275-
self.sc_slot_config.slot_duration
268+
pub fn slot_start_time(&self, slot: Slot) -> Timestamp {
269+
Timestamp::new(self.slot_duration.as_millis() * u64::from(slot))
276270
}
277271
}
278272

demo/node/src/rpc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ where
7474
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
7575
C::Api: BlockBuilder<Block>,
7676
C::Api: sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId>,
77-
C::Api: sidechain_slots::SlotApi<Block>,
7877
C::Api: sp_sidechain::GetGenesisUtxo<Block>,
7978
C::Api: sp_sidechain::GetSidechainStatus<Block>,
8079
C::Api: sp_block_producer_fees::BlockProducerFeesApi<Block, AccountId>,

demo/node/src/service.rs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ use sc_telemetry::{Telemetry, TelemetryWorker};
1616
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
1717
use sidechain_domain::mainchain_epoch::MainchainEpochConfig;
1818
use sidechain_mc_hash::McHashInherentDigest;
19+
use sp_api::ProvideRuntimeApi;
20+
use sp_blockchain::HeaderBackend;
21+
use sp_consensus_aura::AuraApi;
1922
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
2023
use sp_partner_chains_consensus_aura::block_proposal::PartnerChainsProposerFactory;
2124
use sp_runtime::traits::Block as BlockT;
25+
use sp_sidechain::GetEpochDurationApi;
2226
use std::{sync::Arc, time::Duration};
2327
use time_source::SystemTimeSource;
2428
use tokio::task;
@@ -76,6 +80,7 @@ pub fn new_partial(
7680
Option<Telemetry>,
7781
DataSources,
7882
Option<McFollowerMetrics>,
83+
CreateInherentDataConfig,
7984
),
8085
>,
8186
ServiceError,
@@ -134,13 +139,24 @@ pub fn new_partial(
134139
telemetry.as_ref().map(|x| x.handle()),
135140
)?;
136141

137-
let sc_slot_config = sidechain_slots::runtime_api_client::slot_config(&*client)
138-
.map_err(sp_blockchain::Error::from)?;
142+
let slot_duration = client
143+
.runtime_api()
144+
.slot_duration(client.info().best_hash)
145+
.expect("Aura slot duration must be configured in the runtime");
146+
let sc_epoch_duration_millis = client
147+
.runtime_api()
148+
.get_epoch_duration_millis(client.info().best_hash)
149+
.expect("Epoch duration must be configured in the runtime");
139150

140151
let time_source = Arc::new(SystemTimeSource);
141152
let epoch_config = MainchainEpochConfig::read_from_env()
142153
.map_err(|err| ServiceError::Application(err.into()))?;
143-
let inherent_config = CreateInherentDataConfig::new(epoch_config, sc_slot_config, time_source);
154+
let inherent_config = CreateInherentDataConfig::new(
155+
epoch_config,
156+
slot_duration,
157+
sc_epoch_duration_millis,
158+
time_source,
159+
);
144160

145161
let import_queue = partner_chains_aura_import_queue::import_queue::<
146162
AuraPair,
@@ -155,7 +171,7 @@ pub fn new_partial(
155171
justification_import: Some(Box::new(grandpa_block_import.clone())),
156172
client: client.clone(),
157173
create_inherent_data_providers: VerifierCIDP::new(
158-
inherent_config,
174+
inherent_config.clone(),
159175
client.clone(),
160176
data_sources.mc_hash.clone(),
161177
data_sources.authority_selection.clone(),
@@ -178,7 +194,14 @@ pub fn new_partial(
178194
keystore_container,
179195
select_chain,
180196
transaction_pool,
181-
other: (grandpa_block_import, grandpa_link, telemetry, data_sources, mc_follower_metrics),
197+
other: (
198+
grandpa_block_import,
199+
grandpa_link,
200+
telemetry,
201+
data_sources,
202+
mc_follower_metrics,
203+
inherent_config,
204+
),
182205
})
183206
}
184207

@@ -210,7 +233,7 @@ pub async fn new_full_base<Network: sc_network::NetworkBackend<Block, <Block as
210233
keystore_container,
211234
select_chain,
212235
transaction_pool,
213-
other: (block_import, grandpa_link, mut telemetry, data_sources, _),
236+
other: (block_import, grandpa_link, mut telemetry, data_sources, _, inherent_config),
214237
} = new_partial(&config)?;
215238

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

320-
let sc_slot_config = sidechain_slots::runtime_api_client::slot_config(&*client)
321-
.map_err(sp_blockchain::Error::from)?;
322-
let time_source = Arc::new(SystemTimeSource);
323-
let mc_epoch_config = MainchainEpochConfig::read_from_env()
324-
.map_err(|err| ServiceError::Application(err.into()))?;
325-
let inherent_config =
326-
CreateInherentDataConfig::new(mc_epoch_config, sc_slot_config.clone(), time_source);
327343
let aura = sc_partner_chains_consensus_aura::start_aura::<
328344
AuraPair,
329345
_,
@@ -338,7 +354,7 @@ pub async fn new_full_base<Network: sc_network::NetworkBackend<Block, <Block as
338354
_,
339355
McHashInherentDigest,
340356
>(StartAuraParams {
341-
slot_duration: sc_slot_config.slot_duration,
357+
slot_duration: inherent_config.slot_duration,
342358
client: client.clone(),
343359
select_chain,
344360
block_import,

demo/node/src/staging.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ pub fn staging_genesis(
153153
sidechain: SidechainConfig {
154154
genesis_utxo,
155155
epoch_duration: ScEpochDuration::from_millis(
156-
SLOT_DURATION
157-
* u64::from(sidechain_slots::SlotsPerEpoch::read_from_env().unwrap().0),
156+
SLOT_DURATION * read_slots_per_epoch_from_env(),
158157
),
159158
..Default::default()
160159
},

demo/node/src/template_chain_spec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ pub fn chain_spec() -> Result<ChainSpec, envy::Error> {
3535
sidechain: SidechainConfig {
3636
genesis_utxo,
3737
epoch_duration: ScEpochDuration::from_millis(
38-
SLOT_DURATION
39-
* u64::from(sidechain_slots::SlotsPerEpoch::read_from_env().unwrap().0),
38+
SLOT_DURATION * read_slots_per_epoch_from_env(),
4039
),
4140
..Default::default()
4241
},

0 commit comments

Comments
 (0)