diff --git a/substrate/abi/src/block.rs b/substrate/abi/src/block.rs index 4e523f8f..1e5d0bb3 100644 --- a/substrate/abi/src/block.rs +++ b/substrate/abi/src/block.rs @@ -253,7 +253,7 @@ mod substrate { for log in header.consensus.digest.logs() { match log { DigestItem::PreRuntime(consensus, encoded) - if *consensus == SeraiExecutionDigest::CONSENSUS_ID => + if *consensus == SeraiPreExecutionDigest::CONSENSUS_ID => { pre_execution_digest = SeraiPreExecutionDigest::deserialize_reader(&mut encoded.as_slice()).ok(); diff --git a/substrate/node/src/service.rs b/substrate/node/src/service/mod.rs similarity index 98% rename from substrate/node/src/service.rs rename to substrate/node/src/service/mod.rs index 66058390..d3d8e4b6 100644 --- a/substrate/node/src/service.rs +++ b/substrate/node/src/service/mod.rs @@ -22,6 +22,8 @@ use serai_runtime::RuntimeApi; use sc_consensus_babe::{self, SlotProportion}; use sc_consensus_grandpa as grandpa; +mod proposer; + #[cfg(not(feature = "runtime-benchmarks"))] pub type Executor = WasmExecutor>; #[cfg(feature = "runtime-benchmarks")] @@ -32,6 +34,8 @@ pub type Executor = WasmExecutor< type FullBackend = sc_service::TFullBackend; pub type FullClient = TFullClient; +pub type TransactionPool = sc_transaction_pool::TransactionPoolWrapper; + type SelectChain = sc_consensus::LongestChain; type GrandpaBlockImport = grandpa::GrandpaBlockImport; type BabeBlockImport = @@ -42,7 +46,7 @@ type PartialComponents = sc_service::PartialComponents< FullBackend, SelectChain, sc_consensus::DefaultImportQueue, - sc_transaction_pool::TransactionPoolWrapper, + TransactionPool, ( BabeBlockImport, sc_consensus_babe::BabeLink, @@ -391,13 +395,13 @@ pub fn new_full(mut config: Configuration) -> Result keystore: keystore.clone(), client: client.clone(), select_chain, - env: sc_basic_authorship::ProposerFactory::new( + env: proposer::ProposerFactory(sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client, transaction_pool.clone(), prometheus_registry.as_ref(), telemetry.as_ref().map(Telemetry::handle), - ), + )), block_import, sync_oracle: sync_service.clone(), justification_sync_link: sync_service.clone(), diff --git a/substrate/node/src/service/proposer.rs b/substrate/node/src/service/proposer.rs new file mode 100644 index 00000000..3565fd78 --- /dev/null +++ b/substrate/node/src/service/proposer.rs @@ -0,0 +1,56 @@ +use std::time::Duration; + +use sp_runtime::Digest; +use sp_consensus::{InherentData, DisableProofRecording}; + +use serai_abi::{SeraiPreExecutionDigest, SubstrateHeader as Header, SubstrateBlock as Block}; + +use super::{FullClient, TransactionPool}; + +type UnderlyingProposer = + sc_basic_authorship::Proposer; +pub struct Proposer(UnderlyingProposer); +impl sp_consensus::Proposer for Proposer { + type Error = >::Error; + type Proposal = >::Proposal; + type ProofRecording = DisableProofRecording; + type Proof = (); + + fn propose( + self, + inherent_data: InherentData, + mut inherent_digests: Digest, + max_duration: Duration, + block_size_limit: Option, + ) -> Self::Proposal { + Box::pin(async move { + // Insert our expected digest + inherent_digests.logs.push(sp_runtime::generic::DigestItem::PreRuntime( + SeraiPreExecutionDigest::CONSENSUS_ID, + borsh::to_vec(&SeraiPreExecutionDigest { + unix_time_in_millis: inherent_data + .get_data::(&sp_timestamp::INHERENT_IDENTIFIER) + .map_err(|err| sp_blockchain::Error::Application(err.into()))? + .ok_or(sp_blockchain::Error::Application("missing timestamp inherent".into()))? + .as_millis(), + }) + .unwrap(), + )); + + // Call the underlying propose function + self.0.propose(inherent_data, inherent_digests, max_duration, block_size_limit).await + }) + } +} + +type UnderlyingFactory = + sc_basic_authorship::ProposerFactory; +pub struct ProposerFactory(pub UnderlyingFactory); +impl sp_consensus::Environment for ProposerFactory { + type CreateProposer = core::future::Ready>; + type Proposer = Proposer; + type Error = >::Error; + fn init(&mut self, parent_header: &Header) -> Self::CreateProposer { + core::future::ready(self.0.init(parent_header).into_inner().map(Proposer)) + } +}