Skip to content

Commit

Permalink
Update to webb SDK v0.8.0 (#578)
Browse files Browse the repository at this point in the history
* Update to webb SDK v0.8.0

* Pump version
  • Loading branch information
shekohex authored Sep 13, 2023
1 parent 9109819 commit f42ec55
Show file tree
Hide file tree
Showing 34 changed files with 1,776 additions and 4,735 deletions.
5,386 changes: 1,699 additions & 3,687 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.5.12-dev"
version = "0.5.13-dev"
authors = ["Webb Developers <[email protected]>"]
license = "Apache-2.0"
documentation = "https://docs.rs/webb-relayer"
Expand Down Expand Up @@ -41,10 +41,9 @@ tokio = { version = "^1", features = ["full"] }
config = { version = "0.13", default-features = false, features = ["toml", "json"] }
serde_json = { version = "^1", default-features = false }
paw = { version = "^1.0" }
webb = { version = "0.7.3", default-features = false }
# webb = { version = "0.5.24", git = "https://github.com/webb-tools/webb-rs", default-features = false, rev = "13390b9"}
sp-core = { version = "21.0.0", default-features = false }
sp-runtime = { version = "24.0.0", default-features = false }
webb = { version = "0.8.0", default-features = false }
subxt-signer = { version = "0.31", features = ["subxt"] }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { version = "^0.2", features = ["vendored"] }
webb-proposals = { git = "https://github.com/webb-tools/webb-rs", rev="a960eaf", features = ["scale"] }
Expand All @@ -57,7 +56,7 @@ async-trait = "^0.1"
futures = { version = "^0.3", default-features = false }
parking_lot = "^0.12"
rand = { version = "0.8", default-features = false, features = ["getrandom"] }
typed-builder = "0.15.1"
typed-builder = "0.16.0"
backoff = { version = "0.4.0", features = ["tokio"] }
hex = { version = "0.4", default-features = false }
libsecp256k1 = "0.7.1"
Expand All @@ -66,12 +65,6 @@ glob = "^0.3"
serde_path_to_error = "0.1.9"
serde_bytes = "0.11"

# eth2 light client crates
eth-rpc-client = { package = "eth_rpc_client", git = "https://github.com/webb-tools/pallet-eth2-light-client" }
eth2-pallet-init = { git = "https://github.com/webb-tools/pallet-eth2-light-client" }
eth2_to_substrate_relay = { git = "https://github.com/webb-tools/pallet-eth2-light-client" }
eth-types = { git = "https://github.com/webb-tools/pallet-eth2-light-client" }

[profile.release]
strip = "symbols"
lto = "thin"
Expand Down
38 changes: 0 additions & 38 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ following section we will describe the different configuration entries and how t
- [enabled](#enabled-2)
- [explorer](#explorer-1)
- [suri](#suri)
- [beneficiary](#beneficiary-1)
- [runtime](#runtime)
- [tx-queue](#tx-queue-1)
- [max-sleep-interval](#max-sleep-interval-1)
- [pallets](#pallets)
Expand Down Expand Up @@ -952,25 +950,6 @@ Example:
ws-endpoint = "ws://localhost:9944"
```

#### runtime

The runtime of the running substrate node. These are predefined in the relayer, with each having
different types of Options.

- Type: `string`
- Required: `true`
- env: `WEBB_SUBSTRATE_<NODE_NAME>_RUNTIME`
- Possible values:
- `DKG` (that is, `dkg-substrate`)
- `WebbProtocol` (also known as `protocol-substrate`)

Example:

```toml
[substrate.tangle]
runtime = "WebbProtocol"
```

#### enabled

Whether the Substrate node is enabled or not. If it is not enabled, the relayer will not try to add
Expand Down Expand Up @@ -1052,23 +1031,6 @@ Example:
suri = "$TANGLE_SURI"
```

#### beneficiary

The beneficiary is the address that will receive the fees from the transactions. This is optional,
and will default to the address derived from the `suri` if not provided.

- Type: `string`
- Required: `false`
- Default: `null`
- env: `WEBB_SUBSTRATE_<NODE_NAME>_BENEFICIARY`

Example:

```toml
[substrate.tangle]
beneficiary = "5FZ2Wfjy5rZ7g5j7Y9Zwv5Z4Z3Z9Z9Z9Z9Z9Z9Z9Z9Z9Z9Z9Z9"
```

#### Tx Queue

The transaction queue is a queue of transactions that are waiting to be sent to the Substrate node.
Expand Down
6 changes: 4 additions & 2 deletions crates/bridge-registry-backends/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ webb = { workspace = true }
native-tls = { workspace = true, optional = true }
webb-proposals = { workspace = true }
ethereum-types = { workspace = true }
sp-core = { workspace = true }

typed-builder = { workspace = true }
hex-literal = "0.3.4"
hex-literal = "0.4"

[dev-dependencies]
subxt-signer = { workspace = true, features = ["subxt"] }

[features]
default = ["std"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use futures::StreamExt;
use sp_core::sr25519::Pair;
use sp_core::Pair as _;
use webb::substrate::tangle_runtime::api as RuntimeApi;
use webb::substrate::tangle_runtime::api::runtime_types::bounded_collections::bounded_vec::BoundedVec;
use webb::substrate::subxt::tx::{PairSigner, TxProgress, TxStatus};
use webb::substrate::subxt::tx::{TxProgress, TxStatus};
use webb::substrate::subxt::OnlineClient;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::proposal::Proposal;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::proposal::ProposalKind;
Expand Down Expand Up @@ -38,14 +36,11 @@ async fn submit_anchor_update_proposal() {
println!("Source Resource ID: {}", hex::encode(src_resource_id.0));

let tx_api = RuntimeApi::tx().dkg_proposals();
let sudo_account: PairSigner<TangleRuntimeConfig, Pair> =
PairSigner::new(Pair::from_string("//Alice", None).unwrap());
let account_nonce = api
.rpc()
.system_account_next_index(sudo_account.account_id())
.await
.unwrap();

let sudo_account = subxt_signer::sr25519::dev::alice();
// let account_nonce_payload = RuntimeApi::apis().account_nonce_api().account_nonce(Signer::account_id(&sudo_account));
// let account_nonce = api.runtime_api().at_latest().await.unwrap().call(account_nonce_payload).await.unwrap();
// FIXME: account nonce is not correct
let account_nonce = 0;
// following code runs in a loop in original code
{
let proposal_header = ProposalHeader::new(
Expand Down
6 changes: 4 additions & 2 deletions crates/event-watcher-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ webb = { workspace = true }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { workspace = true }
webb-proposals = { workspace = true }
tracing-test = "0.2"
sled = { version = "^0.34" }
sp-core = { workspace = true }
subxt-signer = { workspace = true }

[dev-dependencies]
tracing-test = "0.2"

[features]
default = ["std", "evm", "substrate"]
Expand Down
13 changes: 11 additions & 2 deletions crates/event-watcher-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@
#[cfg(feature = "evm")]
pub mod evm;
#[cfg(feature = "evm")]
pub use evm::*;
pub use evm::{
BridgeWatcher, EthersClient, EthersTimeLagClient,
EventHandler as EVMEventHandler,
EventHandlerWithRetry as EVMEventHandlerWithRetry,
EventWatcher as EVMEventWatcher,
};

#[cfg(feature = "substrate")]
pub mod substrate;
#[cfg(feature = "substrate")]
pub use substrate::*;
pub use substrate::{
EventHandler as SubstrateEventHandler,
EventHandlerWithRetry as SubstrateEventHandlerWithRetry,
SubstrateEventWatcher,
};

#[cfg(test)]
mod tests;
3 changes: 2 additions & 1 deletion crates/price-oracle-backends/src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ where
Default::default(),
)
.expect("Time went backwards");
DateTime::<Utc>::from_utc(ts, Utc) < Utc::now()
DateTime::<Utc>::from_naive_utc_and_offset(ts, Utc)
< Utc::now()
});
// If the cache is expired, add the token to the list of tokens to fetch
if expired {
Expand Down
2 changes: 1 addition & 1 deletion crates/proposal-signing-backends/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ futures = { workspace = true }
tokio = { workspace = true }
hex = { workspace = true }
webb = { workspace = true }
sp-core = { workspace = true }
subxt-signer = { workspace = true }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { workspace = true, optional = true }
webb-proposals = { workspace = true }
Expand Down
6 changes: 1 addition & 5 deletions crates/relayer-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ documentation = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
webb-relayer-store = { path = "../relayer-store" }
webb-relayer-types = { path = "../relayer-types" }
webb-relayer-utils = { path = "../relayer-utils" }
eth2_to_substrate_relay = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true }
tracing = { workspace = true }
url = { workspace = true }
serde = { workspace = true }
config = { workspace = true }
serde_json = { workspace = true }
webb = { workspace = true }
sp-core = { workspace = true }
subxt-signer = { workspace = true }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { workspace = true, optional = true }
webb-proposals = { workspace = true }
Expand All @@ -43,4 +40,3 @@ cli = ["evm-runtime", "substrate-runtime", "anyhow", "tracing-subscriber", "stru
evm-runtime = ["webb/evm-runtime", "webb-proposals/evm"]
substrate-runtime = ["webb/substrate-runtime", "webb-proposals/substrate"]
integration-tests = ["tracing-subscriber/json"]
eth2 = ["eth2_to_substrate_relay"]
3 changes: 0 additions & 3 deletions crates/relayer-config/src/substrate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::*;
use sp_core::sr25519::Public;
use webb_relayer_types::{rpc_url::RpcUrl, suri::Suri};

use crate::event_watcher::EventsWatcherConfig;
Expand Down Expand Up @@ -58,8 +57,6 @@ pub struct SubstrateConfig {
/// `None` is returned if no matches are found.
#[serde(skip_serializing)]
pub suri: Option<Suri>,
/// Optionally, a user can specify an account to receive rewards for relaying
pub beneficiary: Option<Public>,
/// Supported pallets over this substrate node.
#[serde(default)]
pub pallets: Vec<Pallet>,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ webb-price-oracle-backends = { workspace = true, features = ["coingecko"] }
tracing = { workspace = true }
tokio = { workspace = true }
webb = { workspace = true }
sp-core = { workspace = true }
subxt-signer = { workspace = true }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { workspace = true }
serde = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use webb::evm::ethers::core::k256::SecretKey;
use webb::evm::ethers::prelude::*;

#[cfg(feature = "substrate")]
use sp_core::sr25519::Pair as Sr25519Pair;
use subxt_signer::sr25519::Keypair as Sr25519Pair;
use webb::evm::ethers::middleware::gas_oracle::{
Cache as CachedGasOracle, Etherscan as EtherscanGasOracle,
Median as GasOracleMedian, ProviderOracle,
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-handlers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde = { workspace = true }
tokio = { workspace = true }
serde_json = { workspace = true }
webb = { workspace = true }
sp-core = { workspace = true }
subxt-signer = { workspace = true }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { workspace = true }
webb-proposals = { workspace = true }
Expand Down
13 changes: 0 additions & 13 deletions crates/relayer-handlers/src/routes/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::sync::Arc;
use webb_relayer_handler_utils::IpInformationResponse;

use serde::Serialize;
use sp_core::Pair;
use webb::evm::ethers::{
prelude::k256::SecretKey,
signers::{LocalWallet, Signer},
Expand Down Expand Up @@ -65,18 +64,6 @@ pub async fn handle_relayer_info(
v.beneficiary = Some(wallet.address());
webb_relayer_utils::Result::Ok(())
});
let _ = config
.substrate
.values_mut()
.filter(|v| v.beneficiary.is_none())
.try_for_each(|v| {
let suri = v
.suri
.as_ref()
.ok_or(webb_relayer_utils::Error::MissingSecrets)?;
v.beneficiary = Some(suri.public());
webb_relayer_utils::Result::Ok(())
});

// Build info
let build_info = BuildInfo {
Expand Down
2 changes: 1 addition & 1 deletion crates/relayer-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ webb = { workspace = true }
native-tls = { workspace = true }
ethereum-types = { workspace = true }

sp-core = { workspace = true }
subxt-signer = { workspace = true }
tiny-bip39 = "1.0.0"
46 changes: 28 additions & 18 deletions crates/relayer-types/src/suri.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::str::FromStr;

use serde::Deserialize;
use sp_core::sr25519::Pair as Sr25519Pair;
use sp_core::Pair;
use subxt_signer::sr25519::Keypair as Sr25519Pair;

/// [`Substrate Uri`](https://polkadot.js.org/docs/keyring/start/suri/)
#[derive(Clone)]
Expand Down Expand Up @@ -57,25 +58,11 @@ impl<'de> Deserialize<'de> for Suri {
"error while loading this env {var}: {e}",
))
})?;
let maybe_pair =
Sr25519Pair::from_string_with_seed(&val, None);
match maybe_pair {
Ok((pair, _)) => Ok(pair),
Err(e) => {
Err(serde::de::Error::custom(format!("{e:?}")))
}
}
parse_suri(&val)
} else if value.starts_with('>') {
todo!("Implement command execution to extract the private key")
} else {
let maybe_pair =
Sr25519Pair::from_string_with_seed(value, None);
match maybe_pair {
Ok((pair, _)) => Ok(pair),
Err(e) => {
Err(serde::de::Error::custom(format!("{e:?}")))
}
}
parse_suri(value)
}
}
}
Expand All @@ -84,3 +71,26 @@ impl<'de> Deserialize<'de> for Suri {
Ok(Self(secret))
}
}

fn parse_suri<E>(val: &str) -> Result<Sr25519Pair, E>
where
E: serde::de::Error,
{
use subxt_signer::bip39::Mnemonic;
use subxt_signer::SecretUri;

let secret_uri = SecretUri::from_str(val);
if let Ok(secret_uri) = secret_uri {
return Sr25519Pair::from_uri(&secret_uri)
.map_err(|e| serde::de::Error::custom(e.to_string()));
}
let mnemonic = Mnemonic::from_str(val);
if let Ok(mnemonic) = mnemonic {
return Sr25519Pair::from_phrase(&mnemonic, None)
.map_err(|e| serde::de::Error::custom(e.to_string()));
}

Err(serde::de::Error::custom(format!(
"Failed to parse {val} as SURI or mnemonic"
)))
}
5 changes: 2 additions & 3 deletions crates/tx-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ futures = { workspace = true }
backoff = { workspace = true }
tokio = { workspace = true }
webb = { workspace = true }
sp-core = { workspace = true, optional = true }
sp-runtime = { workspace = true, optional = true }
subxt-signer = { workspace = true, optional = true }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { workspace = true, optional = true }
ethereum-types = { workspace = true }
Expand All @@ -36,7 +35,7 @@ rand = { workspace = true, default-features = false, features = ["getrandom"] }
default = ["std", "evm", "substrate"]
std = []
evm = ["webb-relayer-context/evm"]
substrate = ["webb-relayer-context/substrate", "sp-core", "sp-runtime"]
substrate = ["webb-relayer-context/substrate", "subxt-signer"]

[dev-dependencies]
webb-relayer-config = { workspace = true }
Expand Down
Loading

0 comments on commit f42ec55

Please sign in to comment.