Fetch Babe configuration from runtime state (#11760)

* Fetch babe config data from runtime state

* Some renaming

* More renaming

* Final nits

* Fix tests and benches

* Rename  to  in BabeConfiguration

* Remove duplicate babe parameter description

Already specified over the 'PRIMARY_PROBABILITY' constant value

* trigger pipeline

* trigger pipeline
This commit is contained in:
Davide Galassi
2022-09-05 19:41:32 +02:00
committed by GitHub
parent f919894c84
commit 83aec6f93a
14 changed files with 125 additions and 155 deletions
+10 -8
View File
@@ -25,7 +25,7 @@ use jsonrpsee::{
types::{error::CallError, ErrorObject},
};
use sc_consensus_babe::{authorship, Config, Epoch};
use sc_consensus_babe::{authorship, Epoch};
use sc_consensus_epochs::{descendent_query, Epoch as EpochT, SharedEpochChanges};
use sc_rpc_api::DenyUnsafe;
use serde::{Deserialize, Serialize};
@@ -33,7 +33,9 @@ use sp_api::{BlockId, ProvideRuntimeApi};
use sp_application_crypto::AppKey;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus::{Error as ConsensusError, SelectChain};
use sp_consensus_babe::{digests::PreDigest, AuthorityId, BabeApi as BabeRuntimeApi};
use sp_consensus_babe::{
digests::PreDigest, AuthorityId, BabeApi as BabeRuntimeApi, BabeConfiguration,
};
use sp_core::crypto::ByteArray;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use sp_runtime::traits::{Block as BlockT, Header as _};
@@ -57,7 +59,7 @@ pub struct Babe<B: BlockT, C, SC> {
/// shared reference to the Keystore
keystore: SyncCryptoStorePtr,
/// config (actually holds the slot duration)
babe_config: Config,
babe_config: BabeConfiguration,
/// The SelectChain strategy
select_chain: SC,
/// Whether to deny unsafe calls
@@ -70,7 +72,7 @@ impl<B: BlockT, C, SC> Babe<B, C, SC> {
client: Arc<C>,
shared_epoch_changes: SharedEpochChanges<B, Epoch>,
keystore: SyncCryptoStorePtr,
babe_config: Config,
babe_config: BabeConfiguration,
select_chain: SC,
deny_unsafe: DenyUnsafe,
) -> Self {
@@ -185,7 +187,7 @@ impl From<Error> for JsonRpseeError {
async fn epoch_data<B, C, SC>(
epoch_changes: &SharedEpochChanges<B, Epoch>,
client: &Arc<C>,
babe_config: &Config,
babe_config: &BabeConfiguration,
slot: u64,
select_chain: &SC,
) -> Result<Epoch, Error>
@@ -202,7 +204,7 @@ where
&parent.hash(),
*parent.number(),
slot.into(),
|slot| Epoch::genesis(babe_config.genesis_config(), slot),
|slot| Epoch::genesis(babe_config, slot),
)
.map_err(|e| Error::Consensus(ConsensusError::ChainLookup(e.to_string())))?
.ok_or(Error::Consensus(ConsensusError::InvalidAuthoritiesSet))
@@ -221,7 +223,7 @@ mod tests {
TestClientBuilderExt,
};
use sc_consensus_babe::{block_import, AuthorityPair, Config};
use sc_consensus_babe::{block_import, AuthorityPair};
use std::sync::Arc;
/// creates keystore backed by a temp file
@@ -243,7 +245,7 @@ mod tests {
let builder = TestClientBuilder::new();
let (client, longest_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
let config = Config::get(&*client).expect("config available");
let config = sc_consensus_babe::configuration(&*client).expect("config available");
let (_, link) = block_import(config.clone(), client.clone(), client.clone())
.expect("can initialize block-import");