Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
96708232
Unverified
Commit
96708232
authored
1 year ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
add explicit generic names
parent
cc77b92d
No related branches found
No related tags found
1 merge request
!268
Fix #232
Pipeline
#37291
passed
1 year ago
Stage: labels
Stage: quality
Stage: build
Stage: tests
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
runtime/common/src/fees.rs
+66
-64
66 additions, 64 deletions
runtime/common/src/fees.rs
with
66 additions
and
64 deletions
runtime/common/src/fees.rs
+
66
−
64
View file @
96708232
...
...
@@ -41,23 +41,23 @@ use {
};
/// A structure to implement Length to Fee conversion.
/// - `
T
`: The balance type.
/// - `
U
`: The system configuration type, providing access to block weights.
/// - `
X
`: A type providing the target block fullness.
pub
struct
LengthToFeeImpl
<
T
,
U
,
X
>
(
sp_std
::
marker
::
PhantomData
<
T
>
,
sp_std
::
marker
::
PhantomData
<
U
>
,
sp_std
::
marker
::
PhantomData
<
X
>
,
/// - `
Balance
`: The balance type.
/// - `
Runtime
`: The system configuration type, providing access to block weights.
/// - `
Target
`: A type providing the target block fullness.
pub
struct
LengthToFeeImpl
<
Balance
,
Runtime
,
Target
>
(
sp_std
::
marker
::
PhantomData
<
Balance
>
,
sp_std
::
marker
::
PhantomData
<
Runtime
>
,
sp_std
::
marker
::
PhantomData
<
Target
>
,
);
/// Trait implementation for converting transaction length to fee.
impl
<
T
,
U
,
X
>
WeightToFee
for
LengthToFeeImpl
<
T
,
U
,
X
>
impl
<
Balance
,
Runtime
,
Target
>
WeightToFee
for
LengthToFeeImpl
<
Balance
,
Runtime
,
Target
>
where
T
:
BaseArithmetic
+
From
<
u32
>
+
Copy
+
Unsigned
,
U
:
frame_system
::
Config
+
pallet_transaction_payment
::
Config
,
X
:
Get
<
Perquintill
>
,
Balance
:
BaseArithmetic
+
From
<
u32
>
+
Copy
+
Unsigned
,
Runtime
:
frame_system
::
Config
+
pallet_transaction_payment
::
Config
,
Target
:
Get
<
Perquintill
>
,
{
type
Balance
=
T
;
type
Balance
=
Balance
;
/// Function to convert weight to fee when "constant-fees" feature is not enabled.
///
...
...
@@ -66,22 +66,22 @@ where
/// it returns a zero fee. Otherwise, it calculates the fee based on the length in bytes.
#[cfg(not(feature
=
"constant-fees"
))]
fn
weight_to_fee
(
length_in_bytes
:
&
Weight
)
->
Self
::
Balance
{
let
weights
=
U
::
BlockWeights
::
get
();
let
fee_multiplier
=
pallet_transaction_payment
::
Pallet
::
<
U
>
::
next_fee_multiplier
();
let
weights
=
Runtime
::
BlockWeights
::
get
();
let
fee_multiplier
=
pallet_transaction_payment
::
Pallet
::
<
Runtime
>
::
next_fee_multiplier
();
let
normal_max_weight
=
weights
.get
(
DispatchClass
::
Normal
)
.max_total
.unwrap_or
(
weights
.max_block
);
let
current_block_weight
=
<
frame_system
::
Pallet
<
U
>>
::
block_weight
();
let
current_block_weight
=
<
frame_system
::
Pallet
<
Runtime
>>
::
block_weight
();
let
length
=
U
::
BlockLength
::
get
();
let
length
=
Runtime
::
BlockLength
::
get
();
let
normal_max_length
=
*
length
.max
.get
(
DispatchClass
::
Normal
)
as
u64
;
let
current_block_length
=
<
frame_system
::
Pallet
<
U
>>
::
all_extrinsics_len
()
as
u64
;
let
current_block_length
=
<
frame_system
::
Pallet
<
Runtime
>>
::
all_extrinsics_len
()
as
u64
;
if
current_block_weight
.get
(
DispatchClass
::
Normal
)
.all_lt
(
X
::
get
()
*
normal_max_weight
)
&&
current_block_length
<
(
X
::
get
()
*
normal_max_length
)
.all_lt
(
Target
::
get
()
*
normal_max_weight
)
&&
current_block_length
<
(
Target
::
get
()
*
normal_max_length
)
&&
fee_multiplier
.is_one
()
{
0u32
.into
()
...
...
@@ -100,26 +100,26 @@ where
}
/// A structure to implement Weight to Fee conversion.
/// - `
T
`: The balance type.
/// - `
U
`: The system configuration type, providing access to block weights.
/// - `
X
`: A type providing the target block fullness.
pub
struct
WeightToFeeImpl
<
T
,
U
,
X
>
(
sp_std
::
marker
::
PhantomData
<
T
>
,
sp_std
::
marker
::
PhantomData
<
U
>
,
sp_std
::
marker
::
PhantomData
<
X
>
,
/// - `
Balance
`: The balance type.
/// - `
Runtime
`: The system configuration type, providing access to block weights.
/// - `
Target
`: A type providing the target block fullness.
pub
struct
WeightToFeeImpl
<
Balance
,
Runtime
,
Target
>
(
sp_std
::
marker
::
PhantomData
<
Balance
>
,
sp_std
::
marker
::
PhantomData
<
Runtime
>
,
sp_std
::
marker
::
PhantomData
<
Target
>
,
);
/// Trait implementation for converting transaction weight to fee.
///
/// This implementation is only included when the "constant-fees" feature is not enabled.
#[cfg(not(feature
=
"constant-fees"
))]
impl
<
T
,
U
,
X
>
WeightToFeePolynomial
for
WeightToFeeImpl
<
T
,
U
,
X
>
impl
<
Balance
,
Runtime
,
Target
>
WeightToFeePolynomial
for
WeightToFeeImpl
<
Balance
,
Runtime
,
Target
>
where
T
:
BaseArithmetic
+
From
<
u64
>
+
Copy
+
Unsigned
+
From
<
u32
>
+
MultiplyRational
,
U
:
frame_system
::
Config
+
pallet_transaction_payment
::
Config
,
X
:
Get
<
Perquintill
>
,
Balance
:
BaseArithmetic
+
From
<
u64
>
+
Copy
+
Unsigned
+
From
<
u32
>
+
MultiplyRational
,
Runtime
:
frame_system
::
Config
+
pallet_transaction_payment
::
Config
,
Target
:
Get
<
Perquintill
>
,
{
type
Balance
=
T
;
type
Balance
=
Balance
;
/// Function to get the polynomial coefficients for weight to fee conversion.
///
...
...
@@ -127,22 +127,22 @@ where
/// If the current block weight and length are less than a fraction of the block max weight and length, and the fee multiplier is one,
/// it returns zero. Otherwise, it calculates the coefficients based on the extrinsic base weight mapped to 5 cents.
fn
polynomial
()
->
WeightToFeeCoefficients
<
Self
::
Balance
>
{
let
weights
=
U
::
BlockWeights
::
get
();
let
fee_multiplier
=
pallet_transaction_payment
::
Pallet
::
<
U
>
::
next_fee_multiplier
();
let
weights
=
Runtime
::
BlockWeights
::
get
();
let
fee_multiplier
=
pallet_transaction_payment
::
Pallet
::
<
Runtime
>
::
next_fee_multiplier
();
let
normal_max_weight
=
weights
.get
(
DispatchClass
::
Normal
)
.max_total
.unwrap_or
(
weights
.max_block
);
let
current_block_weight
=
<
frame_system
::
Pallet
<
U
>>
::
block_weight
();
let
current_block_weight
=
<
frame_system
::
Pallet
<
Runtime
>>
::
block_weight
();
let
length
=
U
::
BlockLength
::
get
();
let
length
=
Runtime
::
BlockLength
::
get
();
let
normal_max_length
=
*
length
.max
.get
(
DispatchClass
::
Normal
)
as
u64
;
let
current_block_length
=
<
frame_system
::
Pallet
<
U
>>
::
all_extrinsics_len
()
as
u64
;
let
current_block_length
=
<
frame_system
::
Pallet
<
Runtime
>>
::
all_extrinsics_len
()
as
u64
;
if
current_block_weight
.get
(
DispatchClass
::
Normal
)
.all_lt
(
X
::
get
()
*
normal_max_weight
)
&&
current_block_length
<
(
X
::
get
()
*
normal_max_length
)
.all_lt
(
Target
::
get
()
*
normal_max_weight
)
&&
current_block_length
<
(
Target
::
get
()
*
normal_max_length
)
&&
fee_multiplier
.is_one
()
{
smallvec!
[
WeightToFeeCoefficient
{
...
...
@@ -169,11 +169,11 @@ where
///
/// This implementation is only included when the "constant-fees" feature is enabled.
#[cfg(feature
=
"constant-fees"
)]
impl
<
T
,
U
,
X
>
WeightToFee
for
WeightToFeeImpl
<
T
,
U
,
X
>
impl
<
Balance
,
Runtime
,
Target
>
WeightToFee
for
WeightToFeeImpl
<
Balance
,
Runtime
,
Target
>
where
T
:
BaseArithmetic
+
From
<
u32
>
+
Copy
+
Unsigned
,
Balance
:
BaseArithmetic
+
From
<
u32
>
+
Copy
+
Unsigned
,
{
type
Balance
=
T
;
type
Balance
=
Balance
;
fn
weight_to_fee
(
_weight
:
&
Weight
)
->
Self
::
Balance
{
1u32
.into
()
...
...
@@ -182,32 +182,33 @@ where
/// A structure to implement fee multiplier adjustments.
///
/// - `
T
`: The system configuration type.
/// - `
S
`: A type providing the target block fullness.
/// - `
X
`: A type providing the maximum multiplier value.
pub
struct
FeeMultiplier
<
T
,
S
,
X
>
(
sp_std
::
marker
::
PhantomData
<
T
>
,
sp_std
::
marker
::
PhantomData
<
S
>
,
sp_std
::
marker
::
PhantomData
<
X
>
,
/// - `
Runtime
`: The system configuration type.
/// - `
Target
`: A type providing the target block fullness.
/// - `
MaxMultiplier
`: A type providing the maximum multiplier value.
pub
struct
FeeMultiplier
<
Runtime
,
Target
,
MaxMultiplier
>
(
sp_std
::
marker
::
PhantomData
<
Runtime
>
,
sp_std
::
marker
::
PhantomData
<
Target
>
,
sp_std
::
marker
::
PhantomData
<
MaxMultiplier
>
,
);
/// Trait implementation for updating the fee multiplier.
impl
<
T
,
S
,
X
>
MultiplierUpdate
for
FeeMultiplier
<
T
,
S
,
X
>
impl
<
Runtime
,
Target
,
MaxMultiplier
>
MultiplierUpdate
for
FeeMultiplier
<
Runtime
,
Target
,
MaxMultiplier
>
where
T
:
frame_system
::
Config
,
S
:
Get
<
Perquintill
>
,
X
:
Get
<
Multiplier
>
,
Runtime
:
frame_system
::
Config
,
Target
:
Get
<
Perquintill
>
,
MaxMultiplier
:
Get
<
Multiplier
>
,
{
fn
min
()
->
Multiplier
{
0
.into
()
}
fn
max
()
->
Multiplier
{
X
::
get
()
MaxMultiplier
::
get
()
}
fn
target
()
->
Perquintill
{
S
::
get
()
Target
::
get
()
}
fn
variability
()
->
Multiplier
{
...
...
@@ -216,11 +217,12 @@ where
}
/// Trait implementation for converting previous `Multiplier` to another for fee adjustment.
impl
<
T
,
S
,
X
>
Convert
<
Multiplier
,
Multiplier
>
for
FeeMultiplier
<
T
,
S
,
X
>
impl
<
Runtime
,
Target
,
MaxMultiplier
>
Convert
<
Multiplier
,
Multiplier
>
for
FeeMultiplier
<
Runtime
,
Target
,
MaxMultiplier
>
where
T
:
frame_system
::
Config
,
S
:
Get
<
Perquintill
>
,
X
:
Get
<
Multiplier
>
,
Runtime
:
frame_system
::
Config
,
Target
:
Get
<
Perquintill
>
,
MaxMultiplier
:
Get
<
Multiplier
>
,
{
/// Function to convert the previous fee multiplier to a new fee multiplier.
///
...
...
@@ -229,20 +231,20 @@ where
/// - If the current block weight or length is more than the target, it increases the multiplier by one, up to the maximum multiplier.
#[cfg(not(feature
=
"constant-fees"
))]
fn
convert
(
previous
:
Multiplier
)
->
Multiplier
{
let
max_multiplier
=
X
::
get
();
let
target_block_fullness
=
S
::
get
();
let
max_multiplier
=
MaxMultiplier
::
get
();
let
target_block_fullness
=
Target
::
get
();
let
weights
=
T
::
BlockWeights
::
get
();
let
weights
=
Runtime
::
BlockWeights
::
get
();
let
normal_max_weight
=
weights
.get
(
DispatchClass
::
Normal
)
.max_total
.unwrap_or
(
weights
.max_block
);
let
length
=
T
::
BlockLength
::
get
();
let
length
=
Runtime
::
BlockLength
::
get
();
let
normal_max_length
=
*
length
.max
.get
(
DispatchClass
::
Normal
)
as
u64
;
let
current_block_length
=
<
frame_system
::
Pallet
<
T
>>
::
all_extrinsics_len
()
as
u64
;
let
current_block_length
=
<
frame_system
::
Pallet
<
Runtime
>>
::
all_extrinsics_len
()
as
u64
;
if
<
frame_system
::
Pallet
<
T
>>
::
block_weight
()
if
<
frame_system
::
Pallet
<
Runtime
>>
::
block_weight
()
.get
(
DispatchClass
::
Normal
)
.all_lt
(
target_block_fullness
*
normal_max_weight
)
&&
current_block_length
<
(
target_block_fullness
*
normal_max_length
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment