@@ -275,8 +275,10 @@ parameter_types! {
275
275
/// Relay Chain `TransactionByteFee` / 10
276
276
pub const TransactionByteFee : Balance = MILLICENTS ;
277
277
278
+ // parameters used by BlobsFeeAdjustment
279
+ // to update NextFeeMultiplier and NextLengthMultiplier
280
+ //
278
281
// Common constants used in all runtimes for SlowAdjustingFeeUpdate
279
-
280
282
/// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less
281
283
/// than this will decrease the weight and more will increase.
282
284
pub storage TargetBlockFullness : Perquintill = Perquintill :: from_percent( 25 ) ;
@@ -291,44 +293,17 @@ parameter_types! {
291
293
pub MaximumMultiplierBlockFullness : Multiplier = Bounded :: max_value( ) ;
292
294
293
295
294
- // parameters used by BlobsFeeAdjustment
295
-
296
296
pub storage NextLengthMultiplier : Multiplier = Multiplier :: saturating_from_integer( 1 ) ;
297
-
298
- pub storage TargetBlockSize : u32 = 820 * 1024 ; // 0.8MiB
297
+ pub storage TargetBlockSize : Perquintill = Perquintill :: from_percent( 16 ) ; // 0.8MiB
299
298
// TODO: update those value accordingly with https://github.com/thrumdev/blobs/issues/16
300
299
pub AdjustmentVariableBlockSize : Multiplier = Multiplier :: saturating_from_rational( 75 , 1000_000 ) ;
301
300
pub MinimumMultiplierBlockSize : Multiplier = Multiplier :: saturating_from_rational( 1 , 10u128 ) ;
302
301
pub MaximumMultiplierBlockSize : Multiplier = Bounded :: max_value( ) ;
303
-
304
- // A positive number represents the count of consecutive blocks that exceeded
305
- // the TargetBlockSize, while a negative number represents the count of
306
- // consecutive blocks that were below the TargetBlockSize - NegativeDeltaTargetBlockFullness.
307
- pub storage BlockSizeTracker : u32 = 0 ; // 0.8MiB
308
-
309
- // The number of consecutive blocks after which the TargetBlockSize will increase
310
- pub storage IncreaseDeltaBlocks : u32 = 10 * DAYS ;
311
-
312
- // The number of bytes that will be added to TargetBlockSize each update
313
- pub storage DeltaTargetBlockSize : u32 = 205 * 1024 ; // 0.2MiB
314
-
315
- //pub storage DecreaseDeltaBlocks: u32 = 10 * DAYS;,
316
- //pub storage LowerBoundTargetBlockSize
317
302
}
318
303
319
- /// Parameterized slow adjusting fee updated based on
320
- /// <https://research.web3.foundation/Polkadot/overview/token-economics#2-slow-adjusting-mechanism>
321
- //pub type SlowAdjustingFeeUpdate<R> = TargetedFeeAdjustment<
322
- // R,
323
- // TargetBlockFullness,
324
- // AdjustmentVariable,
325
- // MinimumMultiplier,
326
- // MaximumMultiplier,
327
- //>;
328
-
329
304
/// Currently pallet_transaction_payment use the following formula:
330
305
///
331
- /// ```
306
+ /// ```ignore
332
307
/// inclusion_fee = base_fee + length_fee + [targeted_fee_adjustment * weight_fee];
333
308
/// ```
334
309
///
@@ -340,66 +315,41 @@ parameter_types! {
340
315
/// What this struct does is this PLUS a side effect, the goal is to reach a different formula to
341
316
/// calculate fees:
342
317
///
343
- /// ```
318
+ /// ```ignore
344
319
/// inclusion_fee = base_fee + [targeted_length_fee_adjustment * length_fee] + [targeted_weight_fee_adjustment * weight_fee];
345
320
/// ```
346
321
///
347
322
/// As you can see `targeted_fee_adjustment` becomes `targeted_weight_fee_adjustment` but the behavior
348
323
/// remains the same, the side effect is the changing to the value `targeted_length_fee_adjustment`,
349
324
/// this formula is achievable because inside pallet_transaction_payment the function `compute_fee_raw`
350
- /// that just computes the final fee associated with an extrinsic uses the associated type `LenghtToFee `
325
+ /// that just computes the final fee associated with an extrinsic uses the associated type `LengthToFee `
351
326
/// that converts the length of an extrinsic to a fee.
352
327
///
353
328
/// By default the implementation is a constant multiplication but we want to achieve a dynamic formula
354
329
/// that can adapt based on the usage of the network, this can't solely be done by this struct but needs
355
- /// to be bundled with a custom implementation of `LenghtToFee `.
330
+ /// to be bundled with a custom implementation of `LengthToFee `.
356
331
///
357
332
/// This struct ONLY provide a dynamic update of `targeted_length_fee_adjustment` and `targeted_weight_fee_adjustment`
358
333
/// based on the congestion and usage of the blocks, while the formula si effectively implemented like
359
- /// explained above only thanks to `LenghtToFee `
334
+ /// explained above only thanks to `LengthToFee `
360
335
pub struct BlobsFeeAdjustment < T : frame_system:: Config > ( core:: marker:: PhantomData < T > ) ;
361
336
362
337
impl < T : frame_system:: Config > Convert < Multiplier , Multiplier > for BlobsFeeAdjustment < T >
363
338
where
364
339
T : frame_system:: Config ,
365
340
{
366
341
/// This function should be a pure function used to update NextFeeMultiplier
367
- /// but will also has the side effect of update NextLenghtMultiplier
342
+ /// but will also has the side effect of update NextLengthMultiplier
368
343
fn convert ( previous_fee_multiplier : Multiplier ) -> Multiplier {
369
- // Update TargetBlockSize if needed
370
- let all_extrinsic_len = <frame_system:: Pallet < T > >:: all_extrinsics_len ( ) ;
371
-
372
- if all_extrinsic_len > TargetBlockSize :: get ( ) {
373
- // Increase the tracker if needed
374
- let tracker = BlockSizeTracker :: get ( ) ;
375
-
376
- // If the used_block_size is larger than the TargetBlockSize
377
- // for more than IncreaseDeltaBlocks consecutive, then the TargetBlockSize
378
- // will be increased by DeltaTargetBlockSize.
379
- if tracker + 1 >= IncreaseDeltaBlocks :: get ( ) {
380
- let current_target_block_size = TargetBlockSize :: get ( ) ;
381
- TargetBlockSize :: set ( & ( current_target_block_size + DeltaTargetBlockSize :: get ( ) ) ) ;
382
- BlockSizeTracker :: set ( & 0 ) ;
383
- }
384
-
385
- BlockSizeTracker :: set ( & ( tracker + 1 ) ) ;
386
- } else {
387
- // The logic for updating to a new TargetBlockSize currently requires IncreaseDeltaBlocks
388
- // to be constantly larger than TargetBlockSize. However, it might be possible
389
- // to implement a window where we reset the tracker only if the
390
- // block size remains below the TargetBlockSize for a certain number of blocks
391
- BlockSizeTracker :: set ( & 0 ) ;
392
- }
393
-
394
344
// Update NextLengthMultiplier
395
345
396
346
// To update the value will be used the same formula as TargetedFeeAdjustment,
397
347
// described here: https://research.web3.foundation/Polkadot/overview/token-economics#2-slow-adjusting-mechanism
398
348
//
399
349
// so this is mainly a copy paste of that function because it works on normalized mesurments,
400
- // so if it is ref_time, proof_size or lenght of the extrinsic the mutliplier will be evaluated properly.
350
+ // so if it is ref_time, proof_size or length of the extrinsic the mutliplier will be evaluated properly.
401
351
// The main problem is that TargetedFeeAdjustment::convert uses directly a call to the storage to extract
402
- // the weight of the current block so there is no way to pass the lenght as input argument,
352
+ // the weight of the current block so there is no way to pass the length as input argument,
403
353
// here I will copy paste all the needed part to update properly NextLengthMultiplier
404
354
405
355
// Defensive only. The multiplier in storage should always be at most positive. Nonetheless
@@ -409,14 +359,15 @@ where
409
359
let previous_len_multiplier = NextLengthMultiplier :: get ( ) ;
410
360
let min_multiplier = MinimumMultiplierBlockSize :: get ( ) ;
411
361
let max_multiplier = MaximumMultiplierBlockSize :: get ( ) ;
412
- // TODO: why?
413
362
let previous_len_multiplier = previous_len_multiplier. max ( min_multiplier) ;
414
363
415
364
// Pick the limiting dimension. (from TargetedFeeAdjustment::convert)
416
365
//
417
366
// In this case it is the length of all extrinsic, always
418
- let ( normal_limiting_dimension, max_limiting_dimension) =
419
- ( all_extrinsic_len, MAXIMUM_BLOCK_LENGTH ) ;
367
+ let ( normal_limiting_dimension, max_limiting_dimension) = (
368
+ <frame_system:: Pallet < T > >:: all_extrinsics_len ( ) ,
369
+ MAXIMUM_BLOCK_LENGTH as u64 ,
370
+ ) ;
420
371
421
372
let target_block_size = TargetBlockSize :: get ( ) ;
422
373
let adjustment_variable = AdjustmentVariableBlockSize :: get ( ) ;
@@ -462,7 +413,7 @@ where
462
413
//
463
414
// Here is the tricky part, this method return the new value associated with
464
415
// NextFeeMultiplier (in the old fashion) because weight dynamic adjustment is battle tested
465
- // while previously have updated the `NextLengthMultiplier` used in `LenghtToWeight `
416
+ // while previously have updated the `NextLengthMultiplier` used in `LengthToWeight `
466
417
TargetedFeeAdjustment :: <
467
418
T ,
468
419
TargetBlockFullness ,
@@ -508,9 +459,7 @@ impl pallet_transaction_payment::Config for Runtime {
508
459
type RuntimeEvent = RuntimeEvent ;
509
460
type OnChargeTransaction = pallet_transaction_payment:: CurrencyAdapter < Balances , ( ) > ;
510
461
type WeightToFee = WeightToFee ;
511
- //type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
512
462
type LengthToFee = BlobsLengthToFee < Self > ;
513
- //type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
514
463
type FeeMultiplierUpdate = BlobsFeeAdjustment < Self > ;
515
464
type OperationalFeeMultiplier = ConstU8 < 5 > ;
516
465
}
0 commit comments