Skip to content

Commit 6dce68f

Browse files
committed
rework production log
1 parent 488b430 commit 6dce68f

File tree

17 files changed

+150
-719
lines changed

17 files changed

+150
-719
lines changed

Cargo.lock

Lines changed: 3 additions & 17 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
@@ -17,7 +17,6 @@ members = [
1717
"toolkit/committee-selection/pallet",
1818
"toolkit/committee-selection/rpc",
1919
"substrate-extensions/aura/primitives",
20-
"toolkit/block-production-log/primitives",
2120
"toolkit/sidechain/domain",
2221
"toolkit/committee-selection/selection",
2322
"toolkit/committee-selection/authority-selection-inherents",
@@ -308,7 +307,6 @@ sp-partner-chains-consensus-aura = { path = "substrate-extensions/aura/primitive
308307

309308
# block production and rewards
310309
pallet-block-production-log = { path = "toolkit/block-production-log/pallet", default-features = false }
311-
sp-block-production-log = { path = "toolkit/block-production-log/primitives", default-features = false }
312310
pallet-block-participation = { path = "toolkit/block-participation/pallet", default-features = false }
313311
sp-block-participation = { path = "toolkit/block-participation/primitives", default-features = false }
314312

demo/node/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ sp-keyring = { workspace = true }
5252
authority-selection-inherents = { workspace = true }
5353
frame-system = { workspace = true }
5454
pallet-transaction-payment = { workspace = true }
55-
sp-block-production-log = { workspace = true }
5655
sidechain-domain = { workspace = true }
5756
sidechain-slots = { workspace = true }
5857
sp-sidechain = { workspace = true }

demo/node/src/inherent_data.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use sp_block_participation::{
1919
BlockParticipationApi,
2020
inherent_data::{BlockParticipationDataSource, BlockParticipationInherentDataProvider},
2121
};
22-
use sp_block_production_log::{BlockAuthorInherentProvider, BlockProductionLogApi};
2322
use sp_blockchain::HeaderBackend;
2423
use sp_consensus_aura::{
2524
Slot, inherents::InherentDataProvider as AuraIDP, sr25519::AuthorityPair as AuraPair,
@@ -54,7 +53,6 @@ where
5453
T: ProvideRuntimeApi<Block> + Send + Sync + 'static,
5554
T: HeaderBackend<Block>,
5655
T::Api: SessionValidatorManagementApi<Block, CrossChainPublic, SessionKeys, ScEpochNumber>,
57-
T::Api: BlockProductionLogApi<Block, BlockAuthor, Slot>,
5856
T::Api: BlockParticipationApi<Block, BlockAuthor, Slot>,
5957
T::Api: GovernedMapIDPApi<Block>,
6058
T::Api: TokenBridgeIDPRuntimeApi<Block>,
@@ -64,7 +62,6 @@ where
6462
TimestampIDP,
6563
McHashIDP,
6664
AriadneIDP,
67-
BlockAuthorInherentProvider<Slot, BlockAuthor>,
6865
BlockParticipationInherentDataProvider<BlockAuthor, DelegatorKey, Slot>,
6966
GovernedMapInherentDataProvider,
7067
TokenBridgeInherentDataProvider<AccountId>,
@@ -111,8 +108,6 @@ where
111108
mc_hash.mc_epoch(),
112109
)
113110
.await?;
114-
let block_producer_id_provider =
115-
BlockAuthorInherentProvider::new(client.as_ref(), parent_hash, *slot)?;
116111

117112
let payouts = BlockParticipationInherentDataProvider::new(
118113
client.as_ref(),
@@ -140,16 +135,7 @@ where
140135
)
141136
.await?;
142137

143-
Ok((
144-
slot,
145-
timestamp,
146-
mc_hash,
147-
ariadne_data_provider,
148-
block_producer_id_provider,
149-
payouts,
150-
governed_map,
151-
bridge,
152-
))
138+
Ok((slot, timestamp, mc_hash, ariadne_data_provider, payouts, governed_map, bridge))
153139
}
154140
}
155141

@@ -175,15 +161,13 @@ impl<T> CreateInherentDataProviders<Block, (Slot, McBlockHash)> for VerifierCIDP
175161
where
176162
T: ProvideRuntimeApi<Block> + Send + Sync + HeaderBackend<Block>,
177163
T::Api: SessionValidatorManagementApi<Block, CrossChainPublic, SessionKeys, ScEpochNumber>,
178-
T::Api: BlockProductionLogApi<Block, BlockAuthor, Slot>,
179164
T::Api: BlockParticipationApi<Block, BlockAuthor, Slot>,
180165
T::Api: GovernedMapIDPApi<Block>,
181166
T::Api: TokenBridgeIDPRuntimeApi<Block>,
182167
{
183168
type InherentDataProviders = (
184169
TimestampIDP,
185170
AriadneIDP,
186-
BlockAuthorInherentProvider<Slot, BlockAuthor>,
187171
BlockParticipationInherentDataProvider<BlockAuthor, DelegatorKey, Slot>,
188172
GovernedMapInherentDataProvider,
189173
TokenBridgeInherentDataProvider<AccountId>,
@@ -237,9 +221,6 @@ where
237221
)
238222
.await?;
239223

240-
let block_producer_id_provider =
241-
BlockAuthorInherentProvider::new(client.as_ref(), parent_hash, verified_block_slot)?;
242-
243224
let payouts = BlockParticipationInherentDataProvider::new(
244225
client.as_ref(),
245226
block_participation_data_source.as_ref(),
@@ -266,14 +247,7 @@ where
266247
)
267248
.await?;
268249

269-
Ok((
270-
timestamp,
271-
ariadne_data_provider,
272-
block_producer_id_provider,
273-
payouts,
274-
governed_map,
275-
bridge,
276-
))
250+
Ok((timestamp, ariadne_data_provider, payouts, governed_map, bridge))
277251
}
278252
}
279253

demo/node/src/tests/inherent_data_tests.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::tests::runtime_api_mock::{TestApi, mock_header};
77
use authority_selection_inherents::{
88
AuthoritySelectionInputs, mock::MockAuthoritySelectionDataSource,
99
};
10-
use hex_literal::hex;
1110
use partner_chains_demo_runtime::{AccountId, BlockAuthor};
1211
use partner_chains_mock_data_sources::StakeDistributionDataSourceMock;
1312
use partner_chains_mock_data_sources::{GovernedMapDataSourceMock, TokenBridgeDataSourceMock};
@@ -17,9 +16,7 @@ use sidechain_domain::{
1716
};
1817
use sidechain_mc_hash::mock::MockMcHashDataSource;
1918
use sp_block_participation::BlockProductionData;
20-
use sp_block_production_log::BlockProductionInherentDataV1;
2119
use sp_consensus_aura::Slot;
22-
use sp_core::ecdsa;
2320
use sp_inherents::CreateInherentDataProviders;
2421
use sp_inherents::{InherentData, InherentDataProvider};
2522
use sp_timestamp::Timestamp;
@@ -89,22 +86,6 @@ async fn block_proposal_cidp_should_be_created_correctly() {
8986
.unwrap()
9087
.is_some()
9188
);
92-
assert_eq!(
93-
inherent_data
94-
.get_data::<BlockProductionInherentDataV1<u64, BlockAuthor>>(
95-
&sp_block_production_log::INHERENT_IDENTIFIER
96-
)
97-
.unwrap(),
98-
Some(BlockProductionInherentDataV1 {
99-
moment: 30,
100-
block_producer_id: BlockAuthor::ProBono(
101-
ecdsa::Public::from_raw(hex!(
102-
"000000000000000000000000000000000000000000000000000000000000000001"
103-
))
104-
.into()
105-
)
106-
})
107-
);
10889
assert_eq!(
10990
inherent_data
11091
.get_data::<Slot>(&sp_block_participation::INHERENT_IDENTIFIER)
@@ -172,22 +153,6 @@ async fn block_verification_cidp_should_be_created_correctly() {
172153
.unwrap()
173154
.is_some()
174155
);
175-
assert_eq!(
176-
inherent_data
177-
.get_data::<BlockProductionInherentDataV1<u64, BlockAuthor>>(
178-
&sp_block_production_log::INHERENT_IDENTIFIER
179-
)
180-
.unwrap(),
181-
Some(BlockProductionInherentDataV1 {
182-
moment: 30,
183-
block_producer_id: BlockAuthor::ProBono(
184-
ecdsa::Public::from_raw(hex!(
185-
"000000000000000000000000000000000000000000000000000000000000000001"
186-
))
187-
.into()
188-
)
189-
})
190-
);
191156
assert_eq!(
192157
inherent_data
193158
.get_data::<Slot>(&sp_block_participation::INHERENT_IDENTIFIER)

demo/node/src/tests/runtime_api_mock.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::mock::mock_genesis_utxo;
22
use authority_selection_inherents::AuthoritySelectionInputs;
3-
use hex_literal::hex;
43
use partner_chains_demo_runtime::opaque::SessionKeys;
54
use partner_chains_demo_runtime::{BlockAuthor, CrossChainPublic};
65
use sidechain_domain::*;
@@ -103,14 +102,6 @@ sp_api::mock_impl_runtime_apis! {
103102
}
104103
}
105104

106-
impl sp_block_production_log::BlockProductionLogApi<Block, BlockAuthor, Slot> for TestApi {
107-
fn get_author(_slot: &Slot) -> Option<BlockAuthor> {
108-
Some(BlockAuthor::ProBono(
109-
ecdsa::Public::from_raw(hex!("000000000000000000000000000000000000000000000000000000000000000001")).into()
110-
))
111-
}
112-
}
113-
114105
impl sp_block_participation::BlockParticipationApi<Block, BlockAuthor, Slot> for TestApi {
115106
fn blocks_to_process(_slot: &Slot) -> Vec<(Slot, BlockAuthor)> {
116107
self.participation_data.clone()

demo/runtime/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ frame-benchmarking = { workspace = true, optional = true }
7272
frame-system-benchmarking = { workspace = true, optional = true }
7373

7474
# Local Dependencies
75-
sp-block-production-log = { workspace = true }
76-
pallet-block-production-log = { workspace = true, features = ["block-participation"] }
75+
pallet-block-production-log = { workspace = true, features = ["block-participation", "aura-compat"] }
7776
sp-sidechain = { workspace = true }
7877
pallet-sidechain = { workspace = true }
7978
pallet-session-validator-management = { workspace = true }
@@ -161,7 +160,6 @@ std = [
161160
"sidechain-slots/std",
162161
"sidechain-domain/std",
163162
"sp-inherents/std",
164-
"sp-block-production-log/std",
165163
"pallet-block-participation/std",
166164
"sp-block-participation/std",
167165
"pallet-governed-map/std",

demo/runtime/src/lib.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ use sidechain_slots::Slot;
4444
use sp_api::impl_runtime_apis;
4545
use sp_block_participation::AsCardanoSPO;
4646
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
47-
#[cfg(feature = "runtime-benchmarks")]
48-
use sp_core::ByteArray;
4947
use sp_core::{OpaqueMetadata, crypto::KeyTypeId};
5048
use sp_governed_map::MainChainScriptsV1;
5149
use sp_inherents::InherentIdentifier;
@@ -453,19 +451,6 @@ pub struct BlockProducerMetadataType {
453451
pub hash: SizedByteString<32>,
454452
}
455453

456-
#[cfg(feature = "runtime-benchmarks")]
457-
pub struct PalletBlockProductionLogBenchmarkHelper;
458-
459-
#[cfg(feature = "runtime-benchmarks")]
460-
impl pallet_block_production_log::benchmarking::BenchmarkHelper<BlockAuthor>
461-
for PalletBlockProductionLogBenchmarkHelper
462-
{
463-
fn producer_id() -> BlockAuthor {
464-
let id = sp_core::ecdsa::Public::from_slice(&[0u8; 33]).unwrap().into();
465-
BlockAuthor::ProBono(id)
466-
}
467-
}
468-
469454
#[cfg(feature = "runtime-benchmarks")]
470455
pub struct PalletBlockProducerMetadataBenchmarkHelper;
471456

@@ -512,12 +497,11 @@ impl
512497

513498
impl pallet_block_production_log::Config for Runtime {
514499
type BlockProducerId = BlockAuthor;
515-
type WeightInfo = pallet_block_production_log::weights::SubstrateWeight<Runtime>;
516500

517501
type Moment = Slot;
518502

519-
#[cfg(feature = "runtime-benchmarks")]
520-
type BenchmarkHelper = PalletBlockProductionLogBenchmarkHelper;
503+
type GetMoment = Aura;
504+
type GetAuthor = SessionCommitteeManagement;
521505
}
522506

523507
parameter_types! {
@@ -789,7 +773,6 @@ mod benches {
789773
[pallet_balances, Balances]
790774
[pallet_timestamp, Timestamp]
791775
[pallet_sudo, Sudo]
792-
[pallet_block_production_log, BlockProductionLog]
793776
[pallet_address_associations, AddressAssociations]
794777
[pallet_block_producer_fees, BlockProducerFees]
795778
[pallet_block_producer_metadata, BlockProducerMetadata]
@@ -1132,13 +1115,6 @@ impl_runtime_apis! {
11321115
}
11331116
}
11341117

1135-
impl sp_block_production_log::BlockProductionLogApi<Block, BlockAuthor, Slot> for Runtime {
1136-
fn get_author(slot: &Slot) -> Option<BlockAuthor> {
1137-
SessionCommitteeManagement::get_current_authority_round_robin(u64::from(*slot) as usize)
1138-
.map(Into::into)
1139-
}
1140-
}
1141-
11421118
impl sp_block_participation::BlockParticipationApi<Block, BlockAuthor, Slot> for Runtime {
11431119
fn blocks_to_process(slot: &Slot) -> Vec<(Slot, BlockAuthor)> {
11441120
BlockParticipation::blocks_to_process(slot)

docs/developer-guides/block-participation-rewards.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ committee and uses the Ariadne selection algorithm based on D-Param, Validator r
1313
and a permissioned candidate set, as provided by the `authority-selection-inherents` crate.
1414

1515
The following components will be combined to handle block rewards:
16-
1. Block production log (implemented through crates `sp-block-production-log` and `pallet-block-production-log`)
16+
1. Block production log (implemented by `pallet-block-production-log` crate)
1717
to track information on the author of each block produced in the chain
1818
2. Address associations (implemented by the `pallet-address-associations` crate) to store and resolve
1919
mappings between Cardano and Partner Chain identities of SPOs and their delegators.
@@ -92,18 +92,19 @@ having no delegators). As such, this type must implement the `sp_block_participa
9292
to be constructable from `sidechain_domain::DelegatorKey`. To avoid any boilerplate, `sidechain_domain::DelegatorKey`
9393
itself can be used.
9494

95+
#### Block production moment
96+
97+
A `Moment` type representing the moment in time when a block was produced. This type can be a timestamp, slot or
98+
round number or some other monotonically rising value that can be converted to a timestamp. If it represents a time
99+
range, a representative timestamp, such as the start of the range should be computable from it.
100+
95101
### Adding the Partner Chains Toolkit components
96102

97103
#### Block Production Log
98104

99-
The pallet should be added to the runtime and configured to use `BlockAuthor` type as its `BlockProducerId`, and
100-
an inherent data provider of type `BlockAuthorInherentProvider<BlockAuthor>` should be added to both the proposal
101-
and verification IDP stack of the node.
102-
103-
The runtime should implement the `BlockProductionLogApi` runtime API to expose the current block producer to the
104-
inherent data provider via the `get_author` method. This method's implementation depends on the consensus used by
105-
the partner chain. If the consensus mechanism used is Aura, the function `get_current_authority_round_robin`
106-
exposed by the Session Validator Management pallet should be used, which applies the same round-robin algorithm.
105+
The pallet should be added to the runtime and configured to use `BlockAuthor` type as its `BlockProducerId`
106+
and use the `Moment` type. Additionally, it must be provided a source of current block author and moment.
107+
These are provided out of the box for chains using Aura under feature flag `aura-compat`.
107108

108109
#### Address Associations
109110

0 commit comments

Comments
 (0)