Skip to content

Commit

Permalink
Snowbridge - Fix benchmarks, add fee multipler and move config to Eth…
Browse files Browse the repository at this point in the history
…ereum module (#252)

The Snowbridge Inbound Queue pallet benchmarks are failing:

```
2024-03-21 13:50:40 Running  benchmark: snowbridge_pallet_ethereum_client.submit_execution_header(0 args) 1/1 1/1    
Running benchmarks for snowbridge_pallet_inbound_queue to ./bridge-hub-kusama-weights/
2024-03-21 13:50:41 Starting benchmark: snowbridge_pallet_inbound_queue::submit    
2024-03-21 13:50:41 💫 Verifying message with block hash 0x3921…3a3f    
2024-03-21 13:50:41 💫 Receipt verification successful for 0x3921…3a3f    
2024-03-21 13:50:41 panicked at /home/bparity/.cargo/registry/src/index.crates.io-6f17d22bba15001f/snowbridge-pallet-inbound-queue-0.1.0/src/benchmarking/mod.rs:43:13:
Expected Ok(_). Got Err(
    Module(
        ModuleError {
            index: 80,
            error: [
                0,
                0,
                0,
                0,
            ],
            message: Some(
                "InvalidGateway",
            ),
        },
    ),
)    
Error: 
   0: Invalid input: Error executing and verifying runtime benchmark: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
      WASM backtrace:
      error while executing at wasm backtrace:
          0: 0x436fa6 - <unknown>!rust_begin_unwind
          1: 0x2969 - <unknown>!core::panicking::panic_fmt::hbb0c5dd9c7ebab99
          2: 0x329f54 - <unknown>!core::ops::function::FnOnce::call_once{{vtable.shim}}::h0374b352d74ea114
          3: 0x300e24 - <unknown>!<bridge_hub_kusama_runtime::Runtime as frame_benchmarking::utils::runtime_decl_for_benchmark::BenchmarkV1<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u32,sp_runtime::traits::BlakeTwo256>,sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic<sp_runtime::multiaddress::MultiAddress<<<sp_runtime::MultiSignature as sp_runtime::traits::Verify>::Signer as sp_runtime::traits::IdentifyAccount>::AccountId,()>,bridge_hub_kusama_runtime::RuntimeCall,sp_runtime::MultiSignature,(frame_system::extensions::check_non_zero_sender::CheckNonZeroSender<bridge_hub_kusama_runtime::Runtime>,frame_system::extensions::check_spec_version::CheckSpecVersion<bridge_hub_kusama_runtime::Runtime>,frame_system::extensions::check_tx_version::CheckTxVersion<bridge_hub_kusama_runtime::Runtime>,frame_system::extensions::check_genesis::CheckGenesis<bridge_hub_kusama_runtime::Runtime>,frame_system::extensions::check_mortality::CheckMortality<bridge_hub_kusama_runtime::Runtime>,frame_system::extensions::check_nonce::CheckNonce<bridge_hub_kusama_runtime::Runtime>,frame_system::extensions::check_weight::CheckWeight<bridge_hub_kusama_runtime::Runtime>,pallet_transaction_payment::ChargeTransactionPayment<bridge_hub_kusama_runtime::Runtime>,bridge_hub_kusama_runtime::BridgeRejectObsoleteHeadersAndMessages,bridge_runtime_common::refund_relayer_extension::RefundSignedExtensionAdapter<bridge_runtime_common::refund_relayer_extension::RefundBridgedParachainMessages<bridge_hub_kusama_runtime::Runtime,bridge_runtime_common::refund_relayer_extension::RefundableParachain<frame_support::instances::Instance1,bp_bridge_hub_polkadot::BridgeHubPolkadot>,bridge_runtime_common::refund_relayer_extension::RefundableMessagesLane<frame_support::instances::Instance1,bridge_hub_kusama_runtime::bridge_to_polkadot_config::AssetHubKusamaToAssetHubPolkadotMessagesLane>,bridge_runtime_common::refund_relayer_extension::ActualFeeRefund<bridge_hub_kusama_runtime::Runtime>,bridge_hub_kusama_runtime::bridge_to_polkadot_config::PriorityBoostPerMessage,bridge_hub_kusama_runtime::bridge_to_polkadot_config::StrRefundBridgeHubPolkadotMessages>>)>>>>::dispatch_benchmark::h500c8f48422e47bd
          4: 0x3c0b6a - <unknown>!Benchmark_dispatch_benchmark
```

This PR fixes the error (the Ethereum gateway contract address should be
set in the benchmarks since it is verified in the inbound queue when a
message is submitted) and moves the benchmark config into
`bridge_to_ethereum_config.rs`.

- [x] Does not require a CHANGELOG entry

---------

Co-authored-by: claravanstaden <Cats 4 life!>
Co-authored-by: Vincent Geddes <[email protected]>
Co-authored-by: Branislav Kontur <[email protected]>
Co-authored-by: Adrian Catangiu <[email protected]>
Co-authored-by: Vincent Geddes <[email protected]>
  • Loading branch information
5 people authored Mar 25, 2024
1 parent 0d3c832 commit bc9491d
Show file tree
Hide file tree
Showing 39 changed files with 1,318 additions and 1,174 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions chain-spec-generator/src/system_parachains_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ fn bridge_hub_polkadot_genesis(
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"ethereumSystem": bridge_hub_polkadot_runtime::EthereumSystemConfig {
para_id: id,
asset_hub_para_id: polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
..Default::default()
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
Expand Down Expand Up @@ -472,6 +477,11 @@ fn bridge_hub_kusama_genesis(
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"ethereumSystem": bridge_hub_kusama_runtime::EthereumSystemConfig {
para_id: id,
asset_hub_para_id: kusama_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
..Default::default()
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/emulated/helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pallet-message-queue = { version = "32.0.0" }

# Polkadot
xcm = { package = "staging-xcm", version = "8.0.1" }
pallet-xcm = { version = "8.0.3" }
pallet-xcm = { version = "8.0.4" }

# Cumulus
xcm-emulator = { version = "0.6.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pallet-utility = { version = "29.0.0" }
# Polkadot
xcm = { package = "staging-xcm", version = "8.0.1" }
xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "8.0.1" }
pallet-xcm = { version = "8.0.3" }
pallet-xcm = { version = "8.0.4" }
runtime-common = { package = "polkadot-runtime-common", default-features = false, version = "8.0.1" }

# Cumulus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pallet-message-queue = { version = "32.0.0" }
# Polkadot
polkadot-runtime-common = { version = "8.0.1" }
xcm = { package = "staging-xcm", version = "8.0.1" }
pallet-xcm = { version = "8.0.3" }
pallet-xcm = { version = "8.0.4" }
xcm-executor = { package = "staging-xcm-executor", version = "8.0.1" }

# Cumulus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pallet-message-queue = { version = "32.0.0" }

# Polkadot
xcm = { package = "staging-xcm", version = "8.0.1" }
pallet-xcm = { version = "8.0.3" }
pallet-xcm = { version = "8.0.4" }
xcm-executor = { package = "staging-xcm-executor", version = "8.0.1" }

# Cumulus
Expand All @@ -46,8 +46,8 @@ system-parachains-constants = { path = "../../../../../system-parachains/constan

# Snowbridge
snowbridge-beacon-primitives = { version = "0.1.0" }
snowbridge-core = { version = "0.1.0" }
snowbridge-core = { version = "0.1.1" }
snowbridge-router-primitives = { version = "0.1.0" }
snowbridge-pallet-system = { version = "0.1.0" }
snowbridge-pallet-outbound-queue = { version = "0.1.0" }
snowbridge-pallet-system = { version = "0.1.1" }
snowbridge-pallet-outbound-queue = { version = "0.1.1" }
snowbridge-pallet-inbound-queue-fixtures = { version = "0.9.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::*;
use asset_hub_kusama_runtime::xcm_config::bridging::to_ethereum::{
BridgeHubEthereumBaseFee, EthereumNetwork,
use asset_hub_kusama_runtime::xcm_config::{
bridging::to_ethereum::{BridgeHubEthereumBaseFee, EthereumNetwork},
RelayTreasuryPalletAccount,
};
use bp_bridge_hub_kusama::snowbridge::CreateAssetCall;
use bridge_hub_kusama_runtime::{
EthereumBeaconClient, EthereumGatewayAddress, EthereumInboundQueue, Runtime, RuntimeOrigin,
bridge_to_ethereum_config::EthereumGatewayAddress, EthereumBeaconClient, EthereumInboundQueue,
Runtime, RuntimeOrigin,
};
use codec::{Decode, Encode};
use emulated_integration_tests_common::xcm_emulator::ConvertLocation;
Expand Down Expand Up @@ -50,8 +52,6 @@ use system_parachains_constants::kusama::currency::UNITS;

const INITIAL_FUND: u128 = 5_000_000_000 * KUSAMA_ED;
const CHAIN_ID: u64 = 1;
const TREASURY_ACCOUNT: [u8; 32] =
hex!("da5026b2e34b876343bd6becae58eb5af71ec727633bfb972641fa7a89ff4988");
const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d");
const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e");
const GATEWAY_ADDRESS: [u8; 20] = hex!("EDa338E4dC46038493b885327842fD3E301CaB39");
Expand Down Expand Up @@ -439,7 +439,7 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {

BridgeHubKusama::fund_accounts(vec![
(assethub_sovereign.clone(), INITIAL_FUND),
(TREASURY_ACCOUNT.into(), INITIAL_FUND),
(RelayTreasuryPalletAccount::get(), INITIAL_FUND),
]);
AssetHubKusama::fund_accounts(vec![
(AssetHubPolkadotReceiver::get(), INITIAL_FUND),
Expand Down Expand Up @@ -469,6 +469,7 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
local: (1 * UNITS / 100).into(), // 0.01 KSM
remote: meth(1),
},
multiplier: FixedU128::from_rational(1, 1),
}
)
);
Expand Down Expand Up @@ -501,6 +502,11 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
);
});

// check treasury account balance on BH before
let treasury_account_before = BridgeHubKusama::execute_with(|| {
<<BridgeHubKusama as BridgeHubKusamaPallet>::Balances as frame_support::traits::fungible::Inspect<_>>::balance(&RelayTreasuryPalletAccount::get())
});

AssetHubKusama::execute_with(|| {
type RuntimeEvent = <AssetHubKusama as Chain>::RuntimeEvent;
type RuntimeOrigin = <AssetHubKusama as Chain>::RuntimeOrigin;
Expand Down Expand Up @@ -564,22 +570,27 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
RuntimeEvent::EthereumOutboundQueue(snowbridge_pallet_outbound_queue::Event::MessageQueued {..}) => {},
]
);

// check treasury account balance on BH after (should receive some fees)
let treasury_account_after = <<BridgeHubKusama as BridgeHubKusamaPallet>::Balances as frame_support::traits::fungible::Inspect<_>>::balance(&RelayTreasuryPalletAccount::get());
let local_fee = treasury_account_after - treasury_account_before;

let events = BridgeHubKusama::events();
// Check that the local fee was credited to the Snowbridge sovereign account
assert!(
events.iter().any(|event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, amount })
if *who == TREASURY_ACCOUNT.into() && *amount == 169033333
if *who == RelayTreasuryPalletAccount::get() && *amount == local_fee
)),
"Snowbridge sovereign takes local fee."
);
// Check that the remote fee was credited to the AssetHub sovereign account
// Check that the remote delivery fee was credited to the AssetHub sovereign account
assert!(
events.iter().any(|event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, amount })
if *who == assethub_sovereign && *amount == 502500000000,
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. })
if *who == assethub_sovereign,
)),
"AssetHub sovereign takes remote fee."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pallet-message-queue = { version = "32.0.0" }

# Polkadot
xcm = { package = "staging-xcm", version = "8.0.1" }
pallet-xcm = { version = "8.0.3" }
pallet-xcm = { version = "8.0.4" }
xcm-executor = { package = "staging-xcm-executor", version = "8.0.1" }

# Cumulus
Expand All @@ -46,8 +46,8 @@ system-parachains-constants = { path = "../../../../../system-parachains/constan

# Snowbridge
snowbridge-beacon-primitives = { version = "0.1.0" }
snowbridge-core = { version = "0.1.0" }
snowbridge-core = { version = "0.1.1" }
snowbridge-router-primitives = { version = "0.1.0" }
snowbridge-pallet-system = { version = "0.1.0" }
snowbridge-pallet-outbound-queue = { version = "0.1.0" }
snowbridge-pallet-system = { version = "0.1.1" }
snowbridge-pallet-outbound-queue = { version = "0.1.1" }
snowbridge-pallet-inbound-queue-fixtures = { version = "0.9.0" }
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::*;
use asset_hub_polkadot_runtime::xcm_config::bridging::to_ethereum::{
BridgeHubEthereumBaseFee, EthereumNetwork,
use asset_hub_polkadot_runtime::xcm_config::{
bridging::to_ethereum::{BridgeHubEthereumBaseFee, EthereumNetwork},
RelayTreasuryPalletAccount,
};
use bp_bridge_hub_polkadot::snowbridge::CreateAssetCall;
use bridge_hub_polkadot_runtime::{
EthereumBeaconClient, EthereumGatewayAddress, EthereumInboundQueue, Runtime, RuntimeOrigin,
bridge_to_ethereum_config::EthereumGatewayAddress, EthereumBeaconClient, EthereumInboundQueue,
Runtime, RuntimeOrigin,
};
use codec::{Decode, Encode};
use emulated_integration_tests_common::xcm_emulator::ConvertLocation;
Expand Down Expand Up @@ -50,8 +52,6 @@ use system_parachains_constants::polkadot::currency::UNITS;

const INITIAL_FUND: u128 = 5_000_000_000 * POLKADOT_ED;
const CHAIN_ID: u64 = 1;
const TREASURY_ACCOUNT: [u8; 32] =
hex!("af3e7da28608e13e4399cc7d14a57bdb154dde5f3d546f5f293994ef36ef7f11");
const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d");
const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e");
const GATEWAY_ADDRESS: [u8; 20] = hex!("EDa338E4dC46038493b885327842fD3E301CaB39");
Expand Down Expand Up @@ -439,7 +439,7 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {

BridgeHubPolkadot::fund_accounts(vec![
(assethub_sovereign.clone(), INITIAL_FUND),
(TREASURY_ACCOUNT.into(), INITIAL_FUND),
(RelayTreasuryPalletAccount::get(), INITIAL_FUND),
]);
AssetHubPolkadot::fund_accounts(vec![
(AssetHubPolkadotReceiver::get(), INITIAL_FUND),
Expand Down Expand Up @@ -469,6 +469,7 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
local: (1 * UNITS / 100).into(), // 0.01 DOT
remote: meth(1),
},
multiplier: FixedU128::from_rational(1, 1),
}
)
);
Expand Down Expand Up @@ -501,6 +502,11 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
);
});

// check treasury account balance on BH before
let treasury_account_before = BridgeHubPolkadot::execute_with(|| {
<<BridgeHubPolkadot as BridgeHubPolkadotPallet>::Balances as frame_support::traits::fungible::Inspect<_>>::balance(&RelayTreasuryPalletAccount::get())
});

AssetHubPolkadot::execute_with(|| {
type RuntimeEvent = <AssetHubPolkadot as Chain>::RuntimeEvent;
type RuntimeOrigin = <AssetHubPolkadot as Chain>::RuntimeOrigin;
Expand Down Expand Up @@ -568,22 +574,27 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
RuntimeEvent::EthereumOutboundQueue(snowbridge_pallet_outbound_queue::Event::MessageQueued {..}) => {},
]
);

// check treasury account balance on BH after (should receive some fees)
let treasury_account_after = <<BridgeHubPolkadot as BridgeHubPolkadotPallet>::Balances as frame_support::traits::fungible::Inspect<_>>::balance(&RelayTreasuryPalletAccount::get());
let local_fee = treasury_account_after - treasury_account_before;

let events = BridgeHubPolkadot::events();
// Check that the local fee was credited to the Snowbridge sovereign account
assert!(
events.iter().any(|event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, amount })
if *who == TREASURY_ACCOUNT.into() && *amount == 50710000
if *who == RelayTreasuryPalletAccount::get() && *amount == local_fee
)),
"Snowbridge sovereign takes local fee."
);
// Check that the remote fee was credited to the AssetHub sovereign account
// Check that the remote delivery fee was credited to the AssetHub sovereign account
assert!(
events.iter().any(|event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, amount })
if *who == assethub_sovereign && *amount == 5025000000,
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. })
if *who == assethub_sovereign,
)),
"AssetHub sovereign takes remote fee."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pallet-utility = { version = "29.0.0" }
# Polkadot
polkadot-runtime-common = { version = "8.0.1" }
xcm = { package = "staging-xcm", version = "8.0.1" }
pallet-xcm = { version = "8.0.2" }
pallet-xcm = { version = "8.0.4" }
xcm-executor = { package = "staging-xcm-executor", version = "8.0.1" }

# Cumulus
Expand Down
2 changes: 1 addition & 1 deletion relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pallet-treasury = { default-features = false , version = "28.0.0" }
pallet-utility = { default-features = false , version = "29.0.0" }
pallet-vesting = { default-features = false , version = "29.0.0" }
pallet-whitelist = { default-features = false , version = "28.0.0" }
pallet-xcm = { default-features = false , version = "8.0.3" }
pallet-xcm = { default-features = false, version = "8.0.4" }
pallet-xcm-benchmarks = { default-features = false, optional = true , version = "8.0.2" }
frame-election-provider-support = { default-features = false , version = "29.0.0" }

Expand Down
2 changes: 1 addition & 1 deletion relay/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pallet-whitelist = { default-features = false , version = "28.0.0" }
pallet-vesting = { default-features = false , version = "29.0.0" }
pallet-utility = { default-features = false , version = "29.0.0" }
frame-election-provider-support = { default-features = false , version = "29.0.0" }
pallet-xcm = { default-features = false, version = "8.0.3" }
pallet-xcm = { default-features = false, version = "8.0.4" }
pallet-xcm-benchmarks = { default-features = false, optional = true , version = "8.0.2" }

frame-benchmarking = { default-features = false, optional = true , version = "29.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sp-weights = { default-features = false, version = "28.0.0" }
primitive-types = { version = "0.12.2", default-features = false, features = ["codec", "scale-info", "num-traits"] }

# Polkadot
pallet-xcm = { default-features = false, version = "8.0.3" }
pallet-xcm = { default-features = false, version = "8.0.4" }
pallet-xcm-benchmarks = { default-features = false, optional = true , version = "8.0.2" }
polkadot-core-primitives = { default-features = false, version = "8.0.0" }
polkadot-parachain-primitives = { default-features = false, version = "7.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sp-weights = { default-features = false, version = "28.0.0" }
primitive-types = { version = "0.12.2", default-features = false, features = ["codec", "scale-info", "num-traits"] }

# Polkadot
pallet-xcm = { default-features = false, version = "8.0.3" }
pallet-xcm = { default-features = false, version = "8.0.4" }
pallet-xcm-benchmarks = { default-features = false, optional = true , version = "8.0.2" }
polkadot-core-primitives = { default-features = false, version = "8.0.0" }
polkadot-parachain-primitives = { default-features = false, version = "7.0.0" }
Expand Down
Loading

0 comments on commit bc9491d

Please sign in to comment.