Skip to content

Commit

Permalink
feat(voyager): support batch transactions (#1953)
Browse files Browse the repository at this point in the history
note that currently on evm chains, this is implemented by executing each
nested tx individually until we add support for something like
multicall3
  • Loading branch information
benluelo authored May 30, 2024
2 parents cf170d3 + a25ab5a commit 7832944
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 148 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- run: exit 1
packages:
if: github.event.pull_request.draft == false
uses: unionlabs/workflows/.github/workflows/build.yml@54db69f90dc7171e9dd185582c1a47d98ee35ea6
uses: unionlabs/workflows/.github/workflows/build.yml@7c5ff7677d51d9b6d9a62701a6cf8de96510cc8b
secrets:
nixbuild_token: ${{ secrets.nixbuild_token }}
access-tokens: github.com=${{ secrets.GITHUB_TOKEN }}
Expand All @@ -32,7 +32,7 @@ jobs:
lfs: true
devShells:
if: github.event.pull_request.draft == false
uses: unionlabs/workflows/.github/workflows/build.yml@54db69f90dc7171e9dd185582c1a47d98ee35ea6
uses: unionlabs/workflows/.github/workflows/build.yml@7c5ff7677d51d9b6d9a62701a6cf8de96510cc8b
secrets:
nixbuild_token: ${{ secrets.nixbuild_token }}
access-tokens: github.com=${{ secrets.GITHUB_TOKEN }}
Expand All @@ -42,7 +42,7 @@ jobs:
lfs: true
checks:
if: github.event.pull_request.draft == false
uses: unionlabs/workflows/.github/workflows/build.yml@54db69f90dc7171e9dd185582c1a47d98ee35ea6
uses: unionlabs/workflows/.github/workflows/build.yml@7c5ff7677d51d9b6d9a62701a6cf8de96510cc8b
secrets:
nixbuild_token: ${{ secrets.nixbuild_token }}
access-tokens: github.com=${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
build:
uses: unionlabs/workflows/.github/workflows/build.yml@54db69f90dc7171e9dd185582c1a47d98ee35ea6
uses: unionlabs/workflows/.github/workflows/build.yml@7c5ff7677d51d9b6d9a62701a6cf8de96510cc8b
secrets:
nixbuild_token: ${{ secrets.nixbuild_token }}
access-tokens: github.com=${{ secrets.github-token }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
build:
uses: unionlabs/workflows/.github/workflows/build.yml@54db69f90dc7171e9dd185582c1a47d98ee35ea6
uses: unionlabs/workflows/.github/workflows/build.yml@7c5ff7677d51d9b6d9a62701a6cf8de96510cc8b
secrets:
nixbuild_token: ${{ secrets.nixbuild_token }}
access-tokens: github.com=${{ secrets.GITHUB_TOKEN }}
Expand Down
338 changes: 196 additions & 142 deletions lib/relay-message/src/chain_impls/cosmos_sdk.rs

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion lib/relay-message/src/chain_impls/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use crate::{
aggregate::{Aggregate, AnyAggregate},
data::{AnyData, Data, IbcProof, IbcState},
effect::{
AnyEffect, Effect, MsgConnectionOpenAckData, MsgConnectionOpenInitData,
AnyEffect, BatchMsg, Effect, MsgConnectionOpenAckData, MsgConnectionOpenInitData,
MsgConnectionOpenTryData, MsgUpdateClientData,
},
fetch::{AnyFetch, DoFetch, Fetch, FetchUpdateHeaders},
Expand Down Expand Up @@ -278,6 +278,13 @@ where
client_message: data.client_message.clone().encode_as::<EthAbi>().into(),
}),
),
Effect::Batch(BatchMsg(msgs)) => {
for msg in msgs {
Box::pin(do_msg(ibc_handlers, msg, legacy)).await.unwrap();
}

return Ok(());
}
};

let msg = if legacy { msg.legacy() } else { msg };
Expand Down
6 changes: 6 additions & 0 deletions lib/relay-message/src/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum Effect<Hc: ChainExt, Tr: ChainExt> {

CreateClient(MsgCreateClientData<Hc, Tr>),
UpdateClient(MsgUpdateClientData<Hc, Tr>),

Batch(BatchMsg<Hc, Tr>),
}

impl HandleEffect<RelayMessageTypes> for AnyLightClientIdentified<AnyEffect> {
Expand Down Expand Up @@ -158,3 +160,7 @@ pub struct MsgCreateClientData<Hc: ChainExt, Tr: ChainExt> {
pub struct MsgUpdateClientData<Hc: ChainExt, Tr: ChainExt>(
pub MsgUpdateClient<ClientIdOf<Hc>, HeaderOf<Tr>>,
);

#[queue_msg]
#[debug(bound())] // break cyclic debug bounds
pub struct BatchMsg<Hc: ChainExt, Tr: ChainExt>(pub Vec<Effect<Hc, Tr>>);
15 changes: 15 additions & 0 deletions lib/unionlabs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ macro_rules! export_wasm_client_type {
/// Light clients supported by voyager must export a `#[no_mangle] static WASM_CLIENT_TYPE_<TYPE>: u8 = 0` variable.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(rename_all = "snake_case")]
pub enum WasmClientType {
EthereumMinimal,
EthereumMainnet,
Expand All @@ -150,12 +151,26 @@ pub enum WasmClientType {

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(rename_all = "snake_case")]
pub enum ClientType {
Wasm(WasmClientType),
Tendermint,
Cometbls,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn wasm_client_type_serde() {
assert_eq!(
r#"{"wasm":"ethereum_minimal"}"#,
serde_json::to_string(&ClientType::Wasm(WasmClientType::EthereumMinimal)).unwrap()
);
}
}

impl ClientType {
#[must_use]
pub const fn identifier_prefix(self) -> &'static str {
Expand Down

0 comments on commit 7832944

Please sign in to comment.