Skip to content

Commit a573244

Browse files
committed
add length fee adjustments in test runtime
1 parent 6105a44 commit a573244

File tree

5 files changed

+823
-7
lines changed

5 files changed

+823
-7
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sugondat/chain/runtimes/test/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ smallvec = "1.10.0"
2323

2424
# Local
2525
pallet-sugondat-blobs = { path = "../../pallets/blobs", default-features = false }
26+
pallet-sugondat-length-fee-adjustment = { path = "../../pallets/length-fee-adjustment", default-features = false }
2627
sugondat-primitives = { path = "../../primitives", default-features = false }
2728

2829
# Substrate
@@ -76,6 +77,9 @@ pallet-collator-selection = { git = "https://github.com/paritytech/polkadot-sdk.
7677
parachain-info = { package = "staging-parachain-info", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
7778
parachains-common = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.4.0", default-features = false }
7879

80+
[dev-dependencies]
81+
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.4.0"}
82+
7983
[features]
8084
default = [ "std" ]
8185
std = [
@@ -101,6 +105,7 @@ std = [
101105
"pallet-collator-selection/std",
102106
"pallet-message-queue/std",
103107
"pallet-sugondat-blobs/std",
108+
"pallet-sugondat-length-fee-adjustment/std",
104109
"pallet-session/std",
105110
"pallet-sudo/std",
106111
"pallet-timestamp/std",

sugondat/chain/runtimes/test/src/lib.rs

+51-7
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ use sp_api::impl_runtime_apis;
1717
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
1818
use sp_runtime::{
1919
create_runtime_str, generic, impl_opaque_keys,
20-
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
20+
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Bounded},
2121
transaction_validity::{TransactionSource, TransactionValidity},
22-
ApplyExtrinsicResult,
22+
ApplyExtrinsicResult, FixedPointNumber, Perquintill,
2323
};
24-
2524
use sp_std::prelude::*;
2625
#[cfg(feature = "std")]
2726
use sp_version::NativeVersion;
@@ -36,7 +35,7 @@ use frame_support::{
3635
ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, TransformOrigin,
3736
},
3837
weights::{
39-
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
38+
constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightToFeeCoefficient,
4039
WeightToFeeCoefficients, WeightToFeePolynomial,
4140
},
4241
PalletId,
@@ -53,18 +52,21 @@ use sugondat_primitives::{AccountId, AuraId, Balance, BlockNumber, Nonce, Signat
5352
pub use sp_runtime::{MultiAddress, Perbill, Permill};
5453
use xcm_config::{RelayLocation, XcmOriginToTransactDispatchOrigin};
5554

55+
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
56+
5657
#[cfg(any(feature = "std", test))]
5758
pub use sp_runtime::BuildStorage;
5859

5960
// Polkadot imports
60-
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
61+
use polkadot_runtime_common::BlockHashCount;
6162

6263
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
6364

6465
// XCM Imports
6566
use xcm::latest::prelude::BodyId;
6667

6768
pub use pallet_sugondat_blobs;
69+
pub use pallet_sugondat_length_fee_adjustment;
6870

6971
/// A hash of some data used by the chain.
7072
pub type Hash = sp_core::H256;
@@ -176,6 +178,8 @@ pub const DAYS: BlockNumber = HOURS * 24;
176178
pub const UNIT: Balance = 1_000_000_000_000;
177179
pub const MILLIUNIT: Balance = 1_000_000_000;
178180
pub const MICROUNIT: Balance = 1_000_000;
181+
pub const CENTS: Balance = UNIT / (30 * 100);
182+
pub const MILLICENTS: Balance = CENTS / 1_000;
179183

180184
/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
181185
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
@@ -194,6 +198,9 @@ const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
194198
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
195199
);
196200

201+
// Maximum Length of the Block in bytes
202+
pub const MAXIMUM_BLOCK_LENGTH: u32 = 5 * 1024 * 1024;
203+
197204
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
198205
/// into the relay chain.
199206
const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1;
@@ -220,7 +227,7 @@ parameter_types! {
220227
// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
221228
// the lazy contract deletion.
222229
pub RuntimeBlockLength: BlockLength =
223-
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
230+
BlockLength::max_with_normal_ratio(MAXIMUM_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO);
224231
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
225232
.base_block(BlockExecutionWeight::get())
226233
.for_class(DispatchClass::all(), |weights| {
@@ -331,13 +338,49 @@ impl pallet_balances::Config for Runtime {
331338
parameter_types! {
332339
/// Relay Chain `TransactionByteFee` / 10
333340
pub const TransactionByteFee: Balance = 10 * MICROUNIT;
341+
342+
/// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less
343+
/// than this will decrease the weight and more will increase.
344+
pub TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
345+
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
346+
/// change the fees more rapidly.
347+
pub AdjustmentVariableBlockFullness: Multiplier = Multiplier::saturating_from_rational(75, 1_000_000);
348+
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
349+
/// See `multiplier_can_grow_from_zero`.
350+
pub MinimumMultiplierBlockFullness: Multiplier = Multiplier::saturating_from_rational(1, 10u128);
351+
/// The maximum amount of the multiplier.
352+
pub MaximumMultiplierBlockFullness: Multiplier = Bounded::max_value();
353+
354+
pub MaximumBlockLength: u32 = MAXIMUM_BLOCK_LENGTH;
355+
// v = p / k * (1 - s*) = 0.3 / (300 * (1 - 0.16))
356+
// at most 30% (=p) fees variation in one hour, 300 blocks (=k)
357+
pub AdjustmentVariableBlockSize: Multiplier = Multiplier::saturating_from_rational(1, 840);
358+
// TODO: decide the value of MinimumMultiplierBlockSize, https://github.com/thrumdev/blobs/issues/154
359+
pub MinimumMultiplierBlockSize: Multiplier = Multiplier::saturating_from_rational(1, 1000u128);
360+
pub MaximumMultiplierBlockSize: Multiplier = Bounded::max_value();
334361
}
335362

363+
impl pallet_sugondat_length_fee_adjustment::Config for Runtime {
364+
type MaximumBlockLength = MaximumBlockLength;
365+
type TransactionByteFee = TransactionByteFee;
366+
type AdjustmentVariableBlockSize = AdjustmentVariableBlockSize;
367+
type MaximumMultiplierBlockSize = MaximumMultiplierBlockSize;
368+
type MinimumMultiplierBlockSize = MinimumMultiplierBlockSize;
369+
}
370+
371+
pub type SlowAdjustingFeeUpdate<R> = TargetedFeeAdjustment<
372+
R,
373+
TargetBlockFullness,
374+
AdjustmentVariableBlockFullness,
375+
MinimumMultiplierBlockFullness,
376+
MaximumMultiplierBlockFullness,
377+
>;
378+
336379
impl pallet_transaction_payment::Config for Runtime {
337380
type RuntimeEvent = RuntimeEvent;
338381
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
339382
type WeightToFee = WeightToFee;
340-
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
383+
type LengthToFee = LengthFeeAdjustment;
341384
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
342385
type OperationalFeeMultiplier = ConstU8<5>;
343386
}
@@ -518,6 +561,7 @@ construct_runtime!(
518561
MessageQueue: pallet_message_queue = 33,
519562

520563
Blobs: pallet_sugondat_blobs = 40,
564+
LengthFeeAdjustment: pallet_sugondat_length_fee_adjustment = 41,
521565
}
522566
);
523567

0 commit comments

Comments
 (0)