20
20
21
21
/// Methods for querying the relay chain
22
22
pub mod relay;
23
- /// Metadata generated code for interacting with the relay chain
24
- pub mod runtime;
25
23
/// Helper functions and types
26
24
pub mod util;
27
25
@@ -37,8 +35,9 @@ use beefy_verifier_primitives::{
37
35
ConsensusMessage , ConsensusState , MmrProof , ParachainHeader , ParachainProof , SignedCommitment ,
38
36
} ;
39
37
use codec:: { Decode , Encode } ;
38
+ use hex_literal:: hex;
40
39
use primitive_types:: H256 ;
41
- use relay:: { fetch_latest_beefy_justification, fetch_mmr_proof} ;
40
+ use relay:: { fetch_latest_beefy_justification, fetch_mmr_proof, parachain_header_storage_key } ;
42
41
use sp_consensus_beefy:: {
43
42
ecdsa_crypto:: Signature ,
44
43
known_payloads:: MMR_ROOT_ID ,
@@ -62,6 +61,32 @@ pub struct Prover<R: Config, P: Config> {
62
61
pub para_ids : Vec < u32 > ,
63
62
}
64
63
64
+ #[ cfg( not( feature = "local" ) ) ]
65
+ /// Relay chain storage key for beefMmrLeaf.beefyNextAuthorites()
66
+ pub const BEEFY_MMR_LEAF_BEEFY_NEXT_AUTHORITIES : [ u8 ; 32 ] =
67
+ hex ! ( "2ecf93be7260df120a495bd3855c0e600c98535b82c72faf3c64974094af4643" ) ;
68
+ #[ cfg( not( feature = "local" ) ) ]
69
+ /// Relay chain storage key for beefMmrLeaf.beefyAuthorites()
70
+ pub const BEEFY_MMR_LEAF_BEEFY_AUTHORITIES : [ u8 ; 32 ] =
71
+ hex ! ( "2ecf93be7260df120a495bd3855c0e60c52aa943bf0908860a3eea0fad707cdc" ) ;
72
+ #[ cfg( feature = "local" ) ]
73
+ /// Relay chain storage key for beefMmrLeaf.beefyNextAuthorites()
74
+ pub const BEEFY_MMR_LEAF_BEEFY_NEXT_AUTHORITIES : [ u8 ; 32 ] =
75
+ hex ! ( "da7d4185f8093e80caceb64da45219e30c98535b82c72faf3c64974094af4643" ) ;
76
+ #[ cfg( feature = "local" ) ]
77
+ /// Relay chain storage key for beefMmrLeaf.beefyAuthorites()
78
+ pub const BEEFY_MMR_LEAF_BEEFY_AUTHORITIES : [ u8 ; 32 ] =
79
+ hex ! ( "da7d4185f8093e80caceb64da45219e3c52aa943bf0908860a3eea0fad707cdc" ) ;
80
+ /// Relay chain storage key for beefy.authorities()
81
+ pub const BEEFY_AUTHORITIES : [ u8 ; 32 ] =
82
+ hex ! ( "08c41974a97dbf15cfbec28365bea2da5e0621c4869aa60c02be9adcc98a0d1d" ) ;
83
+ /// Relay chain storage key for beefy.validatorSetId()
84
+ pub const BEEFY_VALIDATOR_SET_ID : [ u8 ; 32 ] =
85
+ hex ! ( "08c41974a97dbf15cfbec28365bea2da8f05bccc2f70ec66a32999c5761156be" ) ;
86
+ /// Relay chain storage key for paras.parachains()
87
+ pub const PARAS_PARACHAINS : [ u8 ; 32 ] =
88
+ hex ! ( "cd710b30bd2eab0352ddcc26417aa1940b76934f4cc08dee01012d059e1b83ee" ) ;
89
+
65
90
impl < R : Config , P : Config > Prover < R , P > {
66
91
/// Construct a beefy client state to be submitted to the counterparty chain
67
92
pub async fn get_initial_consensus_state ( & self ) -> Result < ConsensusState , anyhow:: Error > {
@@ -72,35 +97,28 @@ impl<R: Config, P: Config> Prover<R, P> {
72
97
73
98
// Encoding and decoding to fix dependency version conflicts
74
99
let next_authority_set = {
75
- let key = runtime:: storage ( ) . beefy_mmr_leaf ( ) . beefy_next_authorities ( ) ;
76
100
let next_authority_set = self
77
101
. relay
78
- . storage ( )
79
- . at ( latest_beefy_finalized)
80
- . fetch ( & key)
102
+ . rpc ( )
103
+ . storage (
104
+ BEEFY_MMR_LEAF_BEEFY_NEXT_AUTHORITIES . as_slice ( ) ,
105
+ Some ( latest_beefy_finalized) ,
106
+ )
81
107
. await ?
82
108
. expect ( "Should retrieve next authority set" )
83
- . encode ( ) ;
109
+ . 0 ;
84
110
BeefyNextAuthoritySet :: decode ( & mut & * next_authority_set)
85
111
. expect ( "Should decode next authority set correctly" )
86
112
} ;
87
113
88
114
let current_authority_set = {
89
- let key: subxt:: storage:: Address <
90
- subxt:: utils:: Static < subxt:: utils:: Encoded > ,
91
- runtime:: runtime_types:: sp_consensus_beefy:: mmr:: BeefyAuthoritySet < H256 > ,
92
- subxt:: storage:: address:: Yes ,
93
- subxt:: storage:: address:: Yes ,
94
- ( ) ,
95
- > = runtime:: storage ( ) . beefy_mmr_leaf ( ) . beefy_authorities ( ) ;
96
115
let authority_set = self
97
116
. relay
98
- . storage ( )
99
- . at ( latest_beefy_finalized)
100
- . fetch ( & key)
117
+ . rpc ( )
118
+ . storage ( BEEFY_MMR_LEAF_BEEFY_AUTHORITIES . as_slice ( ) , Some ( latest_beefy_finalized) )
101
119
. await ?
102
120
. expect ( "Should retrieve next authority set" )
103
- . encode ( ) ;
121
+ . 0 ;
104
122
BeefyNextAuthoritySet :: decode ( & mut & * authority_set)
105
123
. expect ( "Should decode next authority set correctly" )
106
124
} ;
@@ -138,14 +156,13 @@ impl<R: Config, P: Config> Prover<R, P> {
138
156
. ok_or_else ( || anyhow ! ( "Failed to query blockhash for blocknumber" ) ) ?;
139
157
140
158
let current_authorities = {
141
- let key = runtime:: storage ( ) . beefy ( ) . authorities ( ) ;
142
159
self . relay
143
- . storage ( )
144
- . at ( block_hash)
145
- . fetch ( & key)
160
+ . rpc ( )
161
+ . storage ( BEEFY_AUTHORITIES . as_slice ( ) , Some ( block_hash) )
146
162
. await ?
163
+ . map ( |data| Vec :: < [ u8 ; 33 ] > :: decode ( & mut data. as_ref ( ) ) )
164
+ . transpose ( ) ?
147
165
. ok_or_else ( || anyhow ! ( "No beefy authorities found!" ) ) ?
148
- . 0
149
166
} ;
150
167
151
168
// Current LeafIndex
@@ -173,29 +190,27 @@ impl<R: Config, P: Config> Prover<R, P> {
173
190
} ;
174
191
175
192
let heads = {
176
- let key = runtime:: storage ( ) . paras ( ) . parachains ( ) ;
177
193
let ids = self
178
194
. relay
179
- . storage ( )
180
- . at ( block_hash)
181
- . fetch ( & key)
195
+ . rpc ( )
196
+ . storage ( PARAS_PARACHAINS . as_slice ( ) , Some ( block_hash) )
182
197
. await ?
198
+ . map ( |data| Vec :: < u32 > :: decode ( & mut data. as_ref ( ) ) )
199
+ . transpose ( ) ?
183
200
. ok_or_else ( || anyhow ! ( "No beefy authorities found!" ) ) ?;
184
201
185
202
let mut heads = vec ! [ ] ;
186
203
for id in ids {
187
- let key = runtime:: storage ( ) . paras ( ) . heads ( & id) ;
188
204
let head = self
189
205
. relay
190
- . storage ( )
191
- . at ( block_hash)
192
- . fetch ( & key)
206
+ . rpc ( )
207
+ . storage ( parachain_header_storage_key ( id) . as_ref ( ) , Some ( block_hash) )
193
208
. await ?
194
- . ok_or_else ( || anyhow ! ( "No beefy authorities found!" ) ) ?
195
- . 0 ;
196
- heads. push ( ( id. 0 , head) ) ;
209
+ . map ( |data| Vec :: < u8 > :: decode ( & mut data. as_ref ( ) ) )
210
+ . transpose ( ) ?
211
+ . ok_or_else ( || anyhow ! ( "No beefy authorities found!" ) ) ?;
212
+ heads. push ( ( id, head) ) ;
197
213
}
198
-
199
214
heads. sort ( ) ;
200
215
201
216
heads
0 commit comments