@@ -43,9 +43,10 @@ use futures::FutureExt;
43
43
// darwinia
44
44
use dc_primitives:: * ;
45
45
// substrate
46
- use sc_client_api:: Backend ;
46
+ use sc_client_api:: { Backend , HeaderBackend } ;
47
47
use sc_consensus:: ImportQueue ;
48
48
use sc_network:: NetworkBlock ;
49
+ use sp_core:: Encode ;
49
50
50
51
/// Full client backend type.
51
52
type FullBackend = sc_service:: TFullBackend < Block > ;
@@ -94,7 +95,8 @@ impl IdentifyVariant for Box<dyn sc_service::ChainSpec> {
94
95
95
96
/// A set of APIs that darwinia-like runtimes must implement.
96
97
pub trait RuntimeApiCollection :
97
- cumulus_primitives_core:: CollectCollationInfo < Block >
98
+ cumulus_primitives_aura:: AuraUnincludedSegmentApi < Block >
99
+ + cumulus_primitives_core:: CollectCollationInfo < Block >
98
100
+ fp_rpc:: ConvertTransactionRuntimeApi < Block >
99
101
+ fp_rpc:: EthereumRuntimeRPCApi < Block >
100
102
+ moonbeam_rpc_primitives_debug:: DebugRuntimeApi < Block >
@@ -110,7 +112,8 @@ pub trait RuntimeApiCollection:
110
112
{
111
113
}
112
114
impl < Api > RuntimeApiCollection for Api where
113
- Api : cumulus_primitives_core:: CollectCollationInfo < Block >
115
+ Api : cumulus_primitives_aura:: AuraUnincludedSegmentApi < Block >
116
+ + cumulus_primitives_core:: CollectCollationInfo < Block >
114
117
+ fp_rpc:: ConvertTransactionRuntimeApi < Block >
115
118
+ fp_rpc:: EthereumRuntimeRPCApi < Block >
116
119
+ moonbeam_rpc_primitives_debug:: DebugRuntimeApi < Block >
@@ -261,6 +264,7 @@ where
261
264
Executor : ' static + sc_executor:: NativeExecutionDispatch ,
262
265
SC : FnOnce (
263
266
Arc < FullClient < RuntimeApi , Executor > > ,
267
+ Arc < FullBackend > ,
264
268
ParachainBlockImport < RuntimeApi , Executor > ,
265
269
Option < & substrate_prometheus_endpoint:: Registry > ,
266
270
Option < sc_telemetry:: TelemetryHandle > ,
@@ -296,7 +300,6 @@ where
296
300
telemetry_worker_handle,
297
301
) ,
298
302
} = new_partial :: < RuntimeApi , Executor > ( & parachain_config, eth_rpc_config) ?;
299
-
300
303
let ( relay_chain_interface, collator_key) =
301
304
cumulus_client_service:: build_relay_chain_interface (
302
305
polkadot_config,
@@ -308,12 +311,10 @@ where
308
311
)
309
312
. await
310
313
. map_err ( |e| sc_service:: Error :: Application ( Box :: new ( e) as Box < _ > ) ) ?;
311
-
312
314
let validator = parachain_config. role . is_authority ( ) ;
313
315
let prometheus_registry = parachain_config. prometheus_registry ( ) . cloned ( ) ;
314
316
let import_queue_service = import_queue. service ( ) ;
315
317
let net_config = sc_network:: config:: FullNetworkConfiguration :: new ( & parachain_config. network ) ;
316
-
317
318
let ( network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
318
319
cumulus_client_service:: build_network ( cumulus_client_service:: BuildNetworkParams {
319
320
parachain_config : & parachain_config,
@@ -521,6 +522,7 @@ where
521
522
if validator {
522
523
start_consensus (
523
524
client. clone ( ) ,
525
+ backend. clone ( ) ,
524
526
block_import,
525
527
prometheus_registry. as_ref ( ) ,
526
528
telemetry. as_ref ( ) . map ( |t| t. handle ( ) ) ,
@@ -614,6 +616,7 @@ where
614
616
cumulus_client_service:: CollatorSybilResistance :: Resistant , // Aura
615
617
para_id,
616
618
|client,
619
+ backend,
617
620
block_import,
618
621
prometheus_registry,
619
622
telemetry,
@@ -642,11 +645,17 @@ where
642
645
announce_block,
643
646
client. clone ( ) ,
644
647
) ;
645
- let params = cumulus_client_consensus_aura:: collators:: basic :: Params {
648
+ let params = cumulus_client_consensus_aura:: collators:: lookahead :: Params {
646
649
create_inherent_data_providers : move |_, ( ) | async move { Ok ( ( ) ) } ,
647
650
block_import,
648
- para_client : client,
651
+ para_client : client. clone ( ) ,
652
+ para_backend : backend. clone ( ) ,
649
653
relay_client : relay_chain_interface,
654
+ code_hash_provider : move |block_hash| {
655
+ client. code_at ( block_hash) . ok ( ) . map ( |c| {
656
+ cumulus_primitives_core:: relay_chain:: ValidationCode :: from ( c) . hash ( )
657
+ } )
658
+ } ,
650
659
sync_oracle,
651
660
keystore,
652
661
collator_key,
@@ -657,9 +666,9 @@ where
657
666
proposer,
658
667
collator_service,
659
668
// Very limited proposal time.
660
- authoring_duration : Duration :: from_millis ( 500 ) ,
669
+ authoring_duration : Duration :: from_millis ( 1_500 ) ,
661
670
} ;
662
- let fut = cumulus_client_consensus_aura:: collators:: basic :: run :: <
671
+ let fut = cumulus_client_consensus_aura:: collators:: lookahead :: run :: <
663
672
Block ,
664
673
sp_consensus_aura:: sr25519:: AuthorityPair ,
665
674
_ ,
@@ -669,6 +678,8 @@ where
669
678
_ ,
670
679
_ ,
671
680
_ ,
681
+ _ ,
682
+ _ ,
672
683
> ( params) ;
673
684
674
685
task_manager. spawn_essential_handle ( ) . spawn ( "aura" , None , fut) ;
@@ -685,21 +696,19 @@ where
685
696
/// !!! WARNING: DO NOT USE ELSEWHERE
686
697
pub fn start_dev_node < RuntimeApi , Executor > (
687
698
mut config : sc_service:: Configuration ,
699
+ para_id : cumulus_primitives_core:: ParaId ,
688
700
eth_rpc_config : & crate :: cli:: EthRpcConfig ,
689
701
) -> Result < sc_service:: TaskManager , sc_service:: error:: Error >
690
702
where
691
- RuntimeApi : sp_api :: ConstructRuntimeApi < Block , FullClient < RuntimeApi , Executor > >
703
+ RuntimeApi : ' static
692
704
+ Send
693
705
+ Sync
694
- + ' static ,
706
+ + sp_api :: ConstructRuntimeApi < Block , FullClient < RuntimeApi , Executor > > ,
695
707
RuntimeApi :: RuntimeApi : RuntimeApiCollection ,
696
708
RuntimeApi :: RuntimeApi :
697
709
sp_consensus_aura:: AuraApi < Block , sp_consensus_aura:: sr25519:: AuthorityId > ,
698
710
Executor : ' static + sc_executor:: NativeExecutionDispatch ,
699
711
{
700
- // substrate
701
- use sc_client_api:: HeaderBackend ;
702
-
703
712
let sc_service:: PartialComponents {
704
713
client,
705
714
backend,
@@ -720,7 +729,6 @@ where
720
729
) ,
721
730
} = new_partial :: < RuntimeApi , Executor > ( & config, eth_rpc_config) ?;
722
731
let net_config = sc_network:: config:: FullNetworkConfiguration :: new ( & config. network ) ;
723
-
724
732
let ( network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
725
733
sc_service:: build_network ( sc_service:: BuildNetworkParams {
726
734
config : & config,
@@ -757,17 +765,17 @@ where
757
765
}
758
766
759
767
let force_authoring = config. force_authoring ;
760
- let backoff_authoring_blocks: Option < ( ) > = None ;
768
+ let backoff_authoring_blocks = <Option < ( ) > >:: None ;
769
+ let slot_duration = sc_consensus_aura:: slot_duration ( & * client) ?;
761
770
let proposer_factory = sc_basic_authorship:: ProposerFactory :: new (
762
771
task_manager. spawn_handle ( ) ,
763
772
client. clone ( ) ,
764
773
transaction_pool. clone ( ) ,
765
774
None ,
766
775
None ,
767
776
) ;
768
-
769
- let slot_duration = sc_consensus_aura:: slot_duration ( & * client) ?;
770
777
let client_for_cidp = client. clone ( ) ;
778
+
771
779
if config. role . is_authority ( ) {
772
780
let aura = sc_consensus_aura:: start_aura :: <
773
781
sp_consensus_aura:: sr25519:: AuthorityPair ,
@@ -782,41 +790,54 @@ where
782
790
_ ,
783
791
_ ,
784
792
> ( sc_consensus_aura:: StartAuraParams {
785
- slot_duration : sc_consensus_aura :: slot_duration ( & * client ) ? ,
793
+ slot_duration,
786
794
client : client. clone ( ) ,
787
795
select_chain,
788
796
block_import : instant_finalize:: InstantFinalizeBlockImport :: new ( client. clone ( ) ) ,
789
797
proposer_factory,
790
798
create_inherent_data_providers : move |block : Hash , ( ) | {
791
- let current_para_block = client_for_cidp
792
- . number ( block)
793
- . expect ( "Header lookup should succeed" )
794
- . expect ( "Header passed in as parent should be present in backend." ) ;
799
+ let maybe_current_para_block = client_for_cidp. number ( block) ;
800
+ let maybe_current_block_head = client_for_cidp. expect_header ( block) ;
795
801
let client_for_xcm = client_for_cidp. clone ( ) ;
802
+ // TODO: hack for now.
803
+ let additional_key_values = Some ( vec ! [ (
804
+ array_bytes:: hex2bytes_unchecked(
805
+ "1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed" ,
806
+ ) ,
807
+ cumulus_primitives_aura:: Slot :: from_timestamp(
808
+ sp_timestamp:: Timestamp :: current( ) ,
809
+ slot_duration,
810
+ )
811
+ . encode( ) ,
812
+ ) ] ) ;
796
813
797
814
async move {
815
+ let current_para_block = maybe_current_para_block?
816
+ . ok_or ( sp_blockchain:: Error :: UnknownBlock ( block. to_string ( ) ) ) ?;
817
+ let current_para_block_head =
818
+ Some ( polkadot_primitives:: HeadData ( maybe_current_block_head?. encode ( ) ) ) ;
798
819
let timestamp = sp_timestamp:: InherentDataProvider :: from_system_time ( ) ;
799
-
800
820
let slot = sp_consensus_aura:: inherents:: InherentDataProvider :: from_timestamp_and_slot_duration (
801
821
* timestamp,
802
822
slot_duration,
803
823
) ;
804
-
805
824
let mocked_parachain =
806
825
cumulus_primitives_parachain_inherent:: MockValidationDataInherentDataProvider {
807
826
current_para_block,
827
+ current_para_block_head,
808
828
relay_offset : 1000 ,
809
829
relay_blocks_per_para_block : 2 ,
810
830
para_blocks_per_relay_epoch : 0 ,
811
831
relay_randomness_config : ( ) ,
812
832
xcm_config : cumulus_primitives_parachain_inherent:: MockXcmConfig :: new (
813
833
& * client_for_xcm,
814
834
block,
815
- Default :: default ( ) ,
835
+ para_id ,
816
836
Default :: default ( ) ,
817
837
) ,
818
838
raw_downward_messages : Vec :: new ( ) ,
819
839
raw_horizontal_messages : Vec :: new ( ) ,
840
+ additional_key_values,
820
841
} ;
821
842
822
843
Ok ( ( slot, timestamp, mocked_parachain) )
@@ -887,8 +908,6 @@ where
887
908
let collator = config. role . is_authority ( ) ;
888
909
let eth_rpc_config = eth_rpc_config. clone ( ) ;
889
910
let sync_service = sync_service. clone ( ) ;
890
-
891
- let slot_duration = sc_consensus_aura:: slot_duration ( & * client) ?;
892
911
let pending_create_inherent_data_providers = move |_, ( ) | async move {
893
912
let current = sp_timestamp:: InherentDataProvider :: from_system_time ( ) ;
894
913
let next_slot = current. timestamp ( ) . as_millis ( ) + slot_duration. as_millis ( ) ;
0 commit comments