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

Inbound queue v2 #3

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0e9cca0
Rebase inbound queue
yrong Oct 24, 2024
8f59cc4
Merge branch 'outbound-queue-v2' into inbound-queue-v2
yrong Oct 29, 2024
bd02251
Merge branch 'outbound-queue-v2' into inbound-queue-v2
yrong Oct 29, 2024
9e39dca
Merge branch 'outbound-queue-v2' into inbound-queue-v2
yrong Oct 31, 2024
cf8f536
inbound v2
claravanstaden Nov 1, 2024
3e9b03d
send token unit test
claravanstaden Nov 4, 2024
5b92bd0
xcm decoding
claravanstaden Nov 4, 2024
41170b3
adds more tests
claravanstaden Nov 5, 2024
2250d9b
Merge remote-tracking branch 'ron/outbound-queue-v2' into inbound-que…
claravanstaden Nov 5, 2024
d81affc
converter
claravanstaden Nov 5, 2024
1638660
inbound progress
claravanstaden Nov 6, 2024
716404b
tests
claravanstaden Nov 7, 2024
89a157d
tests
claravanstaden Nov 7, 2024
e814b29
fix alias origin
claravanstaden Nov 7, 2024
697b51c
cleanup runtime interface
claravanstaden Nov 7, 2024
b20b728
dry run xcm
claravanstaden Nov 8, 2024
a0fe8de
cleanup
claravanstaden Nov 18, 2024
490d091
remove unnecessary dry-run logic
claravanstaden Nov 18, 2024
bf500d2
cleanup
claravanstaden Nov 18, 2024
cb9111f
add foreign erc20 token id lookup
claravanstaden Nov 18, 2024
8372cae
Update bridges/snowbridge/primitives/router/src/inbound/v2.rs
claravanstaden Nov 20, 2024
767b0ef
Update bridges/snowbridge/pallets/inbound-queue-v2/src/lib.rs
claravanstaden Nov 20, 2024
324f0c0
Update bridges/snowbridge/pallets/inbound-queue-v2/src/lib.rs
claravanstaden Nov 20, 2024
b9a4e17
rename InboundAsset to Asset
claravanstaden Nov 20, 2024
47fd268
Merge remote-tracking branch 'origin/inbound-queue-v2' into inbound-q…
claravanstaden Nov 20, 2024
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
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ members = [
"bridges/snowbridge/pallets/inbound-queue",
"bridges/snowbridge/pallets/inbound-queue-v2",
"bridges/snowbridge/pallets/inbound-queue-v2/fixtures",
"bridges/snowbridge/pallets/inbound-queue-v2/runtime-api",
"bridges/snowbridge/pallets/inbound-queue/fixtures",
"bridges/snowbridge/pallets/outbound-queue",
"bridges/snowbridge/pallets/outbound-queue-v2",
Expand Down
1 change: 1 addition & 0 deletions bridges/snowbridge/pallets/inbound-queue-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ frame-benchmarking = { workspace = true, default-features = true }
sp-keyring = { workspace = true, default-features = true }
snowbridge-pallet-ethereum-client = { workspace = true, default-features = true }
hex-literal = { workspace = true, default-features = true }
hex = { workspace = true, default-features = true }

[features]
default = ["std"]
Expand Down
32 changes: 32 additions & 0 deletions bridges/snowbridge/pallets/inbound-queue-v2/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "snowbridge-inbound-queue-v2-runtime-api"
description = "Snowbridge Inbound Queue V2 Runtime API"
version = "0.2.0"
authors = ["Snowfork <contact@snowfork.com>"]
edition.workspace = true
repository.workspace = true
license = "Apache-2.0"
categories = ["cryptography::cryptocurrencies"]

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
sp-api = { workspace = true }
snowbridge-merkle-tree = { workspace = true }
snowbridge-core = { workspace = true }
snowbridge-router-primitives = { workspace = true }
xcm = { workspace = true }

[features]
default = ["std"]
std = [
"snowbridge-core/std",
"snowbridge-merkle-tree/std",
"snowbridge-router-primitives/std",
"sp-api/std",
"xcm/std",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ethereum Inbound Queue V2 Runtime API

Provides an API to dry-run inbound messages to get the XCM (and its execution cost) that will be executed on AssetHub.
15 changes: 15 additions & 0 deletions bridges/snowbridge/pallets/inbound-queue-v2/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
#![cfg_attr(not(feature = "std"), no_std)]

use snowbridge_core::inbound::Proof;
use snowbridge_router_primitives::inbound::v2::Message;
use xcm::latest::Xcm;

sp_api::decl_runtime_apis! {
pub trait InboundQueueApiV2
{
/// Dry runs the provided message on AH to provide the XCM payload and execution cost.
fn dry_run(message: Message, proof: Proof) -> (Xcm<()>, u128);
}
}
16 changes: 16 additions & 0 deletions bridges/snowbridge/pallets/inbound-queue-v2/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
//! Implements the dry-run API.

use crate::{Config, Error};
use snowbridge_core::inbound::Proof;
use snowbridge_router_primitives::inbound::v2::{ConvertMessage, Message};
use xcm::latest::Xcm;

pub fn dry_run<T>(message: Message, _proof: Proof) -> Result<Xcm<()>, Error<T>>
where
T: Config,
{
let xcm = T::MessageConverter::convert(message).map_err(|e| Error::<T>::ConvertMessage(e))?;
Ok(xcm)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ mod benchmarks {
create_message.block_roots_root,
);

let sovereign_account = sibling_sovereign_account::<T>(1000u32.into());

let minimum_balance = T::Token::minimum_balance();

// So that the receiving account exists
assert_ok!(T::Token::mint_into(&caller, minimum_balance));
// Fund the sovereign account (parachain sovereign account) so it can transfer a reward
// fee to the caller account
assert_ok!(T::Token::mint_into(
&sovereign_account,
3_000_000_000_000u128
.try_into()
.unwrap_or_else(|_| panic!("unable to cast sovereign account balance")),
));

#[block]
{
assert_ok!(InboundQueue::<T>::submit(
Expand Down
15 changes: 6 additions & 9 deletions bridges/snowbridge/pallets/inbound-queue-v2/src/envelope.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
use snowbridge_core::{inbound::Log, ChannelId};
use snowbridge_core::inbound::Log;

use sp_core::{RuntimeDebug, H160, H256};
use sp_core::{RuntimeDebug, H160};
use sp_std::prelude::*;

use alloy_primitives::B256;
use alloy_sol_types::{sol, SolEvent};

sol! {
event OutboundMessageAccepted(bytes32 indexed channel_id, uint64 nonce, bytes32 indexed message_id, bytes payload);
event OutboundMessageAccepted(uint64 indexed nonce, uint128 fee, bytes payload);
}

/// An inbound message that has had its outer envelope decoded.
#[derive(Clone, RuntimeDebug)]
pub struct Envelope {
/// The address of the outbound queue on Ethereum that emitted this message as an event log
pub gateway: H160,
/// The message Channel
pub channel_id: ChannelId,
/// A nonce for enforcing replay protection and ordering.
pub nonce: u64,
/// An id for tracing the message on its route (has no role in bridge consensus)
pub message_id: H256,
/// Total fee paid in Ether on Ethereum, should cover all the cost
pub fee: u128,
/// The inner payload generated from the source application.
pub payload: Vec<u8>,
}
Expand All @@ -41,9 +39,8 @@ impl TryFrom<&Log> for Envelope {

Ok(Self {
gateway: log.address,
channel_id: ChannelId::from(event.channel_id.as_ref()),
nonce: event.nonce,
message_id: H256::from(event.message_id.as_ref()),
fee: event.fee,
payload: event.payload,
})
}
Expand Down
Loading