@@ -263,6 +263,57 @@ pub fn kusama_new_full(config: Configuration)
263
263
new_full ( config)
264
264
}
265
265
266
+ pub fn kusama_chain_hotfix < Runtime , Dispatch > ( config : & Configuration ) where
267
+ Dispatch : NativeExecutionDispatch ,
268
+ Runtime : Send + Sync ,
269
+ {
270
+ use std:: str:: FromStr ;
271
+ use sp_blockchain:: HeaderBackend ;
272
+
273
+ let client: service:: TFullClient < Block , Runtime , Dispatch > =
274
+ service:: new_full_client ( & config) . unwrap ( ) ;
275
+
276
+ let fork_block = 516510 ; // target_block - reverted_blocks + 1;
277
+ let fork_hash = primitives:: H256 :: from_str (
278
+ "15b1b925b0aa5cfe43c88cd024f74258cb5cfe3af424882c901014e8acd0d241" ,
279
+ ) . unwrap ( ) ;
280
+
281
+ let best_number = client. info ( ) . best_number ;
282
+ let target_hash = client. hash ( fork_block) . unwrap ( ) ;
283
+
284
+ if target_hash == Some ( fork_hash) {
285
+ let diff = best_number. saturating_sub ( fork_block - 1 ) ;
286
+ client. unsafe_revert ( diff) . unwrap ( ) ;
287
+ }
288
+ }
289
+
290
+ pub fn kusama_grandpa_hotfix < Runtime , Dispatch > (
291
+ client : & service:: TFullClient < Block , Runtime , Dispatch > ,
292
+ persistent_data : & mut grandpa:: PersistentData < Block > ,
293
+ ) where
294
+ Dispatch : NativeExecutionDispatch ,
295
+ Runtime : Send + Sync ,
296
+ {
297
+ let authority_set = & persistent_data. authority_set ;
298
+
299
+ let finalized = {
300
+ use sp_blockchain:: HeaderBackend ;
301
+ let info = client. info ( ) ;
302
+ ( info. finalized_hash , info. finalized_number )
303
+ } ;
304
+
305
+ let canon_finalized_height = 516509 ;
306
+ if authority_set. set_id ( ) == 235 && finalized. 1 == canon_finalized_height {
307
+ let set_state = grandpa:: VoterSetState :: < Block > :: live (
308
+ authority_set. set_id ( ) ,
309
+ & authority_set. inner ( ) . read ( ) ,
310
+ finalized,
311
+ ) ;
312
+
313
+ persistent_data. set_state = set_state. into ( ) ;
314
+ }
315
+ }
316
+
266
317
/// Builds a new service for a full client.
267
318
pub fn new_full < Runtime , Dispatch , Extrinsic > ( config : Configuration )
268
319
-> Result < impl AbstractService <
@@ -315,7 +366,7 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
315
366
) ?
316
367
. build ( ) ?;
317
368
318
- let ( block_import, link_half, babe_link) = import_setup. take ( )
369
+ let ( block_import, mut link_half, babe_link) = import_setup. take ( )
319
370
. expect ( "Link Half and Block Import are present for Full Services or setup failed before. qed" ) ;
320
371
321
372
let client = service. client ( ) ;
@@ -411,7 +462,6 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
411
462
let can_author_with =
412
463
consensus_common:: CanAuthorWithNativeVersion :: new ( client. executor ( ) . clone ( ) ) ;
413
464
414
-
415
465
let block_import = availability_store. block_import (
416
466
block_import,
417
467
client. clone ( ) ,
@@ -477,6 +527,11 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
477
527
478
528
let enable_grandpa = !disable_grandpa;
479
529
if enable_grandpa {
530
+ kusama_grandpa_hotfix (
531
+ & client,
532
+ & mut link_half. persistent_data ,
533
+ ) ;
534
+
480
535
// start the full GRANDPA voter
481
536
// NOTE: unlike in substrate we are currently running the full
482
537
// GRANDPA voter protocol for all full nodes (regardless of whether
@@ -493,6 +548,7 @@ pub fn new_full<Runtime, Dispatch, Extrinsic>(config: Configuration)
493
548
voting_rule : grandpa:: VotingRulesBuilder :: default ( ) . build ( ) ,
494
549
executor : service. spawn_task_handle ( ) ,
495
550
} ;
551
+
496
552
service. spawn_essential_task ( grandpa:: run_grandpa_voter ( grandpa_config) ?) ;
497
553
} else {
498
554
grandpa:: setup_disabled_grandpa (
0 commit comments