@@ -80,8 +80,8 @@ use futures::{
8080
8181use error:: { Error , FatalResult } ;
8282use polkadot_node_primitives:: {
83- minimum_votes , AvailableData , InvalidCandidate , PoV , SignedFullStatementWithPVD ,
84- StatementWithPVD , ValidationResult ,
83+ AvailableData , InvalidCandidate , PoV , SignedFullStatementWithPVD , StatementWithPVD ,
84+ ValidationResult ,
8585} ;
8686use polkadot_node_subsystem:: {
8787 messages:: {
@@ -96,8 +96,7 @@ use polkadot_node_subsystem::{
9696use polkadot_node_subsystem_util:: {
9797 self as util,
9898 backing_implicit_view:: { FetchError as ImplicitViewFetchError , View as ImplicitView } ,
99- request_from_runtime, request_session_index_for_child, request_validator_groups,
100- request_validators,
99+ request_from_runtime, request_validator_groups, request_validators,
101100 runtime:: { prospective_parachains_mode, ProspectiveParachainsMode } ,
102101 Validator ,
103102} ;
@@ -116,6 +115,7 @@ use statement_table::{
116115 } ,
117116 Config as TableConfig , Context as TableContextTrait , Table ,
118117} ;
118+ use util:: runtime:: RuntimeInfo ;
119119
120120mod error;
121121
@@ -219,6 +219,8 @@ struct PerRelayParentState {
219219 awaiting_validation : HashSet < CandidateHash > ,
220220 /// Data needed for retrying in case of `ValidatedCandidateCommand::AttestNoPoV`.
221221 fallbacks : HashMap < CandidateHash , AttestingData > ,
222+ /// The minimum backing votes threshold.
223+ minimum_backing_votes : u32 ,
222224}
223225
224226struct PerCandidateState {
@@ -275,6 +277,8 @@ struct State {
275277 background_validation_tx : mpsc:: Sender < ( Hash , ValidatedCandidateCommand ) > ,
276278 /// The handle to the keystore used for signing.
277279 keystore : KeystorePtr ,
280+ /// The minimum backing votes threshold.
281+ runtime_info : RuntimeInfo ,
278282}
279283
280284impl State {
@@ -289,6 +293,7 @@ impl State {
289293 per_candidate : HashMap :: new ( ) ,
290294 background_validation_tx,
291295 keystore,
296+ runtime_info : RuntimeInfo :: new ( None ) ,
292297 }
293298 }
294299}
@@ -400,8 +405,8 @@ impl TableContextTrait for TableContext {
400405 self . groups . get ( group) . map_or ( false , |g| g. iter ( ) . any ( |a| a == authority) )
401406 }
402407
403- fn requisite_votes ( & self , group : & ParaId ) -> usize {
404- self . groups . get ( group) . map_or ( usize :: MAX , |g| minimum_votes ( g. len ( ) ) )
408+ fn get_group_size ( & self , group : & ParaId ) -> Option < usize > {
409+ self . groups . get ( group) . map ( |g| g. len ( ) )
405410 }
406411}
407412
@@ -943,7 +948,14 @@ async fn handle_active_leaves_update<Context>(
943948
944949 // construct a `PerRelayParent` from the runtime API
945950 // and insert it.
946- let per = construct_per_relay_parent_state ( ctx, maybe_new, & state. keystore , mode) . await ?;
951+ let per = construct_per_relay_parent_state (
952+ ctx,
953+ maybe_new,
954+ & state. keystore ,
955+ & mut state. runtime_info ,
956+ mode,
957+ )
958+ . await ?;
947959
948960 if let Some ( per) = per {
949961 state. per_relay_parent . insert ( maybe_new, per) ;
@@ -959,6 +971,7 @@ async fn construct_per_relay_parent_state<Context>(
959971 ctx : & mut Context ,
960972 relay_parent : Hash ,
961973 keystore : & KeystorePtr ,
974+ runtime_info : & mut RuntimeInfo ,
962975 mode : ProspectiveParachainsMode ,
963976) -> Result < Option < PerRelayParentState > , Error > {
964977 macro_rules! try_runtime_api {
@@ -983,10 +996,14 @@ async fn construct_per_relay_parent_state<Context>(
983996
984997 let parent = relay_parent;
985998
986- let ( validators, groups, session_index, cores) = futures:: try_join!(
999+ let session_index =
1000+ try_runtime_api ! ( runtime_info. get_session_index_for_child( ctx. sender( ) , parent) . await ) ;
1001+ let minimum_backing_votes =
1002+ runtime_info. get_min_backing_votes ( ctx. sender ( ) , session_index, parent) . await ;
1003+
1004+ let ( validators, groups, cores) = futures:: try_join!(
9871005 request_validators( parent, ctx. sender( ) ) . await ,
9881006 request_validator_groups( parent, ctx. sender( ) ) . await ,
989- request_session_index_for_child( parent, ctx. sender( ) ) . await ,
9901007 request_from_runtime( parent, ctx. sender( ) , |tx| {
9911008 RuntimeApiRequest :: AvailabilityCores ( tx)
9921009 } , )
@@ -996,8 +1013,8 @@ async fn construct_per_relay_parent_state<Context>(
9961013
9971014 let validators: Vec < _ > = try_runtime_api ! ( validators) ;
9981015 let ( validator_groups, group_rotation_info) = try_runtime_api ! ( groups) ;
999- let session_index = try_runtime_api ! ( session_index) ;
10001016 let cores = try_runtime_api ! ( cores) ;
1017+ let minimum_backing_votes = try_runtime_api ! ( minimum_backing_votes) ;
10011018
10021019 let signing_context = SigningContext { parent_hash : parent, session_index } ;
10031020 let validator =
@@ -1061,6 +1078,7 @@ async fn construct_per_relay_parent_state<Context>(
10611078 issued_statements : HashSet :: new ( ) ,
10621079 awaiting_validation : HashSet :: new ( ) ,
10631080 fallbacks : HashMap :: new ( ) ,
1081+ minimum_backing_votes,
10641082 } ) )
10651083}
10661084
@@ -1563,10 +1581,13 @@ async fn post_import_statement_actions<Context>(
15631581 rp_state : & mut PerRelayParentState ,
15641582 summary : Option < & TableSummary > ,
15651583) -> Result < ( ) , Error > {
1566- if let Some ( attested) = summary
1567- . as_ref ( )
1568- . and_then ( |s| rp_state. table . attested_candidate ( & s. candidate , & rp_state. table_context ) )
1569- {
1584+ if let Some ( attested) = summary. as_ref ( ) . and_then ( |s| {
1585+ rp_state. table . attested_candidate (
1586+ & s. candidate ,
1587+ & rp_state. table_context ,
1588+ rp_state. minimum_backing_votes ,
1589+ )
1590+ } ) {
15701591 let candidate_hash = attested. candidate . hash ( ) ;
15711592
15721593 // `HashSet::insert` returns true if the thing wasn't in there already.
@@ -2009,7 +2030,11 @@ fn handle_get_backed_candidates_message(
20092030 } ;
20102031 rp_state
20112032 . table
2012- . attested_candidate ( & candidate_hash, & rp_state. table_context )
2033+ . attested_candidate (
2034+ & candidate_hash,
2035+ & rp_state. table_context ,
2036+ rp_state. minimum_backing_votes ,
2037+ )
20132038 . and_then ( |attested| table_attested_to_backed ( attested, & rp_state. table_context ) )
20142039 } )
20152040 . collect ( ) ;
0 commit comments