@@ -17,11 +17,10 @@ use sp_api::impl_runtime_apis;
17
17
use sp_core:: { crypto:: KeyTypeId , OpaqueMetadata } ;
18
18
use sp_runtime:: {
19
19
create_runtime_str, generic, impl_opaque_keys,
20
- traits:: { AccountIdLookup , BlakeTwo256 , Block as BlockT } ,
20
+ traits:: { AccountIdLookup , BlakeTwo256 , Block as BlockT , Bounded } ,
21
21
transaction_validity:: { TransactionSource , TransactionValidity } ,
22
- ApplyExtrinsicResult ,
22
+ ApplyExtrinsicResult , FixedPointNumber , Perquintill ,
23
23
} ;
24
-
25
24
use sp_std:: prelude:: * ;
26
25
#[ cfg( feature = "std" ) ]
27
26
use sp_version:: NativeVersion ;
@@ -36,7 +35,7 @@ use frame_support::{
36
35
ConstBool , ConstU32 , ConstU64 , ConstU8 , EitherOfDiverse , Everything , TransformOrigin ,
37
36
} ,
38
37
weights:: {
39
- constants:: WEIGHT_REF_TIME_PER_SECOND , ConstantMultiplier , Weight , WeightToFeeCoefficient ,
38
+ constants:: WEIGHT_REF_TIME_PER_SECOND , Weight , WeightToFeeCoefficient ,
40
39
WeightToFeeCoefficients , WeightToFeePolynomial ,
41
40
} ,
42
41
PalletId ,
@@ -53,18 +52,21 @@ use sugondat_primitives::{AccountId, AuraId, Balance, BlockNumber, Nonce, Signat
53
52
pub use sp_runtime:: { MultiAddress , Perbill , Permill } ;
54
53
use xcm_config:: { RelayLocation , XcmOriginToTransactDispatchOrigin } ;
55
54
55
+ use pallet_transaction_payment:: { Multiplier , TargetedFeeAdjustment } ;
56
+
56
57
#[ cfg( any( feature = "std" , test) ) ]
57
58
pub use sp_runtime:: BuildStorage ;
58
59
59
60
// Polkadot imports
60
- use polkadot_runtime_common:: { BlockHashCount , SlowAdjustingFeeUpdate } ;
61
+ use polkadot_runtime_common:: BlockHashCount ;
61
62
62
63
use weights:: { BlockExecutionWeight , ExtrinsicBaseWeight , RocksDbWeight } ;
63
64
64
65
// XCM Imports
65
66
use xcm:: latest:: prelude:: BodyId ;
66
67
67
68
pub use pallet_sugondat_blobs;
69
+ pub use pallet_sugondat_length_fee_adjustment;
68
70
69
71
/// A hash of some data used by the chain.
70
72
pub type Hash = sp_core:: H256 ;
@@ -176,6 +178,8 @@ pub const DAYS: BlockNumber = HOURS * 24;
176
178
pub const UNIT : Balance = 1_000_000_000_000 ;
177
179
pub const MILLIUNIT : Balance = 1_000_000_000 ;
178
180
pub const MICROUNIT : Balance = 1_000_000 ;
181
+ pub const CENTS : Balance = UNIT / ( 30 * 100 ) ;
182
+ pub const MILLICENTS : Balance = CENTS / 1_000 ;
179
183
180
184
/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
181
185
pub const EXISTENTIAL_DEPOSIT : Balance = MILLIUNIT ;
@@ -194,6 +198,9 @@ const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
194
198
cumulus_primitives_core:: relay_chain:: MAX_POV_SIZE as u64 ,
195
199
) ;
196
200
201
+ // Maximum Length of the Block in bytes
202
+ pub const MAXIMUM_BLOCK_LENGTH : u32 = 5 * 1024 * 1024 ;
203
+
197
204
/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included
198
205
/// into the relay chain.
199
206
const UNINCLUDED_SEGMENT_CAPACITY : u32 = 1 ;
@@ -220,7 +227,7 @@ parameter_types! {
220
227
// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
221
228
// the lazy contract deletion.
222
229
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 ) ;
224
231
pub RuntimeBlockWeights : BlockWeights = BlockWeights :: builder( )
225
232
. base_block( BlockExecutionWeight :: get( ) )
226
233
. for_class( DispatchClass :: all( ) , |weights| {
@@ -331,13 +338,49 @@ impl pallet_balances::Config for Runtime {
331
338
parameter_types ! {
332
339
/// Relay Chain `TransactionByteFee` / 10
333
340
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( ) ;
334
361
}
335
362
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
+
336
379
impl pallet_transaction_payment:: Config for Runtime {
337
380
type RuntimeEvent = RuntimeEvent ;
338
381
type OnChargeTransaction = pallet_transaction_payment:: CurrencyAdapter < Balances , ( ) > ;
339
382
type WeightToFee = WeightToFee ;
340
- type LengthToFee = ConstantMultiplier < Balance , TransactionByteFee > ;
383
+ type LengthToFee = LengthFeeAdjustment ;
341
384
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate < Self > ;
342
385
type OperationalFeeMultiplier = ConstU8 < 5 > ;
343
386
}
@@ -518,6 +561,7 @@ construct_runtime!(
518
561
MessageQueue : pallet_message_queue = 33 ,
519
562
520
563
Blobs : pallet_sugondat_blobs = 40 ,
564
+ LengthFeeAdjustment : pallet_sugondat_length_fee_adjustment = 41 ,
521
565
}
522
566
) ;
523
567
0 commit comments