18
18
19
19
//! Module implementing the logic for verifying and importing AuRa blocks.
20
20
21
- use crate :: { aura_err, authorities, find_pre_digest, slot_author, AuthorityId , Error } ;
21
+ use crate :: {
22
+ aura_err, authorities, find_pre_digest, slot_author, AuthorityId , CompatibilityMode , Error ,
23
+ } ;
22
24
use codec:: { Codec , Decode , Encode } ;
23
25
use log:: { debug, info, trace} ;
24
26
use prometheus_endpoint:: Registry ;
@@ -31,21 +33,15 @@ use sc_consensus_slots::{check_equivocation, CheckedHeader, InherentDataProvider
31
33
use sc_telemetry:: { telemetry, TelemetryHandle , CONSENSUS_DEBUG , CONSENSUS_TRACE } ;
32
34
use sp_api:: { ApiExt , ProvideRuntimeApi } ;
33
35
use sp_block_builder:: BlockBuilder as BlockBuilderApi ;
34
- use sp_blockchain:: {
35
- well_known_cache_keys:: { self , Id as CacheKeyId } ,
36
- HeaderBackend ,
37
- } ;
36
+ use sp_blockchain:: { well_known_cache_keys:: Id as CacheKeyId , HeaderBackend } ;
38
37
use sp_consensus:: Error as ConsensusError ;
39
- use sp_consensus_aura:: {
40
- digests:: CompatibleDigestItem , inherents:: AuraInherentData , AuraApi , ConsensusLog ,
41
- AURA_ENGINE_ID ,
42
- } ;
38
+ use sp_consensus_aura:: { digests:: CompatibleDigestItem , inherents:: AuraInherentData , AuraApi } ;
43
39
use sp_consensus_slots:: Slot ;
44
40
use sp_core:: { crypto:: Pair , ExecutionContext } ;
45
41
use sp_inherents:: { CreateInherentDataProviders , InherentDataProvider as _} ;
46
42
use sp_runtime:: {
47
- generic:: { BlockId , OpaqueDigestItemId } ,
48
- traits:: { Block as BlockT , Header } ,
43
+ generic:: BlockId ,
44
+ traits:: { Block as BlockT , Header , NumberFor } ,
49
45
DigestItem ,
50
46
} ;
51
47
use std:: { fmt:: Debug , hash:: Hash , marker:: PhantomData , sync:: Arc } ;
@@ -109,32 +105,35 @@ where
109
105
}
110
106
111
107
/// A verifier for Aura blocks.
112
- pub struct AuraVerifier < C , P , CIDP > {
108
+ pub struct AuraVerifier < C , P , CIDP , N > {
113
109
client : Arc < C > ,
114
110
phantom : PhantomData < P > ,
115
111
create_inherent_data_providers : CIDP ,
116
112
check_for_equivocation : CheckForEquivocation ,
117
113
telemetry : Option < TelemetryHandle > ,
114
+ compatibility_mode : CompatibilityMode < N > ,
118
115
}
119
116
120
- impl < C , P , CIDP > AuraVerifier < C , P , CIDP > {
117
+ impl < C , P , CIDP , N > AuraVerifier < C , P , CIDP , N > {
121
118
pub ( crate ) fn new (
122
119
client : Arc < C > ,
123
120
create_inherent_data_providers : CIDP ,
124
121
check_for_equivocation : CheckForEquivocation ,
125
122
telemetry : Option < TelemetryHandle > ,
123
+ compatibility_mode : CompatibilityMode < N > ,
126
124
) -> Self {
127
125
Self {
128
126
client,
129
127
create_inherent_data_providers,
130
128
check_for_equivocation,
131
129
telemetry,
130
+ compatibility_mode,
132
131
phantom : PhantomData ,
133
132
}
134
133
}
135
134
}
136
135
137
- impl < C , P , CIDP > AuraVerifier < C , P , CIDP >
136
+ impl < C , P , CIDP , N > AuraVerifier < C , P , CIDP , N >
138
137
where
139
138
P : Send + Sync + ' static ,
140
139
CIDP : Send ,
@@ -172,9 +171,9 @@ where
172
171
}
173
172
174
173
#[ async_trait:: async_trait]
175
- impl < B : BlockT , C , P , CIDP > Verifier < B > for AuraVerifier < C , P , CIDP >
174
+ impl < B : BlockT , C , P , CIDP > Verifier < B > for AuraVerifier < C , P , CIDP , NumberFor < B > >
176
175
where
177
- C : ProvideRuntimeApi < B > + Send + Sync + sc_client_api:: backend:: AuxStore + BlockOf ,
176
+ C : ProvideRuntimeApi < B > + Send + Sync + sc_client_api:: backend:: AuxStore ,
178
177
C :: Api : BlockBuilderApi < B > + AuraApi < B , AuthorityId < P > > + ApiExt < B > ,
179
178
P : Pair + Send + Sync + ' static ,
180
179
P :: Public : Send + Sync + Hash + Eq + Clone + Decode + Encode + Debug + ' static ,
@@ -188,8 +187,13 @@ where
188
187
) -> Result < ( BlockImportParams < B , ( ) > , Option < Vec < ( CacheKeyId , Vec < u8 > ) > > ) , String > {
189
188
let hash = block. header . hash ( ) ;
190
189
let parent_hash = * block. header . parent_hash ( ) ;
191
- let authorities = authorities ( self . client . as_ref ( ) , & BlockId :: Hash ( parent_hash) )
192
- . map_err ( |e| format ! ( "Could not fetch authorities at {:?}: {}" , parent_hash, e) ) ?;
190
+ let authorities = authorities (
191
+ self . client . as_ref ( ) ,
192
+ parent_hash,
193
+ * block. header . number ( ) ,
194
+ & self . compatibility_mode ,
195
+ )
196
+ . map_err ( |e| format ! ( "Could not fetch authorities at {:?}: {}" , parent_hash, e) ) ?;
193
197
194
198
let create_inherent_data_providers = self
195
199
. create_inherent_data_providers
@@ -259,28 +263,12 @@ where
259
263
"pre_header" => ?pre_header,
260
264
) ;
261
265
262
- // Look for an authorities-change log.
263
- let maybe_keys = pre_header
264
- . digest ( )
265
- . logs ( )
266
- . iter ( )
267
- . filter_map ( |l| {
268
- l. try_to :: < ConsensusLog < AuthorityId < P > > > ( OpaqueDigestItemId :: Consensus (
269
- & AURA_ENGINE_ID ,
270
- ) )
271
- } )
272
- . find_map ( |l| match l {
273
- ConsensusLog :: AuthoritiesChange ( a) =>
274
- Some ( vec ! [ ( well_known_cache_keys:: AUTHORITIES , a. encode( ) ) ] ) ,
275
- _ => None ,
276
- } ) ;
277
-
278
266
block. header = pre_header;
279
267
block. post_digests . push ( seal) ;
280
268
block. fork_choice = Some ( ForkChoiceStrategy :: LongestChain ) ;
281
269
block. post_hash = Some ( hash) ;
282
270
283
- Ok ( ( block, maybe_keys ) )
271
+ Ok ( ( block, None ) )
284
272
} ,
285
273
CheckedHeader :: Deferred ( a, b) => {
286
274
debug ! ( target: "aura" , "Checking {:?} failed; {:?}, {:?}." , hash, a, b) ;
@@ -323,7 +311,7 @@ impl Default for CheckForEquivocation {
323
311
}
324
312
325
313
/// Parameters of [`import_queue`].
326
- pub struct ImportQueueParams < ' a , Block , I , C , S , CIDP > {
314
+ pub struct ImportQueueParams < ' a , Block : BlockT , I , C , S , CIDP > {
327
315
/// The block import to use.
328
316
pub block_import : I ,
329
317
/// The justification import.
@@ -340,6 +328,10 @@ pub struct ImportQueueParams<'a, Block, I, C, S, CIDP> {
340
328
pub check_for_equivocation : CheckForEquivocation ,
341
329
/// Telemetry instance used to report telemetry metrics.
342
330
pub telemetry : Option < TelemetryHandle > ,
331
+ /// Compatibility mode that should be used.
332
+ ///
333
+ /// If in doubt, use `Default::default()`.
334
+ pub compatibility_mode : CompatibilityMode < NumberFor < Block > > ,
343
335
}
344
336
345
337
/// Start an import queue for the Aura consensus algorithm.
@@ -353,6 +345,7 @@ pub fn import_queue<P, Block, I, C, S, CIDP>(
353
345
registry,
354
346
check_for_equivocation,
355
347
telemetry,
348
+ compatibility_mode,
356
349
} : ImportQueueParams < Block , I , C , S , CIDP > ,
357
350
) -> Result < DefaultImportQueue < Block , C > , sp_consensus:: Error >
358
351
where
@@ -377,18 +370,19 @@ where
377
370
CIDP : CreateInherentDataProviders < Block , ( ) > + Sync + Send + ' static ,
378
371
CIDP :: InherentDataProviders : InherentDataProviderExt + Send + Sync ,
379
372
{
380
- let verifier = build_verifier :: < P , _ , _ > ( BuildVerifierParams {
373
+ let verifier = build_verifier :: < P , _ , _ , _ > ( BuildVerifierParams {
381
374
client,
382
375
create_inherent_data_providers,
383
376
check_for_equivocation,
384
377
telemetry,
378
+ compatibility_mode,
385
379
} ) ;
386
380
387
381
Ok ( BasicQueue :: new ( verifier, Box :: new ( block_import) , justification_import, spawner, registry) )
388
382
}
389
383
390
384
/// Parameters of [`build_verifier`].
391
- pub struct BuildVerifierParams < C , CIDP > {
385
+ pub struct BuildVerifierParams < C , CIDP , N > {
392
386
/// The client to interact with the chain.
393
387
pub client : Arc < C > ,
394
388
/// Something that can create the inherent data providers.
@@ -397,21 +391,27 @@ pub struct BuildVerifierParams<C, CIDP> {
397
391
pub check_for_equivocation : CheckForEquivocation ,
398
392
/// Telemetry instance used to report telemetry metrics.
399
393
pub telemetry : Option < TelemetryHandle > ,
394
+ /// Compatibility mode that should be used.
395
+ ///
396
+ /// If in doubt, use `Default::default()`.
397
+ pub compatibility_mode : CompatibilityMode < N > ,
400
398
}
401
399
402
400
/// Build the [`AuraVerifier`]
403
- pub fn build_verifier < P , C , CIDP > (
401
+ pub fn build_verifier < P , C , CIDP , N > (
404
402
BuildVerifierParams {
405
403
client,
406
404
create_inherent_data_providers,
407
405
check_for_equivocation,
408
406
telemetry,
409
- } : BuildVerifierParams < C , CIDP > ,
410
- ) -> AuraVerifier < C , P , CIDP > {
411
- AuraVerifier :: < _ , P , _ > :: new (
407
+ compatibility_mode,
408
+ } : BuildVerifierParams < C , CIDP , N > ,
409
+ ) -> AuraVerifier < C , P , CIDP , N > {
410
+ AuraVerifier :: < _ , P , _ , _ > :: new (
412
411
client,
413
412
create_inherent_data_providers,
414
413
check_for_equivocation,
415
414
telemetry,
415
+ compatibility_mode,
416
416
)
417
417
}
0 commit comments