Skip to content

Commit

Permalink
Merge branch 'main' into it/simplify-xtransfer-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Jun 24, 2024
2 parents 415a158 + cce79b6 commit 7f79140
Show file tree
Hide file tree
Showing 17 changed files with 891 additions and 17 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"libs/types",
"libs/utils",
"pallets/anchors",
"pallets/anchors-v2",
"pallets/bridge",
"pallets/block-rewards",
"pallets/collator-allowlist",
Expand Down Expand Up @@ -219,6 +220,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-s
axelar-gateway-precompile = { path = "pallets/liquidity-pools-gateway/axelar-gateway-precompile", default-features = false }
liquidity-pools-gateway-routers = { path = "pallets/liquidity-pools-gateway/routers", default-features = false }
pallet-anchors = { path = "pallets/anchors", default-features = false }
pallet-anchors-v2 = { path = "pallets/anchors-v2", default-features = false }
pallet-block-rewards = { path = "pallets/block-rewards", default-features = false }
pallet-bridge = { path = "pallets/bridge", default-features = false }
pallet-collator-allowlist = { path = "pallets/collator-allowlist", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Centrifuge is the infrastructure that facilitates the decentralized financing of
On top of the [Substrate FRAME](https://docs.substrate.io/reference/frame-pallets/) framework, Centrifuge Chain is composed of custom pallets which can be found inside the `pallets` folder. The following list gives a brief overview, and links to the corresponding documentation:

- [**anchors**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/anchors) ([docs](https://reference.centrifuge.io/pallet_anchors/index.html)): Storing hashes of documents on-chain. The documents are stored in the Private Off-chain Data (POD) node network.
-
- [**anchors-v2**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/anchors-v2) ([docs](https://reference.centrifuge.io/pallet_anchors_v2/index.html)): Second version of the pallet used to store document hashes on-chain.

- [**block-rewards**](https://github.com/centrifuge/centrifuge-chain/tree/main/pallets/block-rewards) ([docs](https://reference.centrifuge.io/pallet_block_rewards/index.html)): Provides means of configuring and distributing block rewards to collators as well as the annual treasury inflation.

Expand Down
52 changes: 52 additions & 0 deletions pallets/anchors-v2/Cargo.toml
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",
]
91 changes: 91 additions & 0 deletions pallets/anchors-v2/src/benchmarking.rs
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);
}
Loading

0 comments on commit 7f79140

Please sign in to comment.