diff --git a/Cargo.lock b/Cargo.lock index 4dda0e98de0e..1ab4858dc0e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19157,6 +19157,7 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", + "snowbridge-core", "sp-core", "sp-io", "sp-runtime", @@ -19181,6 +19182,7 @@ dependencies = [ "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-pallet-ethereum-client", + "snowbridge-pallet-gas-price", "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-router-primitives", "sp-core", diff --git a/bridges/snowbridge/pallets/ethereum-client/Cargo.toml b/bridges/snowbridge/pallets/ethereum-client/Cargo.toml index 23dc4ee4ea01..3e76a57186e6 100644 --- a/bridges/snowbridge/pallets/ethereum-client/Cargo.toml +++ b/bridges/snowbridge/pallets/ethereum-client/Cargo.toml @@ -84,6 +84,7 @@ runtime-benchmarks = [ "pallet-timestamp?/runtime-benchmarks", "snowbridge-core/runtime-benchmarks", "snowbridge-pallet-ethereum-client-fixtures/runtime-benchmarks", + "snowbridge-pallet-gas-price/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] try-runtime = [ diff --git a/bridges/snowbridge/pallets/ethereum-client/src/lib.rs b/bridges/snowbridge/pallets/ethereum-client/src/lib.rs index f39d4b249294..9f2c50ab95ac 100644 --- a/bridges/snowbridge/pallets/ethereum-client/src/lib.rs +++ b/bridges/snowbridge/pallets/ethereum-client/src/lib.rs @@ -40,7 +40,7 @@ use primitives::{ fast_aggregate_verify, verify_merkle_branch, verify_receipt_proof, BeaconHeader, BlsError, CompactBeaconState, ForkData, ForkVersion, ForkVersions, PublicKeyPrepared, SigningData, }; -use snowbridge_core::{BasicOperatingMode, RingBufferMap}; +use snowbridge_core::{BasicOperatingMode, GasPriceProvider, RingBufferMap}; use sp_core::H256; use sp_std::prelude::*; pub use weights::WeightInfo; @@ -49,7 +49,6 @@ use functions::{ compute_epoch, compute_period, decompress_sync_committee_bits, sync_committee_sum, }; pub use pallet::*; -use snowbridge_pallet_gas_price::impls::GasPriceProvider; use types::{CheckpointUpdate, FinalizedBeaconStateBuffer, SyncCommitteePrepared, Update}; pub use config::SLOTS_PER_HISTORICAL_ROOT; @@ -489,7 +488,7 @@ pub mod pallet { Self::store_finalized_header(update.finalized_header, update.block_roots_root)?; } - T::GasPrice::store( + T::GasPrice::update( update.execution_header.base_fee_per_gas(), update.finalized_header.slot, ); diff --git a/bridges/snowbridge/pallets/gas-price/Cargo.toml b/bridges/snowbridge/pallets/gas-price/Cargo.toml index 0ad67a9671ba..6d6d1150e713 100644 --- a/bridges/snowbridge/pallets/gas-price/Cargo.toml +++ b/bridges/snowbridge/pallets/gas-price/Cargo.toml @@ -26,6 +26,7 @@ sp-core = { path = "../../../../substrate/primitives/core", default-features = f sp-std = { path = "../../../../substrate/primitives/std", default-features = false } sp-runtime = { path = "../../../../substrate/primitives/runtime", default-features = false } sp-io = { path = "../../../../substrate/primitives/io", default-features = false, optional = true } +snowbridge-core = { path = "../../primitives/core", default-features = false } [features] default = ["std"] @@ -35,6 +36,7 @@ std = [ "frame-system/std", "log/std", "scale-info/std", + "snowbridge-core/std", "sp-core/std", "sp-io/std", "sp-runtime/std", @@ -45,10 +47,6 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "snowbridge-core/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/bridges/snowbridge/pallets/gas-price/src/impls.rs b/bridges/snowbridge/pallets/gas-price/src/impls.rs deleted file mode 100644 index e6ede655e0da..000000000000 --- a/bridges/snowbridge/pallets/gas-price/src/impls.rs +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2023 Snowfork -use crate::BaseFeePerGas; -use sp_core::U256; -/// A trait for retrieving the base fee per gas. - -pub trait GasPriceProvider { - fn store(value: U256, slot: u64); - fn get() -> BaseFeePerGas; -} diff --git a/bridges/snowbridge/pallets/gas-price/src/lib.rs b/bridges/snowbridge/pallets/gas-price/src/lib.rs index 0fe2d10fadca..188b88165090 100644 --- a/bridges/snowbridge/pallets/gas-price/src/lib.rs +++ b/bridges/snowbridge/pallets/gas-price/src/lib.rs @@ -1,12 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 Snowfork #![cfg_attr(not(feature = "std"), no_std)] -pub mod impls; -pub mod types; -use crate::{impls::GasPriceProvider, types::BaseFeePerGas}; use frame_system::WeightInfo; pub use pallet::*; +use snowbridge_core::{BaseFeePerGas, GasPriceProvider}; use sp_core::U256; pub const LOG_TARGET: &str = "gas-price"; @@ -44,7 +42,7 @@ pub mod pallet { } impl GasPriceProvider for Pallet { - fn store(value: U256, slot: u64) { + fn update(value: U256, slot: u64) { >::set(BaseFeePerGas { value, slot }); Self::deposit_event(Event::GasPriceUpdate { value, slot }); diff --git a/bridges/snowbridge/pallets/gas-price/src/types.rs b/bridges/snowbridge/pallets/gas-price/src/types.rs deleted file mode 100644 index 5dc901f1f841..000000000000 --- a/bridges/snowbridge/pallets/gas-price/src/types.rs +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2023 Snowfork -use codec::{Decode, Encode, MaxEncodedLen}; -use scale_info::TypeInfo; -use sp_core::U256; -#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, MaxEncodedLen, Default)] -pub struct BaseFeePerGas { - pub value: U256, - pub slot: u64, -} diff --git a/bridges/snowbridge/pallets/inbound-queue/Cargo.toml b/bridges/snowbridge/pallets/inbound-queue/Cargo.toml index d63398770f20..21b96713fe47 100644 --- a/bridges/snowbridge/pallets/inbound-queue/Cargo.toml +++ b/bridges/snowbridge/pallets/inbound-queue/Cargo.toml @@ -39,6 +39,7 @@ snowbridge-core = { path = "../../primitives/core", default-features = false } snowbridge-router-primitives = { path = "../../primitives/router", default-features = false } snowbridge-beacon-primitives = { path = "../../primitives/beacon", default-features = false } snowbridge-pallet-inbound-queue-fixtures = { path = "fixtures", default-features = false, optional = true } +snowbridge-pallet-gas-price = { path = "../gas-price", default-features = false } [dev-dependencies] frame-benchmarking = { path = "../../../../substrate/frame/benchmarking" } @@ -46,6 +47,7 @@ sp-keyring = { path = "../../../../substrate/primitives/keyring" } snowbridge-pallet-ethereum-client = { path = "../ethereum-client" } hex-literal = { version = "0.4.1" } + [features] default = ["std"] std = [ @@ -61,6 +63,7 @@ std = [ "serde", "snowbridge-beacon-primitives/std", "snowbridge-core/std", + "snowbridge-pallet-gas-price/std", "snowbridge-pallet-inbound-queue-fixtures?/std", "snowbridge-router-primitives/std", "sp-core/std", @@ -79,6 +82,7 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "snowbridge-core/runtime-benchmarks", "snowbridge-pallet-ethereum-client/runtime-benchmarks", + "snowbridge-pallet-gas-price/runtime-benchmarks", "snowbridge-pallet-inbound-queue-fixtures/runtime-benchmarks", "snowbridge-router-primitives/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/bridges/snowbridge/pallets/inbound-queue/src/mock.rs b/bridges/snowbridge/pallets/inbound-queue/src/mock.rs index 05481ca2f6b4..be3c23c6cbf6 100644 --- a/bridges/snowbridge/pallets/inbound-queue/src/mock.rs +++ b/bridges/snowbridge/pallets/inbound-queue/src/mock.rs @@ -12,7 +12,6 @@ use snowbridge_beacon_primitives::{ types::deneb, BeaconHeader, ExecutionProof, Fork, ForkVersions, VersionedExecutionPayloadHeader, }; use snowbridge_core::{ - gwei, inbound::{Log, Proof, VerificationError}, meth, Channel, ChannelId, PricingParameters, Rewards, StaticLookup, }; @@ -37,6 +36,7 @@ frame_support::construct_runtime!( Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, EthereumBeaconClient: snowbridge_pallet_ethereum_client::{Pallet, Call, Storage, Event}, InboundQueue: inbound_queue::{Pallet, Call, Storage, Event}, + GasPrice: snowbridge_pallet_gas_price::{Pallet, Call, Storage, Event}, } ); @@ -107,10 +107,16 @@ parameter_types! { }; } +impl snowbridge_pallet_gas_price::Config for Test { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); +} + impl snowbridge_pallet_ethereum_client::Config for Test { type RuntimeEvent = RuntimeEvent; type ForkVersions = ChainForkVersions; type WeightInfo = (); + type GasPrice = GasPrice; } // Mock verifier @@ -171,7 +177,6 @@ parameter_types! { pub const OwnParaId: ParaId = ParaId::new(1013); pub Parameters: PricingParameters = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), - fee_per_gas: gwei(20), rewards: Rewards { local: DOT, remote: meth(1) }, multiplier: FixedU128::from_rational(1, 1), }; diff --git a/bridges/snowbridge/pallets/outbound-queue/Cargo.toml b/bridges/snowbridge/pallets/outbound-queue/Cargo.toml index 31fec7b83069..89ad4cd11c95 100644 --- a/bridges/snowbridge/pallets/outbound-queue/Cargo.toml +++ b/bridges/snowbridge/pallets/outbound-queue/Cargo.toml @@ -32,8 +32,8 @@ bridge-hub-common = { path = "../../../../cumulus/parachains/runtimes/bridge-hub snowbridge-core = { path = "../../primitives/core", default-features = false, features = ["serde"] } snowbridge-outbound-queue-merkle-tree = { path = "merkle-tree", default-features = false } -snowbridge-pallet-gas-price = { path = "../gas-price", default-features = false } ethabi = { package = "ethabi-decode", version = "1.0.0", default-features = false } +snowbridge-pallet-gas-price = { path = "../gas-price", default-features = false } [dev-dependencies] pallet-message-queue = { path = "../../../../substrate/frame/message-queue", default-features = false } @@ -68,6 +68,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "snowbridge-core/runtime-benchmarks", + "snowbridge-pallet-gas-price/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] try-runtime = [ diff --git a/bridges/snowbridge/pallets/outbound-queue/src/lib.rs b/bridges/snowbridge/pallets/outbound-queue/src/lib.rs index 9d7665043ee6..0d3bb58e725d 100644 --- a/bridges/snowbridge/pallets/outbound-queue/src/lib.rs +++ b/bridges/snowbridge/pallets/outbound-queue/src/lib.rs @@ -112,11 +112,10 @@ use frame_support::{ }; use snowbridge_core::{ outbound::{Fee, GasMeter, QueuedMessage, VersionedQueuedMessage, ETHER_DECIMALS}, - BasicOperatingMode, ChannelId, + BasicOperatingMode, ChannelId, GasPriceProvider, }; use snowbridge_outbound_queue_merkle_tree::merkle_root; pub use snowbridge_outbound_queue_merkle_tree::MerkleProof; -pub use snowbridge_pallet_gas_price::GasPriceProvider; use sp_core::{H256, U256}; use sp_runtime::{ traits::{CheckedDiv, Hash}, @@ -351,10 +350,7 @@ pub mod pallet { command, params, max_dispatch_gas, - max_fee_per_gas: T::GasPrice::get() - .value - .try_into() - .defensive_unwrap_or(u128::MAX), + max_fee_per_gas: T::GasPrice::get().value.try_into().defensive_unwrap_or(u128::MAX), reward: reward.try_into().defensive_unwrap_or(u128::MAX), id: queued_message.id, }; diff --git a/bridges/snowbridge/pallets/outbound-queue/src/test.rs b/bridges/snowbridge/pallets/outbound-queue/src/test.rs index 4bd06e1667b4..41e0dacc6390 100644 --- a/bridges/snowbridge/pallets/outbound-queue/src/test.rs +++ b/bridges/snowbridge/pallets/outbound-queue/src/test.rs @@ -270,7 +270,7 @@ fn encode_digest_item() { #[test] fn test_calculate_fees_with_unit_multiplier() { new_tester().execute_with(|| { - ::GasPrice::store(10000_u32.into(), 400); + ::GasPrice::update(10000_u32.into(), 400); let gas_used: u64 = 250000; let price_params: PricingParameters<::Balance> = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), @@ -286,7 +286,7 @@ fn test_calculate_fees_with_unit_multiplier() { #[test] fn test_calculate_fees_with_multiplier() { new_tester().execute_with(|| { - ::GasPrice::store(10000_u32.into(), 400); + ::GasPrice::update(10000_u32.into(), 400); let gas_used: u64 = 250000; let price_params: PricingParameters<::Balance> = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), @@ -302,7 +302,7 @@ fn test_calculate_fees_with_multiplier() { #[test] fn test_calculate_fees_with_valid_exchange_rate_but_remote_fee_calculated_as_zero() { new_tester().execute_with(|| { - ::GasPrice::store(1_u32.into(), 400); + ::GasPrice::update(1_u32.into(), 400); let gas_used: u64 = 250000; let price_params: PricingParameters<::Balance> = PricingParameters { exchange_rate: FixedU128::from_rational(1, 1), diff --git a/bridges/snowbridge/primitives/core/src/lib.rs b/bridges/snowbridge/primitives/core/src/lib.rs index ed1af4225d24..c594725f3a64 100644 --- a/bridges/snowbridge/primitives/core/src/lib.rs +++ b/bridges/snowbridge/primitives/core/src/lib.rs @@ -35,7 +35,7 @@ use xcm_builder::{DescribeAllTerminal, DescribeFamily, DescribeLocation, HashedD pub type AgentId = H256; pub use operating_mode::BasicOperatingMode; -pub use pricing::{PricingParameters, Rewards}; +pub use pricing::{BaseFeePerGas, GasPriceProvider, PricingParameters, Rewards}; pub fn sibling_sovereign_account(para_id: ParaId) -> T::AccountId where diff --git a/bridges/snowbridge/primitives/core/src/pricing.rs b/bridges/snowbridge/primitives/core/src/pricing.rs index 532dbc7252ea..e8cbc99b9d95 100644 --- a/bridges/snowbridge/primitives/core/src/pricing.rs +++ b/bridges/snowbridge/primitives/core/src/pricing.rs @@ -65,3 +65,15 @@ impl UD60x18 { self.0 } } + +#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, MaxEncodedLen, Default)] +pub struct BaseFeePerGas { + pub value: U256, + pub slot: u64, +} + +/// A trait for retrieving the base fee per gas. +pub trait GasPriceProvider { + fn update(value: U256, slot: u64); + fn get() -> BaseFeePerGas; +} diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 5ba0525d01f0..5d762d7ed9ab 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -255,6 +255,7 @@ runtime-benchmarks = [ "polkadot-runtime-common/runtime-benchmarks", "snowbridge-core/runtime-benchmarks", "snowbridge-pallet-ethereum-client/runtime-benchmarks", + "snowbridge-pallet-gas-price/runtime-benchmarks", "snowbridge-pallet-inbound-queue/runtime-benchmarks", "snowbridge-pallet-outbound-queue/runtime-benchmarks", "snowbridge-pallet-system/runtime-benchmarks",