forked from laminar-protocol/substrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial draft * Enlarge function drafted. * Thaw draft * Retract_bid draft * Final bits of draft impl. * Test mockup * Tests * Docs * Add benchmark scaffold * Integrate weights * All benchmarks done * Missing file * Remove stale comments * Fixes * Fixes * Allow for priority queuing. * Another test and a fix * Fixes * Fixes * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_gilt --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/gilt/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Grumble * Update frame/gilt/src/tests.rs Co-authored-by: Shawn Tabrizi <[email protected]> * Update frame/gilt/src/tests.rs Co-authored-by: Shawn Tabrizi <[email protected]> * Grumble * Update frame/gilt/src/tests.rs Co-authored-by: Shawn Tabrizi <[email protected]> * Update frame/gilt/src/lib.rs Co-authored-by: Shawn Tabrizi <[email protected]> * Update frame/gilt/src/lib.rs Co-authored-by: Shawn Tabrizi <[email protected]> * Fix unreserve ordering * Grumble * Fixes Co-authored-by: Parity Benchmarking Bot <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]>
- Loading branch information
1 parent
b95822e
commit 4cdc230
Showing
14 changed files
with
1,626 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[package] | ||
name = "pallet-gilt" | ||
version = "3.0.0" | ||
authors = ["Parity Technologies <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
homepage = "https://substrate.dev" | ||
repository = "https://github.com/paritytech/substrate/" | ||
description = "FRAME pallet for rewarding account freezing." | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
serde = { version = "1.0.101", optional = true } | ||
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } | ||
sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" } | ||
sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" } | ||
sp-arithmetic = { version = "3.0.0", default-features = false, path = "../../primitives/arithmetic" } | ||
frame-benchmarking = { version = "3.0.0", default-features = false, path = "../benchmarking", optional = true } | ||
frame-support = { version = "3.0.0", default-features = false, path = "../support" } | ||
frame-system = { version = "3.0.0", default-features = false, path = "../system" } | ||
|
||
[dev-dependencies] | ||
sp-io = { version = "3.0.0", path = "../../primitives/io" } | ||
sp-core = { version = "3.0.0", path = "../../primitives/core" } | ||
pallet-balances = { version = "3.0.0", path = "../balances" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"serde", | ||
"codec/std", | ||
"sp-std/std", | ||
"sp-runtime/std", | ||
"sp-arithmetic/std", | ||
"frame-benchmarking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
License: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2021 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Benchmarks for Gilt Pallet | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use sp_std::prelude::*; | ||
use super::*; | ||
use sp_runtime::traits::{Zero, Bounded}; | ||
use sp_arithmetic::Perquintill; | ||
use frame_system::RawOrigin; | ||
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite}; | ||
use frame_support::{traits::{Currency, Get, EnsureOrigin}, dispatch::UnfilteredDispatchable}; | ||
|
||
use crate::Pallet as Gilt; | ||
|
||
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance; | ||
|
||
benchmarks! { | ||
place_bid { | ||
let l in 0..(T::MaxQueueLen::get() - 1); | ||
let caller: T::AccountId = whitelisted_caller(); | ||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); | ||
for i in 0..l { | ||
Gilt::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinFreeze::get(), 1)?; | ||
} | ||
}: _(RawOrigin::Signed(caller.clone()), T::MinFreeze::get() * BalanceOf::<T>::from(2u32), 1) | ||
verify { | ||
assert_eq!(QueueTotals::<T>::get()[0], (l + 1, T::MinFreeze::get() * BalanceOf::<T>::from(l + 2))); | ||
} | ||
|
||
place_bid_max { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); | ||
for i in 0..T::MaxQueueLen::get() { | ||
Gilt::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinFreeze::get(), 1)?; | ||
} | ||
}: { | ||
Gilt::<T>::place_bid( | ||
RawOrigin::Signed(caller.clone()).into(), | ||
T::MinFreeze::get() * BalanceOf::<T>::from(2u32), | ||
1, | ||
)? | ||
} | ||
verify { | ||
assert_eq!(QueueTotals::<T>::get()[0], ( | ||
T::MaxQueueLen::get(), | ||
T::MinFreeze::get() * BalanceOf::<T>::from(T::MaxQueueLen::get() + 1), | ||
)); | ||
} | ||
|
||
retract_bid { | ||
let l in 1..T::MaxQueueLen::get(); | ||
let caller: T::AccountId = whitelisted_caller(); | ||
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); | ||
for i in 0..l { | ||
Gilt::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinFreeze::get(), 1)?; | ||
} | ||
}: _(RawOrigin::Signed(caller.clone()), T::MinFreeze::get(), 1) | ||
verify { | ||
assert_eq!(QueueTotals::<T>::get()[0], (l - 1, T::MinFreeze::get() * BalanceOf::<T>::from(l - 1))); | ||
} | ||
|
||
set_target { | ||
let call = Call::<T>::set_target(Default::default()); | ||
let origin = T::AdminOrigin::successful_origin(); | ||
}: { call.dispatch_bypass_filter(origin)? } | ||
|
||
thaw { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
T::Currency::make_free_balance_be(&caller, T::MinFreeze::get() * BalanceOf::<T>::from(3u32)); | ||
Gilt::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinFreeze::get(), 1)?; | ||
Gilt::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinFreeze::get(), 1)?; | ||
Gilt::<T>::enlarge(T::MinFreeze::get() * BalanceOf::<T>::from(2u32), 2); | ||
Active::<T>::mutate(0, |m_g| if let Some(ref mut g) = m_g { g.expiry = Zero::zero() }); | ||
}: _(RawOrigin::Signed(caller.clone()), 0) | ||
verify { | ||
assert!(Active::<T>::get(0).is_none()); | ||
} | ||
|
||
pursue_target_noop { | ||
}: { Gilt::<T>::pursue_target(0) } | ||
|
||
pursue_target_per_item { | ||
// bids taken | ||
let b in 1..T::MaxQueueLen::get(); | ||
|
||
let caller: T::AccountId = whitelisted_caller(); | ||
T::Currency::make_free_balance_be(&caller, T::MinFreeze::get() * BalanceOf::<T>::from(b + 1)); | ||
|
||
for _ in 0..b { | ||
Gilt::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinFreeze::get(), 1)?; | ||
} | ||
|
||
Call::<T>::set_target(Perquintill::from_percent(100)) | ||
.dispatch_bypass_filter(T::AdminOrigin::successful_origin())?; | ||
|
||
}: { Gilt::<T>::pursue_target(b) } | ||
|
||
pursue_target_per_queue { | ||
// total queues hit | ||
let q in 1..T::QueueCount::get(); | ||
|
||
let caller: T::AccountId = whitelisted_caller(); | ||
T::Currency::make_free_balance_be(&caller, T::MinFreeze::get() * BalanceOf::<T>::from(q + 1)); | ||
|
||
for i in 0..q { | ||
Gilt::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinFreeze::get(), i + 1)?; | ||
} | ||
|
||
Call::<T>::set_target(Perquintill::from_percent(100)) | ||
.dispatch_bypass_filter(T::AdminOrigin::successful_origin())?; | ||
|
||
}: { Gilt::<T>::pursue_target(q) } | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Gilt, | ||
crate::mock::new_test_ext(), | ||
crate::mock::Test, | ||
); |
Oops, something went wrong.