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
Merge requests
!190
Quota pallet benchmark
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Quota pallet benchmark
bgallois/duniter-v2s:pallet-quotas-benchmarks
into
master
Overview
4
Commits
4
Pipelines
42
Changes
5
All threads resolved!
Hide all comments
Merged
Benjamin Gallois
requested to merge
bgallois/duniter-v2s:pallet-quotas-benchmarks
into
master
1 year ago
Overview
4
Commits
4
Pipelines
42
Changes
5
All threads resolved!
Hide all comments
Expand
0
0
Merge request reports
Compare
master
version 20
81e24c6d
1 year ago
version 19
ce9c33a4
1 year ago
version 18
5bdc542e
1 year ago
version 17
cc2ac004
1 year ago
version 16
58ac953c
1 year ago
version 15
eb86c04c
1 year ago
version 14
a0b2e57e
1 year ago
version 13
db70c617
1 year ago
version 12
f8e496f6
1 year ago
version 11
0cfd0056
1 year ago
version 10
5042d06b
1 year ago
version 9
da8e289c
1 year ago
version 8
8857e186
1 year ago
version 7
c2dd6399
1 year ago
version 6
4b5ca95a
1 year ago
version 5
869af9bd
1 year ago
version 4
06bbe913
1 year ago
version 3
1e1d9cd1
1 year ago
version 2
0fe84712
1 year ago
version 1
d0397e91
1 year ago
master (base)
and
version 20
latest version
c24ee2e2
4 commits,
1 year ago
version 20
81e24c6d
4 commits,
1 year ago
version 19
ce9c33a4
4 commits,
1 year ago
version 18
5bdc542e
4 commits,
1 year ago
version 17
cc2ac004
4 commits,
1 year ago
version 16
58ac953c
4 commits,
1 year ago
version 15
eb86c04c
4 commits,
1 year ago
version 14
a0b2e57e
4 commits,
1 year ago
version 13
db70c617
3 commits,
1 year ago
version 12
f8e496f6
3 commits,
1 year ago
version 11
0cfd0056
3 commits,
1 year ago
version 10
5042d06b
2 commits,
1 year ago
version 9
da8e289c
2 commits,
1 year ago
version 8
8857e186
3 commits,
1 year ago
version 7
c2dd6399
2 commits,
1 year ago
version 6
4b5ca95a
1 commit,
1 year ago
version 5
869af9bd
10 commits,
1 year ago
version 4
06bbe913
10 commits,
1 year ago
version 3
1e1d9cd1
10 commits,
1 year ago
version 2
0fe84712
10 commits,
1 year ago
version 1
d0397e91
10 commits,
1 year ago
5 files
+
337
−
72
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
pallets/quota/src/benchmarking.rs
+
104
−
13
Options
@@ -18,47 +18,138 @@
use
super
::
*
;
use
frame_benchmarking
::{
account
,
benchmarks
};
use
sp_runtime
::
traits
::
One
;
// FIXME this is a naïve implementation of benchmarks:
// - without properly prepare data
// - without "verify" blocks
// - without thinking about worst case scenario
// - without writing complexity in the term of refund queue length
// It's there as a seed for benchmark implementation and to use WeightInfo where needed.
fn
assert_has_event
<
T
:
Config
>
(
generic_event
:
<
T
as
Config
>
::
RuntimeEvent
)
{
frame_system
::
Pallet
::
<
T
>
::
assert_has_event
(
generic_event
.into
());
}
benchmarks!
{
where_clause
{
where
IdtyId
<
T
>
:
From
<
u32
>
,
BalanceOf
<
T
>
:
From
<
u64
>
,
T
::
AccountId
:
From
<
[
u8
;
32
]
>
,
}
queue_refund
{
let
account
:
T
::
AccountId
=
account
(
"Alice"
,
1
,
1
);
let
dummy_refund
=
Refund
{
account
:
account
.clone
(),
identity
:
0u32
.into
(),
amount
:
20u64
.into
(),
};
let
refund
=
Refund
{
account
,
identity
:
1u32
.into
(),
amount
:
10u64
.into
(),
};
}:
{
Pallet
::
<
T
>
::
queue_refund
(
refund
)
}
// Complexity is bound to MAX_QUEUD_REFUNDS where an insertion is O(n-1)
for
i
in
0
..
MAX_QUEUED_REFUNDS
-
1
{
Pallet
::
<
T
>
::
queue_refund
(
dummy_refund
.clone
())
}
}:
{
Pallet
::
<
T
>
::
queue_refund
(
refund
.clone
())
}
verify
{
assert_eq!
(
RefundQueue
::
<
T
>
::
get
()
.last
(),
Some
(
refund
)
.as_ref
());
assert_eq!
(
RefundQueue
::
<
T
>
::
get
()
.len
()
as
u32
,
MAX_QUEUED_REFUNDS
);
}
spend_quota
{
let
idty_id
=
1u32
;
let
amount
=
1u64
;
let
idty_id
:
IdtyId
<
T
>
=
1u32
.into
();
let
amount
=
2u64
;
let
quota_amount
=
10u64
;
IdtyQuota
::
<
T
>
::
insert
(
idty_id
,
Quota
{
last_use
:
T
::
BlockNumber
::
zero
(),
amount
:
quota_amount
.into
(),
},
);
}:
{
Pallet
::
<
T
>
::
spend_quota
(
idty_id
.into
(),
amount
.into
())
}
verify
{
let
quota_growth
=
sp_runtime
::
Perbill
::
from_rational
(
T
::
BlockNumber
::
one
(),
T
::
ReloadRate
::
get
(),
)
.mul_floor
(
T
::
MaxQuota
::
get
());
assert_eq!
(
IdtyQuota
::
<
T
>
::
get
(
idty_id
)
.unwrap
()
.amount
,
quota_growth
+
quota_amount
.into
()
-
amount
.into
());
}
try_refund
{
let
account
:
T
::
AccountId
=
account
(
"Alice"
,
1
,
1
);
let
idty_id
:
IdtyId
<
T
>
=
1u32
.into
();
IdtyQuota
::
<
T
>
::
insert
(
idty_id
,
Quota
{
last_use
:
T
::
BlockNumber
::
zero
(),
amount
:
10u64
.into
(),
},
);
let
_
=
CurrencyOf
::
<
T
>
::
make_free_balance_be
(
&
T
::
RefundAccount
::
get
(),
u32
::
MAX
.into
(),
);
// The worst-case scenario is when the refund fails
// and can only be triggered if the account is dead,
// in this case by having no balance in the account.
let
refund
=
Refund
{
account
,
account
:
account
.clone
()
,
identity
:
1u32
.into
(),
amount
:
10u64
.into
(),
};
}:
{
Pallet
::
<
T
>
::
try_refund
(
refund
)
}
verify
{
assert_has_event
::
<
T
>
(
Event
::
<
T
>
::
RefundFailed
(
account
)
.into
());
}
do_refund
{
let
account
:
T
::
AccountId
=
account
(
"Alice"
,
1
,
1
);
let
_
=
CurrencyOf
::
<
T
>
::
make_free_balance_be
(
&
T
::
RefundAccount
::
get
(),
u32
::
MAX
.into
(),
);
// The worst-case scenario is when the refund fails
// and can only be triggered if the account is dead,
// in this case by having no balance in the account.
let
refund
=
Refund
{
account
,
account
:
account
.clone
()
,
identity
:
1u32
.into
(),
amount
:
10u64
.into
(),
};
let
amount
=
5u64
.into
();
}:
{
Pallet
::
<
T
>
::
do_refund
(
refund
,
amount
)
}
}:
{
Pallet
::
<
T
>
::
try_refund
(
refund
)
}
verify
{
assert_has_event
::
<
T
>
(
Event
::
<
T
>
::
RefundFailed
(
account
)
.into
());
}
// The base weight consumed on processing refund queue when empty.
on_process_refund_queue
{
assert_eq!
(
RefundQueue
::
<
T
>
::
get
()
.len
()
as
u32
,
0
);
}:
{
Pallet
::
<
T
>
::
process_refund_queue
(
Weight
::
MAX
)
}
// The weight consumed on processing refund queue with one element.
// Can deduce the process_refund_queue overhead by subtracting try_refund weight.
#[pov_mode
=
Measured]
on_process_refund_queue_elements
{
let
i
in
1
..
MAX_QUEUED_REFUNDS
;
let
account
:
T
::
AccountId
=
account
(
"Alice"
,
1
,
1
);
let
idty_id
:
IdtyId
<
T
>
=
1u32
.into
();
IdtyQuota
::
<
T
>
::
insert
(
idty_id
,
Quota
{
last_use
:
T
::
BlockNumber
::
zero
(),
amount
:
10u64
.into
(),
},
);
let
_
=
CurrencyOf
::
<
T
>
::
make_free_balance_be
(
&
T
::
RefundAccount
::
get
(),
u32
::
MAX
.into
(),
);
// The worst-case scenario is when the refund fails
// and can only be triggered if the account is dead,
// in this case by having no balance in the account.
let
refund
=
Refund
{
account
:
account
.clone
(),
identity
:
1u32
.into
(),
amount
:
10u64
.into
(),
};
for
_
in
0
..
i
{
Pallet
::
<
T
>
::
queue_refund
(
refund
.clone
());
}
assert_eq!
(
RefundQueue
::
<
T
>
::
get
()
.len
()
as
u32
,
i
);
}:
{
Pallet
::
<
T
>
::
process_refund_queue
(
Weight
::
MAX
)
}
verify
{
assert_eq!
(
RefundQueue
::
<
T
>
::
get
()
.len
()
as
u32
,
0
);
assert_has_event
::
<
T
>
(
Event
::
<
T
>
::
RefundFailed
(
account
)
.into
());
}
impl_benchmark_test_suite!
(
Pallet
,
crate
::
mock
::
new_test_ext
(
crate
::
mock
::
QuotaConfig
{
identities
:
vec!
[
1
,
2
]}),
crate
::
mock
::
Test
);
}
Loading