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
15 changes: 15 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
"frame/hotfix-sufficients",
"client/api",
"client/aura",
"client/babe",
"client/consensus",
"client/rpc-core",
"client/rpc",
Expand Down Expand Up @@ -91,6 +92,7 @@ sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk", tag = "pol
sc-client-db = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6", default-features = false }
sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6" }
sc-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6" }
sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6" }
sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6" }
sc-consensus-manual-seal = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6" }
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6" }
Expand All @@ -112,6 +114,7 @@ sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk", tag = "
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6", default-features = false }
sp-consensus = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6", default-features = false }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6", default-features = false }
sp-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6", default-features = false }
sp-crypto-hashing = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2503-6", default-features = false }
Expand Down Expand Up @@ -176,6 +179,7 @@ ark-std = { version = "0.4.0", default-features = false }
# Frontier Client
fc-api = { path = "client/api" }
fc-aura = { path = "client/aura" }
fc-babe = { path = "client/babe" }
fc-cli = { path = "client/cli", default-features = false }
fc-consensus = { path = "client/consensus" }
fc-db = { path = "client/db", default-features = false }
Expand Down
21 changes: 21 additions & 0 deletions client/babe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "fc-babe"
version = "1.0.0-dev"
authors = { workspace = true }
edition = { workspace = true }
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
repository = { workspace = true }
description = "Babe consensus data provider for pending runtime calls"

[dependencies]
# Substrate
sc-client-api = { workspace = true }
sc-consensus-babe = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus-babe = { workspace = true }
sp-inherents = { workspace = true }
sp-runtime = { workspace = true }
sp-timestamp = { workspace = true }
# Frontier
fc-rpc = { workspace = true }
60 changes: 60 additions & 0 deletions client/babe/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::{marker::PhantomData, sync::Arc};

use fc_rpc::pending::ConsensusDataProvider;
use sc_client_api::{AuxStore, UsageProvider};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::Error;
use sp_consensus_babe::{digests::CompatibleDigestItem, BabeApi, BabeConfiguration, Slot};
use sp_inherents::InherentData;
use sp_runtime::{traits::Block as BlockT, Digest, DigestItem};
use sp_timestamp::TimestampInherentData;

pub struct BabeConsensusDataProvider<B, C> {
babe_config: BabeConfiguration,
_phantom: PhantomData<(B, C)>,
}

impl<B, C> BabeConsensusDataProvider<B, C>
where
B: BlockT,
C: AuxStore + ProvideRuntimeApi<B> + UsageProvider<B>,
C::Api: BabeApi<B>,
{
/// Creates a new instance of the [`BabeConsensusDataProvider`], requires that `client`
/// implements [`sp_consensus_babe::BabeApi`]
pub fn new(client: Arc<C>) -> Result<Self, Error> {
let babe_config = sc_consensus_babe::configuration(&*client)?;
Ok(Self {
babe_config,
_phantom: PhantomData,
})
}
}

impl<B: BlockT, C: Send + Sync> ConsensusDataProvider<B> for BabeConsensusDataProvider<B, C> {
fn create_digest(
&self,
_parent: &B::Header,
data: &InherentData,
) -> Result<Digest, sp_inherents::Error> {
let timestamp = data
.timestamp_inherent_data()?
.expect("Timestamp is always present; qed");

let slot_duration = self.babe_config.slot_duration();
let slot = Slot::from_timestamp(timestamp, slot_duration);

let digest_item = <DigestItem as CompatibleDigestItem>::babe_pre_digest(
sp_consensus_babe::digests::PreDigest::SecondaryPlain(
sp_consensus_babe::digests::SecondaryPlainPreDigest {
slot,
authority_index: 0, // Use first authority for pending blocks
},
),
);

Ok(Digest {
logs: vec![digest_item],
})
}
}
Loading