Skip to content

Commit 239752a

Browse files
committed
Send the collator peer id from the client
1 parent 64fb9a6 commit 239752a

File tree

13 files changed

+86
-33
lines changed

13 files changed

+86
-33
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use cumulus_primitives_core::{
3838
use cumulus_relay_chain_interface::RelayChainInterface;
3939

4040
use polkadot_node_primitives::{Collation, MaybeCompressedPoV};
41-
use polkadot_primitives::{Header as PHeader, Id as ParaId};
41+
use polkadot_primitives::{ApprovedPeerId, Header as PHeader, Id as ParaId};
4242

4343
use crate::collators::RelayParentData;
4444
use futures::prelude::*;
@@ -69,6 +69,8 @@ pub struct Params<BI, CIDP, RClient, Proposer, CS> {
6969
pub relay_client: RClient,
7070
/// The keystore handle used for accessing parachain key material.
7171
pub keystore: KeystorePtr,
72+
/// The collator network peer id.
73+
pub collator_peer_id: ApprovedPeerId,
7274
/// The identifier of the parachain within the relay-chain.
7375
pub para_id: ParaId,
7476
/// The block proposer used for building blocks.
@@ -128,6 +130,7 @@ where
128130
parent_hash: Block::Hash,
129131
timestamp: impl Into<Option<Timestamp>>,
130132
relay_parent_descendants: Option<RelayParentData>,
133+
collator_peer_id: ApprovedPeerId,
131134
) -> Result<(ParachainInherentData, InherentData), Box<dyn Error + Send + Sync + 'static>> {
132135
let paras_inherent_data = ParachainInherentDataProvider::create_at(
133136
relay_parent,
@@ -138,6 +141,7 @@ where
138141
.map(RelayParentData::into_inherent_descendant_list)
139142
.unwrap_or_default(),
140143
Vec::new(),
144+
collator_peer_id,
141145
)
142146
.await;
143147

@@ -173,13 +177,15 @@ where
173177
validation_data: &PersistedValidationData,
174178
parent_hash: Block::Hash,
175179
timestamp: impl Into<Option<Timestamp>>,
180+
collator_peer_id: ApprovedPeerId,
176181
) -> Result<(ParachainInherentData, InherentData), Box<dyn Error + Send + Sync + 'static>> {
177182
self.create_inherent_data_with_rp_offset(
178183
relay_parent,
179184
validation_data,
180185
parent_hash,
181186
timestamp,
182187
None,
188+
collator_peer_id,
183189
)
184190
.await
185191
}

cumulus/client/consensus/aura/src/collators/basic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use cumulus_relay_chain_interface::RelayChainInterface;
3434

3535
use polkadot_node_primitives::CollationResult;
3636
use polkadot_overseer::Handle as OverseerHandle;
37-
use polkadot_primitives::{CollatorPair, Id as ParaId, ValidationCode};
37+
use polkadot_primitives::{ApprovedPeerId, CollatorPair, Id as ParaId, ValidationCode};
3838

3939
use futures::{channel::mpsc::Receiver, prelude::*};
4040
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf};
@@ -68,6 +68,8 @@ pub struct Params<BI, CIDP, Client, RClient, Proposer, CS> {
6868
pub keystore: KeystorePtr,
6969
/// The collator key used to sign collations before submitting to validators.
7070
pub collator_key: CollatorPair,
71+
/// The collator network peer id.
72+
pub collator_peer_id: ApprovedPeerId,
7173
/// The para's ID.
7274
pub para_id: ParaId,
7375
/// A handle to the relay-chain client's "Overseer" or task orchestrator.
@@ -130,6 +132,7 @@ where
130132
block_import: params.block_import,
131133
relay_client: params.relay_client.clone(),
132134
keystore: params.keystore.clone(),
135+
collator_peer_id: params.collator_peer_id.clone(),
133136
para_id: params.para_id,
134137
proposer: params.proposer,
135138
collator_service: params.collator_service,
@@ -234,6 +237,7 @@ where
234237
&validation_data,
235238
parent_hash,
236239
claim.timestamp(),
240+
params.collator_peer_id.clone(),
237241
)
238242
.await
239243
);

cumulus/client/consensus/aura/src/collators/lookahead.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use cumulus_relay_chain_interface::RelayChainInterface;
4343
use polkadot_node_primitives::SubmitCollationParams;
4444
use polkadot_node_subsystem::messages::CollationGenerationMessage;
4545
use polkadot_overseer::Handle as OverseerHandle;
46-
use polkadot_primitives::{CollatorPair, Id as ParaId, OccupiedCoreAssumption};
46+
use polkadot_primitives::{ApprovedPeerId, CollatorPair, Id as ParaId, OccupiedCoreAssumption};
4747

4848
use crate::{collator as collator_util, collators::claim_queue_at, export_pov_to_path};
4949
use futures::prelude::*;
@@ -79,6 +79,8 @@ pub struct Params<BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS> {
7979
pub keystore: KeystorePtr,
8080
/// The collator key used to sign collations before submitting to validators.
8181
pub collator_key: CollatorPair,
82+
/// The collator network peer id.
83+
pub collator_peer_id: ApprovedPeerId,
8284
/// The para's ID.
8385
pub para_id: ParaId,
8486
/// A handle to the relay-chain client's "Overseer" or task orchestrator.
@@ -207,6 +209,7 @@ where
207209
block_import: params.block_import,
208210
relay_client: params.relay_client.clone(),
209211
keystore: params.keystore.clone(),
212+
collator_peer_id: params.collator_peer_id.clone(),
210213
para_id: params.para_id,
211214
proposer: params.proposer,
212215
collator_service: params.collator_service,
@@ -345,6 +348,7 @@ where
345348
&validation_data,
346349
parent_hash,
347350
slot_claim.timestamp(),
351+
params.collator_peer_id.clone(),
348352
)
349353
.await
350354
{

cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ use cumulus_primitives_core::{
4141
use cumulus_relay_chain_interface::RelayChainInterface;
4242
use futures::prelude::*;
4343
use polkadot_primitives::{
44-
Block as RelayBlock, CoreIndex, Hash as RelayHash, Header as RelayHeader, Id as ParaId,
44+
ApprovedPeerId, Block as RelayBlock, CoreIndex, Hash as RelayHash, Header as RelayHeader,
45+
Id as ParaId,
4546
};
4647
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider};
4748
use sc_consensus::BlockImport;
@@ -84,6 +85,8 @@ pub struct BuilderTaskParams<
8485
pub code_hash_provider: CHP,
8586
/// The underlying keystore, which should contain Aura consensus keys.
8687
pub keystore: KeystorePtr,
88+
/// The collator network peer id.
89+
pub collator_peer_id: ApprovedPeerId,
8790
/// The para's ID.
8891
pub para_id: ParaId,
8992
/// The underlying block proposer this should call into.
@@ -146,6 +149,7 @@ where
146149
para_client,
147150
keystore,
148151
block_import,
152+
collator_peer_id,
149153
para_id,
150154
proposer,
151155
collator_service,
@@ -170,6 +174,7 @@ where
170174
block_import,
171175
relay_client: relay_client.clone(),
172176
keystore: keystore.clone(),
177+
collator_peer_id: collator_peer_id.clone(),
173178
para_id,
174179
proposer,
175180
collator_service,
@@ -350,6 +355,7 @@ where
350355
parent_hash,
351356
slot_claim.timestamp(),
352357
Some(rp_data),
358+
collator_peer_id.clone(),
353359
)
354360
.await
355361
{

cumulus/client/consensus/aura/src/collators/slot_based/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use cumulus_primitives_core::RelayParentOffsetApi;
7878
use cumulus_relay_chain_interface::RelayChainInterface;
7979
use futures::FutureExt;
8080
use polkadot_primitives::{
81-
CollatorPair, CoreIndex, Hash as RelayHash, Id as ParaId, ValidationCodeHash,
81+
ApprovedPeerId, CollatorPair, CoreIndex, Hash as RelayHash, Id as ParaId, ValidationCodeHash,
8282
};
8383
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider};
8484
use sc_consensus::BlockImport;
@@ -122,6 +122,8 @@ pub struct Params<Block, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS,
122122
pub keystore: KeystorePtr,
123123
/// The collator key used to sign collations before submitting to validators.
124124
pub collator_key: CollatorPair,
125+
/// The collator network peer id.
126+
pub collator_peer_id: ApprovedPeerId,
125127
/// The para's ID.
126128
pub para_id: ParaId,
127129
/// The underlying block proposer this should call into.
@@ -186,6 +188,7 @@ pub fn run<Block, P, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS, Spaw
186188
code_hash_provider,
187189
keystore,
188190
collator_key,
191+
collator_peer_id,
189192
para_id,
190193
proposer,
191194
collator_service,
@@ -221,6 +224,7 @@ pub fn run<Block, P, BI, CIDP, Client, Backend, RClient, CHP, Proposer, CS, Spaw
221224
relay_client,
222225
code_hash_provider,
223226
keystore,
227+
collator_peer_id,
224228
para_id,
225229
proposer,
226230
collator_service,

cumulus/client/parachain-inherent/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use cumulus_relay_chain_interface::RelayChainInterface;
2525

2626
mod mock;
2727

28-
use cumulus_primitives_core::relay_chain::Header as RelayHeader;
28+
use cumulus_primitives_core::relay_chain::{ApprovedPeerId, Header as RelayHeader};
2929
pub use cumulus_primitives_parachain_inherent::{ParachainInherentData, INHERENT_IDENTIFIER};
3030
pub use mock::{MockValidationDataInherentDataProvider, MockXcmConfig};
3131

@@ -168,6 +168,7 @@ impl ParachainInherentDataProvider {
168168
para_id: ParaId,
169169
relay_parent_descendants: Vec<RelayHeader>,
170170
additional_relay_state_keys: Vec<Vec<u8>>,
171+
collator_peer_id: ApprovedPeerId,
171172
) -> Option<ParachainInherentData> {
172173
// Only include next epoch authorities when the descendants include an epoch digest.
173174
// Skip the first entry because this is the relay parent itself.
@@ -218,7 +219,7 @@ impl ParachainInherentDataProvider {
218219
validation_data: validation_data.clone(),
219220
relay_chain_state,
220221
relay_parent_descendants,
221-
collator_peer_id: None,
222+
collator_peer_id: Some(collator_peer_id),
222223
})
223224
}
224225
}

cumulus/polkadot-omni-node/lib/src/common/spec.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ use prometheus_endpoint::Registry;
4545
use sc_client_api::Backend;
4646
use sc_consensus::DefaultImportQueue;
4747
use sc_executor::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_STRATEGY};
48-
use sc_network::{config::FullNetworkConfiguration, NetworkBackend, NetworkBlock};
48+
use sc_network::{
49+
config::FullNetworkConfiguration, NetworkBackend, NetworkBlock, NetworkStateInfo, PeerId,
50+
};
4951
use sc_service::{Configuration, ImportQueue, PartialComponents, TaskManager};
5052
use sc_statement_store::Store;
5153
use sc_sysinfo::HwBench;
@@ -89,6 +91,7 @@ where
8991
relay_chain_slot_duration: Duration,
9092
para_id: ParaId,
9193
collator_key: CollatorPair,
94+
collator_peer_id: PeerId,
9295
overseer_handle: OverseerHandle,
9396
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
9497
backend: Arc<ParachainBackend<Block>>,
@@ -380,6 +383,7 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
380383
metrics,
381384
})
382385
.await?;
386+
let peer_id = network.local_peer_id();
383387

384388
let statement_store = statement_handler_proto
385389
.map(|statement_handler_proto| {
@@ -536,6 +540,7 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
536540
relay_chain_slot_duration,
537541
para_id,
538542
collator_key.expect("Command line arguments do not allow this. qed"),
543+
peer_id,
539544
overseer_handle,
540545
announce_block,
541546
backend.clone(),

cumulus/polkadot-omni-node/lib/src/nodes/aura.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use cumulus_primitives_core::{
5454
};
5555
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};
5656
use futures::{prelude::*, FutureExt};
57-
use polkadot_primitives::{CollatorPair, UpgradeGoAhead};
57+
use polkadot_primitives::{unchecked_new_approved_peer_id, CollatorPair, UpgradeGoAhead};
5858
use prometheus_endpoint::Registry;
5959
use sc_client_api::{Backend, BlockchainEvents};
6060
use sc_client_db::DbHash;
@@ -63,7 +63,7 @@ use sc_consensus::{
6363
BlockImportParams, DefaultImportQueue, LongestChain,
6464
};
6565
use sc_consensus_manual_seal::consensus::aura::AuraConsensusDataProvider;
66-
use sc_network::{config::FullNetworkConfiguration, NotificationMetrics};
66+
use sc_network::{config::FullNetworkConfiguration, NotificationMetrics, PeerId};
6767
use sc_service::{Configuration, Error, PartialComponents, TaskManager};
6868
use sc_telemetry::TelemetryHandle;
6969
use sc_transaction_pool::TransactionPoolHandle;
@@ -564,6 +564,7 @@ where
564564
relay_chain_slot_duration: Duration,
565565
para_id: ParaId,
566566
collator_key: CollatorPair,
567+
collator_peer_id: PeerId,
567568
_overseer_handle: OverseerHandle,
568569
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
569570
backend: Arc<ParachainBackend<Block>>,
@@ -586,6 +587,7 @@ where
586587
);
587588

588589
let client_for_aura = client.clone();
590+
let collator_peer_id = unchecked_new_approved_peer_id(collator_peer_id.to_bytes());
589591
let params = SlotBasedParams {
590592
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
591593
block_import,
@@ -598,6 +600,7 @@ where
598600
},
599601
keystore,
600602
collator_key,
603+
collator_peer_id,
601604
para_id,
602605
proposer,
603606
collator_service,
@@ -688,20 +691,21 @@ where
688691
relay_chain_slot_duration: Duration,
689692
para_id: ParaId,
690693
collator_key: CollatorPair,
694+
collator_peer_id: PeerId,
691695
overseer_handle: OverseerHandle,
692696
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
693697
backend: Arc<ParachainBackend<Block>>,
694698
node_extra_args: NodeExtraArgs,
695699
_: (),
696700
) -> Result<(), Error> {
701+
let collator_peer_id = unchecked_new_approved_peer_id(collator_peer_id.to_bytes());
697702
let proposer = sc_basic_authorship::ProposerFactory::with_proof_recording(
698703
task_manager.spawn_handle(),
699704
client.clone(),
700705
transaction_pool,
701706
prometheus_registry,
702707
telemetry.clone(),
703708
);
704-
705709
let collator_service = CollatorService::new(
706710
client.clone(),
707711
Arc::new(task_manager.spawn_handle()),
@@ -725,6 +729,7 @@ where
725729
},
726730
keystore,
727731
collator_key,
732+
collator_peer_id,
728733
para_id,
729734
overseer_handle,
730735
relay_chain_slot_duration,

cumulus/test/service/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use cumulus_test_runtime::{Hash, NodeBlock as Block, RuntimeApi};
6565
use frame_system_rpc_runtime_api::AccountNonceApi;
6666
use polkadot_node_subsystem::{errors::RecoveryError, messages::AvailabilityRecoveryMessage};
6767
use polkadot_overseer::Handle as OverseerHandle;
68-
use polkadot_primitives::{CandidateHash, CollatorPair};
68+
use polkadot_primitives::{unchecked_new_approved_peer_id, CandidateHash, CollatorPair};
6969
use polkadot_service::ProvideRuntimeApi;
7070
use sc_consensus::ImportQueue;
7171
use sc_network::{
@@ -431,6 +431,8 @@ where
431431
prometheus_registry: None,
432432
})?;
433433

434+
let collator_peer_id = network.local_peer_id();
435+
let collator_peer_id = unchecked_new_approved_peer_id(collator_peer_id.to_bytes());
434436
if let Some(collator_key) = collator_key {
435437
let proposer = sc_basic_authorship::ProposerFactory::with_proof_recording(
436438
task_manager.spawn_handle(),
@@ -473,6 +475,7 @@ where
473475
spawner: task_manager.spawn_handle(),
474476
export_pov: None,
475477
max_pov_percentage: None,
478+
collator_peer_id,
476479
};
477480

478481
slot_based::run::<Block, AuthorityPair, _, _, _, _, _, _, _, _, _>(params);
@@ -489,6 +492,7 @@ where
489492
},
490493
keystore,
491494
collator_key,
495+
collator_peer_id,
492496
para_id,
493497
overseer_handle,
494498
relay_chain_slot_duration,

0 commit comments

Comments
 (0)