Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

[Free Calls] Use list of eligible accounts rather than locked tokens #200

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

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

68 changes: 68 additions & 0 deletions pallets/free-calls/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[package]
name = 'pallet-free-calls'
version = '0.7.2'
authors = ['DappForce <[email protected]>']
edition = '2018'
license = 'GPL-3.0-only'
homepage = 'https://subsocial.network'
repository = 'https://github.com/dappforce/dappforce-subsocial-node'
description = 'Pallet for allowing accounts to send free calls based on a set quota.'
keywords = ['blockchain', 'cryptocurrency', 'social-network', 'news-feed', 'marketplace']
categories = ['cryptography::cryptocurrencies']

[features]
default = ['std']
std = [
'serde',
'codec/std',
'scale-info/std',
'sp-runtime/std',
'frame-support/std',
'frame-system/std',
'sp-std/std',
'pallet-utils/std',
'pallet-locker-mirror/std',
'pallet-balances/std',
'df-traits/std',
'pallet-permissions/std',
'frame-benchmarking/std',
'subsocial-primitives/std',
]

runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]

[dependencies.codec]
default-features = false
features = ['derive']
package = 'parity-scale-codec'
version = '2.0.0'


[dependencies]
impl-trait-for-tuples = '0.1.3'
serde = { features = ['derive'], optional = true, version = '1.0.119' }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }

# Local dependencies
df-traits = { default-features = false, path = '../traits' }
pallet-utils = { default-features = false, path = '../utils' }
pallet-permissions = { default-features = false, path = '../permissions' }
pallet-locker-mirror = { default-features = false, path = '../locker-mirror' }
pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
subsocial-primitives = { default-features = false, path = '../../primitives' }

# Substrate dependencies
frame-benchmarking = { optional = true, git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
frame-support = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
frame-system = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
sp-runtime = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
sp-std = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }

[dev-dependencies]
sp-core = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
sp-io = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.12', default-features = false }
rand = "0.8.4"
61 changes: 61 additions & 0 deletions pallets/free-calls/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! Benchmarks for Template Pallet
#![cfg(feature = "runtime-benchmarks")]

use crate::*;
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_system::RawOrigin;
use frame_benchmarking::Box;
use frame_benchmarking::vec;
use sp_runtime::traits::Bounded;
use frame_support::traits::Get;
use frame_support::BoundedVec;
use sp_std::convert::TryInto;
use sp_std::prelude;
use crate::benchmarking::prelude::Vec;
use pallet_locker_mirror::{BalanceOf, LockedInfo, LockedInfoByAccount};

fn _create_eligible_account<T: Config>(index: u32) -> T::AccountId {
account("eligible_account", index, 1)
}

fn _create_eligible_accounts<T: Config>(accounts_number: u32) -> Vec<T::AccountId> {
let mut eligible_accounts: Vec<T::AccountId> = Vec::new();
for i in 0..accounts_number {
eligible_accounts.push(_create_eligible_account::<T>(i));
}

eligible_accounts
}

benchmarks!{
// Individual benchmarks are placed here
try_free_call {
let caller: T::AccountId = whitelisted_caller();
let call = Box::new(frame_system::Call::<T>::remark { remark: vec![] }.into());
let current_block = <frame_system::Pallet<T>>::block_number();
<LockedInfoByAccount<T>>::insert(caller.clone(), LockedInfo {
expires_at: None,
locked_amount: BalanceOf::<T>::max_value(),
locked_at: current_block + 1000u32.into(),
});
}: try_free_call(RawOrigin::Signed(caller.clone()), call)
verify {
let found_stats = <WindowStatsByConsumer<T>>::get(caller.clone()).is_empty() == false;
ensure!(found_stats, "Stats should be recorded after the call");
<WindowStatsByConsumer<T>>::remove(caller.clone());
}

add_eligible_accounts {
let a in 1 .. T::AccountsSetLimit::get() => ();
let eligible_accounts = _create_eligible_accounts::<T>(a);
}: _(RawOrigin::Root, eligible_accounts.try_into().unwrap())
verify {
ensure!(EligibleAccounts::<T>::iter().count() as u32 == a, "Eligible accounts not added");
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::ExtBuilder::default().build(),
crate::mock::Test,
);
}
Loading