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

Transfer governor ownership #609

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ tokio = { version = "^1", features = ["full"] }
config = { version = "0.13", default-features = false, features = ["toml", "json"] }
serde_json = { version = "^1", default-features = false, features = ["raw_value"] }
paw = { version = "^1.0" }
webb = { version = "0.8.5", default-features = false }
#webb = { version = "0.8.5", default-features = false }
webb = { path = "/Users/salman/Webb-tools/webb-rs", default-features = false}
subxt-signer = { version = "0.34", features = ["subxt"] }
# Used by ethers (but we need it to be vendored with the lib).
native-tls = { version = "^0.2", features = ["vendored"] }
Expand Down
7 changes: 2 additions & 5 deletions crates/relayer-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,9 @@ pub enum BridgeCommand {
},
/// 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,
job_id: u64,
pub_key: Vec<u8>,
/// The signature of the hash of the nonce+public key, Signed by the proposal signing
/// The signature of the hash of the public key, Signed by the proposal signing
/// backend.
signature: Vec<u8>,
},
Expand Down
68 changes: 16 additions & 52 deletions event-watchers/evm/src/signature_bridge_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,14 @@ impl BridgeWatcher for SignatureBridgeContractWatcher {
.await?;
}
TransferOwnership {
job_id,
pub_key,
nonce,
voter_merkle_root,
voter_count,
session_length,
signature,
} => {
self.transfer_ownership_with_signature(
store,
&wrapper.contract,
(
pub_key,
nonce,
voter_merkle_root,
voter_count,
session_length,
signature,
),
(job_id, pub_key, signature),
)
.await?
}
Expand Down Expand Up @@ -364,14 +354,7 @@ where
&self,
store: Arc<<Self as EventWatcher>::Store>,
contract: &SignatureBridgeContract<EthersTimeLagClient>,
(
public_key,
nonce,
voter_merkle_root,
voter_count,
session_length,
signature,
): (Vec<u8>, u32, [u8; 32], u32, u64, Vec<u8>),
(job_id, public_key, signature): (u64, Vec<u8>, 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 All @@ -396,65 +379,49 @@ where
}
// we need to do some checks here:
// 1. convert the public key to address and check it is not the same as the current governor.
// 2. check if the nonce is greater than the current nonce.
// 2. check if the job_id of new governor is greater than the current.
// 3. ~check if the signature is valid.~
let current_governor_address = contract.governor().call().await?;
if new_governor_address == current_governor_address {
tracing::warn!(
%new_governor_address,
%current_governor_address,
public_key = %hex::encode(&public_key),
%nonce,
%job_id,
signature = %hex::encode(&signature),
"Skipping transfer ownership since the new governor is the same as the current one",
);
return Ok(());
}
// JobId of the current governor
let current_job_id = contract.job_id().call().await?;

let refresh_nonce = contract.refresh_nonce().call().await?;

// require(refreshNonce < nonce, "Invalid nonce")
if nonce < refresh_nonce {
tracing::warn!(
%refresh_nonce,
%nonce,
public_key = %hex::encode(&public_key),
signature = %hex::encode(&signature),
"Skipping transfer ownership since the nonce is less than the refresh nonce",
);
return Ok(());
}
// require(nonce <= refreshNonce + 1, "Nonce must increment by 1");
if nonce != refresh_nonce + 1 {
// require( job_id > current_job_id, "Invalid Job Id")
if job_id < current_job_id {
tracing::warn!(
%refresh_nonce,
%nonce,
%current_job_id,
%job_id,
public_key = %hex::encode(&public_key),
signature = %hex::encode(&signature),
"Skipping transfer ownership since the nonce must increment by 1",
"Skipping transfer ownership since new job id is less than the current one",
);
return Ok(());
}

tracing::event!(
target: webb_relayer_utils::probe::TARGET,
tracing::Level::DEBUG,
kind = %webb_relayer_utils::probe::Kind::SignatureBridge,
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,
%job_id,
signature = %hex::encode(&signature),
);
// estimated gas
let estimate_gas = contract
.transfer_ownership_with_signature(
voter_merkle_root,
session_length,
voter_count,
nonce,
job_id.clone(),
public_key.clone().into(),
signature.clone().into(),
)
Expand All @@ -464,10 +431,7 @@ where
// get the current governor nonce.
let call = contract
.transfer_ownership_with_signature(
voter_merkle_root,
session_length,
voter_count,
nonce,
job_id.clone(),
public_key.into(),
signature.into(),
)
Expand Down
61 changes: 58 additions & 3 deletions event-watchers/tangle/src/job_result_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ use webb_relayer_utils::{metric, TangleRuntimeConfig};
use webb_event_watcher_traits::substrate::EventHandler;

/// JobResultHandler handles the `JobResultSubmitted` event.
#[derive(Copy, Clone, Debug, Default)]
pub struct JobResultHandler;
#[derive(Clone, Debug)]
pub struct JobResultHandler {
relayer_config: webb_relayer_config::WebbRelayerConfig,
}

impl JobResultHandler {
pub fn new(relayer_config: webb_relayer_config::WebbRelayerConfig) -> Self {
Self { relayer_config }
}
}

#[async_trait::async_trait]
impl EventHandler<TangleRuntimeConfig> for JobResultHandler {
Expand Down Expand Up @@ -79,9 +87,10 @@ impl EventHandler<TangleRuntimeConfig> for JobResultHandler {
.collect();
for event in job_result_submitted_events {
// Fetch submitted job result
let job_id = event.clone().job_id;
let known_result_addrs = RuntimeApi::storage()
.jobs()
.known_results(event.clone().role_type, event.clone().job_id);
.known_results(event.clone().role_type, job_id.clone());

let maybe_result = client
.storage()
Expand Down Expand Up @@ -129,6 +138,52 @@ impl EventHandler<TangleRuntimeConfig> for JobResultHandler {
item,
)?;
}

JobResult::DKGPhaseFour(result) => {
tracing::debug!("DKG Phase Four result received");
let mut bridge_keys = Vec::new();
for (_, config) in self.relayer_config.evm.iter() {
let typed_chain_id =
webb_proposals::TypedChainId::Evm(
config.chain_id,
);
let bridge_key = BridgeKey::new(typed_chain_id);
bridge_keys.push(bridge_key);
}

// Now we just signal every signature bridge to transfer the ownership.
for bridge_key in bridge_keys {
tracing::debug!(
%bridge_key,
?event,
"Signaling Signature Bridge to transfer ownership",
);
tracing::event!(
target: webb_relayer_utils::probe::TARGET,
tracing::Level::DEBUG,
kind = %webb_relayer_utils::probe::Kind::SigningBackend,
backend = "DKG",
signal_bridge = %bridge_key,
public_key = %hex::encode(&result.key.clone().0),
previoud_job_id = %result.phase_one_id,
new_job_id = %result.new_phase_one_id,
signature = %hex::encode(&result.signature.clone().0),
);

let item = QueueItem::new(
BridgeCommand::TransferOwnership {
job_id: result.new_phase_one_id,
pub_key: result.key.clone().0,
signature: result.signature.clone().0,
},
);

store.enqueue_item(
SledQueueKey::from_bridge_key(bridge_key),
item,
)?;
}
}
_ => unimplemented!("Phase results not supported"),
}
}
Expand Down
5 changes: 3 additions & 2 deletions services/webb-relayer/src/service/tangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ pub fn start_job_result_watcher(
tracing::debug!("Job Result events watcher for ({}) Started.", chain_id,);
let mut shutdown_signal = ctx.shutdown_signal();
let metrics = ctx.metrics.clone();
let webb_config = ctx.config.clone();
let my_config = config.clone();
let task = async move {
let job_result_watcher = JobResultWatcher;
let job_result_event_handler = JobResultHandler;
let job_result_watcher = JobResultWatcher::default();
let job_result_event_handler = JobResultHandler::new(webb_config);
let job_result_watcher_task = job_result_watcher.run(
chain_id,
ctx.clone(),
Expand Down
Loading