Skip to content

Commit

Permalink
Add source and destination metadata to Timeout events (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege authored May 8, 2024
1 parent 13ce0d6 commit 158c3e9
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 311 deletions.
20 changes: 13 additions & 7 deletions evm/abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ ethers-contract-abigen = { workspace = true }
forge-testsuite = { workspace = true }

[dependencies]
primitive-types = { workspace = true, default-features = true }
anyhow.workspace = true
primitive-types = { workspace = true }
anyhow = { workspace = true }

ethers = { workspace = true }
ismp = { workspace = true }

mmr-primitives = { workspace = true, optional = true }
sp-consensus-beefy = { workspace = true, features = ["default"], optional = true }
merkle-mountain-range = { workspace = true, features = ["default"], optional = true }
beefy-verifier-primitives = { workspace = true, optional = true }
mmr-primitives = { workspace = true, default-features = true, optional = true }
sp-consensus-beefy = { workspace = true, default-features = true, optional = true }
merkle-mountain-range = { workspace = true, default-features = true, optional = true }
beefy-verifier-primitives = { workspace = true, default-features = true, optional = true }


[features]
default = ["beefy"]
default = ["beefy", "std"]
std = [
"primitive-types/std",
"anyhow/std",
"ethers/default",
"ismp/std",
]
build-abi = []
beefy = ["merkle-mountain-range", "sp-consensus-beefy", "beefy-verifier-primitives", "mmr-primitives"]
27 changes: 21 additions & 6 deletions evm/abi/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,33 @@ impl TryFrom<EvmHostEvents> for ismp::events::Event {
},
latest_height: filter.height.low_u64(),
})),
EvmHostEvents::PostRequestTimeoutHandledFilter(handled) =>
EvmHostEvents::PostRequestTimeoutHandledFilter(handled) => {
let dest = StateMachine::from_str(&String::from_utf8(handled.dest.to_vec())?)
.map_err(|e| anyhow!("{}", e))?;
Ok(ismp::events::Event::PostRequestTimeoutHandled(TimeoutHandled {
commitment: handled.commitment.into(),
})),
EvmHostEvents::PostResponseTimeoutHandledFilter(handled) =>
dest: dest.clone(),
source: dest.clone(),
}))
},
EvmHostEvents::PostResponseTimeoutHandledFilter(handled) => {
let dest = StateMachine::from_str(&String::from_utf8(handled.dest.to_vec())?)
.map_err(|e| anyhow!("{}", e))?;
Ok(ismp::events::Event::PostResponseTimeoutHandled(TimeoutHandled {
commitment: handled.commitment.into(),
})),
EvmHostEvents::GetRequestTimeoutHandledFilter(handled) =>
dest: dest.clone(),
source: dest.clone(),
}))
},
EvmHostEvents::GetRequestTimeoutHandledFilter(handled) => {
let dest = StateMachine::from_str(&String::from_utf8(handled.dest.to_vec())?)
.map_err(|e| anyhow!("{}", e))?;
Ok(ismp::events::Event::GetRequestTimeoutHandled(TimeoutHandled {
commitment: handled.commitment.into(),
})),
dest: dest.clone(),
source: dest.clone(),
}))
},
EvmHostEvents::StateCommitmentVetoedFilter(vetoed) =>
Ok(ismp::events::Event::StateCommitmentVetoed(StateCommitmentVetoed {
height: ismp::consensus::StateMachineHeight {
Expand Down
30 changes: 27 additions & 3 deletions evm/abi/src/generated/evm_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,11 @@ pub mod evm_host {
),
indexed: false,
},
::ethers::core::abi::ethabi::EventParam {
name: ::std::borrow::ToOwned::to_owned("dest"),
kind: ::ethers::core::abi::ethabi::ParamType::Bytes,
indexed: false,
},
],
anonymous: false,
},
Expand Down Expand Up @@ -1554,6 +1559,11 @@ pub mod evm_host {
),
indexed: false,
},
::ethers::core::abi::ethabi::EventParam {
name: ::std::borrow::ToOwned::to_owned("dest"),
kind: ::ethers::core::abi::ethabi::ParamType::Bytes,
indexed: false,
},
],
anonymous: false,
},
Expand Down Expand Up @@ -1670,6 +1680,11 @@ pub mod evm_host {
),
indexed: false,
},
::ethers::core::abi::ethabi::EventParam {
name: ::std::borrow::ToOwned::to_owned("dest"),
kind: ::ethers::core::abi::ethabi::ParamType::Bytes,
indexed: false,
},
],
anonymous: false,
},
Expand Down Expand Up @@ -2296,9 +2311,10 @@ pub mod evm_host {
Eq,
Hash,
)]
#[ethevent(name = "GetRequestTimeoutHandled", abi = "GetRequestTimeoutHandled(bytes32)")]
#[ethevent(name = "GetRequestTimeoutHandled", abi = "GetRequestTimeoutHandled(bytes32,bytes)")]
pub struct GetRequestTimeoutHandledFilter {
pub commitment: [u8; 32],
pub dest: ::ethers::core::types::Bytes,
}
#[derive(
Clone,
Expand Down Expand Up @@ -2350,9 +2366,13 @@ pub mod evm_host {
Eq,
Hash,
)]
#[ethevent(name = "PostRequestTimeoutHandled", abi = "PostRequestTimeoutHandled(bytes32)")]
#[ethevent(
name = "PostRequestTimeoutHandled",
abi = "PostRequestTimeoutHandled(bytes32,bytes)"
)]
pub struct PostRequestTimeoutHandledFilter {
pub commitment: [u8; 32],
pub dest: ::ethers::core::types::Bytes,
}
#[derive(
Clone,
Expand Down Expand Up @@ -2406,9 +2426,13 @@ pub mod evm_host {
Eq,
Hash,
)]
#[ethevent(name = "PostResponseTimeoutHandled", abi = "PostResponseTimeoutHandled(bytes32)")]
#[ethevent(
name = "PostResponseTimeoutHandled",
abi = "PostResponseTimeoutHandled(bytes32,bytes)"
)]
pub struct PostResponseTimeoutHandledFilter {
pub commitment: [u8; 32],
pub dest: ::ethers::core::types::Bytes,
}
#[derive(
Clone,
Expand Down
4 changes: 2 additions & 2 deletions evm/abi/src/generated/host_manager.rs

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions evm/src/hosts/EvmHost.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,23 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
// Emitted when an incoming POST request is handled
event PostRequestHandled(bytes32 commitment, address relayer);

// Emitted when an outgoing POST request timeout is handled
event PostRequestTimeoutHandled(bytes32 commitment);
// Emitted when an outgoing POST request timeout is handled, `dest` refers
// to the destination for the request
event PostRequestTimeoutHandled(bytes32 commitment, bytes dest);

// Emitted when an incoming POST response is handled
event PostResponseHandled(bytes32 commitment, address relayer);

// Emitted when an outgoing POST timeout response is handled
event PostResponseTimeoutHandled(bytes32 commitment);
// Emitted when an outgoing POST response timeout is handled, `dest` refers
// to the destination for the response
event PostResponseTimeoutHandled(bytes32 commitment, bytes dest);

// Emitted when an outgoing GET request is handled
event GetRequestHandled(bytes32 commitment, address relayer);

// Emitted when an outgoing GET request timeout is handled
event GetRequestTimeoutHandled(bytes32 commitment);
// Emitted when an outgoing GET request timeout is handled, `dest` refers
// to the destination for the request
event GetRequestTimeoutHandled(bytes32 commitment, bytes dest);

// Emitted when new heights are finalized
event StateMachineUpdated(bytes stateMachineId, uint256 height);
Expand Down Expand Up @@ -624,7 +627,7 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
// refund relayer fee
IERC20(feeToken()).transfer(meta.sender, meta.fee);
}
emit GetRequestTimeoutHandled({commitment: commitment});
emit GetRequestTimeoutHandled({commitment: commitment, dest: request.dest});
}

/**
Expand Down Expand Up @@ -652,7 +655,7 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
// refund relayer fee
IERC20(feeToken()).transfer(meta.sender, meta.fee);
}
emit PostRequestTimeoutHandled({commitment: commitment});
emit PostRequestTimeoutHandled({commitment: commitment, dest: request.dest});
}

/**
Expand Down Expand Up @@ -683,7 +686,7 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
// refund relayer fee
IERC20(feeToken()).transfer(meta.sender, meta.fee);
}
emit PostResponseTimeoutHandled({commitment: commitment});
emit PostResponseTimeoutHandled({commitment: commitment, dest: response.request.source});
}

/**
Expand Down
5 changes: 2 additions & 3 deletions evm/src/modules/TokenGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ struct AssetFees {
uint256 protocolFeePercentage;
}

enum OnAcceptActions
// Incoming asset from a chain
{
enum OnAcceptActions {
// Incoming asset from a chain
IncomingAsset,
// Governance action to update protocol parameters
GovernanceAction
Expand Down
1 change: 1 addition & 0 deletions modules/hyperclient/tests/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async fn subscribe_to_request_status() -> Result<(), anyhow::Error> {
}

#[wasm_bindgen_test]
#[ignore]
async fn test_timeout_request() -> Result<(), anyhow::Error> {
init_tracing();

Expand Down
4 changes: 4 additions & 0 deletions modules/ismp/core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ pub struct RequestResponseHandled {
pub struct TimeoutHandled {
/// The commitment to the request or response
pub commitment: H256,
/// The source chain of the message
pub source: StateMachine,
/// The destination chain of the message
pub dest: StateMachine,
}

/// This represents events that should be emitted by ismp-rs wrappers
Expand Down
18 changes: 15 additions & 3 deletions modules/ismp/core/src/handlers/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ where
}
let res = cb.on_timeout(request.clone().into()).map(|_| {
let commitment = hash_request::<H>(&request);
Event::PostRequestTimeoutHandled(TimeoutHandled { commitment })
Event::PostRequestTimeoutHandled(TimeoutHandled {
commitment,
source: request.source_chain(),
dest: request.dest_chain(),
})
});
// If module callback failed restore commitment so it can be retried
if res.is_err() {
Expand Down Expand Up @@ -156,7 +160,11 @@ where
}
let res = cb.on_timeout(response.clone().into()).map(|_| {
let commitment = hash_post_response::<H>(&response);
Event::PostResponseTimeoutHandled(TimeoutHandled { commitment })
Event::PostResponseTimeoutHandled(TimeoutHandled {
commitment,
source: response.source_chain(),
dest: response.dest_chain(),
})
});
// If module callback failed restore commitment so it can be retried
if res.is_err() {
Expand Down Expand Up @@ -200,7 +208,11 @@ where
let meta = host.delete_request_commitment(&request)?;
let res = cb.on_timeout(request.clone().into()).map(|_| {
let commitment = hash_request::<H>(&request);
Event::GetRequestTimeoutHandled(TimeoutHandled { commitment })
Event::GetRequestTimeoutHandled(TimeoutHandled {
commitment,
source: request.source_chain(),
dest: request.dest_chain(),
})
});
// If module callback failed, restore commitment so it can be retried
if res.is_err() {
Expand Down
Loading

0 comments on commit 158c3e9

Please sign in to comment.