Skip to content

Commit aebb32a

Browse files
committed
remove slot dependency from pallet-block-production-log
1 parent 4fb701c commit aebb32a

File tree

19 files changed

+213
-205
lines changed

19 files changed

+213
-205
lines changed

Cargo.lock

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

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Pallet Session new parameters should be: `type KeyDeposit = ();` and `type Curre
1212
* Updated partner-chains-smart-contracts (raw-scripts) dependency to v8.2.0. Not breaking.
1313
* `SessionManager` and `ShouldEndSession` implementations of `pallet-session-validator-management` rotate one additional
1414
session in order to make `pallet_session` use authorities with less delay.
15+
* `pallet-block-production-log` no longer uses slots and is instead parametrized by a `Moment` type.
16+
To match this change, `BlockProductionLogApi::get_author` now accepts a `Moment` value and `BlockAuthorInherentProvider`
17+
also takes `Moment` as type and constructor parameter.
1518

1619
## Removed
1720

demo/node/src/inherent_data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ where
6060
AuthoritySelectionInputs,
6161
ScEpochNumber,
6262
>,
63-
T::Api: BlockProductionLogApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>>,
63+
T::Api: BlockProductionLogApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>, Slot>,
6464
T::Api: BlockParticipationApi<Block, BlockAuthor>,
6565
T::Api: GovernedMapIDPApi<Block>,
6666
T::Api: TokenBridgeIDPRuntimeApi<Block>,
@@ -70,7 +70,7 @@ where
7070
TimestampIDP,
7171
McHashIDP,
7272
AriadneIDP,
73-
BlockAuthorInherentProvider<BlockAuthor>,
73+
BlockAuthorInherentProvider<Slot, BlockAuthor>,
7474
BlockParticipationInherentDataProvider<BlockAuthor, DelegatorKey>,
7575
GovernedMapInherentDataProvider,
7676
TokenBridgeInherentDataProvider<AccountId>,
@@ -183,15 +183,15 @@ where
183183
AuthoritySelectionInputs,
184184
ScEpochNumber,
185185
>,
186-
T::Api: BlockProductionLogApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>>,
186+
T::Api: BlockProductionLogApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>, Slot>,
187187
T::Api: BlockParticipationApi<Block, BlockAuthor>,
188188
T::Api: GovernedMapIDPApi<Block>,
189189
T::Api: TokenBridgeIDPRuntimeApi<Block>,
190190
{
191191
type InherentDataProviders = (
192192
TimestampIDP,
193193
AriadneIDP,
194-
BlockAuthorInherentProvider<BlockAuthor>,
194+
BlockAuthorInherentProvider<Slot, BlockAuthor>,
195195
BlockParticipationInherentDataProvider<BlockAuthor, DelegatorKey>,
196196
GovernedMapInherentDataProvider,
197197
TokenBridgeInherentDataProvider<AccountId>,

demo/node/src/tests/inherent_data_tests.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use sidechain_domain::{
1515
};
1616
use sidechain_mc_hash::mock::MockMcHashDataSource;
1717
use sp_block_participation::BlockProductionData;
18+
use sp_block_production_log::BlockProductionInherentDataV1;
1819
use sp_consensus_aura::Slot;
1920
use sp_core::ecdsa;
2021
use sp_inherents::CreateInherentDataProviders;
@@ -87,14 +88,19 @@ async fn block_proposal_cidp_should_be_created_correctly() {
8788
);
8889
assert_eq!(
8990
inherent_data
90-
.get_data::<BlockAuthor>(&sp_block_production_log::INHERENT_IDENTIFIER)
91+
.get_data::<BlockProductionInherentDataV1<u64, BlockAuthor>>(
92+
&sp_block_production_log::INHERENT_IDENTIFIER
93+
)
9194
.unwrap(),
92-
Some(BlockAuthor::ProBono(
93-
ecdsa::Public::from_raw(hex!(
94-
"000000000000000000000000000000000000000000000000000000000000000001"
95-
))
96-
.into()
97-
))
95+
Some(BlockProductionInherentDataV1 {
96+
moment: 30,
97+
block_producer_id: BlockAuthor::ProBono(
98+
ecdsa::Public::from_raw(hex!(
99+
"000000000000000000000000000000000000000000000000000000000000000001"
100+
))
101+
.into()
102+
)
103+
})
98104
);
99105
assert_eq!(
100106
inherent_data
@@ -163,14 +169,19 @@ async fn block_verification_cidp_should_be_created_correctly() {
163169
);
164170
assert_eq!(
165171
inherent_data
166-
.get_data::<BlockAuthor>(&sp_block_production_log::INHERENT_IDENTIFIER)
172+
.get_data::<BlockProductionInherentDataV1<u64, BlockAuthor>>(
173+
&sp_block_production_log::INHERENT_IDENTIFIER
174+
)
167175
.unwrap(),
168-
Some(BlockAuthor::ProBono(
169-
ecdsa::Public::from_raw(hex!(
170-
"000000000000000000000000000000000000000000000000000000000000000001"
171-
))
172-
.into()
173-
))
176+
Some(BlockProductionInherentDataV1 {
177+
moment: 30,
178+
block_producer_id: BlockAuthor::ProBono(
179+
ecdsa::Public::from_raw(hex!(
180+
"000000000000000000000000000000000000000000000000000000000000000001"
181+
))
182+
.into()
183+
)
184+
})
174185
);
175186
assert_eq!(
176187
inherent_data

demo/node/src/tests/runtime_api_mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ sp_api::mock_impl_runtime_apis! {
9797
}
9898
}
9999

100-
impl sp_block_production_log::BlockProductionLogApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>> for TestApi {
101-
fn get_author(_slot: Slot) -> Option<CommitteeMember<CrossChainPublic, SessionKeys>> {
100+
impl sp_block_production_log::BlockProductionLogApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>, Slot> for TestApi {
101+
fn get_author(_slot: &Slot) -> Option<CommitteeMember<CrossChainPublic, SessionKeys>> {
102102
Some(CommitteeMember::permissioned(
103103
ecdsa::Public::from_raw(hex!("000000000000000000000000000000000000000000000000000000000000000001")).into(),
104104
SessionKeys {

demo/runtime/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,7 @@ impl pallet_block_production_log::Config for Runtime {
514514
type BlockProducerId = BlockAuthor;
515515
type WeightInfo = pallet_block_production_log::weights::SubstrateWeight<Runtime>;
516516

517-
fn current_slot() -> sp_consensus_slots::Slot {
518-
let slot: u64 = pallet_aura::CurrentSlot::<Runtime>::get().into();
519-
sp_consensus_slots::Slot::from(slot)
520-
}
517+
type Moment = Slot;
521518

522519
#[cfg(feature = "runtime-benchmarks")]
523520
type BenchmarkHelper = PalletBlockProductionLogBenchmarkHelper;
@@ -1135,9 +1132,9 @@ impl_runtime_apis! {
11351132
}
11361133
}
11371134

1138-
impl sp_block_production_log::BlockProductionLogApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>> for Runtime {
1139-
fn get_author(slot: Slot) -> Option<CommitteeMember<CrossChainPublic, SessionKeys>> {
1140-
SessionCommitteeManagement::get_current_authority_round_robin(*slot as usize)
1135+
impl sp_block_production_log::BlockProductionLogApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>, Slot> for Runtime {
1136+
fn get_author(slot: &Slot) -> Option<CommitteeMember<CrossChainPublic, SessionKeys>> {
1137+
SessionCommitteeManagement::get_current_authority_round_robin(u64::from(*slot) as usize)
11411138
}
11421139
}
11431140

e2e-tests/src/substrate_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,12 @@ def get_validator_set(self, block):
597597
result.append(memberParams)
598598
return result
599599

600+
def get_block_slot(self, block):
601+
return self.substrate.query("Aura", "CurrentSlot", block_hash=block["header"]["hash"]).value
602+
603+
def get_block_timestamp(self, block):
604+
return self.substrate.query("Timestamp", "Now", block_hash=block["header"]["hash"]).value
605+
600606
def get_block_author_and_slot(self, block, validator_set):
601607
"""Custom implementation of substrate.get_block(include_author=True) to get block author, and block slot.
602608
py-substrate-interface does not work because it calls "Validators" function from "Session" pallet,

e2e-tests/tests/delegator_rewards/test_block_production_log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def test_block_production_log_pallet(api: BlockchainApi, config: ApiConfig):
1717
block_production_log.reverse()
1818
for slot, block_producer_id in block_production_log:
1919
committee = api.get_validator_set(block)
20+
2021
author_aura_key = committee[slot % len(committee)]["keys"]["aura"]
2122
expected_node = next(x for x in config.nodes_config.nodes.values() if x.aura_public_key == author_aura_key)
2223

toolkit/block-production-log/pallet/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pallet-block-production-log"
33
version.workspace = true
4-
description = "Keeps log of slot to block producer id"
4+
description = "Keeps log of timestamp to block producer id"
55
license = "Apache-2.0"
66
readme = "README.md"
77
authors.workspace = true
@@ -21,7 +21,6 @@ parity-scale-codec = { workspace = true }
2121
scale-info = { workspace = true }
2222
sidechain-domain = { workspace = true }
2323
sp-block-production-log = { workspace = true }
24-
sp-consensus-slots = { workspace = true, features = ["serde"] }
2524
sp-runtime = { workspace = true }
2625
sp-std = { workspace = true }
2726

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Block Production Log pallet
22

3-
This pallet keeps a sorted log of Slot to BlockProducerId.
3+
This pallet keeps a sorted log of timestamp to BlockProducerId.
44
It is a user decision what is the concrete type of BlockProducerId.
55
Inherent data provider that provides BlockProducerId should be wired into the node to make this pallet useful.
66
User should periodically call `take_prefix` to shrink used storage and consume the log according to their needs.
7-
Pallet supports handling many blocks per slot.

0 commit comments

Comments
 (0)