Skip to content

Commit

Permalink
Update webb to v0.7.3 (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekohex authored Jul 19, 2023
1 parent 62dec71 commit 2dd3388
Show file tree
Hide file tree
Showing 23 changed files with 624 additions and 5,844 deletions.
238 changes: 134 additions & 104 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.5.6-dev"
version = "0.5.7-dev"
authors = ["Webb Developers <drew@webb.tools>"]
license = "Apache-2.0"
documentation = "https://docs.rs/webb-relayer"
Expand Down Expand Up @@ -41,7 +41,7 @@ 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.6.1", default-features = false }
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 }
Expand All @@ -57,7 +57,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.14.0"
typed-builder = "0.15.1"
backoff = { version = "0.4.0", features = ["tokio"] }
hex = { version = "0.4", default-features = false }
libsecp256k1 = "0.7.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ 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::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::bounded_collections::bounded_vec::BoundedVec;
use webb::substrate::subxt::tx::{PairSigner, TxProgress, TxStatus};
use webb::substrate::subxt::OnlineClient;
Expand Down Expand Up @@ -71,12 +68,7 @@ async fn submit_anchor_update_proposal() {
kind: ProposalKind::AnchorUpdate,
data: BoundedVec(anchor_update_proposal.to_vec()),
};
let xt = tx_api.acknowledge_proposal(
DkgNonce(account_nonce),
DkgTypedChainId::Evm(5001),
DkgResourceId(resource_id.into_bytes()),
unsigned_proposal,
);
let xt = tx_api.acknowledge_proposal(unsigned_proposal);

let mut progress = api
.tx()
Expand Down
15 changes: 3 additions & 12 deletions crates/proposal-signing-backends/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use std::sync::Arc;
use tokio::sync::Mutex;
use webb::substrate::tangle_runtime::api::runtime_types::bounded_collections::bounded_vec::BoundedVec;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::{TypedChainId, ResourceId};
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::nonce::Nonce;
use webb::substrate::subxt::OnlineClient;
use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::proposal::{Proposal, ProposalKind};
use webb_proposals::ProposalTrait;
use webb::substrate::scale::{Encode, Decode};
use webb_relayer_store::queue::{QueueStore, QueueItem, TransactionQueueItemKey};
use webb_relayer_utils::{metric, TangleRuntimeConfig};
use webb::substrate::tangle_runtime::api as RuntimeApi;
Expand Down Expand Up @@ -96,27 +94,20 @@ impl super::ProposalSigningBackend for DkgProposalSigningBackend {
let tx_api = RuntimeApi::tx().dkg_proposals();
let resource_id = proposal.header().resource_id();
let nonce = proposal.header().nonce();
let src_chain_id =
webb_proposals_typed_chain_converter(self.src_chain_id);
tracing::debug!(
nonce = nonce.0,
resource_id = hex::encode(resource_id.into_bytes()),
src_chain_id = ?self.src_chain_id,
proposal = hex::encode(proposal.to_vec()),
proposal = format!("0x{}", hex::encode(proposal.to_vec())),
"sending proposal to DKG runtime"
);

let nonce = Nonce::decode(&mut nonce.encode().as_slice())?;
let unsigned_proposal = Proposal::Unsigned {
kind: ProposalKind::AnchorUpdate,
data: BoundedVec(proposal.to_vec()),
};
let acknowledge_proposal_tx = tx_api.acknowledge_proposal(
nonce,
src_chain_id,
ResourceId(resource_id.into_bytes()),
unsigned_proposal,
);
let acknowledge_proposal_tx =
tx_api.acknowledge_proposal(unsigned_proposal);
let metadata = self.client.metadata();
let tx = TypeErasedStaticTxPayload::try_from((
&metadata,
Expand Down
22 changes: 13 additions & 9 deletions crates/relayer-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,13 @@ pub enum BridgeCommand {
/// backend.
signature: Vec<u8>,
},
/// A Command sent to the Signature Bridge to transfer the ownership with a signature.
TransferOwnershipWithSignature {
/// The new owner public key.
public_key: Vec<u8>,
/// The nonce of this transfer.
/// A Command sent to the Signature Bridge to transfer the ownership of the bridge
TransferOwnership {
voter_merkle_root: [u8; 32],
session_length: u64,
voter_count: u32,
nonce: u32,
pub_key: Vec<u8>,
/// The signature of the hash of the nonce+public key, Signed by the proposal signing
/// backend.
signature: Vec<u8>,
Expand Down Expand Up @@ -411,10 +412,13 @@ pub enum BridgeCommand {

impl From<dkg::events::PublicKeySignatureChanged> for BridgeCommand {
fn from(event: dkg::events::PublicKeySignatureChanged) -> Self {
Self::TransferOwnershipWithSignature {
public_key: event.uncompressed_pub_key,
nonce: event.nonce,
signature: event.pub_key_sig,
Self::TransferOwnership {
signature: event.signature,
voter_merkle_root: event.voter_merkle_root,
session_length: event.session_length,
voter_count: event.voter_count,
nonce: event.nonce.0,
pub_key: event.pub_key,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/relayer-utils/src/static_tx_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct TypeErasedStaticTxPayload {
call_name: String,
#[serde(with = "serde_bytes")]
tx_data: Vec<u8>,
validation_hash: [u8; 32],
}

impl TypeErasedStaticTxPayload {
Expand All @@ -26,6 +27,7 @@ impl std::fmt::Debug for TypeErasedStaticTxPayload {
.field("pallet_name", &self.pallet_name)
.field("call_name", &self.call_name)
.field("tx_data", &hex::encode(&self.tx_data))
.field("validation_hash", &hex::encode(self.validation_hash))
.finish()
}
}
Expand Down Expand Up @@ -59,6 +61,7 @@ impl<'a, CallData: EncodeAsFields>
pallet_name: details.pallet_name.to_owned(),
call_name: details.call_name.to_owned(),
tx_data,
validation_hash: details.hash,
})
}
}
Expand Down
29 changes: 8 additions & 21 deletions crates/tx-queue/src/substrate/substrate_tx_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,15 @@ where
)?;
}
Ok(DryRunResult::TransactionValidityError) => {
// This kinda bugged in Substrate, as it returns this error
// in multiple scenarios, like when the transaction is mostly will
// exhaust the resources. However, the transaction may still be valid
// and succeed if actually included in the block.
//
// Hence, we are not marking this as an error, instead it is a warning.
tracing::event!(
target: webb_relayer_utils::probe::TARGET,
tracing::Level::DEBUG,
tracing::Level::WARN,
kind = %webb_relayer_utils::probe::Kind::TxQueue,
ty = "SUBSTRATE",
chain_id = %chain_id,
Expand All @@ -230,30 +236,11 @@ where
signed_extrinsic = %hex::encode(signed_extrinsic.encoded()),
dry_run = "transaction_validity_error"
);
// update transaction status as Failed and re insert into queue.
store.shift_item_to_end(
SledQueueKey::from_substrate_with_custom_key(
chain_id,
tx_item_key,
),
|item: &mut QueueItem<
TypeErasedStaticTxPayload,
>| {
let state = QueueItemState::Failed {
reason: "Transaction validity error"
.to_string(),
};
item.set_state(state);
Ok(())
},
)?;

continue; // keep going.
}
Ok(DryRunResult::DispatchError(err)) => {
tracing::event!(
target: webb_relayer_utils::probe::TARGET,
tracing::Level::DEBUG,
tracing::Level::ERROR,
kind = %webb_relayer_utils::probe::Kind::TxQueue,
ty = "SUBSTRATE",
chain_id = %chain_id,
Expand Down
34 changes: 19 additions & 15 deletions event-watchers/dkg/src/public_key_changed_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ impl EventHandler<TangleRuntimeConfig> for DKGPublicKeyChangedHandler {
.flatten()
.collect::<Vec<_>>();
for event in pub_key_changed_events {
let event_details = event.clone();
let public_key_uncompressed = event_details.uncompressed_pub_key;
let nonce = event_details.nonce;
tracing::debug!(
public_key_uncompressed = %hex::encode(&public_key_uncompressed),
%nonce,
public_key = %hex::encode(&event.pub_key),
nonce = %event.nonce.0,
voter_merkle_root = %hex::encode(event.voter_merkle_root),
voter_count = %event.voter_count,
session_length = %event.session_length,
signature = %hex::encode(&event.signature),
%block_number,
"DKG Public Key Changed",
);
Expand Down Expand Up @@ -107,17 +108,20 @@ impl EventHandler<TangleRuntimeConfig> for DKGPublicKeyChangedHandler {
kind = %webb_relayer_utils::probe::Kind::SigningBackend,
backend = "DKG",
signal_bridge = %bridge_key,
public_key = %hex::encode(&public_key_uncompressed),
nonce = %nonce,
signature = %hex::encode(&event.pub_key_sig),
);
let item = QueueItem::new(
BridgeCommand::TransferOwnershipWithSignature {
public_key: public_key_uncompressed.clone(),
nonce,
signature: event.pub_key_sig.clone(),
},
public_key = %hex::encode(&event.pub_key),
nonce = %event.nonce.0,
signature = %hex::encode(&event.signature),
);

let item = QueueItem::new(BridgeCommand::TransferOwnership {
nonce: event.nonce.0,
pub_key: event.pub_key.clone(),
signature: event.signature.clone(),
voter_count: event.voter_count,
voter_merkle_root: event.voter_merkle_root,
session_length: event.session_length,
});

store.enqueue_item(
SledQueueKey::from_bridge_key(bridge_key),
item,
Expand Down
44 changes: 35 additions & 9 deletions event-watchers/evm/src/signature_bridge_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,25 @@ impl BridgeWatcher for SignatureBridgeContractWatcher {
)
.await?;
}
TransferOwnershipWithSignature {
public_key,
TransferOwnership {
pub_key,
nonce,
voter_merkle_root,
voter_count,
session_length,
signature,
} => {
self.transfer_ownership_with_signature(
store,
&wrapper.contract,
(public_key, nonce, signature),
(
pub_key,
nonce,
voter_merkle_root,
voter_count,
session_length,
signature,
),
)
.await?
}
Expand Down Expand Up @@ -354,7 +364,14 @@ where
&self,
store: Arc<<Self as EventWatcher>::Store>,
contract: &SignatureBridgeContract<EthersTimeLagClient>,
(public_key, nonce, signature): (Vec<u8>, u32, Vec<u8>),
(
public_key,
nonce,
voter_merkle_root,
voter_count,
session_length,
signature,
): (Vec<u8>, u32, [u8; 32], u32, u64, Vec<u8>),
) -> webb_relayer_utils::Result<()> {
// before doing anything, we need to do just two things:
// 1. check if we already have this transaction in the queue.
Expand Down Expand Up @@ -422,27 +439,36 @@ where
target: webb_relayer_utils::probe::TARGET,
tracing::Level::DEBUG,
kind = %webb_relayer_utils::probe::Kind::SignatureBridge,
call = "transfer_ownership_with_signature_pub_key",
call = "transfer_ownership_with_signature",
chain_id = %chain_id.as_u64(),
public_key = %hex::encode(&public_key),
%nonce,
voter_merkle_root = %hex::encode(voter_merkle_root),
%voter_count,
%session_length,
signature = %hex::encode(&signature),
);
// estimated gas
let estimate_gas = contract
.transfer_ownership_with_signature_pub_key(
public_key.clone().into(),
.transfer_ownership_with_signature(
voter_merkle_root,
session_length,
voter_count,
nonce,
public_key.clone().into(),
signature.clone().into(),
)
.estimate_gas()
.await?;

// get the current governor nonce.
let call = contract
.transfer_ownership_with_signature_pub_key(
public_key.into(),
.transfer_ownership_with_signature(
voter_merkle_root,
session_length,
voter_count,
nonce,
public_key.into(),
signature.into(),
)
.gas(estimate_gas.saturating_mul(U256::from(2)));
Expand Down
Loading

0 comments on commit 2dd3388

Please sign in to comment.