Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Fix compile & more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Jun 11, 2024
1 parent ab62865 commit 649263a
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 45 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bridges/snowbridge/pallets/ethereum-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
5 changes: 2 additions & 3 deletions bridges/snowbridge/pallets/ethereum-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
);
Expand Down
8 changes: 3 additions & 5 deletions bridges/snowbridge/pallets/gas-price/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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",
Expand All @@ -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",
]
10 changes: 0 additions & 10 deletions bridges/snowbridge/pallets/gas-price/src/impls.rs

This file was deleted.

6 changes: 2 additions & 4 deletions bridges/snowbridge/pallets/gas-price/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
#![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";

Expand Down Expand Up @@ -44,7 +42,7 @@ pub mod pallet {
}

impl<T: Config> GasPriceProvider for Pallet<T> {
fn store(value: U256, slot: u64) {
fn update(value: U256, slot: u64) {
<GasPrice<T>>::set(BaseFeePerGas { value, slot });

Self::deposit_event(Event::GasPriceUpdate { value, slot });
Expand Down
10 changes: 0 additions & 10 deletions bridges/snowbridge/pallets/gas-price/src/types.rs

This file was deleted.

4 changes: 4 additions & 0 deletions bridges/snowbridge/pallets/inbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ 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" }
sp-keyring = { path = "../../../../substrate/primitives/keyring" }
snowbridge-pallet-ethereum-client = { path = "../ethereum-client" }
hex-literal = { version = "0.4.1" }


[features]
default = ["std"]
std = [
Expand All @@ -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",
Expand All @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions bridges/snowbridge/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -37,6 +36,7 @@ frame_support::construct_runtime!(
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
EthereumBeaconClient: snowbridge_pallet_ethereum_client::{Pallet, Call, Storage, Event<T>},
InboundQueue: inbound_queue::{Pallet, Call, Storage, Event<T>},
GasPrice: snowbridge_pallet_gas_price::{Pallet, Call, Storage, Event<T>},
}
);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -171,7 +177,6 @@ parameter_types! {
pub const OwnParaId: ParaId = ParaId::new(1013);
pub Parameters: PricingParameters<u128> = 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),
};
Expand Down
3 changes: 2 additions & 1 deletion bridges/snowbridge/pallets/outbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 = [
Expand Down
8 changes: 2 additions & 6 deletions bridges/snowbridge/pallets/outbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
};
Expand Down
6 changes: 3 additions & 3 deletions bridges/snowbridge/pallets/outbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn encode_digest_item() {
#[test]
fn test_calculate_fees_with_unit_multiplier() {
new_tester().execute_with(|| {
<Test as Config>::GasPrice::store(10000_u32.into(), 400);
<Test as Config>::GasPrice::update(10000_u32.into(), 400);
let gas_used: u64 = 250000;
let price_params: PricingParameters<<Test as Config>::Balance> = PricingParameters {
exchange_rate: FixedU128::from_rational(1, 400),
Expand All @@ -286,7 +286,7 @@ fn test_calculate_fees_with_unit_multiplier() {
#[test]
fn test_calculate_fees_with_multiplier() {
new_tester().execute_with(|| {
<Test as Config>::GasPrice::store(10000_u32.into(), 400);
<Test as Config>::GasPrice::update(10000_u32.into(), 400);
let gas_used: u64 = 250000;
let price_params: PricingParameters<<Test as Config>::Balance> = PricingParameters {
exchange_rate: FixedU128::from_rational(1, 400),
Expand All @@ -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(|| {
<Test as Config>::GasPrice::store(1_u32.into(), 400);
<Test as Config>::GasPrice::update(1_u32.into(), 400);
let gas_used: u64 = 250000;
let price_params: PricingParameters<<Test as Config>::Balance> = PricingParameters {
exchange_rate: FixedU128::from_rational(1, 1),
Expand Down
2 changes: 1 addition & 1 deletion bridges/snowbridge/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(para_id: ParaId) -> T::AccountId
where
Expand Down
12 changes: 12 additions & 0 deletions bridges/snowbridge/primitives/core/src/pricing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 649263a

Please sign in to comment.