-
Notifications
You must be signed in to change notification settings - Fork 4
Update substrate and subxt #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d5a854e
f5cb853
598838b
c548e62
bd68140
fc7fd06
2f55f8f
b014868
01d9fcc
f2bb38a
136dfc2
0678845
2b02b7a
f0ba64f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,14 @@ entropy-shared ={ path="../shared", default-features=false } | |
synedrion ={ git="ssh://[email protected]/entropyxyz/synedrion.git", tag="v0.0.9" } | ||
serde ={ version="1.0", features=["derive"], default-features=false } | ||
serde-big-array="0.5.1" | ||
subxt ={ package="subxt", git="https://github.com/paritytech/subxt.git", tag="v0.29.0", default-features=false } | ||
subxt ={ package="subxt", git="https://github.com/paritytech/subxt.git", tag="v0.32.1", default-features=false } | ||
subxt-signer ={ version="0.31.0", features=[] } | ||
tokio ={ version="1.16", features=["sync", "rt", "macros"] } | ||
x25519-dalek ="2.0.0-pre.1" | ||
futures ="0.3" | ||
hex ="*" | ||
blake2 ="0.10.4" | ||
thiserror ="1.0.40" | ||
thiserror ="1.0.48" | ||
snow ="0.9.2" | ||
getrandom ={ version="0.2", features=["js"] } | ||
rand_core ={ version="0.6.4", features=["getrandom"] } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
use entropy_shared::{KeyVisibility, SIGNING_PARTY_SIZE}; | ||
use subxt::{ext::sp_core::sr25519, tx::PairSigner, utils::AccountId32, Config, OnlineClient}; | ||
use subxt::{ | ||
backend::legacy::LegacyRpcMethods, ext::sp_core::sr25519, tx::PairSigner, utils::AccountId32, | ||
Config, OnlineClient, | ||
}; | ||
|
||
use crate::{ | ||
chain_api::{entropy, EntropyConfig}, | ||
|
@@ -9,16 +12,21 @@ use crate::{ | |
/// gets the subgroup of the working validator | ||
pub async fn get_subgroup( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
signer: &PairSigner<EntropyConfig, sr25519::Pair>, | ||
) -> Result<(Option<u8>, AccountId32), UserErr> { | ||
let mut subgroup: Option<u8> = None; | ||
let threshold_address = signer.account_id(); | ||
let stash_address_query = | ||
entropy::storage().staking_extension().threshold_to_stash(threshold_address); | ||
let block_hash = rpc | ||
.chain_get_block_hash(None) | ||
.await? | ||
.ok_or_else(|| UserErr::OptionUnwrapError("Errir getting block hash"))?; | ||
|
||
let stash_address = api | ||
.storage() | ||
.at_latest() | ||
.await? | ||
.at(block_hash) | ||
.fetch(&stash_address_query) | ||
.await? | ||
.ok_or_else(|| UserErr::SubgroupError("Stash Fetch Error"))?; | ||
|
@@ -27,8 +35,7 @@ pub async fn get_subgroup( | |
entropy::storage().staking_extension().signing_groups(i as u8); | ||
let signing_group_addresses = api | ||
.storage() | ||
.at_latest() | ||
.await? | ||
.at(block_hash) | ||
.fetch(&signing_group_addresses_query) | ||
.await? | ||
.ok_or_else(|| UserErr::SubgroupError("Subgroup Error"))?; | ||
|
@@ -43,13 +50,17 @@ pub async fn get_subgroup( | |
/// Returns all the addresses of a specific subgroup | ||
pub async fn return_all_addresses_of_subgroup( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
subgroup: u8, | ||
) -> Result<Vec<AccountId32>, UserErr> { | ||
let subgroup_addresses_query = entropy::storage().staking_extension().signing_groups(subgroup); | ||
let block_hash = rpc | ||
.chain_get_block_hash(None) | ||
.await? | ||
.ok_or_else(|| UserErr::OptionUnwrapError("Errir getting block hash"))?; | ||
let subgroup_addresses = api | ||
.storage() | ||
.at_latest() | ||
.await? | ||
.at(block_hash) | ||
.fetch(&subgroup_addresses_query) | ||
.await? | ||
.ok_or_else(|| UserErr::SubgroupError("Subgroup Error"))?; | ||
|
@@ -59,14 +70,18 @@ pub async fn return_all_addresses_of_subgroup( | |
/// Queries the user's program from the chain | ||
pub async fn get_program( | ||
substrate_api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
sig_req_account: &<EntropyConfig as Config>::AccountId, | ||
) -> Result<Vec<u8>, UserErr> { | ||
let bytecode_address = entropy::storage().constraints().bytecode(sig_req_account); | ||
let block_hash = rpc | ||
.chain_get_block_hash(None) | ||
.await? | ||
.ok_or_else(|| UserErr::OptionUnwrapError("Errir getting block hash"))?; | ||
|
||
substrate_api | ||
.storage() | ||
.at_latest() | ||
.await? | ||
.at(block_hash) | ||
.fetch(&bytecode_address) | ||
.await? | ||
.ok_or(UserErr::NoProgramDefined) | ||
|
@@ -77,6 +92,7 @@ pub async fn get_program( | |
#[cfg(test)] | ||
pub async fn make_register( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
sig_req_keyring: sr25519::Pair, | ||
constraint_account: &AccountId32, | ||
key_visibility: KeyVisibility, | ||
|
@@ -86,8 +102,8 @@ pub async fn make_register( | |
let sig_req_account = PairSigner::<EntropyConfig, sr25519::Pair>::new(sig_req_keyring); | ||
|
||
let registering_query = entropy::storage().relayer().registering(sig_req_account.account_id()); | ||
let is_registering_1 = | ||
api.storage().at_latest().await.unwrap().fetch(®istering_query).await.unwrap(); | ||
let block_hash = rpc.chain_get_block_hash(None).await.unwrap().unwrap(); | ||
let is_registering_1 = api.storage().at(block_hash).fetch(®istering_query).await.unwrap(); | ||
assert!(is_registering_1.is_none()); | ||
|
||
// register the user | ||
|
@@ -109,21 +125,26 @@ pub async fn make_register( | |
.await | ||
.unwrap(); | ||
|
||
let query_registering_status = | ||
api.storage().at_latest().await.unwrap().fetch(®istering_query).await; | ||
let block_hash_2 = rpc.chain_get_block_hash(None).await.unwrap().unwrap(); | ||
|
||
let query_registering_status = api.storage().at(block_hash_2).fetch(®istering_query).await; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why we are switching from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ya this was brutal so pretty much at_latest checks only finalized blocks, so we need to get the non finalized blocks now as the finalization lags and in tests due to running one node never happens |
||
assert!(query_registering_status.unwrap().unwrap().is_registering); | ||
} | ||
|
||
/// Returns wether an account is registered | ||
pub async fn get_key_visibility( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
who: &<EntropyConfig as Config>::AccountId, | ||
) -> Result<KeyVisibility, UserErr> { | ||
let registered_info_query = entropy::storage().relayer().registered(who); | ||
let block_hash = rpc | ||
.chain_get_block_hash(None) | ||
.await? | ||
.ok_or_else(|| UserErr::OptionUnwrapError("Errir getting block hash"))?; | ||
let result = api | ||
.storage() | ||
.at_latest() | ||
.await? | ||
.at(block_hash) | ||
.fetch(®istered_info_query) | ||
.await? | ||
.ok_or_else(|| UserErr::NotRegistering("Register Onchain first"))?; | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,7 @@ use entropy_shared::{KeyVisibility, SETUP_TIMEOUT_SECONDS}; | |||||
use parity_scale_codec::Encode; | ||||||
use sp_core::crypto::AccountId32; | ||||||
use subxt::{ | ||||||
backend::legacy::LegacyRpcMethods, | ||||||
ext::sp_core::{sr25519, Bytes}, | ||||||
tx::PairSigner, | ||||||
utils::AccountId32 as SubxtAccountId32, | ||||||
|
@@ -97,6 +98,7 @@ pub async fn do_dkg( | |||||
/// Send's user key share to other members of signing subgroup | ||||||
pub async fn send_key( | ||||||
api: &OnlineClient<EntropyConfig>, | ||||||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||||||
stash_address: &SubxtAccountId32, | ||||||
addresses_in_subgroup: &mut Vec<SubxtAccountId32>, | ||||||
user_registration_info: UserRegistrationInfo, | ||||||
|
@@ -108,12 +110,16 @@ pub async fn send_key( | |||||
.position(|address| *address == *stash_address) | ||||||
.ok_or_else(|| UserErr::OptionUnwrapError("Validator not in subgroup"))?, | ||||||
); | ||||||
let block_hash = rpc | ||||||
.chain_get_block_hash(None) | ||||||
.await? | ||||||
.ok_or_else(|| UserErr::OptionUnwrapError("Errir getting block hash"))?; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This needs to be updated in a few other places |
||||||
|
||||||
for validator in addresses_in_subgroup { | ||||||
let server_info_query = entropy::storage().staking_extension().threshold_servers(validator); | ||||||
let server_info = api | ||||||
.storage() | ||||||
.at_latest() | ||||||
.await? | ||||||
.at(block_hash) | ||||||
.fetch(&server_info_query) | ||||||
.await? | ||||||
.ok_or_else(|| UserErr::OptionUnwrapError("Server Info Fetch Error"))?; | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.