Skip to content
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

Use tangle runtime metadata #462

Merged
merged 22 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ jobs:
run: cd tests && dvc pull && yarn

- name: Pull Docker Images used for testing.
run: docker pull ghcr.io/webb-tools/protocol-substrate-standalone-node:stable
run: docker pull ghcr.io/webb-tools/tangle/tangle-standalone-integration-tests:main

- name: Webb Relayer Integration tests.
run: cd tests && yarn ${{ matrix.test-type }}
Expand Down
6 changes: 3 additions & 3 deletions crates/bridge-registry-backends/src/dkg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use webb::substrate::subxt::{OnlineClient, PolkadotConfig};
use webb::substrate::dkg_runtime::api as RuntimeApi;
use webb::substrate::dkg_runtime::api::runtime_types::pallet_bridge_registry::types::BridgeMetadata;
use webb::substrate::tangle_runtime::api as RuntimeApi;
use webb::substrate::tangle_runtime::api::runtime_types::pallet_bridge_registry::types::BridgeMetadata;
use webb_proposals::ResourceId;

pub struct DkgBridgeRegistryBackend {
Expand Down Expand Up @@ -32,7 +32,7 @@ impl super::BridgeRegistryBackend for DkgBridgeRegistryBackend {
&self,
resource_id: &ResourceId,
) -> Option<u32> {
let resource_id2 = webb::substrate::dkg_runtime::api::runtime_types::webb_proposals::header::ResourceId(resource_id.0);
let resource_id2 = webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::ResourceId(resource_id.0);
let storage = RuntimeApi::storage().bridge_registry();
let resource_to_bridge_index =
storage.resource_to_bridge_index(resource_id2);
Expand Down
2 changes: 1 addition & 1 deletion crates/bridge-registry-backends/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! - `DKGBridgeRegistryBackend`: This is the actual backend that is used in production.

use ethereum_types::H256;
use webb::substrate::dkg_runtime::api::runtime_types::pallet_bridge_registry::types::BridgeMetadata;
use webb::substrate::tangle_runtime::api::runtime_types::pallet_bridge_registry::types::BridgeMetadata;
use webb_proposals::ResourceId;
use webb_relayer_config::anchor::LinkedAnchorConfig;
use webb_relayer_config::anchor::RawResourceId;
Expand Down
8 changes: 4 additions & 4 deletions crates/bridge-registry-backends/src/mocked.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use typed_builder::TypedBuilder;
use webb::substrate::dkg_runtime::api::runtime_types::pallet_bridge_registry::types::{BridgeInfo, BridgeMetadata, SerdeData};
use webb::substrate::dkg_runtime::api::runtime_types::pallet_identity::types::Data;
use webb::substrate::tangle_runtime::api::runtime_types::pallet_bridge_registry::types::{BridgeInfo, BridgeMetadata, SerdeData};
use webb::substrate::tangle_runtime::api::runtime_types::pallet_identity::types::Data;
use webb::substrate::scale::DecodeAll;
use crate::BridgeRegistryBackend;use hex_literal::hex;
use webb::substrate::dkg_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec;
use webb::substrate::dkg_runtime::api::runtime_types::webb_proposals::header::ResourceId;
use webb::substrate::tangle_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::ResourceId;

#[derive(TypedBuilder)]
pub struct MockedBridgeRegistryBackend {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use futures::StreamExt;
use sp_core::sr25519::Pair;
use sp_core::Pair as _;
use webb::substrate::dkg_runtime::api as RuntimeApi;
use webb::substrate::dkg_runtime::api::runtime_types::webb_proposals::header::ResourceId as DkgResourceId;
use webb::substrate::dkg_runtime::api::runtime_types::webb_proposals::header::TypedChainId as DkgTypedChainId;
use webb::substrate::dkg_runtime::api::runtime_types::webb_proposals::nonce::Nonce as DkgNonce;
use webb::substrate::dkg_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec;
use webb::substrate::tangle_runtime::api as RuntimeApi;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::ResourceId as DkgResourceId;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::TypedChainId as DkgTypedChainId;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::nonce::Nonce as DkgNonce;
use webb::substrate::tangle_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec;
use webb::substrate::subxt::tx::{PairSigner, TxProgress, TxStatus};
use webb::substrate::subxt::{OnlineClient, PolkadotConfig};
use webb_bridge_registry_backends::dkg::DkgBridgeRegistryBackend;
Expand Down
2 changes: 1 addition & 1 deletion crates/event-watcher-traits/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

use std::sync::Arc;
use tokio::sync::Mutex;
use webb::substrate::dkg_runtime::api::system;
use webb::substrate::subxt::{self, Config, OnlineClient, PolkadotConfig};
use webb::substrate::tangle_runtime::api::system;
use webb_relayer_config::event_watcher::EventsWatcherConfig;
use webb_relayer_context::RelayerContext;
use webb_relayer_store::sled::SledStore;
Expand Down
8 changes: 4 additions & 4 deletions crates/proposal-signing-backends/src/dkg.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::sync::Arc;
use tokio::sync::Mutex;
use webb::substrate::dkg_runtime::api::runtime_types::webb_proposals::header::{TypedChainId, ResourceId};
use webb::substrate::dkg_runtime::api::runtime_types::webb_proposals::nonce::Nonce;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::{TypedChainId, ResourceId};
use webb::substrate::tangle_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::nonce::Nonce;
use webb::substrate::subxt::{OnlineClient, PolkadotConfig};
use sp_core::sr25519::Pair as Sr25519Pair;
use webb::evm::ethers::utils;
use webb_proposals::ProposalTrait;
use webb::substrate::scale::{Encode, Decode};
use webb_relayer_utils::metric;
use webb::substrate::dkg_runtime::api as RuntimeApi;
use webb::substrate::tangle_runtime::api as RuntimeApi;
use webb_relayer_store::{QueueStore, SledStore};
use webb_relayer_store::sled::SledQueueKey;
use webb::substrate::subxt::tx::PairSigner;
use webb::substrate::dkg_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec;

type DkgConfig = PolkadotConfig;
type DkgClient = OnlineClient<DkgConfig>;
Expand Down
12 changes: 0 additions & 12 deletions crates/relayer-config/src/substrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ pub struct SubstrateConfig {
pub suri: Option<Suri>,
/// Optionally, a user can specify an account to receive rewards for relaying
pub beneficiary: Option<Public>,
/// Which Substrate Runtime to use?
pub runtime: SubstrateRuntime,
/// Supported pallets over this substrate node.
#[serde(default)]
pub pallets: Vec<Pallet>,
Expand Down Expand Up @@ -102,16 +100,6 @@ pub enum Pallet {
VAnchorBn254(VAnchorBn254PalletConfig),
}

/// Enumerates the supported Substrate runtimes.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SubstrateRuntime {
/// The DKG runtime. (dkg-substrate)
#[serde(rename = "DKG")]
Dkg,
/// The Webb Protocol runtime. (protocol-substrate)
WebbProtocol,
}

/// DKGProposalsPalletConfig represents the configuration for the DKGProposals pallet.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all(serialize = "camelCase", deserialize = "kebab-case"))]
Expand Down
8 changes: 4 additions & 4 deletions crates/tx-relay/src/substrate/mixer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::*;
use crate::substrate::handle_substrate_tx;
use webb::substrate::protocol_substrate_runtime::api as RuntimeApi;
use webb::substrate::tangle_runtime::api as RuntimeApi;
use webb::substrate::tangle_runtime::api::runtime_types::tangle_standalone_runtime::protocol_substrate_config::Element;
use webb::substrate::{
protocol_substrate_runtime::api::runtime_types::webb_primitives::runtime::Element,
subxt::{tx::PairSigner, SubstrateConfig},
subxt::{tx::PairSigner, PolkadotConfig},
};
use webb_relayer_context::RelayerContext;
use webb_relayer_handler_utils::SubstrateMixerCommand;
Expand All @@ -27,7 +27,7 @@ pub async fn handle_substrate_mixer_relay_tx<'a>(

let requested_chain = cmd.chain_id;
let client = ctx
.substrate_provider::<SubstrateConfig>(&requested_chain.to_string())
.substrate_provider::<PolkadotConfig>(&requested_chain.to_string())
.await
.map_err(|e| {
Error(format!("Error while getting Substrate client: {e}"))
Expand Down
7 changes: 2 additions & 5 deletions crates/tx-relay/src/substrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ethereum_types::H256;
use futures::TryStreamExt;
use webb::substrate::subxt::{
tx::TxProgress, tx::TxStatus as TransactionStatus, OnlineClient,
SubstrateConfig,
PolkadotConfig,
};
use webb_relayer_handler_utils::{
CommandResponse, CommandStream, WithdrawStatus,
Expand All @@ -19,10 +19,7 @@ pub mod vanchor;
/// is intended to be used in a variety of places for all kinds of submitted Substrate
/// transactions.
pub async fn handle_substrate_tx(
mut event_stream: TxProgress<
SubstrateConfig,
OnlineClient<SubstrateConfig>,
>,
mut event_stream: TxProgress<PolkadotConfig, OnlineClient<PolkadotConfig>>,
stream: CommandStream,
chain_id: u64,
) -> Result<(), CommandResponse> {
Expand Down
11 changes: 6 additions & 5 deletions crates/tx-relay/src/substrate/vanchor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use super::*;
use crate::substrate::handle_substrate_tx;
use webb::evm::ethers::utils::hex;
use webb::substrate::protocol_substrate_runtime::api as RuntimeApi;
use webb::substrate::tangle_runtime::api as RuntimeApi;
use webb::substrate::subxt::utils::AccountId32;
use webb::substrate::tangle_runtime::api::runtime_types::tangle_standalone_runtime::protocol_substrate_config::Element;
use webb::substrate::{
protocol_substrate_runtime::api::runtime_types::{
webb_primitives::runtime::Element, webb_primitives::types::vanchor,
tangle_runtime::api::runtime_types::{
webb_primitives::types::vanchor,
},
subxt::{tx::PairSigner, SubstrateConfig},
subxt::{tx::PairSigner, PolkadotConfig},
};
use webb_proposals::{
ResourceId, SubstrateTargetSystem, TargetSystem, TypedChainId,
Expand Down Expand Up @@ -61,7 +62,7 @@ pub async fn handle_substrate_vanchor_relay_tx<'a>(

let requested_chain = cmd.chain_id;
let maybe_client = ctx
.substrate_provider::<SubstrateConfig>(&requested_chain.to_string())
.substrate_provider::<PolkadotConfig>(&requested_chain.to_string())
.await;
let client = maybe_client.map_err(|e| {
Error(format!("Error while getting Substrate client: {e}"))
Expand Down
6 changes: 3 additions & 3 deletions event-watchers/dkg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ pub use proposal_signed_handler::*;
mod public_key_changed_handler;
#[doc(hidden)]
pub use public_key_changed_handler::*;
use webb::substrate::dkg_runtime::api::{
use webb::substrate::subxt::events::StaticEvent;
use webb::substrate::subxt::{self, PolkadotConfig};
use webb::substrate::tangle_runtime::api::{
dkg::events::PublicKeySignatureChanged,
dkg_proposal_handler::events::ProposalSigned,
};
use webb::substrate::subxt::events::StaticEvent;
use webb::substrate::subxt::{self, PolkadotConfig};
use webb_event_watcher_traits::SubstrateEventWatcher;

/// The DKGMetadataWatcher watches for the events from Dkg Pallet.
Expand Down
4 changes: 2 additions & 2 deletions event-watchers/dkg/src/proposal_signed_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use std::sync::Arc;

use tokio::sync::Mutex;

use webb::substrate::dkg_runtime::api::dkg_proposal_handler;
use webb::substrate::dkg_runtime::api::runtime_types::webb_proposals::header::TypedChainId;
use webb::substrate::tangle_runtime::api::dkg_proposal_handler;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::TypedChainId;
use webb::substrate::subxt::{self, OnlineClient, PolkadotConfig};

use webb_relayer_store::sled::{SledQueueKey, SledStore};
Expand Down
2 changes: 1 addition & 1 deletion event-watchers/dkg/src/public_key_changed_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

use std::sync::Arc;
use tokio::sync::Mutex;
use webb::substrate::dkg_runtime::api::dkg;
use webb::substrate::subxt::{self, OnlineClient, PolkadotConfig};
use webb::substrate::tangle_runtime::api::dkg;

use webb_relayer_store::sled::{SledQueueKey, SledStore};
use webb_relayer_store::{BridgeCommand, BridgeKey, QueueStore};
Expand Down
8 changes: 4 additions & 4 deletions event-watchers/substrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub use vanchor_encrypted_output_handler::*;
pub use vanchor_leaves_handler::*;
use webb::substrate::subxt::events::StaticEvent;
use webb::substrate::{
protocol_substrate_runtime::api::v_anchor_bn254::events::Transaction,
subxt::{OnlineClient, SubstrateConfig},
subxt::{OnlineClient, PolkadotConfig},
tangle_runtime::api::v_anchor_bn254::events::Transaction,
};
use webb_event_watcher_traits::SubstrateEventWatcher;
use webb_relayer_store::SledStore;
Expand All @@ -37,12 +37,12 @@ use webb_relayer_store::SledStore;
pub struct SubstrateVAnchorEventWatcher;

#[async_trait::async_trait]
impl SubstrateEventWatcher<SubstrateConfig> for SubstrateVAnchorEventWatcher {
impl SubstrateEventWatcher<PolkadotConfig> for SubstrateVAnchorEventWatcher {
const TAG: &'static str = "Substrate VAnchor Event Watcher";

const PALLET_NAME: &'static str = Transaction::PALLET;

type Client = OnlineClient<SubstrateConfig>;
type Client = OnlineClient<PolkadotConfig>;

type Store = SledStore;
}
37 changes: 19 additions & 18 deletions event-watchers/substrate/src/signature_bridge_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::sync::Arc;
use tokio::sync::Mutex;

use sp_core::hashing::keccak_256;
use webb::substrate::subxt::config::SubstrateConfig;
use webb::substrate::subxt::config::PolkadotConfig;
use webb::substrate::subxt::events::StaticEvent;

use sp_core::sr25519::Pair as Sr25519Pair;
Expand All @@ -30,27 +30,28 @@ use webb_relayer_store::sled::{SledQueueKey, SledStore};
use webb_relayer_store::{BridgeCommand, QueueStore};

use webb::evm::ethers::utils;
use webb::substrate::protocol_substrate_runtime::api as RuntimeApi;
use webb::substrate::protocol_substrate_runtime::api::signature_bridge::events::MaintainerSet;
use webb::substrate::tangle_runtime::api as RuntimeApi;
use webb::substrate::tangle_runtime::api::signature_bridge::events::MaintainerSet;

use webb::substrate::scale::Encode;
use webb_relayer_utils::{metric, Error};

use webb::substrate::protocol_substrate_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec;
use webb::substrate::tangle_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec;

/// A MaintainerSetEvent handler handles `MaintainerSet` events and signals signature bridge watcher
/// to remove pending tx trying to do governor transfer.
#[derive(Copy, Clone, Debug, Default)]
pub struct MaintainerSetEventHandler;

#[async_trait::async_trait]
impl EventHandler<SubstrateConfig> for MaintainerSetEventHandler {
type Client = OnlineClient<SubstrateConfig>;
impl EventHandler<PolkadotConfig> for MaintainerSetEventHandler {
type Client = OnlineClient<PolkadotConfig>;

type Store = SledStore;

async fn can_handle_events(
&self,
events: subxt::events::Events<SubstrateConfig>,
events: subxt::events::Events<PolkadotConfig>,
) -> webb_relayer_utils::Result<bool> {
let has_event = events.has::<MaintainerSet>()?;
Ok(has_event)
Expand All @@ -60,7 +61,7 @@ impl EventHandler<SubstrateConfig> for MaintainerSetEventHandler {
&self,
_store: Arc<Self::Store>,
_client: Arc<Self::Client>,
(events, _block_number): (subxt::events::Events<SubstrateConfig>, u64),
(events, _block_number): (subxt::events::Events<PolkadotConfig>, u64),
_metrics: Arc<Mutex<metric::Metrics>>,
) -> webb_relayer_utils::Result<()> {
// todo
Expand Down Expand Up @@ -94,15 +95,15 @@ impl EventHandler<SubstrateConfig> for MaintainerSetEventHandler {
#[derive(Copy, Clone, Debug, Default)]
pub struct SubstrateBridgeEventWatcher;

impl SubstrateEventWatcher<SubstrateConfig> for SubstrateBridgeEventWatcher {
impl SubstrateEventWatcher<PolkadotConfig> for SubstrateBridgeEventWatcher {
const TAG: &'static str = "Substrate bridge pallet Watcher";
const PALLET_NAME: &'static str = MaintainerSet::PALLET;
type Client = OnlineClient<SubstrateConfig>;
type Client = OnlineClient<PolkadotConfig>;
type Store = SledStore;
}

#[async_trait::async_trait]
impl SubstrateBridgeWatcher<SubstrateConfig> for SubstrateBridgeEventWatcher {
impl SubstrateBridgeWatcher<PolkadotConfig> for SubstrateBridgeEventWatcher {
#[tracing::instrument(skip_all)]
async fn handle_cmd(
&self,
Expand Down Expand Up @@ -146,14 +147,14 @@ impl SubstrateBridgeWatcher<SubstrateConfig> for SubstrateBridgeEventWatcher {

impl SubstrateBridgeEventWatcher
where
Self: SubstrateBridgeWatcher<SubstrateConfig>,
Self: SubstrateBridgeWatcher<PolkadotConfig>,
{
#[tracing::instrument(skip_all)]
async fn execute_proposal_with_signature(
&self,
chain_id: u32,
store: Arc<<Self as SubstrateEventWatcher<SubstrateConfig>>::Store>,
api: Arc<<Self as SubstrateEventWatcher<SubstrateConfig>>::Client>,
store: Arc<<Self as SubstrateEventWatcher<PolkadotConfig>>::Store>,
api: Arc<<Self as SubstrateEventWatcher<PolkadotConfig>>::Client>,
pair: Sr25519Pair,
(proposal_data, signature): (Vec<u8>, Vec<u8>),
) -> webb_relayer_utils::Result<()> {
Expand Down Expand Up @@ -220,7 +221,7 @@ where
BoundedVec(signature),
);

let signer: PairSigner<SubstrateConfig, Sr25519Pair> =
let signer: PairSigner<PolkadotConfig, Sr25519Pair> =
subxt::tx::PairSigner::new(pair);
let signed_execute_proposal_tx = api
.tx()
Expand Down Expand Up @@ -250,8 +251,8 @@ where
async fn transfer_ownership_with_signature(
&self,
chain_id: u32,
store: Arc<<Self as SubstrateEventWatcher<SubstrateConfig>>::Store>,
api: Arc<<Self as SubstrateEventWatcher<SubstrateConfig>>::Client>,
store: Arc<<Self as SubstrateEventWatcher<PolkadotConfig>>::Store>,
api: Arc<<Self as SubstrateEventWatcher<PolkadotConfig>>::Client>,
pair: Sr25519Pair,
(public_key, nonce, signature): (Vec<u8>, u32, Vec<u8>),
) -> webb_relayer_utils::Result<()> {
Expand Down Expand Up @@ -323,7 +324,7 @@ where
.signature_bridge()
.set_maintainer(BoundedVec(message), BoundedVec(signature));

let signer: PairSigner<SubstrateConfig, Sr25519Pair> =
let signer: PairSigner<PolkadotConfig, Sr25519Pair> =
subxt::tx::PairSigner::new(pair);
let signed_set_maintainer_tx = api
.tx()
Expand Down
Loading