Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit c6f272d

Browse files
committed
fmt
1 parent 3397395 commit c6f272d

File tree

6 files changed

+113
-100
lines changed

6 files changed

+113
-100
lines changed

client/collator/src/service.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ pub trait ServiceInterface<Block: BlockT> {
6969
) -> oneshot::Sender<CollationSecondedSignal>;
7070

7171
/// Directly announce a block on the network.
72-
fn announce_block(
73-
&self,
74-
block_hash: Block::Hash,
75-
data: Option<Vec<u8>>,
76-
);
72+
fn announce_block(&self, block_hash: Block::Hash, data: Option<Vec<u8>>);
7773
}
7874

7975
/// The [`CollatorService`] provides common utilities for parachain consensus and authoring.
@@ -113,7 +109,8 @@ where
113109
announce_block: Arc<dyn Fn(Block::Hash, Option<Vec<u8>>) + Send + Sync>,
114110
runtime_api: Arc<RA>,
115111
) -> Self {
116-
let wait_to_announce = Arc::new(Mutex::new(WaitToAnnounce::new(spawner, announce_block.clone())));
112+
let wait_to_announce =
113+
Arc::new(Mutex::new(WaitToAnnounce::new(spawner, announce_block.clone())));
117114

118115
Self { block_status, wait_to_announce, announce_block, runtime_api }
119116
}
@@ -328,11 +325,7 @@ where
328325
CollatorService::announce_with_barrier(self, block_hash)
329326
}
330327

331-
fn announce_block(
332-
&self,
333-
block_hash: Block::Hash,
334-
data: Option<Vec<u8>>,
335-
) {
328+
fn announce_block(&self, block_hash: Block::Hash, data: Option<Vec<u8>>) {
336329
(self.announce_block)(block_hash, data)
337330
}
338331
}

client/consensus/aura/src/collator.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
2727
use codec::{Decode, Encode};
2828
use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface;
29-
use cumulus_client_consensus_common::{self as consensus_common, ParachainBlockImportMarker, ParachainCandidate};
29+
use cumulus_client_consensus_common::{
30+
self as consensus_common, ParachainBlockImportMarker, ParachainCandidate,
31+
};
3032
use cumulus_client_consensus_proposer::ProposerInterface;
3133
use cumulus_primitives_core::{
3234
relay_chain::Hash as PHash, DigestItem, ParachainBlockData, PersistedValidationData,
@@ -253,16 +255,13 @@ impl<Pub> SlotClaim<Pub> {
253255
///
254256
/// This does not check whether the author actually owns the slot or the timestamp
255257
/// falls within the slot.
256-
pub fn unchecked<P>(author_pub: Pub, slot: Slot, timestamp: Timestamp) -> Self where
258+
pub fn unchecked<P>(author_pub: Pub, slot: Slot, timestamp: Timestamp) -> Self
259+
where
257260
P: Pair<Public = Pub>,
258261
P::Public: Encode + Decode,
259-
P::Signature: Encode + Decode
262+
P::Signature: Encode + Decode,
260263
{
261-
SlotClaim {
262-
author_pub,
263-
timestamp,
264-
pre_digest: aura_internal::pre_digest::<P>(slot),
265-
}
264+
SlotClaim { author_pub, timestamp, pre_digest: aura_internal::pre_digest::<P>(slot) }
266265
}
267266

268267
/// Get the author's public key.

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,30 +181,34 @@ pub async fn run<Block, P, BI, CIDP, Client, RClient, SO, Proposer, CS>(
181181
};
182182

183183
let (parachain_inherent_data, other_inherent_data) = try_request!(
184-
collator.create_inherent_data(
185-
*request.relay_parent(),
186-
&validation_data,
187-
parent_hash,
188-
claim.timestamp(),
189-
).await
184+
collator
185+
.create_inherent_data(
186+
*request.relay_parent(),
187+
&validation_data,
188+
parent_hash,
189+
claim.timestamp(),
190+
)
191+
.await
190192
);
191193

192194
let (collation, _, post_hash) = try_request!(
193-
collator.collate(
194-
&parent_header,
195-
&claim,
196-
None,
197-
(parachain_inherent_data, other_inherent_data),
198-
// TODO [https://github.com/paritytech/cumulus/issues/2439]
199-
// We should call out to a pluggable interface that provides
200-
// the proposal duration.
201-
Duration::from_millis(500),
202-
// Set the block limit to 50% of the maximum PoV size.
203-
//
204-
// TODO: If we got benchmarking that includes the proof size,
205-
// we should be able to use the maximum pov size.
206-
(validation_data.max_pov_size / 2) as usize,
207-
).await
195+
collator
196+
.collate(
197+
&parent_header,
198+
&claim,
199+
None,
200+
(parachain_inherent_data, other_inherent_data),
201+
// TODO [https://github.com/paritytech/cumulus/issues/2439]
202+
// We should call out to a pluggable interface that provides
203+
// the proposal duration.
204+
Duration::from_millis(500),
205+
// Set the block limit to 50% of the maximum PoV size.
206+
//
207+
// TODO: If we got benchmarking that includes the proof size,
208+
// we should be able to use the maximum pov size.
209+
(validation_data.max_pov_size / 2) as usize,
210+
)
211+
.await
208212
);
209213

210214
let result_sender = Some(collator.collator_service().announce_with_barrier(post_hash));

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

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
use codec::{Decode, Encode};
3535
use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface;
3636
use cumulus_client_consensus_common::{
37-
self as consensus_common,
38-
ParachainBlockImportMarker, ParachainCandidate, ParentSearchParams,
37+
self as consensus_common, ParachainBlockImportMarker, ParachainCandidate, ParentSearchParams,
3938
};
4039
use cumulus_client_consensus_proposer::ProposerInterface;
4140
use cumulus_primitives_core::{
@@ -46,7 +45,9 @@ use cumulus_relay_chain_interface::RelayChainInterface;
4645

4746
use polkadot_node_primitives::{CollationResult, MaybeCompressedPoV};
4847
use polkadot_overseer::Handle as OverseerHandle;
49-
use polkadot_primitives::{Block as PBlock, CollatorPair, Header as PHeader, Id as ParaId, OccupiedCoreAssumption};
48+
use polkadot_primitives::{
49+
Block as PBlock, CollatorPair, Header as PHeader, Id as ParaId, OccupiedCoreAssumption,
50+
};
5051

5152
use futures::prelude::*;
5253
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf};
@@ -163,17 +164,21 @@ pub async fn run<Block, P, BI, CIDP, Client, Backend, RClient, SO, Proposer, CS>
163164
// TODO [now]: get asynchronous backing parameters from the relay-chain
164165
// runtime. why? for the parent search parameters.
165166

166-
let max_pov_size = match params.relay_client.persisted_validation_data(
167-
relay_parent,
168-
params.para_id,
169-
OccupiedCoreAssumption::Included,
170-
).await {
167+
let max_pov_size = match params
168+
.relay_client
169+
.persisted_validation_data(
170+
relay_parent,
171+
params.para_id,
172+
OccupiedCoreAssumption::Included,
173+
)
174+
.await
175+
{
171176
Ok(None) => continue,
172177
Ok(Some(pvd)) => pvd.max_pov_size,
173178
Err(err) => {
174179
tracing::error!(target: crate::LOG_TARGET, ?err, "Failed to gather information from relay-client");
175-
continue;
176-
}
180+
continue
181+
},
177182
};
178183

179184
let (slot_now, timestamp) = match consensus_common::relay_slot_and_timestamp(
@@ -220,14 +225,16 @@ pub async fn run<Block, P, BI, CIDP, Client, Backend, RClient, SO, Proposer, CS>
220225

221226
let para_client = &*params.para_client;
222227
let keystore = &params.keystore;
223-
let can_build_upon = |block_hash| can_build_upon::<_, _, P>(
224-
slot_now,
225-
timestamp,
226-
block_hash,
227-
included_block,
228-
para_client,
229-
&keystore,
230-
);
228+
let can_build_upon = |block_hash| {
229+
can_build_upon::<_, _, P>(
230+
slot_now,
231+
timestamp,
232+
block_hash,
233+
included_block,
234+
para_client,
235+
&keystore,
236+
)
237+
};
231238

232239
// Sort by depth, ascending, to choose the longest chain.
233240
//
@@ -258,31 +265,37 @@ pub async fn run<Block, P, BI, CIDP, Client, Backend, RClient, SO, Proposer, CS>
258265

259266
// Build and announce collations recursively until
260267
// `can_build_upon` fails or building a collation fails.
261-
let (parachain_inherent_data, other_inherent_data) = match collator.create_inherent_data(
262-
relay_parent,
263-
&validation_data,
264-
parent_hash,
265-
slot_claim.timestamp(),
266-
).await {
268+
let (parachain_inherent_data, other_inherent_data) = match collator
269+
.create_inherent_data(
270+
relay_parent,
271+
&validation_data,
272+
parent_hash,
273+
slot_claim.timestamp(),
274+
)
275+
.await
276+
{
267277
Err(err) => {
268278
tracing::error!(target: crate::LOG_TARGET, ?err);
269-
break;
279+
break
270280
},
271281
Ok(x) => x,
272282
};
273283

274-
match collator.collate(
275-
&parent_header,
276-
&slot_claim,
277-
None,
278-
(parachain_inherent_data, other_inherent_data),
279-
params.authoring_duration,
280-
// Set the block limit to 50% of the maximum PoV size.
281-
//
282-
// TODO: If we got benchmarking that includes the proof size,
283-
// we should be able to use the maximum pov size.
284-
(validation_data.max_pov_size / 2) as usize,
285-
).await {
284+
match collator
285+
.collate(
286+
&parent_header,
287+
&slot_claim,
288+
None,
289+
(parachain_inherent_data, other_inherent_data),
290+
params.authoring_duration,
291+
// Set the block limit to 50% of the maximum PoV size.
292+
//
293+
// TODO: If we got benchmarking that includes the proof size,
294+
// we should be able to use the maximum pov size.
295+
(validation_data.max_pov_size / 2) as usize,
296+
)
297+
.await
298+
{
286299
Ok((collation, block_data, new_block_hash)) => {
287300
parent_hash = new_block_hash;
288301
parent_header = block_data.into_header();
@@ -293,11 +306,11 @@ pub async fn run<Block, P, BI, CIDP, Client, Backend, RClient, SO, Proposer, CS>
293306

294307
// TODO [https://github.com/paritytech/polkadot/issues/5056]:
295308
// announce collation to relay-chain validators.
296-
}
309+
},
297310
Err(err) => {
298311
tracing::error!(target: crate::LOG_TARGET, ?err);
299-
break;
300-
}
312+
break
313+
},
301314
}
302315
}
303316
}

client/consensus/common/src/lib.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use codec::Decode;
18-
use polkadot_primitives::{Block as PBlock, Hash as PHash, Header as PHeader, PersistedValidationData};
18+
use polkadot_primitives::{
19+
Block as PBlock, Hash as PHash, Header as PHeader, PersistedValidationData,
20+
};
1921

2022
use cumulus_primitives_core::{relay_chain::OccupiedCoreAssumption, ParaId};
2123
use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface};
2224

2325
use sc_client_api::Backend;
2426
use sc_consensus::{shared_data::SharedData, BlockImport, ImportResult};
2527
use sp_consensus_slots::{Slot, SlotDuration};
26-
use sp_timestamp::Timestamp;
2728
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
29+
use sp_timestamp::Timestamp;
2830

2931
use std::sync::Arc;
3032

@@ -358,10 +360,12 @@ pub fn relay_slot_and_timestamp(
358360
relay_parent_header: &PHeader,
359361
relay_chain_slot_duration: SlotDuration,
360362
) -> Option<(Slot, Timestamp)> {
361-
sc_consensus_babe::find_pre_digest::<PBlock>(relay_parent_header).map(|babe_pre_digest| {
362-
let slot = babe_pre_digest.slot();
363-
let t = Timestamp::new(relay_chain_slot_duration.as_millis() * *slot);
364-
365-
(slot, t)
366-
}).ok()
363+
sc_consensus_babe::find_pre_digest::<PBlock>(relay_parent_header)
364+
.map(|babe_pre_digest| {
365+
let slot = babe_pre_digest.slot();
366+
let t = Timestamp::new(relay_chain_slot_duration.as_millis() * *slot);
367+
368+
(slot, t)
369+
})
370+
.ok()
367371
}

client/network/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,13 @@ impl BlockAnnounceData {
8989
///
9090
/// This will not check the signature, for this you should use [`BlockAnnounceData::check_signature`].
9191
fn validate(&self, encoded_header: Vec<u8>) -> Result<(), Validation> {
92-
let candidate_hash = if let CompactStatement::Seconded(h) =
93-
self.statement.unchecked_payload()
94-
{
95-
h
96-
} else {
97-
tracing::debug!(target: LOG_TARGET, "`CompactStatement` isn't the candidate variant!",);
98-
return Err(Validation::Failure { disconnect: true })
99-
};
92+
let candidate_hash =
93+
if let CompactStatement::Seconded(h) = self.statement.unchecked_payload() {
94+
h
95+
} else {
96+
tracing::debug!(target: LOG_TARGET, "`CompactStatement` isn't the candidate variant!",);
97+
return Err(Validation::Failure { disconnect: true })
98+
};
10099

101100
if *candidate_hash != self.receipt.hash() {
102101
tracing::debug!(
@@ -188,7 +187,8 @@ impl TryFrom<&'_ CollationSecondedSignal> for BlockAnnounceData {
188187

189188
/// A type alias for the [`RequireSecondedInBlockAnnounce`] validator.
190189
#[deprecated = "This has been renamed to RequireSecondedInBlockAnnounce"]
191-
pub type BlockAnnounceValidator<Block, RCInterface> = RequireSecondedInBlockAnnounce<Block, RCInterface>;
190+
pub type BlockAnnounceValidator<Block, RCInterface> =
191+
RequireSecondedInBlockAnnounce<Block, RCInterface>;
192192

193193
/// Parachain specific block announce validator.
194194
///
@@ -342,9 +342,9 @@ where
342342
let relay_chain_is_syncing = relay_chain_interface
343343
.is_major_syncing()
344344
.await
345-
.map_err(|e| {
346-
tracing::error!(target: LOG_TARGET, "Unable to determine sync status. {}", e)
347-
})
345+
.map_err(
346+
|e| tracing::error!(target: LOG_TARGET, "Unable to determine sync status. {}", e),
347+
)
348348
.unwrap_or(false);
349349

350350
if relay_chain_is_syncing {

0 commit comments

Comments
 (0)