Skip to content

Commit

Permalink
Update Polkadot SDK (#28)
Browse files Browse the repository at this point in the history
* add test for asset-reserve and fee-reserve both at destination

* add test for asset-reserve and fee-reserve both at remote chain

* add test for asset-reserve at destination while fee-reserve is local

* add test for asset local-reserve while fee-reserve is destination

* add test for asset local-reserve while fee-reserve is remote chain

* refactor tests using better naming and conceptual examples

* add test for asset destination-reserve while fee-reserve is remote chain

* fix some typos

* deduplicate code for do_teleport_assets()

* add test for asset local-reserve while teleporting fees

* add test for asset destination-reserve while teleporting fees

* fix cases when asset reserve is remote, add test remote-asset and teleported fee

* add test for transfer asset remote reserve and fee local reserve

* add test for transfer asset remote reserve and fee destination reserve

* disallow teleportable assets in reserve-transfer, add regression test

* asset-hubs: fix emulated tests and deduplicate code

* asset-hubs: use non-system para IDs in tests where non-system paras are intended

* pallet-xcm: refactor newly added tests

* pallet-xcm: fix benchmarks

* fix pallet-xcm benchmarks for all runtimes

* address review comments

* expose TransferType through XcmExecutor::traits::AssetTransferSupport instead of pallet_xcm

* allow transfer for non-fungible assets too

* fix merge damage

* fmt

* pallet-xcm: split asset transfer tests to own file

* address review comments

* pallet-xcm: disallow combining remote reserves with other xfer types

* xcm-barriers: allow SetFeesMode in BuyExecution barrier and fix tests

* adds message queue pallet

* adds outbound queue

* fix compiler errors

* adds snowbridge to rococo bridgehub

* asset hub rococo

* asset hub rococo

* finishing up applying changes

* fix incorrect pallet-xcm imports

* verify assets and beneficiary in over-bridge test

* fix AHs tests

* AHs: fix emulated tests

* AHs: include delivery-fee checking in tests

* fix runtime-benchmarks for AHRococo

* fix clippy

* fixing tests

* adds upstream changes

* cleanup comments, fix upgrade gateway test

* withdraw fees before buyexecution - still broken because of executor appended ClearOrigin

* pallet-xcm: uses single custom XCM to send both fees and assets

* pallet-xcm: handle teleport checking account when custom burn+teleport

* fixes plus tests

* fix pallet-xcm tests

* fix AHs tests

* attempts to fix xcm config

* fixes send token

* remove unused SetFeesMode instruction

* add missing import

* allows all networks

* fmt

* pallet-xcm: fix broken reserve_transfer_assets benchmark

* try add pallet-assets for benchmarking to rococo

* Revert "try add pallet-assets for benchmarking to rococo"

This reverts commit c82330b.

* pallet-xcm benchmarking: most chains do not have pallet-assets, use pallet-balances instead

* pallet-xcm: fix teleport_assets benchmark

* fix runtimes benchmarks for pallet-xcm

* AHs simplify test_cases_over_bridge

* runtimes: add dedicated benchmarking config for pallet-xcm

* AHs benchmarks: fix transfer to sibling parachain

* fixed token transfer test

* fixes after rebase

* fixes after rebase

* fixes after rebase

* Update polkadot/xcm/xcm-executor/src/traits/asset_transfer.rs

Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>

* Update polkadot/xcm/pallet-xcm/src/lib.rs

Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>

* fmt

* Polkadot sdk update v2 (#3)

* adds message queue pallet

* adds outbound queue

* fix compiler errors

* adds snowbridge to rococo bridgehub

* asset hub rococo

* asset hub rococo

* finishing up applying changes

* fix incorrect pallet-xcm imports

* fixing tests

* adds upstream changes

* cleanup comments, fix upgrade gateway test

* attempts to fix xcm config

* fixes send token

* fmt

* fixes after rebase

* fixes after rebase

* correct relay network check

---------

Co-authored-by: claravanstaden <Cats 4 life!>

* Runtime changes for refactored outbound-queue pallet

* updates relay

* Update polkadot/xcm/xcm-builder/src/barriers.rs

Co-authored-by: Branislav Kontur <bkontur@gmail.com>

* Update polkadot/xcm/pallet-xcm/src/lib.rs

Co-authored-by: Branislav Kontur <bkontur@gmail.com>

* Update polkadot/xcm/pallet-xcm/src/lib.rs

Co-authored-by: Branislav Kontur <bkontur@gmail.com>

* Update polkadot/xcm/pallet-xcm/src/lib.rs

Co-authored-by: Branislav Kontur <bkontur@gmail.com>

* fmt

* Update bridge

* Add WeightToFee to inbound queue config

* remove comments

* Add back treasury account

* fix warnings

* Update for benchmark

* Update for benchmark

* xcm-emulator: configure penpal for asset transfers and enhance existing tests

* xcm-emulator: add relay to penpal native transfer test

* xcm-emulator: add ah to penpal native asset transfer test

* xcm: MultiLocation::chain_location() takes nonmut reference

* pallet-xcm: benchmarks: enforce single asset transfer at the api level

* xcm-executor: rename AssetTransferSupport to XcmAssetTransfer

* clippy

* fixes

* remove duplicated trait

* AssetHub tests: account for Westend higher delivery fees

* fix merge damage

* Added withdraw reserve to scripts

* bridge-hub-westend-runtime: fix benchmarks

* unknown import

* move AllowSiblingsOnly to core

* Adds transfer token user fee (#7)

* adds transfer token user fee

* updates fee calc

* starts with adding snowbridge conf

* updates fee

* correct ROC amount

* correct ROC amount

---------

Co-authored-by: claravanstaden <Cats 4 life!>

* Improve xcm integration test (#13)

* Fix tests

* Improve integration tests

* Add weight for update_fees

* remove gateway contract location

* fmt

* remove todos

* use the correct bridge config

* Enable utility calls

* xcm-emulator: add ah to penpal multiple mixed assets transfer test

* fix merge damage

* remove limited from test names, all transfers use limited method now

* barriers: allow withdrawing multiple assets in AllowTopLevelPaidExecutionFrom

* Rename to set_token_transfer_fees

* Adds Ethereum router (#16)

* configures ethereum router

* adds benchmarks and fmt

---------

Co-authored-by: claravanstaden <Cats 4 life!>

* fixed warning

* pallet-xcm: add trace logs

* fixes after merge

* fix runtime-benchmarks

* updated exporter

* pallet-xcm: fix tests

* increase fee

* tweaked fee

* xcm-emulator: remove unused pallet import

* xcm-barrier: enforce MAX_ASSETS_FOR_BUY_EXECUTION

* Change to Ethereum sovereign

* chore

* Tests for token transfer

* fix tests

* Support for message ids

* rename some variables and fns

* add explicit incomplete local execution error

* rename fns

* pallet-xcm: fix pallet extrinsic default weights

* fix some errors

* Update Cargo.lock

* working on new bridge config

* Fix assethub fee (#21)

* updates fee after fixing decimals

* adds fee in dot

* adds fee in ksm

* updates comment

---------

Co-authored-by: claravanstaden <Cats 4 life!>

* working on new bridge config

* progress on config

* pallet-xcm: also buy execution as part of custom fee handling

* pallet-xcm: fix lossy fees math

* fix merge damage

* Add commons crate for BridgeHub runtime

* fix merge damage

* Fix emulated tests

* fixes

* attempting to fix message queue things

* fix message queue things

* fixes

* Update Cargo.lock

* re-use pallet

* added fee handler trait

* whitespace

* move to treasury to snowbridge sovereign

* remove treasury

* remove TREASURY_PALLET_ID

* remove unused imports

* add fee trait

* fix error

* added full logic

* adds tests

* renamed trait

* use siblings

* address feedback

* add snowbridge-runtime-common

* fix build

* cleanup

* cleaner implementation

* cargo lock

* update cargo lock

* latest updates and fmt

* increases message queue sizes for beacon checkpoint

* updates pallet indices

* fixes

* move to runtime folder

* remove uneeded code

* remove snowbridge sovereign from tests

* use Balance

* added refund

* increased fee

* Not going to refund treasuries

* revert MessageQueueServiceWeight

* update from polkadot upstream

* update from polkadot and snowbridge upstream

* fix merge damage

* adds test back and fmt

* add channel-id support

* Fix breaking tests

---------

Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: claravanstaden <Cats 4 life!>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Clara van Staden <claravanstaden64@gmail.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: ron <yrong1997@gmail.com>
Co-authored-by: Alistair Singh <alistair.singh7@gmail.com>
  • Loading branch information
7 people authored Nov 15, 2023
1 parent 1825737 commit 0362047
Show file tree
Hide file tree
Showing 40 changed files with 2,425 additions and 146 deletions.
814 changes: 742 additions & 72 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ members = [
"cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot",
"cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo",
"cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend",
"cumulus/parachains/runtimes/bridge-hubs/common",
"cumulus/parachains/runtimes/bridge-hubs/test-utils",
"cumulus/parachains/runtimes/collectives/collectives-polkadot",
"cumulus/parachains/runtimes/contracts/contracts-rococo",
Expand Down
6 changes: 3 additions & 3 deletions cumulus/parachain-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn development_config() -> ChainSpec {
Extensions {
relay_chain: "rococo-local".into(),
// You MUST set this to the correct network!
para_id: 1000,
para_id: 1001,
},
)
.with_name("Development")
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn development_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
1000.into(),
1001.into(),
))
.build()
}
Expand All @@ -125,7 +125,7 @@ pub fn local_testnet_config() -> ChainSpec {
Extensions {
relay_chain: "rococo-local".into(),
// You MUST set this to the correct network!
para_id: 1000,
para_id: 1001,
},
)
.with_name("Local Testnet")
Expand Down
7 changes: 7 additions & 0 deletions cumulus/parachain-template/pallets/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive
frame-benchmarking = { path = "../../../../substrate/frame/benchmarking", default-features = false, optional = true}
frame-support = { path = "../../../../substrate/frame/support", default-features = false}
frame-system = { path = "../../../../substrate/frame/system", default-features = false}
sp-std = { path = "../../../../substrate/primitives/std", default-features = false}

pallet-xcm = { path = "../../../../polkadot/xcm/pallet-xcm", default-features = false}
xcm = { package = "staging-xcm", path = "../../../../polkadot/xcm", default-features = false}

[dev-dependencies]
serde = { version = "1.0.188" }
Expand All @@ -45,6 +49,9 @@ std = [
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"pallet-xcm/std",
"xcm/std",
]
try-runtime = [
"frame-support/try-runtime",
Expand Down
37 changes: 36 additions & 1 deletion cumulus/parachain-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ mod benchmarking;
pub mod pallet {
use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*};
use frame_system::pallet_prelude::*;
use sp_std::boxed::Box;
use xcm::{v3::prelude::*, VersionedMultiLocation, VersionedXcm};

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config {
pub trait Config: frame_system::Config + pallet_xcm::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
Expand All @@ -45,6 +47,8 @@ pub mod pallet {
/// Event documentation should end with an array that provides descriptive names for event
/// parameters. [something, who]
SomethingStored(u32, T::AccountId),
/// XCM message sent. \[to, message\]
Sent { from: T::AccountId, to: MultiLocation, message: Xcm<()> },
}

// Errors inform users that something went wrong.
Expand All @@ -54,6 +58,15 @@ pub mod pallet {
NoneValue,
/// Errors should have helpful documentation associated with them.
StorageOverflow,
/// The message and destination combination was not recognized as being
/// reachable.
Unreachable,
/// The message and destination was recognized as being reachable but
/// the operation could not be completed.
SendFailure,
/// The version of the `Versioned` value used is not able to be
/// interpreted.
BadVersion,
}

#[pallet::hooks]
Expand Down Expand Up @@ -102,5 +115,27 @@ pub mod pallet {
},
}
}

/// Send an XCM message as parachain sovereign.
#[pallet::call_index(2)]
#[pallet::weight(Weight::from_parts(100_000_000, 0))]
pub fn send_xcm(
origin: OriginFor<T>,
dest: Box<VersionedMultiLocation>,
message: Box<VersionedXcm<()>>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let dest = MultiLocation::try_from(*dest).map_err(|()| Error::<T>::BadVersion)?;
let message: Xcm<()> = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;

pallet_xcm::Pallet::<T>::send_xcm(Here, dest, message.clone()).map_err(
|e| match e {
SendError::Unroutable => Error::<T>::Unreachable,
_ => Error::<T>::SendFailure,
},
)?;
Self::deposit_event(Event::Sent { from: who, to: dest, message });
Ok(())
}
}
}
1 change: 1 addition & 0 deletions cumulus/parachains/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod kusama;
pub mod message_queue;
pub mod polkadot;
pub mod rococo;
pub mod snowbridge_config;
pub mod westend;
pub mod wococo;
pub mod xcm_config;
Expand Down
9 changes: 9 additions & 0 deletions cumulus/parachains/common/src/snowbridge_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
frame_support::parameter_types! {
/// User fee for ERC20 token transfer back to Ethereum.
/// (initially was calculated by test `OutboundQueue::calculate_fees` - ETH/ROC 1/400 and fee_per_gas 20 GWEI = 2200698000000 + *25%)
/// Needs to be more than fee calculated from DefaultFeeConfig FeeConfigRecord in snowbridge:parachain/pallets/outbound-queue/src/lib.rs
/// Polkadot uses 12 decimals, Kusama and Rococo 10 decimals.
pub const BridgeHubEthereumBaseFeeInDOT: u128 = 27_508_725_000;
pub const BridgeHubEthereumBaseFeeInKSM: u128 = 2_750_872_500_000;
pub const BridgeHubEthereumBaseFeeInRocs: u128 = 2_750_872_500_000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ parachains-common = { path = "../../../../../../../parachains/common" }
cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false }
emulated-integration-tests-common = { path = "../../../../common", default-features = false }
bridge-hub-rococo-runtime = { path = "../../../../../../runtimes/bridge-hubs/bridge-hub-rococo" }

# Snowbridge
snowbridge-core = { path = "../../../../../../../../../parachain/primitives/core", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../../../../parachain/primitives/router", default-features = false }
snowbridge-control = { path = "../../../../../../../../../parachain/pallets/control", default-features = false }
snowbridge-inbound-queue = { path = "../../../../../../../../../parachain/pallets/inbound-queue", default-features = false }
snowbridge-outbound-queue = { path = "../../../../../../../../../parachain/pallets/outbound-queue", default-features = false }

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm,
Balances: bridge_hub_rococo_runtime::Balances,
EthereumControl: bridge_hub_rococo_runtime::EthereumControl,
EthereumInboundQueue: bridge_hub_rococo_runtime::EthereumInboundQueue,
EthereumOutboundQueue: bridge_hub_rococo_runtime::EthereumOutboundQueue,
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ publish = false

[dependencies]
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
hex = "0.4.3"
hex-literal = "0.4.1"

# Substrate
sp-core = { path = "../../../../../../../substrate/primitives/core", default-features = false}
frame-support = { path = "../../../../../../../substrate/frame/support", default-features = false}
pallet-message-queue = { path = "../../../../../../../substrate/frame/message-queue" }
pallet-assets = { path = "../../../../../../../substrate/frame/assets", default-features = false }
pallet-balances = { path = "../../../../../../../substrate/frame/balances", default-features = false }

# Polkadot
xcm = { package = "staging-xcm", path = "../../../../../../../polkadot/xcm", default-features = false}
Expand All @@ -30,4 +36,13 @@ cumulus-pallet-xcmp-queue = { path = "../../../../../../pallets/xcmp-queue", def
cumulus-pallet-dmp-queue = { path = "../../../../../../pallets/dmp-queue", default-features = false}
bridge-hub-rococo-runtime = { path = "../../../../../../parachains/runtimes/bridge-hubs/bridge-hub-rococo", default-features = false }
emulated-integration-tests-common = { path = "../../../common", default-features = false}
rococo-wococo-system-emulated-network ={ path = "../../../networks/rococo-wococo-system" }
rococo-wococo-system-emulated-network = { path = "../../../networks/rococo-wococo-system" }
bridge-hub-rococo-emulated-chain = { path = "../../../chains/parachains/bridges/bridge-hub-rococo"}
asset-hub-rococo-emulated-chain = { path = "../../../chains/parachains/assets/asset-hub-rococo"}

# Snowbridge
snowbridge-core = { path = "../../../../../../../../parachain/primitives/core", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../../../parachain/primitives/router", default-features = false }
snowbridge-control = { path = "../../../../../../../../parachain/pallets/control", default-features = false }
snowbridge-inbound-queue = { path = "../../../../../../../../parachain/pallets/inbound-queue", default-features = false }
snowbridge-outbound-queue = { path = "../../../../../../../../parachain/pallets/outbound-queue", default-features = false }
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
// limitations under the License.

mod example;
mod snowbridge;
mod teleport;
Loading

0 comments on commit 0362047

Please sign in to comment.