@@ -17,11 +17,10 @@ use sp_api::impl_runtime_apis;
1717use sp_core:: { crypto:: KeyTypeId , OpaqueMetadata } ;
1818use 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-
2524use sp_std:: prelude:: * ;
2625#[ cfg( feature = "std" ) ]
2726use 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
5352pub use sp_runtime:: { MultiAddress , Perbill , Permill } ;
5453use xcm_config:: { RelayLocation , XcmOriginToTransactDispatchOrigin } ;
5554
55+ use pallet_transaction_payment:: { Multiplier , TargetedFeeAdjustment } ;
56+
5657#[ cfg( any( feature = "std" , test) ) ]
5758pub use sp_runtime:: BuildStorage ;
5859
5960// Polkadot imports
60- use polkadot_runtime_common:: { BlockHashCount , SlowAdjustingFeeUpdate } ;
61+ use polkadot_runtime_common:: BlockHashCount ;
6162
6263use weights:: { BlockExecutionWeight , ExtrinsicBaseWeight , RocksDbWeight } ;
6364
6465// XCM Imports
6566use xcm:: latest:: prelude:: BodyId ;
6667
6768pub use pallet_sugondat_blobs;
69+ pub use pallet_sugondat_length_fee_adjustment;
6870
6971/// A hash of some data used by the chain.
7072pub type Hash = sp_core:: H256 ;
@@ -176,6 +178,8 @@ pub const DAYS: BlockNumber = HOURS * 24;
176178pub const UNIT : Balance = 1_000_000_000_000 ;
177179pub const MILLIUNIT : Balance = 1_000_000_000 ;
178180pub 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.
181185pub 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.
199206const 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 {
331338parameter_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+
336379impl 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