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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
a010e531
Unverified
Commit
a010e531
authored
2 years ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
feat(pallet_provide_randomness): add weights info
parent
10dd4b86
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pallets/provide-randomness/src/lib.rs
+6
-2
6 additions, 2 deletions
pallets/provide-randomness/src/lib.rs
pallets/provide-randomness/src/weights.rs
+58
-0
58 additions, 0 deletions
pallets/provide-randomness/src/weights.rs
with
64 additions
and
2 deletions
pallets/provide-randomness/src/lib.rs
+
6
−
2
View file @
a010e531
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
mod
benchmarking
;
mod
benchmarking
;
mod
types
;
mod
types
;
pub
mod
weights
;
use
frame_support
::
pallet_prelude
::
Weight
;
use
frame_support
::
pallet_prelude
::
Weight
;
use
sp_core
::
H256
;
use
sp_core
::
H256
;
...
@@ -28,6 +29,7 @@ use sp_std::prelude::*;
...
@@ -28,6 +29,7 @@ use sp_std::prelude::*;
pub
use
pallet
::
*
;
pub
use
pallet
::
*
;
pub
use
types
::
*
;
pub
use
types
::
*
;
pub
use
weights
::
WeightInfo
;
pub
type
RequestId
=
u64
;
pub
type
RequestId
=
u64
;
...
@@ -88,6 +90,8 @@ pub mod pallet {
...
@@ -88,6 +90,8 @@ pub mod pallet {
type
RandomnessFromOneEpochAgo
:
Randomness
<
H256
,
Self
::
BlockNumber
>
;
type
RandomnessFromOneEpochAgo
:
Randomness
<
H256
,
Self
::
BlockNumber
>
;
/// The overarching event type.
/// The overarching event type.
type
RuntimeEvent
:
From
<
Event
>
+
IsType
<<
Self
as
frame_system
::
Config
>
::
RuntimeEvent
>
;
type
RuntimeEvent
:
From
<
Event
>
+
IsType
<<
Self
as
frame_system
::
Config
>
::
RuntimeEvent
>
;
/// Type representing the weight of this pallet
type
WeightInfo
:
WeightInfo
;
}
}
// STORAGE //
// STORAGE //
...
@@ -143,7 +147,7 @@ pub mod pallet {
...
@@ -143,7 +147,7 @@ pub mod pallet {
#[pallet::call]
#[pallet::call]
impl
<
T
:
Config
>
Pallet
<
T
>
{
impl
<
T
:
Config
>
Pallet
<
T
>
{
/// Request a randomness
/// Request a randomness
#[pallet::weight(
500_000_000
)]
#[pallet::weight(
T::WeightInfo::request()
)]
pub
fn
request
(
pub
fn
request
(
origin
:
OriginFor
<
T
>
,
origin
:
OriginFor
<
T
>
,
randomness_type
:
RandomnessType
,
randomness_type
:
RandomnessType
,
...
@@ -168,7 +172,7 @@ pub mod pallet {
...
@@ -168,7 +172,7 @@ pub mod pallet {
#[pallet::hooks]
#[pallet::hooks]
impl
<
T
:
Config
>
Hooks
<
BlockNumberFor
<
T
>>
for
Pallet
<
T
>
{
impl
<
T
:
Config
>
Hooks
<
BlockNumberFor
<
T
>>
for
Pallet
<
T
>
{
fn
on_initialize
(
_
:
T
::
BlockNumber
)
->
Weight
{
fn
on_initialize
(
_
:
T
::
BlockNumber
)
->
Weight
{
let
request_weight
=
Weight
::
from_ref_time
(
100_000
);
let
request_weight
=
T
::
Weight
Info
::
on_initialize
(
T
::
MaxRequests
::
get
()
);
let
mut
total_weight
=
Weight
::
zero
();
let
mut
total_weight
=
Weight
::
zero
();
...
...
This diff is collapsed.
Click to expand it.
pallets/provide-randomness/src/weights.rs
0 → 100644
+
58
−
0
View file @
a010e531
// Copyright 2021-2023 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![allow(clippy::unnecessary_cast)]
use
frame_support
::
weights
::{
constants
::
RocksDbWeight
,
Weight
};
/// Weight functions needed for pallet_universal_dividend.
pub
trait
WeightInfo
{
fn
on_initialize
(
i
:
u32
)
->
Weight
;
fn
request
()
->
Weight
;
}
// Insecure weights implementation, use it for tests only!
impl
WeightInfo
for
()
{
// Storage: ProvideRandomness CounterForRequestsIds (r:1 w:1)
// Storage: ProvideRandomness RequestIdProvider (r:1 w:1)
// Storage: ProvideRandomness RequestsIds (r:1 w:1)
// Storage: Babe EpochIndex (r:1 w:0)
// Storage: ProvideRandomness NexEpochHookIn (r:1 w:0)
// Storage: ProvideRandomness RequestsReadyAtEpoch (r:1 w:1)
fn
request
()
->
Weight
{
// Minimum execution time: 321_822 nanoseconds.
Weight
::
from_ref_time
(
338_919_000
as
u64
)
.saturating_add
(
RocksDbWeight
::
get
()
.reads
(
6
as
u64
))
.saturating_add
(
RocksDbWeight
::
get
()
.writes
(
4
as
u64
))
}
// Storage: ProvideRandomness RequestsReadyAtNextBlock (r:1 w:1)
// Storage: Babe AuthorVrfRandomness (r:1 w:0)
// Storage: ProvideRandomness RequestsIds (r:1 w:1)
// Storage: ProvideRandomness CounterForRequestsIds (r:1 w:1)
// Storage: Account PendingRandomIdAssignments (r:1 w:0)
// Storage: ProvideRandomness NexEpochHookIn (r:1 w:1)
/// The range of component `i` is `[1, 100]`.
fn
on_initialize
(
i
:
u32
)
->
Weight
{
// Minimum execution time: 175_645 nanoseconds.
Weight
::
from_ref_time
(
461_442_906
as
u64
)
// Standard Error: 1_523_561
.saturating_add
(
Weight
::
from_ref_time
(
43_315_015
as
u64
)
.saturating_mul
(
i
as
u64
))
.saturating_add
(
RocksDbWeight
::
get
()
.reads
(
4
as
u64
))
.saturating_add
(
RocksDbWeight
::
get
()
.reads
((
2
as
u64
)
.saturating_mul
(
i
as
u64
)))
.saturating_add
(
RocksDbWeight
::
get
()
.writes
(
3
as
u64
))
.saturating_add
(
RocksDbWeight
::
get
()
.writes
((
1
as
u64
)
.saturating_mul
(
i
as
u64
)))
}
}
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