Skip to content

Commit

Permalink
Use custom Command enum and do_process_message impl
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Nov 7, 2024
1 parent 78ba7d2 commit 676792c
Show file tree
Hide file tree
Showing 9 changed files with 761 additions and 338 deletions.
666 changes: 346 additions & 320 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ 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" }

ethabi = { version = "1.0.0", default-features = false, package = "ethabi-decode" }
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
7 changes: 5 additions & 2 deletions pallets/external-validator-slashes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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 @@ -49,7 +50,8 @@ std = [
"sp-staking/std",
"sp-std/std",
"tp-traits/std",
"snowbridge-core/std"
"snowbridge-core/std",
"tp-bridge/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand All @@ -60,7 +62,8 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"tp-traits/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks"
"snowbridge-core/runtime-benchmarks",
"tp-bridge/runtime-benchmarks"
]

try-runtime = [
Expand Down
25 changes: 15 additions & 10 deletions pallets/external-validator-slashes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ use {
tp_traits::{EraIndexProvider, InvulnerablesProvider, OnEraStart},
};

use snowbridge_core::{
outbound::{AgentExecuteCommand, Command, Message, SendMessage},
AgentId, ChannelId, ParaId,
};
use snowbridge_core::{outbound::SendMessage, ChannelId};
use tp_bridge::{Command, Message, OutboundQueueConfig};

pub use pallet::*;

Expand Down Expand Up @@ -128,8 +126,11 @@ pub mod pallet {

/// Invulnerable provider, used to get the invulnerables to know when not to slash
type InvulnerablesProvider: InvulnerablesProvider<Self::ValidatorId>;

type OutboundQueue: SendMessage<Balance = u128>;
type OutboundQueueConfig: OutboundQueueConfig;
type OutboundQueue: SendMessage<
Balance = u128,
Ticket = tp_bridge::Ticket<Self::OutboundQueueConfig>,
>;

/// The weight information of this pallet.
type WeightInfo: WeightInfo;
Expand Down Expand Up @@ -277,22 +278,26 @@ pub mod pallet {
pub fn root_test_send_msg_to_eth(
origin: OriginFor<T>,
message_id: H256,
agent_id: H256,
payload: H256,
) -> DispatchResult {
ensure_root(origin)?;

// Example command, this should be something like "ReportSlashes"
let command = Command::CreateAgent { agent_id };
let command = Command::Test(payload.as_ref().to_vec());

// Validate
//let channel_id: ChannelId = ParaId::from(para_id).into();
let channel_id: ChannelId = snowbridge_core::PRIMARY_GOVERNANCE_CHANNEL;

let outbound_message = Message { id: Some(message_id), channel_id, command };
let outbound_message = Message {
id: Some(message_id),
channel_id,
command,
};

// validate the message
// Ignore fee because for now only root can send messages
let (ticket, _fee) = T::OutboundQueue::validate(&outbound_message).map_err(|err| {
let (ticket, _fee) = outbound_message.validate().map_err(|err| {
log::error!(target: "xcm::ethereum_blob_exporter", "OutboundQueue validation of message failed. {err:?}");
Error::<T>::EmptyTargets
})?;
Expand Down
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 }
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 }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
snowbridge-beacon-primitives = { workspace = true }
snowbridge-core = { workspace = true }
snowbridge-pallet-outbound-queue = { workspace = true }
ethabi = { 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",
"frame-support/std",
"parity-scale-codec/std",
"scale-info/std",
"serde/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"snowbridge-beacon-primitives/std",
"snowbridge-core/std",
"ethabi/std",
"frame-system/std",
"snowbridge-pallet-outbound-queue/std"
]
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"snowbridge-core/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"snowbridge-pallet-outbound-queue/runtime-benchmarks"
]
Loading

0 comments on commit 676792c

Please sign in to comment.