-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pallets: Add Anchors V2 pallet #1878
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
68b71f8
pallets: Add Anchors V2 pallet
cdamian 0266be8
taplo: Fix
cdamian 7f7153d
pallet: Fix imports
cdamian 354701e
pallet: Use benchmarking v2, drop AnchorOf
cdamian d3ded71
pallet: Drop associated types for document id and version
cdamian 3510e99
pallet: Fix and add more tests
cdamian 7f3e467
docs: Add Anchors V2 pallet to README.
cdamian 96bcc0e
runtime: Add nonce type, fix weight impl.
cdamian 3b0ac0c
pallet: Move import
cdamian aaa3701
pallet: Remove AnchorIdNonce
cdamian 01f23f7
fmt: Fix
cdamian bf3d2e4
runtime: Add missing feature, remove extra import
cdamian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[package] | ||
name = "pallet-anchors-v2" | ||
description = "Anchors V2 pallet for runtime" | ||
version = "1.0.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
documentation.workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true } | ||
scale-info = { workspace = true } | ||
|
||
frame-benchmarking = { workspace = true, optional = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
|
||
[dev-dependencies] | ||
pallet-balances = { workspace = true, default-features = true } | ||
sp-core = { workspace = true, default-features = true } | ||
sp-io = { workspace = true, default-features = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
"frame-benchmarking/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
] | ||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"sp-runtime/try-runtime", | ||
] |
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,91 @@ | ||
// Copyright 2021 Centrifuge Foundation (centrifuge.io). | ||
// This file is part of Centrifuge chain project. | ||
|
||
// Centrifuge is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version (see http://www.gnu.org/licenses). | ||
|
||
// Centrifuge 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 General Public License for more details. | ||
|
||
use frame_benchmarking::{account, impl_benchmark_test_suite, v2::*}; | ||
use frame_support::traits::Currency; | ||
use frame_system::RawOrigin; | ||
use parity_scale_codec::EncodeLike; | ||
use sp_core::H256; | ||
|
||
use super::*; | ||
|
||
#[benchmarks( | ||
where | ||
T: Config<Balance = u128, Hash = H256>, | ||
T::AccountId: EncodeLike<<T as frame_system::Config>::AccountId>, | ||
)] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn set_anchor() -> Result<(), BenchmarkError> { | ||
let caller: T::AccountId = account("acc_0", 0, 0); | ||
|
||
let document_id = 123; | ||
let document_version = 456; | ||
let hash = H256::from_low_u64_be(1); | ||
|
||
let _ = T::Currency::deposit_creating( | ||
&caller.clone().into(), | ||
T::Currency::minimum_balance() + T::DefaultAnchorDeposit::get(), | ||
); | ||
|
||
#[extrinsic_call] | ||
set_anchor( | ||
RawOrigin::Signed(caller), | ||
document_id, | ||
document_version, | ||
hash, | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[benchmark] | ||
fn remove_anchor() -> Result<(), BenchmarkError> { | ||
let caller: T::AccountId = account("acc_0", 0, 0); | ||
|
||
let document_id = 123; | ||
let document_version = 456; | ||
let hash = H256::from_low_u64_be(1); | ||
let deposit = AnchorDeposit::<T>::get(); | ||
|
||
let anchor = Anchor::<T> { | ||
account_id: caller.clone(), | ||
document_id, | ||
document_version, | ||
hash, | ||
deposit, | ||
}; | ||
|
||
Anchors::<T>::insert((document_id, document_version), anchor); | ||
PersonalAnchors::<T>::insert(caller.clone(), (document_id, document_version), ()); | ||
|
||
#[extrinsic_call] | ||
remove_anchor(RawOrigin::Signed(caller), document_id, document_version); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[benchmark] | ||
fn set_deposit_value() -> Result<(), BenchmarkError> { | ||
let deposit = 2 * T::DefaultAnchorDeposit::get(); | ||
|
||
#[extrinsic_call] | ||
set_deposit_value(RawOrigin::Root, deposit); | ||
|
||
Ok(()) | ||
} | ||
|
||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not bad, and probably this pallet is only for us, so it will not be an issue. But to explain the why:
These bounds force the user of this pallet to always choose
Balance = u128
andHash = H256
in their runtime if they want to perform the benchmarks. Ideally, we do not want to restrict the usage of the bounds to certain concrete types. We want to allow any type that can be configured by the pallet.The solution for that is to add extra bounds to those associated types as:
Not blocker at all, just for reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can leave it as it is for now, these benchmarks are still tests at the end of the day and I think it's fine to have some hardcoded types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, not blocker 👍🏻