Skip to content

Commit

Permalink
Update substrate (#370)
Browse files Browse the repository at this point in the history
* package conflicts

* server compiling

* runtime compiling

* compiles

* server tests working

* all tests passing

* fix weights

* clean warnings

* clean

* clean

* fmt

* lint

* lint

* lint

* change root key

* fix redundant clone bug

* remove unused sp-core

* lint

* remove a subsitute type

---------

Co-authored-by: jesse <jesse@entropy.wxy>
  • Loading branch information
JesseAbram and jesse authored Jul 14, 2023
1 parent c73494d commit dff3249
Show file tree
Hide file tree
Showing 70 changed files with 6,943 additions and 4,031 deletions.
7,873 changes: 5,071 additions & 2,802 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
panic='unwind'

[workspace]
members=['crypto/*', 'node/*', 'pallets/*', 'runtime']
resolver="2"
members =['crypto/*', 'node/*', 'pallets/*', 'runtime']
14 changes: 3 additions & 11 deletions crypto/constraints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ edition="2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
thiserror="1.0"
thiserror="1.0.40"

# parsing

serde ={ version="1.0.147", default-features=false, features=["derive"] }
serde_json ={ version="1.0", default-features=false, features=["alloc"] }
entropy-shared={ path="../shared", default-features=false }
sp-core ={ git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.31", default-features=false }

# EVM
ethers-core={ version="0.13.0", default-features=false }
ethers-core={ version="2.0.7", default-features=false }
rlp={ version="0.5.2", default-features=false }
hex="0.4.3"
primitive-types={ version="0.11.1", default-features=false, features=[
Expand All @@ -26,11 +25,4 @@ primitive-types={ version="0.11.1", default-features=false, features=[

[features]
default=["std"]
std=[
"serde/std",
"serde_json/std",
"entropy-shared/std",
"sp-core/std",
"rlp/std",
"primitive-types/std",
]
std =["serde/std", "serde_json/std", "entropy-shared/std", "rlp/std", "primitive-types/std"]
12 changes: 8 additions & 4 deletions crypto/constraints/src/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@ use crate::{Architecture, Error, Evm};

/// Constraints must implement an evaluation trait that parses.
pub trait Evaluate<A: Architecture> {
fn eval(self, tx: A::TransactionRequest) -> Result<(), Error>;
fn eval(&self, tx: A::TransactionRequest) -> Result<(), Error>;
}

// TODO This can likely be made generic over any architecture with GetRecipient and GetSender traits
#[allow(clippy::needless_collect)]
impl Evaluate<Evm> for Acl<[u8; 20]> {
fn eval(self, tx: <Evm as Architecture>::TransactionRequest) -> Result<(), Error> {
fn eval(&self, tx: <Evm as Architecture>::TransactionRequest) -> Result<(), Error> {
if tx.to.is_none() {
return match self.allow_null_recipient {
true => Ok(()),
false => Err(Error::Evaluation("Null recipients are not allowed.")),
};
}

let converted_addresses: Vec<NameOrAddress> =
self.addresses.into_iter().map(|a| NameOrAddress::Address(H160::from(a))).collect();
let converted_addresses: Vec<NameOrAddress> = self
.clone()
.addresses
.into_iter()
.map(|a| NameOrAddress::Address(H160::from(a)))
.collect();

match (
converted_addresses
Expand Down
6 changes: 3 additions & 3 deletions crypto/kvdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ edition="2021"
# Common
rand ={ version="0.8", default-features=false }
serde ={ version="1.0", features=["derive"] }
thiserror="1.0.31"
thiserror="1.0.40"
hex ="0.4"

# Substrate
sp-core={ package="sp-core", git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.31" }
sp-core={ version="21.0.0", default-features=false }

# Crypto
zeroize ={ version="1.4", features=["zeroize_derive"], default-features=false }
rpassword ={ version="5.0", default-features=false }
scrypt ={ version="0.8", default-features=false, features=["std"] }
scrypt ={ version="0.11.0", default-features=false, features=["std"] }
chacha20poly1305={ version="0.9", features=["alloc"], default-features=false }
synedrion ={ git="ssh://git@github.com/entropyxyz/synedrion.git", tag="v0.0.3" }

Expand Down
14 changes: 7 additions & 7 deletions crypto/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition="2021"
serde ={ version="1.0", default-features=false, features=["derive"] }
serde_json ="1.0"
anyhow ="1.0.53"
thiserror ="1.0.31"
thiserror ="1.0.40"
blake2 ="0.10.4"
x25519-dalek ="2.0.0-pre.1"
chacha20poly1305 ="0.10.1"
Expand All @@ -30,22 +30,22 @@ reqwest ={ version="0.11", features=["json", "stream"] }
axum ={ version="0.6.18", features=["ws"] }
axum-macros="0.3.7"
# Substrate
subxt ={ package="subxt", git="https://github.com/entropyxyz/subxt.git", branch="polkadot-v0.9.31" }
parity-scale-codec="3.0.0"
sp-core ={ package="sp-core", git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.31" }
subxt ={ package="subxt", git="https://github.com/paritytech/subxt.git", tag="v0.29.0" }
parity-scale-codec="3.4.0"
sp-core ={ version="21.0.0", default-features=false }

# Entropy
entropy-shared={ path="../shared" }
kvdb ={ path="../kvdb", default-features=false }

# Constraints
entropy-constraints={ path="../constraints" }
ethers-core ="0.13.0"
ethers-core ="2.0.7"

# Logging
log ="0.4.17" # todo: remove, overlaps tracing
tracing ="0.1.37"
tracing-subscriber={ version="0.3.16", features=["env-filter", "json"] }
tracing-subscriber={ version="0.3.17", features=["env-filter", "json"] }
tower-http ={ version="0.3.4", features=["trace", "cors"] }

# Misc
Expand All @@ -63,7 +63,7 @@ testing-utils={ path="../testing-utils" }
serial_test ="0.8.0"
hex-literal ="0.3.4"
project-root ="0.2.2"
sp-keyring ={ package="sp-keyring", git="https://github.com/paritytech/substrate", branch="polkadot-v0.9.31" }
sp-keyring ="24.0.0"

[features]
default=['std']
Expand Down
Binary file modified crypto/server/entropy_metadata.scale
Binary file not shown.
17 changes: 8 additions & 9 deletions crypto/server/src/chain_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
pub use subxt::config::PolkadotConfig as EntropyConfig;
use subxt::OnlineClient;

#[subxt::subxt(runtime_metadata_path = "entropy_metadata.scale")]
pub mod entropy {
#[subxt::subxt(substitute_type = "entropy_shared::constraints::acl::Acl")]
use ::entropy_shared::Acl;
#[subxt::subxt(substitute_type = "entropy_shared::constraints::Constraints")]
use ::entropy_shared::Constraints;
#[subxt::subxt(substitute_type = "sp_core::crypto::AccountId32")]
use ::sp_core::crypto::AccountId32;
}
#[subxt::subxt(
runtime_metadata_path = "entropy_metadata.scale",
substitute_type(
path = "entropy_shared::constraints::acl::Acl<Address>",
with = "::subxt::utils::Static<::entropy_shared::Acl<Address>>",
)
)]
pub mod entropy {}

/// Creates an api instance to talk to chain
/// Chain endpoint set on launch
Expand Down
7 changes: 4 additions & 3 deletions crypto/server/src/helpers/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,19 @@ pub async fn do_signing(
let signing_service = ThresholdSigningService::new(state, kv_manager);
let signer =
get_signer(kv_manager).await.map_err(|_| SigningErr::UserError("Error getting Signer"))?;
let my_id = PartyId::new(signer.account_id().clone());
let account_sp_core = AccountId32::new(*signer.account_id().clone().as_ref());
let my_id = PartyId::new(account_sp_core.clone());
// set up context for signing protocol execution
let sign_context = signing_service.get_sign_context(info.clone()).await?;

let tss_accounts: Vec<AccountId32> = message
.validators_info
.iter()
.map(|validator_info| validator_info.tss_account.clone())
.map(|validator_info| AccountId32::new(*validator_info.tss_account.clone().as_ref()))
.collect();

// subscribe to all other participating parties. Listener waits for other subscribers.
let (rx_ready, rx_from_others, listener) = Listener::new(message, signer.account_id());
let (rx_ready, rx_from_others, listener) = Listener::new(message, &account_sp_core);
state
.listeners
.lock()
Expand Down
53 changes: 34 additions & 19 deletions crypto/server/src/helpers/substrate.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use entropy_shared::{Constraints, SIGNING_PARTY_SIZE};
use sp_core::crypto::AccountId32;
use entropy_shared::{Acl, Constraints, SIGNING_PARTY_SIZE};
#[cfg(test)]
use sp_keyring::Sr25519Keyring;
use subxt::{ext::sp_core::sr25519, tx::PairSigner, Config, OnlineClient};
use subxt::utils::AccountId32;
use subxt::{ext::sp_core::sr25519, tx::PairSigner, utils::Static, Config, OnlineClient};

use crate::{
chain_api::{entropy, EntropyConfig},
Expand All @@ -20,15 +19,19 @@ pub async fn get_subgroup(
entropy::storage().staking_extension().threshold_to_stash(threshold_address);
let stash_address = api
.storage()
.fetch(&stash_address_query, None)
.at_latest()
.await?
.fetch(&stash_address_query)
.await?
.ok_or_else(|| UserErr::SubgroupError("Stash Fetch Error"))?;
for i in 0..SIGNING_PARTY_SIZE {
let signing_group_addresses_query =
entropy::storage().staking_extension().signing_groups(i as u8);
let signing_group_addresses = api
.storage()
.fetch(&signing_group_addresses_query, None)
.at_latest()
.await?
.fetch(&signing_group_addresses_query)
.await?
.ok_or_else(|| UserErr::SubgroupError("Subgroup Error"))?;
if signing_group_addresses.contains(&stash_address) {
Expand All @@ -52,8 +55,8 @@ pub async fn get_constraints(
let btc_acl_storage_address = entropy::storage().constraints().btc_acl(sig_req_account);

let (evm_acl_result, btc_acl_result) = futures::join!(
substrate_api.storage().fetch(&evm_acl_storage_address, None),
substrate_api.storage().fetch(&btc_acl_storage_address, None)
substrate_api.storage().at_latest().await?.fetch(&evm_acl_storage_address),
substrate_api.storage().at_latest().await?.fetch(&btc_acl_storage_address)
);

// if both are errors, the user has no constraints set, and we should error
Expand All @@ -62,8 +65,18 @@ pub async fn get_constraints(
}

Ok(Constraints {
evm_acl: evm_acl_result.unwrap_or_default(),
btc_acl: btc_acl_result.unwrap_or_default(),
evm_acl: Some(
evm_acl_result
.unwrap_or_default()
.unwrap_or_else(|| Static(Acl::<[u8; 20]>::default()))
.0,
),
btc_acl: Some(
btc_acl_result
.unwrap_or_default()
.unwrap_or_else(|| Static(Acl::<[u8; 32]>::default()))
.0,
),
})
}

Expand All @@ -72,15 +85,14 @@ pub async fn get_constraints(
#[cfg(test)]
pub async fn make_register(
api: &OnlineClient<EntropyConfig>,
sig_req_keyring: &Sr25519Keyring,
sig_req_keyring: sr25519::Pair,
constraint_account: &AccountId32,
) {
let sig_req_account =
PairSigner::<EntropyConfig, sp_core::sr25519::Pair>::new(sig_req_keyring.pair());
let sig_req_account = PairSigner::<EntropyConfig, sr25519::Pair>::new(sig_req_keyring);

let registering_query =
entropy::storage().relayer().registering(sig_req_keyring.to_account_id());
let is_registering_1 = api.storage().fetch(&registering_query, None).await.unwrap();
let registering_query = entropy::storage().relayer().registering(sig_req_account.account_id());
let is_registering_1 =
api.storage().at_latest().await.unwrap().fetch(&registering_query).await.unwrap();
println!("is_registering_1: {:?}", is_registering_1);
assert!(is_registering_1.is_none());

Expand All @@ -98,19 +110,22 @@ pub async fn make_register(
.await
.unwrap();

let query_registering_status = api.storage().fetch(&registering_query, None).await;
let query_registering_status =
api.storage().at_latest().await.unwrap().fetch(&registering_query).await;
assert!(query_registering_status.unwrap().unwrap().is_registering);
}

/// Returns wether an account is registered
pub async fn is_registered(
api: &OnlineClient<EntropyConfig>,
who: &AccountId32,
who: &<EntropyConfig as Config>::AccountId,
) -> Result<(), UserErr> {
let registered_info_query = entropy::storage().relayer().registered(who);
let _ = api
.storage()
.fetch(&registered_info_query, None)
.at_latest()
.await?
.fetch(&registered_info_query)
.await?
.ok_or_else(|| UserErr::NotRegistering("Register Onchain first"))?;
Ok(())
Expand Down
Loading

0 comments on commit dff3249

Please sign in to comment.