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

Add eth outbound queue and system pallets #742

Merged
merged 43 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
715712c
WIP does not compile, needs cherry pick AggregateMessageOrigin
tmpolaczyk Nov 5, 2024
039944f
Add eth outbound queue and system pallets
tmpolaczyk Nov 5, 2024
74c1e45
Use fork branch tomasz-generic-aggregate-message-origin
tmpolaczyk Nov 5, 2024
8de7e4e
Update Cargo.lock
tmpolaczyk Nov 5, 2024
abcfc96
Fix outdated fork branches
tmpolaczyk Nov 5, 2024
64dd2e7
Fix tests and benchmarks
tmpolaczyk Nov 6, 2024
d4907e3
Merge remote-tracking branch 'origin/master' into tomasz-generic-aggr…
tmpolaczyk Nov 6, 2024
d52fc32
Fix compilation and toml
tmpolaczyk Nov 6, 2024
78ba7d2
WIP root_test_send_msg_to_eth
tmpolaczyk Nov 7, 2024
676792c
Use custom Command enum and do_process_message impl
tmpolaczyk Nov 7, 2024
2286b76
Create validate trait
tmpolaczyk Nov 7, 2024
0873ec0
Fix tests
tmpolaczyk Nov 7, 2024
76b393e
Fix unused variable
tmpolaczyk Nov 7, 2024
2d4ae6d
Fix toml
tmpolaczyk Nov 7, 2024
37f405f
Add integration test
tmpolaczyk Nov 7, 2024
153a76e
pnpm lint and fmt
tmpolaczyk Nov 7, 2024
88c21ca
typescript-api
tmpolaczyk Nov 7, 2024
2e45e28
Also support original Command enum
tmpolaczyk Nov 8, 2024
f6511b6
typescript-api
tmpolaczyk Nov 8, 2024
153c28a
Add test using snowbridge message
tmpolaczyk Nov 8, 2024
b68d289
Add different origin for custom snowbridge messages vs original ones
tmpolaczyk Nov 11, 2024
2a8d873
PR review
tmpolaczyk Nov 12, 2024
d658039
Merge remote-tracking branch 'origin/master' into tomasz-generic-aggr…
tmpolaczyk Nov 12, 2024
647b875
Fix tests
tmpolaczyk Nov 12, 2024
176df0f
polkadot-sdk branch merged, use stable2407 again
tmpolaczyk Nov 12, 2024
90c2446
typescript-api
tmpolaczyk Nov 12, 2024
72f296c
Test message limits: max numMsg and msgSize
tmpolaczyk Nov 13, 2024
cd341db
Merge remote-tracking branch 'origin/master' into tomasz-generic-aggr…
tmpolaczyk Nov 20, 2024
23124e3
Add benchmarks
tmpolaczyk Nov 20, 2024
804fafd
fmt
tmpolaczyk Nov 20, 2024
32d3fe2
Fix accidental refactor
tmpolaczyk Nov 20, 2024
679fb69
typescript-api
tmpolaczyk Nov 20, 2024
54ec73d
PR comments
tmpolaczyk Nov 21, 2024
d0b70c3
Merge remote-tracking branch 'origin/master' into tomasz-generic-aggr…
tmpolaczyk Nov 21, 2024
53d8847
Merge branch 'master' into tomasz-generic-aggregate-message-origin
tmpolaczyk Nov 22, 2024
1622364
Merge remote-tracking branch 'origin/master' into tomasz-generic-aggr…
tmpolaczyk Nov 25, 2024
63bebcc
Copy
tmpolaczyk Nov 25, 2024
d6f217c
PR comments
tmpolaczyk Nov 25, 2024
671b482
Merge remote-tracking branch 'origin/master' into tomasz-generic-aggr…
tmpolaczyk Nov 25, 2024
4ddf63e
Fix merge conflicts
tmpolaczyk Nov 25, 2024
daa534d
typescript-api
tmpolaczyk Nov 26, 2024
387bce9
Parents 1
tmpolaczyk Nov 26, 2024
b481252
Undo zombienet logs
tmpolaczyk Nov 26, 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
730 changes: 414 additions & 316 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ flashbox-runtime = { path = "runtime/flashbox", default-features = false }

dancelight-runtime = { path = "solo-chains/runtime/dancelight", default-features = false }
dancelight-runtime-constants = { path = "solo-chains/runtime/dancelight/constants", default-features = false }
ethabi = { package = "ethabi-decode", version = "1.0.0", default-features = false }
manual-xcm-rpc = { path = "client/manual-xcm" }
node-common = { path = "client/node-common" }
services-payment-rpc = { path = "client/services-payment" }
Expand All @@ -96,9 +97,8 @@ tanssi-runtime-common = { path = "runtime/common", default-features = false }
tc-consensus = { path = "client/consensus" }
tc-orchestrator-chain-rpc-interface = { path = "client/orchestrator-chain-rpc-interface" }
tc-service-container-chain = { path = "client/service-container-chain" }

tp-author-noting-inherent = { path = "primitives/author-noting-inherent", default-features = false }
tp-fungibles-ext = { path = "primitives/fungibles-ext", default-features = false }
tp-bridge = { path = "primitives/bridge", default-features = false }
tp-maths = { path = "primitives/maths", default-features = false }
tp-traits = { path = "primitives/traits", default-features = false }
tp-xcm-core-buyer = { path = "primitives/xcm-core-buyer", default-features = false }
Expand Down Expand Up @@ -261,7 +261,10 @@ xcm-runtime-apis = { git = "https://github.com/moondance-labs/polkadot-sdk", bra
# Bridges (wasm)
milagro-bls = { package = "snowbridge-milagro-bls", version = "1.5.4", default-features = false }
snowbridge-beacon-primitives = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false }
snowbridge-core = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false }
snowbridge-pallet-ethereum-client = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false }
snowbridge-pallet-outbound-queue = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false }
snowbridge-pallet-system = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false }

# Polkadot (client)
polkadot-cli = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407" }
Expand Down
7 changes: 7 additions & 0 deletions pallets/external-validator-slashes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ pallet-session = { workspace = true }
pallet-staking = { workspace = true }
parity-scale-codec = { workspace = true, features = [ "derive", "max-encoded-len" ] }
scale-info = { workspace = true }
snowbridge-core = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-staking = { workspace = true }
sp-std = { workspace = true }
tp-bridge = { workspace = true }
tp-traits = { workspace = true }

[dev-dependencies]
Expand All @@ -41,20 +44,24 @@ std = [
"pallet-staking/std",
"parity-scale-codec/std",
"scale-info/std",
"snowbridge-core/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-staking/std",
"sp-std/std",
"tp-bridge/std",
"tp-traits/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"tp-bridge/runtime-benchmarks",
"tp-traits/runtime-benchmarks",
]

Expand Down
13 changes: 13 additions & 0 deletions pallets/external-validator-slashes/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ mod benchmarks {
Ok(())
}

#[benchmark]
fn root_test_send_msg_to_eth() -> Result<(), BenchmarkError> {
let nonce = Default::default();
// Max limits depend on runtime, these are for Dancelight
let num_msgs = 32;
let msg_size = 900;

#[extrinsic_call]
_(RawOrigin::Root, nonce, num_msgs, msg_size);

Ok(())
}

impl_benchmark_test_suite!(
ExternalValidatorSlashes,
crate::mock::new_test_ext(),
Expand Down
66 changes: 66 additions & 0 deletions pallets/external-validator-slashes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use {
pallet_staking::SessionInterface,
parity_scale_codec::FullCodec,
parity_scale_codec::{Decode, Encode},
sp_core::H256,
sp_runtime::traits::{Convert, Debug, One, Saturating, Zero},
sp_runtime::DispatchResult,
sp_runtime::Perbill,
Expand All @@ -47,6 +48,9 @@ use {
tp_traits::{EraIndexProvider, InvulnerablesProvider, OnEraStart},
};

use snowbridge_core::ChannelId;
use tp_bridge::{Command, Message, ValidateMessage};

pub use pallet::*;

#[cfg(test)]
Expand All @@ -63,6 +67,7 @@ pub mod weights;
pub mod pallet {
use super::*;
pub use crate::weights::WeightInfo;
use tp_bridge::DeliverMessage;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
Expand Down Expand Up @@ -123,6 +128,14 @@ pub mod pallet {
/// Invulnerable provider, used to get the invulnerables to know when not to slash
type InvulnerablesProvider: InvulnerablesProvider<Self::ValidatorId>;

/// Validate a message that will be sent to Ethereum.
type ValidateMessage: ValidateMessage;

/// Send a message to Ethereum. Needs to be validated first.
type OutboundQueue: DeliverMessage<
Agusrodri marked this conversation as resolved.
Show resolved Hide resolved
Ticket = <<Self as pallet::Config>::ValidateMessage as ValidateMessage>::Ticket,
>;

/// The weight information of this pallet.
type WeightInfo: WeightInfo;
}
Expand All @@ -143,6 +156,10 @@ pub mod pallet {
DeferPeriodIsOver,
/// There was an error computing the slash
ErrorComputingSlash,
/// Failed to validate the message that was going to be sent to Ethereum
EthereumValidateFail,
/// Failed to deliver the message to Ethereum
EthereumDeliverFail,
}

#[pallet::pallet]
Expand Down Expand Up @@ -263,6 +280,55 @@ pub mod pallet {
NextSlashId::<T>::put(next_slash_id.saturating_add(One::one()));
Ok(())
}

#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::root_test_send_msg_to_eth())]
pub fn root_test_send_msg_to_eth(
girazoki marked this conversation as resolved.
Show resolved Hide resolved
origin: OriginFor<T>,
nonce: H256,
num_msgs: u32,
msg_size: u32,
) -> DispatchResult {
ensure_root(origin)?;

for i in 0..num_msgs {
// Make sure each message has a different payload
let mut payload = sp_core::blake2_256((nonce, i).encode().as_ref()).to_vec();
// Extend with zeros until msg_size is reached
payload.resize(msg_size as usize, 0);
// Example command, this should be something like "ReportSlashes"
let command = Command::Test(payload);

// Validate
let channel_id: ChannelId = snowbridge_core::PRIMARY_GOVERNANCE_CHANNEL;

let outbound_message = Message {
id: None,
channel_id,
command,
};

// validate the message
// Ignore fee because for now only root can send messages
let (ticket, _fee) =
T::ValidateMessage::validate(&outbound_message).map_err(|err| {
log::error!(
"root_test_send_msg_to_eth: validation of message {i} failed. {err:?}"
);
crate::pallet::Error::<T>::EthereumValidateFail
})?;

// Deliver
T::OutboundQueue::deliver(ticket).map_err(|err| {
log::error!(
"root_test_send_msg_to_eth: delivery of message {i} failed. {err:?}"
);
crate::pallet::Error::<T>::EthereumDeliverFail
})?;
}

Ok(())
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions pallets/external-validator-slashes/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use {
traits::{ConstU16, ConstU64, Get},
},
frame_system as system,
snowbridge_core::outbound::{SendError, SendMessageFeeProvider},
sp_core::H256,
sp_runtime::{
testing::UintAuthorityId,
Expand Down Expand Up @@ -196,6 +197,23 @@ impl DeferPeriodGetter {
}
}

pub struct MockOkOutboundQueue;
impl tp_bridge::DeliverMessage for MockOkOutboundQueue {
type Ticket = ();

fn deliver(_: Self::Ticket) -> Result<H256, SendError> {
Ok(H256::zero())
}
}

impl SendMessageFeeProvider for MockOkOutboundQueue {
type Balance = u128;

fn local_fee() -> Self::Balance {
1
}
}

parameter_types! {
pub const BondingDuration: u32 = 5u32;
}
Expand All @@ -210,6 +228,8 @@ impl external_validator_slashes::Config for Test {
type SessionInterface = ();
type EraIndexProvider = MockEraIndexProvider;
type InvulnerablesProvider = MockInvulnerableProvider;
type ValidateMessage = ();
type OutboundQueue = MockOkOutboundQueue;
type WeightInfo = ();
}

Expand Down
21 changes: 21 additions & 0 deletions pallets/external-validator-slashes/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use sp_std::marker::PhantomData;
pub trait WeightInfo {
fn cancel_deferred_slash(s: u32, ) -> Weight;
fn force_inject_slash() -> Weight;
fn root_test_send_msg_to_eth() -> Weight;
}

/// Weights for pallet_external_validator_slashes using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -91,6 +92,16 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}

fn root_test_send_msg_to_eth() -> Weight {
// Proof Size summary in bytes:
// Measured: `322`
// Estimated: `3601`
// Minimum execution time: 994_654_000 picoseconds.
Weight::from_parts(1_015_195_000, 3601)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -126,4 +137,14 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}

fn root_test_send_msg_to_eth() -> Weight {
// Proof Size summary in bytes:
// Measured: `322`
// Estimated: `3601`
// Minimum execution time: 994_654_000 picoseconds.
Weight::from_parts(1_015_195_000, 3601)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
}
59 changes: 59 additions & 0 deletions primitives/bridge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[package]
name = "tp-bridge"
authors = { workspace = true }
description = "Tanssi bridge primitive"
edition = "2021"
license = "GPL-3.0-only"
version = "0.1.0"

[lints]
workspace = true

[dependencies]
dp-chain-state-snapshot = { workspace = true }
dp-container-chain-genesis-data = { workspace = true }
ethabi = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
impl-trait-for-tuples = { workspace = true }
macro_rules_attribute = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
serde = { workspace = true }
snowbridge-beacon-primitives = { workspace = true }
snowbridge-core = { workspace = true }
snowbridge-pallet-outbound-queue = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Cumulus
cumulus-primitives-core = { workspace = true }

[features]
default = [ "std" ]
std = [
"cumulus-primitives-core/std",
"dp-chain-state-snapshot/std",
"dp-container-chain-genesis-data/std",
"ethabi/std",
"frame-support/std",
"frame-system/std",
"parity-scale-codec/std",
"scale-info/std",
"serde/std",
"snowbridge-beacon-primitives/std",
"snowbridge-core/std",
"snowbridge-pallet-outbound-queue/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
]
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"snowbridge-pallet-outbound-queue/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Loading
Loading