@@ -442,15 +442,30 @@ where
442
442
// The block is initialized inside "trace_block"
443
443
api. trace_block ( parent_block_hash, exts, eth_tx_hashes, & header)
444
444
} else {
445
- // Pre pallet-message-queue
445
+ // Get core runtime api version
446
+ let core_api_version = if let Ok ( Some ( api_version) ) =
447
+ api. api_version :: < dyn Core < B > > ( parent_block_hash)
448
+ {
449
+ api_version
450
+ } else {
451
+ return Err ( internal_err (
452
+ "Runtime api version call failed (core)" . to_string ( ) ,
453
+ ) ) ;
454
+ } ;
446
455
447
456
// Initialize block: calls the "on_initialize" hook on every pallet
448
457
// in AllPalletsWithSystem
449
458
// This was fine before pallet-message-queue because the XCM messages
450
459
// were processed by the "setValidationData" inherent call and not on an
451
460
// "on_initialize" hook, which runs before enabling XCM tracing
452
- api. initialize_block ( parent_block_hash, & header)
453
- . map_err ( |e| internal_err ( format ! ( "Runtime api access error: {:?}" , e) ) ) ?;
461
+ if core_api_version >= 5 {
462
+ api. initialize_block ( parent_block_hash, & header)
463
+ . map_err ( |e| internal_err ( format ! ( "Runtime api access error: {:?}" , e) ) ) ?;
464
+ } else {
465
+ #[ allow( deprecated) ]
466
+ api. initialize_block_before_version_5 ( parent_block_hash, & header)
467
+ . map_err ( |e| internal_err ( format ! ( "Runtime api access error: {:?}" , e) ) ) ?;
468
+ }
454
469
455
470
#[ allow( deprecated) ]
456
471
api. trace_block_before_version_5 ( parent_block_hash, exts, eth_tx_hashes)
@@ -583,15 +598,34 @@ where
583
598
// The block is initialized inside "trace_transaction"
584
599
api. trace_transaction ( parent_block_hash, exts, & transaction, & header)
585
600
} else {
601
+ // Get core runtime api version
602
+ let core_api_version = if let Ok ( Some ( api_version) ) =
603
+ api. api_version :: < dyn Core < B > > ( parent_block_hash)
604
+ {
605
+ api_version
606
+ } else {
607
+ return Err ( internal_err (
608
+ "Runtime api version call failed (core)" . to_string ( ) ,
609
+ ) ) ;
610
+ } ;
611
+
586
612
// Initialize block: calls the "on_initialize" hook on every pallet
587
613
// in AllPalletsWithSystem
588
614
// This was fine before pallet-message-queue because the XCM messages
589
615
// were processed by the "setValidationData" inherent call and not on an
590
616
// "on_initialize" hook, which runs before enabling XCM tracing
591
- api. initialize_block ( parent_block_hash, & header)
592
- . map_err ( |e| {
593
- internal_err ( format ! ( "Runtime api access error: {:?}" , e) )
594
- } ) ?;
617
+ if core_api_version >= 5 {
618
+ api. initialize_block ( parent_block_hash, & header)
619
+ . map_err ( |e| {
620
+ internal_err ( format ! ( "Runtime api access error: {:?}" , e) )
621
+ } ) ?;
622
+ } else {
623
+ #[ allow( deprecated) ]
624
+ api. initialize_block_before_version_5 ( parent_block_hash, & header)
625
+ . map_err ( |e| {
626
+ internal_err ( format ! ( "Runtime api access error: {:?}" , e) )
627
+ } ) ?;
628
+ }
595
629
596
630
if trace_api_version == 4 {
597
631
// Pre pallet-message-queue
0 commit comments