Skip to content

Commit 3170047

Browse files
authored
Beefy Prover: Remove generated subxt types (#310)
1 parent c1c436d commit 3170047

File tree

9 files changed

+73
-48311
lines changed

9 files changed

+73
-48311
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

evm/integration-tests/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ismp = { workspace = true, default-features = true }
4040
pallet-ismp = { workspace = true, default-features = true }
4141
pallet-ismp-host-executive = { workspace = true, default-features = true }
4242
pallet-mmr = { workspace = true, default-features = true }
43-
beefy-prover = { workspace = true, default-features = true }
43+
beefy-prover = { workspace = true, default-features = true, features = ["local"]}
4444
beefy-verifier-primitives = { workspace = true, default-features = true }
4545
pallet-ismp-relayer = { workspace = true, default-features = true }
4646

evm/integration-tests/src/tests/beefy_v1.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ impl subxt::Config for HyperbridgeConfig {
5454
}
5555

5656
fn default_para_id() -> u32 {
57-
4009
57+
2000
5858
}
5959
fn activation_block() -> u32 {
6060
0
6161
}
6262
fn default_relay_ws_url() -> String {
63-
"ws://127.0.0.1:9944".to_string()
63+
"ws://127.0.0.1:9922".to_string()
6464
}
6565
fn default_para_ws_url() -> String {
66-
"ws://127.0.0.1:9988".to_string()
66+
"ws://127.0.0.1:9990".to_string()
6767
}
6868
#[derive(Deserialize, Debug)]
6969
struct Config {

modules/consensus/beefy/prover/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ primitive-types = { workspace = true, features = ["codec"] }
1616
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
1717
derive_more = { version = "0.99.17", features = ["from"] }
1818
rs_merkle = { git = "https://github.com/polytope-labs/rs-merkle", branch = "seun/2d-merkle-proofs" }
19+
hex-literal = "0.4.1"
1920

2021
# substrate
2122
sp-runtime = { workspace = true, features = ["default"] }
@@ -35,3 +36,5 @@ serde_json = { version = "1.0.74" }
3536
hex = { version = "0.4.3" }
3637
beefy-verifier-primitives = { path = "../primitives" }
3738

39+
[features]
40+
local = []

modules/consensus/beefy/prover/src/lib.rs

+51-36
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
/// Methods for querying the relay chain
2222
pub mod relay;
23-
/// Metadata generated code for interacting with the relay chain
24-
pub mod runtime;
2523
/// Helper functions and types
2624
pub mod util;
2725

@@ -37,8 +35,9 @@ use beefy_verifier_primitives::{
3735
ConsensusMessage, ConsensusState, MmrProof, ParachainHeader, ParachainProof, SignedCommitment,
3836
};
3937
use codec::{Decode, Encode};
38+
use hex_literal::hex;
4039
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};
4241
use sp_consensus_beefy::{
4342
ecdsa_crypto::Signature,
4443
known_payloads::MMR_ROOT_ID,
@@ -62,6 +61,32 @@ pub struct Prover<R: Config, P: Config> {
6261
pub para_ids: Vec<u32>,
6362
}
6463

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+
6590
impl<R: Config, P: Config> Prover<R, P> {
6691
/// Construct a beefy client state to be submitted to the counterparty chain
6792
pub async fn get_initial_consensus_state(&self) -> Result<ConsensusState, anyhow::Error> {
@@ -72,35 +97,28 @@ impl<R: Config, P: Config> Prover<R, P> {
7297

7398
// Encoding and decoding to fix dependency version conflicts
7499
let next_authority_set = {
75-
let key = runtime::storage().beefy_mmr_leaf().beefy_next_authorities();
76100
let next_authority_set = self
77101
.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+
)
81107
.await?
82108
.expect("Should retrieve next authority set")
83-
.encode();
109+
.0;
84110
BeefyNextAuthoritySet::decode(&mut &*next_authority_set)
85111
.expect("Should decode next authority set correctly")
86112
};
87113

88114
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();
96115
let authority_set = self
97116
.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))
101119
.await?
102120
.expect("Should retrieve next authority set")
103-
.encode();
121+
.0;
104122
BeefyNextAuthoritySet::decode(&mut &*authority_set)
105123
.expect("Should decode next authority set correctly")
106124
};
@@ -138,14 +156,13 @@ impl<R: Config, P: Config> Prover<R, P> {
138156
.ok_or_else(|| anyhow!("Failed to query blockhash for blocknumber"))?;
139157

140158
let current_authorities = {
141-
let key = runtime::storage().beefy().authorities();
142159
self.relay
143-
.storage()
144-
.at(block_hash)
145-
.fetch(&key)
160+
.rpc()
161+
.storage(BEEFY_AUTHORITIES.as_slice(), Some(block_hash))
146162
.await?
163+
.map(|data| Vec::<[u8; 33]>::decode(&mut data.as_ref()))
164+
.transpose()?
147165
.ok_or_else(|| anyhow!("No beefy authorities found!"))?
148-
.0
149166
};
150167

151168
// Current LeafIndex
@@ -173,29 +190,27 @@ impl<R: Config, P: Config> Prover<R, P> {
173190
};
174191

175192
let heads = {
176-
let key = runtime::storage().paras().parachains();
177193
let ids = self
178194
.relay
179-
.storage()
180-
.at(block_hash)
181-
.fetch(&key)
195+
.rpc()
196+
.storage(PARAS_PARACHAINS.as_slice(), Some(block_hash))
182197
.await?
198+
.map(|data| Vec::<u32>::decode(&mut data.as_ref()))
199+
.transpose()?
183200
.ok_or_else(|| anyhow!("No beefy authorities found!"))?;
184201

185202
let mut heads = vec![];
186203
for id in ids {
187-
let key = runtime::storage().paras().heads(&id);
188204
let head = self
189205
.relay
190-
.storage()
191-
.at(block_hash)
192-
.fetch(&key)
206+
.rpc()
207+
.storage(parachain_header_storage_key(id).as_ref(), Some(block_hash))
193208
.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));
197213
}
198-
199214
heads.sort();
200215

201216
heads

modules/consensus/beefy/prover/src/relay.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use subxt::{
2626
Config, OnlineClient,
2727
};
2828

29+
use crate::BEEFY_VALIDATOR_SET_ID;
30+
2931
/// This contains the leaf indices of the relay chain blocks and a map of relay chain heights to a
3032
/// map of all parachain headers at those heights Used for generating [`ParaHeadsProof`]
3133
pub struct FinalizedParaHeads {
@@ -81,10 +83,11 @@ pub async fn fetch_next_beefy_justification<T: Config>(
8183

8284
let (signed_commitment, latest_beefy_finalized) = loop {
8385
let set_id = client
84-
.storage()
85-
.at(block_hash)
86-
.fetch(&crate::runtime::storage().beefy().validator_set_id())
86+
.rpc()
87+
.storage(BEEFY_VALIDATOR_SET_ID.as_slice(), Some(block_hash))
8788
.await?
89+
.map(|data| u64::decode(&mut data.as_ref()))
90+
.transpose()?
8891
.ok_or_else(|| anyhow!("Couldn't fetch latest beefy authority set"))?;
8992

9093
let block = client

modules/consensus/beefy/prover/src/runtime.rs

-2
This file was deleted.

0 commit comments

Comments
 (0)