Skip to content

Commit

Permalink
Changes in dancelight to enable solochain message relay + integration…
Browse files Browse the repository at this point in the history
… of scripts
  • Loading branch information
ParthDesai committed Jan 17, 2025
1 parent ec6c96f commit 61798f7
Show file tree
Hide file tree
Showing 25 changed files with 5,517 additions and 5,234 deletions.
675 changes: 351 additions & 324 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pallet-inflation-rewards = { path = "pallets/inflation-rewards", default-feature
pallet-initializer = { path = "pallets/initializer", default-features = false }
pallet-invulnerables = { path = "pallets/invulnerables", default-features = false }
pallet-ocw-testing = { path = "pallets/ocw-testing", default-features = false }
pallet-outbound-message-commitment-recorder = { path = "pallets/oubound-message-commitment-recorder", default-features = false }
pallet-pooled-staking = { path = "pallets/pooled-staking", default-features = false }
pallet-registrar = { path = "pallets/registrar", default-features = false }
pallet-registrar-runtime-api = { path = "pallets/registrar/runtime-api", default-features = false }
Expand Down Expand Up @@ -269,6 +270,7 @@ milagro-bls = { package = "snowbridge-milagro-bls", version = "1.5.4", default-f
snowbridge-beacon-primitives = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2409", default-features = false }
snowbridge-core = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2409", default-features = false }
snowbridge-outbound-queue-merkle-tree = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2409", default-features = false }
snowbridge-outbound-queue-runtime-api = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2409", default-features = false }
snowbridge-pallet-ethereum-client = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2409", default-features = false }
snowbridge-pallet-inbound-queue = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2409", default-features = false }
snowbridge-pallet-inbound-queue-fixtures = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2409", default-features = false }
Expand Down
6 changes: 6 additions & 0 deletions chains/orchestrator-relays/runtime/dancelight/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pallet-author-noting-runtime-api = { workspace = true }
pallet-configuration = { workspace = true }
pallet-data-preservers = { workspace = true }
pallet-inflation-rewards = { workspace = true }
pallet-outbound-message-commitment-recorder = { workspace = true }
pallet-pooled-staking = { workspace = true }
pallet-registrar = { workspace = true }
pallet-registrar-runtime-api = { workspace = true }
Expand All @@ -149,6 +150,7 @@ pallet-migrations = { workspace = true }
# Bridges
snowbridge-beacon-primitives = { workspace = true }
snowbridge-core = { workspace = true }
snowbridge-outbound-queue-runtime-api = { workspace = true }
snowbridge-pallet-ethereum-client = { workspace = true }
snowbridge-pallet-inbound-queue = { workspace = true }
snowbridge-pallet-inbound-queue-fixtures = { workspace = true, optional = true }
Expand Down Expand Up @@ -249,6 +251,7 @@ std = [
"pallet-multiblock-migrations/std",
"pallet-multisig/std",
"pallet-offences/std",
"pallet-outbound-message-commitment-recorder/std",
"pallet-parameters/std",
"pallet-pooled-staking/std",
"pallet-preimage/std",
Expand Down Expand Up @@ -287,6 +290,7 @@ std = [
"serde_json/std",
"snowbridge-beacon-primitives/std",
"snowbridge-core/std",
"snowbridge-outbound-queue-runtime-api/std",
"snowbridge-pallet-ethereum-client/fuzzing",
"snowbridge-pallet-ethereum-client/std",
"snowbridge-pallet-inbound-queue-fixtures/std",
Expand Down Expand Up @@ -367,6 +371,7 @@ runtime-benchmarks = [
"pallet-multiblock-migrations/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-offences/runtime-benchmarks",
"pallet-outbound-message-commitment-recorder/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-pooled-staking/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
Expand Down Expand Up @@ -450,6 +455,7 @@ try-runtime = [
"pallet-multiblock-migrations/try-runtime",
"pallet-multisig/try-runtime",
"pallet-offences/try-runtime",
"pallet-outbound-message-commitment-recorder/try-runtime",
"pallet-parameters/try-runtime",
"pallet-pooled-staking/try-runtime",
"pallet-preimage/try-runtime",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ use {
crate::{
parameter_types, weights, xcm_config, xcm_config::UniversalLocation,
AggregateMessageOrigin, Balance, Balances, EthereumInboundQueue, EthereumOutboundQueue,
EthereumSystem, FixedU128, GetAggregateMessageOrigin, Keccak256, MessageQueue, Runtime,
RuntimeEvent, TransactionByteFee, TreasuryAccount, WeightToFee, UNITS,
EthereumSystem, FixedU128, GetAggregateMessageOrigin, Keccak256, MessageQueue,
OutboundMessageCommitmentRecorder, Runtime, RuntimeEvent, TransactionByteFee,
TreasuryAccount, WeightToFee, UNITS,
},
dancelight_runtime_constants::snowbridge::EthereumLocation,
frame_support::{traits::Nothing, weights::ConstantMultiplier},
pallet_xcm::EnsureXcm,
snowbridge_beacon_primitives::{Fork, ForkVersions},
snowbridge_core::{gwei, meth, PricingParameters, Rewards},
sp_core::{ConstU32, ConstU8, H160},
snowbridge_pallet_outbound_queue::OnNewCommitment,
sp_core::{ConstU32, ConstU8, H160, H256},
tp_bridge::{DoNothingConvertMessage, DoNothingRouter},
};

Expand All @@ -52,6 +54,18 @@ parameter_types! {
};
}

pub struct CommitmentRecorder;

impl OnNewCommitment for CommitmentRecorder {
fn on_new_commitment(commitment: H256) {
OutboundMessageCommitmentRecorder::record_commitment_root(commitment);
}
}

impl pallet_outbound_message_commitment_recorder::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

// https://github.com/paritytech/polkadot-sdk/blob/2ae79be8e028a995b850621ee55f46c041eceefe/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs#L105
impl snowbridge_pallet_outbound_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand All @@ -68,6 +82,7 @@ impl snowbridge_pallet_outbound_queue::Config for Runtime {
type WeightInfo = crate::weights::snowbridge_pallet_outbound_queue::SubstrateWeight<Runtime>;
type PricingParameters = EthereumSystem;
type Channels = EthereumSystem;
type OnNewCommitment = CommitmentRecorder;
}

// For tests, benchmarks and fast-runtime configurations we use the mocked fork versions
Expand Down
54 changes: 41 additions & 13 deletions chains/orchestrator-relays/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ use {
},
scale_info::TypeInfo,
serde::{Deserialize, Serialize},
snowbridge_core::ChannelId,
snowbridge_core::{
outbound::{Command, Fee},
ChannelId, PricingParameters,
},
snowbridge_pallet_outbound_queue::MerkleProof,
sp_core::{storage::well_known_keys as StorageWellKnownKeys, Get},
sp_genesis_builder::PresetId,
Expand Down Expand Up @@ -1315,27 +1318,41 @@ parameter_types! {
pub LeafVersion: MmrLeafVersion = MmrLeafVersion::new(0, 0);
}

pub struct ParaHeadsRootProvider;
impl BeefyDataProvider<H256> for ParaHeadsRootProvider {
fn extra_data() -> H256 {
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct LeafExtraData {
para_heads_root: H256,
commitment_root: H256,
}

pub struct LeafExtraDataProvider;
impl BeefyDataProvider<LeafExtraData> for LeafExtraDataProvider {
fn extra_data() -> LeafExtraData {
let mut para_heads: Vec<(u32, Vec<u8>)> = parachains_paras::Parachains::<Runtime>::get()
.into_iter()
.filter_map(|id| {
parachains_paras::Heads::<Runtime>::get(id).map(|head| (id.into(), head.0))
})
.collect();
para_heads.sort();
binary_merkle_tree::merkle_root::<mmr::Hashing, _>(
let para_heads_root = binary_merkle_tree::merkle_root::<mmr::Hashing, _>(
para_heads.into_iter().map(|pair| pair.encode()),
)
);

let commitment_root =
OutboundMessageCommitmentRecorder::take_commitment_root().unwrap_or_default();

LeafExtraData {
para_heads_root,
commitment_root,
}
}
}

impl pallet_beefy_mmr::Config for Runtime {
type LeafVersion = LeafVersion;
type BeefyAuthorityToMerkleLeaf = pallet_beefy_mmr::BeefyEcdsaToEthereum;
type LeafExtra = H256;
type BeefyDataProvider = ParaHeadsRootProvider;
type LeafExtra = LeafExtraData;
type BeefyDataProvider = LeafExtraDataProvider;
type WeightInfo = ();
}

Expand Down Expand Up @@ -1837,6 +1854,12 @@ construct_runtime! {
ExternalValidatorSlashes: pallet_external_validator_slashes = 21,
ExternalValidatorsRewards: pallet_external_validators_rewards = 22,

// Bridging stuff - 1
EthereumOutboundQueue: snowbridge_pallet_outbound_queue = 23,
EthereumInboundQueue: snowbridge_pallet_inbound_queue = 24,
EthereumSystem: snowbridge_pallet_system = 25,
OutboundMessageCommitmentRecorder: pallet_outbound_message_commitment_recorder = 26,

// Session management
Session: pallet_session = 30,
Grandpa: pallet_grandpa = 31,
Expand Down Expand Up @@ -1901,11 +1924,6 @@ construct_runtime! {
// Pallet for sending XCM.
XcmPallet: pallet_xcm = 90,

// Bridging stuff
EthereumInboundQueue: snowbridge_pallet_inbound_queue = 91,
EthereumOutboundQueue: snowbridge_pallet_outbound_queue = 101,
EthereumSystem: snowbridge_pallet_system = 103,

// Migration stuff
Migrations: pallet_migrations = 120,
MultiBlockMigrations: pallet_multiblock_migrations = 121,
Expand Down Expand Up @@ -2940,6 +2958,16 @@ sp_api::impl_runtime_apis! {
}
}

impl snowbridge_outbound_queue_runtime_api::OutboundQueueApi<Block, Balance> for Runtime {
fn prove_message(leaf_index: u64) -> Option<MerkleProof> {
snowbridge_pallet_outbound_queue::api::prove_message::<Runtime>(leaf_index)
}

fn calculate_fee(command: Command, parameters: Option<PricingParameters<Balance>>) -> Fee<Balance> {
snowbridge_pallet_outbound_queue::api::calculate_fee::<Runtime>(command, parameters)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Expand Down
43 changes: 43 additions & 0 deletions pallets/oubound-message-commitment-recorder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "pallet-outbound-message-commitment-recorder"
authors = { workspace = true }
description = "Pallet that stores last block's message commitment root"
edition = "2021"
license = "GPL-3.0-only"
version = "0.1.0"

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

[lints]
workspace = true

[dependencies]
frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }


[features]
default = [ "std" ]
std = [
"frame-support/std",
"frame-system/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-core/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
72 changes: 72 additions & 0 deletions pallets/oubound-message-commitment-recorder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

//! Commitment recorder pallet.
//!
//! A pallet to record outbound message commitment.
//!
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
use {frame_support::pallet_prelude::*, sp_core::H256};

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config {
/// Overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
NewCommitmentRootRecorded { commitment: H256 },
CommitmentRootRead { commitment: H256 },
}

/// Message commitment from last block.
/// This will be set only when there are messages to relay.
#[pallet::storage]
pub type RecordedCommitment<T: Config> = StorageValue<_, H256, OptionQuery>;

impl<T: Config> Pallet<T> {
pub fn take_commitment_root() -> Option<H256> {
let maybe_commitment = RecordedCommitment::<T>::take();
if let Some(commitment) = maybe_commitment {
Pallet::<T>::deposit_event(Event::<T>::CommitmentRootRead { commitment });
Some(commitment)
} else {
None
}
}

pub fn record_commitment_root(commitment: H256) {
RecordedCommitment::<T>::put(commitment);
Pallet::<T>::deposit_event(Event::<T>::NewCommitmentRootRecorded { commitment });
}
}
}
1 change: 0 additions & 1 deletion test/scripts/bridge-build-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ check_tool
GOBIN=$output_bin_dir go install github.com/ferranbt/fastssz/sszgen@v0.1.4

$bridge_scripts/build-ethereum-node.sh
$bridge_scripts/checkout-tanssi-symbiotic.sh
$bridge_scripts/build-relayer.sh
$bridge_scripts/build-symbiotic-contracts.sh

Expand Down
13 changes: 9 additions & 4 deletions test/scripts/bridge/assets/beefy-relay.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"source": {
"polkadot": {
"endpoint": ""
},
"fast-forward-depth": 20,
"update-period": 0
}
},
"sink": {
"ethereum": {
Expand All @@ -13,7 +11,14 @@
},
"descendants-until-final": 3,
"contracts": {
"BeefyClient": null
"BeefyClient": null,
"Gateway": null
}
},
"on-demand-sync": {
"asset-hub-channel-id": "0x0000000000000000000000000000000000000000000000000000000000000001",
"max-tokens": 5,
"refill-amount": 1,
"refill-period": 3600
}
}
28 changes: 28 additions & 0 deletions test/scripts/bridge/assets/substrate-relay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"source": {
"ethereum": {
"endpoint": ""
},
"polkadot": {
"endpoint": ""
},
"contracts": {
"BeefyClient": null,
"Gateway": null
},
"channel-id": null
},
"sink": {
"ethereum": {
"endpoint": ""
},
"contracts": {
"Gateway": null
}
},
"schedule": {
"id": 0,
"totalRelayerCount": 1,
"sleepInterval": 10
}
}
Loading

0 comments on commit 61798f7

Please sign in to comment.