Skip to content

Commit 2732b6a

Browse files
authored
Remove deprecated/unused consensus code (#9869)
This pull request removes unused consensus-related code from the codebase. The removed code was not referenced or required by any existing logic or features, and its removal helps to: - Reduce technical debt - Simplify the codebase for future maintenance
1 parent 0e272fe commit 2732b6a

File tree

8 files changed

+25
-531
lines changed

8 files changed

+25
-531
lines changed

cumulus/client/consensus/aura/src/lib.rs

Lines changed: 5 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,17 @@
1818
//! The AuRa consensus algorithm for parachains.
1919
//!
2020
//! This extends the Substrate provided AuRa consensus implementation to make it compatible for
21-
//! parachains. The main entry points for of this consensus algorithm are [`AuraConsensus::build`]
22-
//! and [`fn@import_queue`].
21+
//! parachains.
2322
//!
2423
//! For more information about AuRa, the Substrate crate should be checked.
2524
26-
use codec::{Codec, Encode};
27-
use cumulus_client_consensus_common::{
28-
ParachainBlockImportMarker, ParachainCandidate, ParachainConsensus,
29-
};
30-
use cumulus_primitives_core::{relay_chain::Hash as PHash, PersistedValidationData};
25+
use codec::Encode;
26+
use cumulus_primitives_core::PersistedValidationData;
3127

3228
use cumulus_primitives_core::relay_chain::HeadData;
33-
use futures::lock::Mutex;
3429
use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash};
35-
use sc_client_api::{backend::AuxStore, BlockOf};
36-
use sc_consensus::BlockImport;
37-
use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, SimpleSlotWorker, SlotInfo};
38-
use sc_telemetry::TelemetryHandle;
39-
use sp_api::ProvideRuntimeApi;
40-
use sp_application_crypto::AppPublic;
41-
use sp_blockchain::HeaderBackend;
42-
use sp_consensus::{EnableProofRecording, Environment, ProofRecording, Proposer, SyncOracle};
43-
use sp_consensus_aura::{AuraApi, SlotDuration};
44-
use sp_core::crypto::Pair;
45-
use sp_inherents::CreateInherentDataProviders;
46-
use sp_keystore::KeystorePtr;
47-
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member, NumberFor};
48-
use std::{
49-
convert::TryFrom,
50-
fs,
51-
fs::File,
52-
marker::PhantomData,
53-
path::PathBuf,
54-
sync::{
55-
atomic::{AtomicU64, Ordering},
56-
Arc,
57-
},
58-
};
30+
use sp_runtime::traits::{Block as BlockT, NumberFor};
31+
use std::{fs, fs::File, path::PathBuf};
5932

6033
mod import_queue;
6134

@@ -73,192 +46,6 @@ pub mod equivocation_import_queue;
7346

7447
const LOG_TARGET: &str = "aura::cumulus";
7548

76-
/// The implementation of the AURA consensus for parachains.
77-
pub struct AuraConsensus<B, CIDP, W> {
78-
create_inherent_data_providers: Arc<CIDP>,
79-
aura_worker: Arc<Mutex<W>>,
80-
slot_duration: SlotDuration,
81-
last_slot_processed: Arc<AtomicU64>,
82-
_phantom: PhantomData<B>,
83-
}
84-
85-
impl<B, CIDP, W> Clone for AuraConsensus<B, CIDP, W> {
86-
fn clone(&self) -> Self {
87-
Self {
88-
create_inherent_data_providers: self.create_inherent_data_providers.clone(),
89-
aura_worker: self.aura_worker.clone(),
90-
slot_duration: self.slot_duration,
91-
last_slot_processed: self.last_slot_processed.clone(),
92-
_phantom: PhantomData,
93-
}
94-
}
95-
}
96-
97-
/// Parameters of [`AuraConsensus::build`].
98-
#[deprecated = "Use the `aura::collators::basic` collator instead"]
99-
pub struct BuildAuraConsensusParams<PF, BI, CIDP, Client, BS, SO> {
100-
pub proposer_factory: PF,
101-
pub create_inherent_data_providers: CIDP,
102-
pub block_import: BI,
103-
pub para_client: Arc<Client>,
104-
pub backoff_authoring_blocks: Option<BS>,
105-
pub sync_oracle: SO,
106-
pub keystore: KeystorePtr,
107-
pub force_authoring: bool,
108-
pub slot_duration: SlotDuration,
109-
pub telemetry: Option<TelemetryHandle>,
110-
pub block_proposal_slot_portion: SlotProportion,
111-
pub max_block_proposal_slot_portion: Option<SlotProportion>,
112-
}
113-
114-
impl<B, CIDP> AuraConsensus<B, CIDP, ()>
115-
where
116-
B: BlockT,
117-
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + 'static,
118-
CIDP::InherentDataProviders: InherentDataProviderExt,
119-
{
120-
/// Create a new boxed instance of AURA consensus.
121-
#[allow(deprecated)]
122-
#[deprecated = "Use the `aura::collators::basic` collator instead"]
123-
pub fn build<P, Client, BI, SO, PF, BS, Error>(
124-
BuildAuraConsensusParams {
125-
proposer_factory,
126-
create_inherent_data_providers,
127-
block_import,
128-
para_client,
129-
backoff_authoring_blocks,
130-
sync_oracle,
131-
keystore,
132-
force_authoring,
133-
slot_duration,
134-
telemetry,
135-
block_proposal_slot_portion,
136-
max_block_proposal_slot_portion,
137-
}: BuildAuraConsensusParams<PF, BI, CIDP, Client, BS, SO>,
138-
) -> Box<dyn ParachainConsensus<B>>
139-
where
140-
Client:
141-
ProvideRuntimeApi<B> + BlockOf + AuxStore + HeaderBackend<B> + Send + Sync + 'static,
142-
Client::Api: AuraApi<B, P::Public>,
143-
BI: BlockImport<B> + ParachainBlockImportMarker + Send + Sync + 'static,
144-
SO: SyncOracle + Send + Sync + Clone + 'static,
145-
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Send + Sync + 'static,
146-
PF: Environment<B, Error = Error> + Send + Sync + 'static,
147-
PF::Proposer: Proposer<
148-
B,
149-
Error = Error,
150-
ProofRecording = EnableProofRecording,
151-
Proof = <EnableProofRecording as ProofRecording>::Proof,
152-
>,
153-
Error: std::error::Error + Send + From<sp_consensus::Error> + 'static,
154-
P: Pair + 'static,
155-
P::Public: AppPublic + Member + Codec,
156-
P::Signature: TryFrom<Vec<u8>> + Member + Codec,
157-
{
158-
let worker = sc_consensus_aura::build_aura_worker::<P, _, _, _, _, _, _, _, _>(
159-
BuildAuraWorkerParams {
160-
client: para_client,
161-
block_import,
162-
justification_sync_link: (),
163-
proposer_factory,
164-
sync_oracle,
165-
force_authoring,
166-
backoff_authoring_blocks,
167-
keystore,
168-
telemetry,
169-
block_proposal_slot_portion,
170-
max_block_proposal_slot_portion,
171-
compatibility_mode: sc_consensus_aura::CompatibilityMode::None,
172-
},
173-
);
174-
175-
Box::new(AuraConsensus {
176-
create_inherent_data_providers: Arc::new(create_inherent_data_providers),
177-
aura_worker: Arc::new(Mutex::new(worker)),
178-
last_slot_processed: Default::default(),
179-
slot_duration,
180-
_phantom: PhantomData,
181-
})
182-
}
183-
}
184-
185-
impl<B, CIDP, W> AuraConsensus<B, CIDP, W>
186-
where
187-
B: BlockT,
188-
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + 'static,
189-
CIDP::InherentDataProviders: InherentDataProviderExt,
190-
{
191-
/// Create the inherent data.
192-
///
193-
/// Returns the created inherent data and the inherent data providers used.
194-
async fn inherent_data(
195-
&self,
196-
parent: B::Hash,
197-
validation_data: &PersistedValidationData,
198-
relay_parent: PHash,
199-
) -> Option<CIDP::InherentDataProviders> {
200-
self.create_inherent_data_providers
201-
.create_inherent_data_providers(parent, (relay_parent, validation_data.clone()))
202-
.await
203-
.map_err(|e| {
204-
tracing::error!(
205-
target: LOG_TARGET,
206-
error = ?e,
207-
"Failed to create inherent data providers.",
208-
)
209-
})
210-
.ok()
211-
}
212-
}
213-
214-
#[async_trait::async_trait]
215-
impl<B, CIDP, W> ParachainConsensus<B> for AuraConsensus<B, CIDP, W>
216-
where
217-
B: BlockT,
218-
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + Send + Sync + 'static,
219-
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
220-
W: SimpleSlotWorker<B> + Send + Sync,
221-
W::Proposer: Proposer<B, Proof = <EnableProofRecording as ProofRecording>::Proof>,
222-
{
223-
async fn produce_candidate(
224-
&mut self,
225-
parent: &B::Header,
226-
relay_parent: PHash,
227-
validation_data: &PersistedValidationData,
228-
) -> Option<ParachainCandidate<B>> {
229-
let inherent_data_providers =
230-
self.inherent_data(parent.hash(), validation_data, relay_parent).await?;
231-
232-
let info = SlotInfo::new(
233-
inherent_data_providers.slot(),
234-
Box::new(inherent_data_providers),
235-
self.slot_duration.as_duration(),
236-
parent.clone(),
237-
// Set the block limit to 50% of the maximum PoV size.
238-
//
239-
// TODO: If we got benchmarking that includes the proof size,
240-
// we should be able to use the maximum pov size.
241-
Some((validation_data.max_pov_size / 2) as usize),
242-
);
243-
244-
// With async backing this function will be called every relay chain block.
245-
//
246-
// Most parachains currently run with 12 seconds slots and thus, they would try to produce
247-
// multiple blocks per slot which very likely would fail on chain. Thus, we have this "hack"
248-
// to only produce on block per slot.
249-
//
250-
// With https://github.com/paritytech/polkadot-sdk/issues/3168 this implementation will be
251-
// obsolete and also the underlying issue will be fixed.
252-
if self.last_slot_processed.fetch_max(*info.slot, Ordering::Relaxed) >= *info.slot {
253-
return None
254-
}
255-
256-
let res = self.aura_worker.lock().await.on_slot(info).await?;
257-
258-
Some(ParachainCandidate { block: res.block, proof: res.storage_proof })
259-
}
260-
}
261-
26249
/// Export the given `pov` to the file system at `path`.
26350
///
26451
/// The file will be named `block_hash_block_number.pov`.

cumulus/client/consensus/common/src/lib.rs

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
// along with Cumulus. If not, see <https://www.gnu.org/licenses/>.
1717

1818
use codec::Decode;
19-
use polkadot_primitives::{
20-
Block as PBlock, Hash as PHash, Header as PHeader, PersistedValidationData, ValidationCodeHash,
21-
};
19+
use polkadot_primitives::{Block as PBlock, Hash as PHash, Header as PHeader, ValidationCodeHash};
2220

2321
use cumulus_primitives_core::{relay_chain, AbridgedHostConfiguration};
2422
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface};
@@ -63,54 +61,14 @@ where
6361
}
6462
}
6563

66-
/// The result of [`ParachainConsensus::produce_candidate`].
64+
/// The result from building a collation.
6765
pub struct ParachainCandidate<B> {
6866
/// The block that was built for this candidate.
6967
pub block: B,
7068
/// The proof that was recorded while building the block.
7169
pub proof: sp_trie::StorageProof,
7270
}
7371

74-
/// A specific parachain consensus implementation that can be used by a collator to produce
75-
/// candidates.
76-
///
77-
/// The collator will call [`Self::produce_candidate`] every time there is a free core for the
78-
/// parachain this collator is collating for. It is the job of the consensus implementation to
79-
/// decide if this specific collator should build a candidate for the given relay chain block. The
80-
/// consensus implementation could, for example, check whether this specific collator is part of a
81-
/// staked set.
82-
#[async_trait::async_trait]
83-
pub trait ParachainConsensus<B: BlockT>: Send + Sync + dyn_clone::DynClone {
84-
/// Produce a new candidate at the given parent block and relay-parent blocks.
85-
///
86-
/// Should return `None` if the consensus implementation decided that it shouldn't build a
87-
/// candidate or if there occurred any error.
88-
///
89-
/// # NOTE
90-
///
91-
/// It is expected that the block is already imported when the future resolves.
92-
async fn produce_candidate(
93-
&mut self,
94-
parent: &B::Header,
95-
relay_parent: PHash,
96-
validation_data: &PersistedValidationData,
97-
) -> Option<ParachainCandidate<B>>;
98-
}
99-
100-
dyn_clone::clone_trait_object!(<B> ParachainConsensus<B> where B: BlockT);
101-
102-
#[async_trait::async_trait]
103-
impl<B: BlockT> ParachainConsensus<B> for Box<dyn ParachainConsensus<B> + Send + Sync> {
104-
async fn produce_candidate(
105-
&mut self,
106-
parent: &B::Header,
107-
relay_parent: PHash,
108-
validation_data: &PersistedValidationData,
109-
) -> Option<ParachainCandidate<B>> {
110-
(*self).produce_candidate(parent, relay_parent, validation_data).await
111-
}
112-
}
113-
11472
/// Parachain specific block import.
11573
///
11674
/// Specialized block import for parachains. It supports to delay setting the best block until the

cumulus/client/consensus/common/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use codec::Encode;
2222
use cumulus_client_pov_recovery::RecoveryKind;
2323
use cumulus_primitives_core::{
2424
relay_chain::{BlockId, BlockNumber, CoreState},
25-
CumulusDigestItem, InboundDownwardMessage, InboundHrmpMessage,
25+
CumulusDigestItem, InboundDownwardMessage, InboundHrmpMessage, PersistedValidationData,
2626
};
2727
use cumulus_relay_chain_interface::{
2828
CommittedCandidateReceipt, CoreIndex, OccupiedCoreAssumption, OverseerHandle, PHeader, ParaId,

cumulus/client/consensus/relay-chain/src/import_queue.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@
1717

1818
use std::{marker::PhantomData, sync::Arc};
1919

20-
use cumulus_client_consensus_common::ParachainBlockImportMarker;
21-
22-
use sc_consensus::{
23-
import_queue::{BasicQueue, Verifier as VerifierT},
24-
BlockImport, BlockImportParams,
25-
};
20+
use sc_consensus::{import_queue::Verifier as VerifierT, BlockImportParams};
2621
use sp_api::ProvideRuntimeApi;
2722
use sp_block_builder::BlockBuilder as BlockBuilderApi;
28-
use sp_blockchain::Result as ClientResult;
29-
use sp_consensus::error::Error as ConsensusError;
3023
use sp_inherents::CreateInherentDataProviders;
3124
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
3225

@@ -93,26 +86,3 @@ where
9386
Ok(block_params)
9487
}
9588
}
96-
97-
/// Start an import queue for a Cumulus collator that does not uses any special authoring logic.
98-
pub fn import_queue<Client, Block: BlockT, I, CIDP>(
99-
client: Arc<Client>,
100-
block_import: I,
101-
create_inherent_data_providers: CIDP,
102-
spawner: &impl sp_core::traits::SpawnEssentialNamed,
103-
registry: Option<&prometheus_endpoint::Registry>,
104-
) -> ClientResult<BasicQueue<Block>>
105-
where
106-
I: BlockImport<Block, Error = ConsensusError>
107-
+ ParachainBlockImportMarker
108-
+ Send
109-
+ Sync
110-
+ 'static,
111-
Client: ProvideRuntimeApi<Block> + Send + Sync + 'static,
112-
<Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
113-
CIDP: CreateInherentDataProviders<Block, ()> + 'static,
114-
{
115-
let verifier = Verifier::new(client, create_inherent_data_providers);
116-
117-
Ok(BasicQueue::new(verifier, Box::new(block_import), None, spawner, registry))
118-
}

0 commit comments

Comments
 (0)