diff --git a/client/consensus/src/collators.rs b/client/consensus/src/collators.rs index ebec38d5e..89ddc88a2 100644 --- a/client/consensus/src/collators.rs +++ b/client/consensus/src/collators.rs @@ -264,6 +264,7 @@ where pub struct SlotClaim { author_pub: Pub, pre_digest: Vec, + slot: Slot, } impl SlotClaim { @@ -276,6 +277,7 @@ impl SlotClaim { SlotClaim { author_pub: author_pub.clone(), pre_digest: pre_digest_data::

(slot, author_pub), + slot, } } @@ -288,6 +290,11 @@ impl SlotClaim { pub fn pre_digest(&self) -> &Vec { &self.pre_digest } + + /// Get the slot assigned to this claim. + pub fn slot(&self) -> Slot { + self.slot + } } /// Attempt to claim a slot locally. diff --git a/client/consensus/src/collators/basic.rs b/client/consensus/src/collators/basic.rs index 30104011a..92e0d6a69 100644 --- a/client/consensus/src/collators/basic.rs +++ b/client/consensus/src/collators/basic.rs @@ -130,6 +130,8 @@ pub async fn run( collator_util::Collator::::new(params) }; + let mut last_processed_slot = 0; + while let Some(request) = collation_requests.next().await { macro_rules! reject_with_error { ($err:expr) => {{ @@ -211,6 +213,18 @@ pub async fn run( Ok(Some(h)) => h, }; + // With async backing this function will be called every relay chain block. + // + // Most parachains currently run with 12 seconds slots and thus, they would try to + // produce multiple blocks per slot which very likely would fail on chain. Thus, we have + // this "hack" to only produce on block per slot. + // + // With https://github.com/paritytech/polkadot-sdk/issues/3168 this implementation will be + // obsolete and also the underlying issue will be fixed. + if last_processed_slot >= *claim.slot() { + continue; + } + let (parachain_inherent_data, other_inherent_data) = try_request!( collator .create_inherent_data(*request.relay_parent(), validation_data, parent_hash, None,) @@ -244,5 +258,6 @@ pub async fn run( request.complete(None); tracing::debug!(target: crate::LOG_TARGET, "No block proposal"); } + last_processed_slot = *claim.slot(); } }