Skip to content
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

Thea: Fisherman and Batch Signing #894

Merged
merged 36 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
01e8252
Add on-chain signature aggregation
Gauthamastro Jan 5, 2024
f475a46
Added Fisherman and dealing with misbehaviour logic
Gauthamastro Jan 5, 2024
302eb2c
Thea core logic completed
Gauthamastro Jan 5, 2024
b7b7732
Fix runtime
Gauthamastro Jan 12, 2024
1c95c94
Added chnages for eth
zktony Jan 15, 2024
919e0f7
Update thea logic
Gauthamastro Jan 15, 2024
badf4c4
Added changes for Ethereum (#896)
Gauthamastro Jan 15, 2024
9a2682a
cargo fmt
Gauthamastro Jan 15, 2024
4199ff5
fix thea tests
Gauthamastro Jan 15, 2024
423c4e9
fix thea-executor tests
Gauthamastro Jan 15, 2024
753e224
Update Thea message handler
Gauthamastro Jan 15, 2024
f1f2f6c
Fix tests
Gauthamastro Jan 15, 2024
84ddda8
Fix benchmarks
Gauthamastro Jan 15, 2024
d53e1f5
Resolve clippy errors
Gauthamastro Jan 15, 2024
01eb5ee
cargo fmt
Gauthamastro Jan 15, 2024
d5f37bb
Fix benchmarking
Gauthamastro Jan 15, 2024
6c88298
Added sign_prehash
zktony Jan 15, 2024
507b15d
Removed comment
zktony Jan 15, 2024
79abe06
Changed sign to sign_prehash (#897)
Gauthamastro Jan 15, 2024
428b623
fix cargo test
Gauthamastro Jan 15, 2024
8f9921b
Added benchmarks
zktony Jan 26, 2024
8bccd4a
Added on_init benchmark
zktony Jan 29, 2024
7d36fcc
Added benchmark code for Thea Pallet and thea Executor Pallet (#905)
zktony Jan 29, 2024
afc2717
feat(weights): Updated thea weights
serhii-temchenko Jan 29, 2024
65ac207
Resolved all the comments
zktony Jan 30, 2024
3e9f25c
Resolved all the comments (#906)
zktony Jan 30, 2024
1c294d5
Fixed ci issues
zktony Jan 30, 2024
9e6cc7e
Fix CI Issues
zktony Jan 30, 2024
d9c595e
feat(weights): Updated weights for thea related pallets
serhii-temchenko Jan 30, 2024
85764bd
Fixed tests
zktony Jan 30, 2024
ec7bee6
Merge branch 'gj/thea-final' of https://github.com/Polkadex-Substrate…
zktony Jan 30, 2024
9f9631d
Fixed tests
zktony Feb 1, 2024
8fd9050
Fixed CI
zktony Feb 1, 2024
2ea4a27
Update the correct runtime spec_version
Gauthamastro Feb 1, 2024
0bbe823
Update the correct parachain runtime spec_version
Gauthamastro Feb 1, 2024
1d9e71c
feat(weights): Updated thea related pallets weights
serhii-temchenko Feb 1, 2024
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
127 changes: 93 additions & 34 deletions pallets/thea-executor/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,37 @@

#![cfg(feature = "runtime-benchmarks")]
use super::*;

use sp_runtime::traits::AccountIdConversion;
use sp_std::{boxed::Box, vec, vec::Vec};

use crate::Pallet as TheaExecutor;
use frame_benchmarking::v1::{account, benchmarks};
use frame_support::traits::{
fungible::Mutate as NativeMutate,
fungible::{Inspect as NativeInspect, Mutate as NativeMutate},
fungibles::{Create, Inspect, Mutate},
Get,
Get, OnInitialize,
};
use frame_system::RawOrigin;
use sp_runtime::SaturatedConversion;
use thea_primitives::types::{AssetMetadata, Deposit};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use parity_scale_codec::Decode;
use polkadex_primitives::UNIT_BALANCE;
use sp_runtime::{traits::AccountIdConversion, SaturatedConversion};
use sp_std::{boxed::Box, collections::btree_set::BTreeSet, vec, vec::Vec};
use thea_primitives::types::{AssetMetadata, Deposit, Withdraw};
use xcm::VersionedMultiLocation;

fn create_deposit<T: Config>(recipient: T::AccountId) -> Vec<Deposit<T::AccountId>> {
let mut pending_deposits = vec![];
let asset_id = 100;
for _i in 1..20 {
let deposit: Deposit<T::AccountId> = Deposit {
id: vec![],
recipient: recipient.clone(),
asset_id,
amount: 1_000_000_000_000,
extra: vec![],
};
pending_deposits.push(deposit);
}
pending_deposits
}

benchmarks! {
set_withdrawal_fee {
let r in 1 .. 1000;
Expand All @@ -53,21 +69,6 @@ benchmarks! {
assert_eq!(<Metadata<T>>::get(asset_id), Some(metadata));
}

claim_deposit {
let r in 1 .. 1000;
let account = account::<T::AccountId>("alice", 1, r);
let asset_id: <T as pallet::Config>::AssetId = 100u128.into();
let deposits = create_deposit::<T>(account.clone());
let metadata = AssetMetadata::new(10).unwrap();
<Metadata<T>>::insert(100, metadata);
<T as pallet::Config>::Currency::mint_into(&account, 100_000_000_000_000u128.saturated_into()).unwrap();
<ApprovedDeposits<T>>::insert(account.clone(), deposits);
}: _(RawOrigin::Signed(account.clone()), 10,account.clone())
verify {
let current_balance = <T as pallet::Config>::Assets::balance(asset_id.into(), &account);
assert_eq!(current_balance, 1_000_000_000_000_000u128.saturated_into());
}

withdraw {
let r in 1 .. 1000;
let asset_id: <T as pallet::Config>::AssetId = 100u128.into();
Expand Down Expand Up @@ -111,22 +112,80 @@ benchmarks! {
let ready_withdrawal = <ReadyWithdrawals<T>>::get(<frame_system::Pallet<T>>::block_number(), network_id);
assert_eq!(ready_withdrawal.len(), 1);
}
}

fn create_deposit<T: Config>(recipient: T::AccountId) -> Vec<Deposit<T::AccountId>> {
let mut pending_deposits = vec![];
let asset_id = 100;
for _i in 1..20 {
let deposit: Deposit<T::AccountId> = Deposit {
ethereum_withdraw {
let r in 1 .. 1000;
let asset_id: <T as pallet::Config>::AssetId = 100u128.into();
let admin = account::<T::AccountId>("admin", 1, r);
let network_id = 2;
<T as pallet::Config>::Assets::create(asset_id.into(), admin, true, 1u128.saturated_into()).unwrap();
let pallet_acc = T::TheaPalletId::get().into_account_truncating();
<T as pallet::Config>::Currency::mint_into(&pallet_acc, 100_000_000_000_000_000_000u128.saturated_into()).unwrap();
let account = account::<T::AccountId>("alice", 1, r);
<T as pallet::Config>::Assets::mint_into(asset_id.into(), &account, 100_000_000_000_000_000_000u128.saturated_into()).unwrap();
<T as pallet::Config>::Currency::mint_into(&account, 100_000_000_000_000u128.saturated_into()).unwrap();
let metadata = AssetMetadata::new(10).unwrap();
<Metadata<T>>::insert(100, metadata);
<WithdrawalFees<T>>::insert(network_id, 1_000);
let beneficiary: sp_core::H160 = sp_core::H160::default();
}: _(RawOrigin::Signed(account.clone()), 100, 1_000_000_000_000, beneficiary, true, false)
verify {
let ready_withdrawal = <ReadyWithdrawals<T>>::get(<frame_system::Pallet<T>>::block_number(), network_id);
assert_eq!(ready_withdrawal.len(), 1);
}

on_initialize {
let x in 1 .. 1_000;
let y in 1 .. 1_000;
let network_len: usize = x as usize;
let network_len: u8 = network_len as u8;
let withdrawal = Withdraw {
id: vec![],
recipient: recipient.clone(),
asset_id,
asset_id: 100,
amount: 1_000_000_000_000,
destination: vec![],
is_blocked: false,
extra: vec![],
};
pending_deposits.push(deposit);
let mut withdrawal_vec = Vec::new();
for _ in 0..y {
withdrawal_vec.push(withdrawal.clone());
}
let block_no: u32 = 10;
let mut networks: BTreeSet<u8> = BTreeSet::new();
for i in 0..network_len {
networks.insert(i);
}
let block_no: BlockNumberFor<T> = block_no.into();
for network_id in networks {
<ReadyWithdrawals<T>>::insert(block_no, network_id, withdrawal_vec.clone());
}
}: {
TheaExecutor::<T>::on_initialize(block_no);
}

burn_native_tokens{
let account: T::AccountId = T::AccountId::decode(&mut &[0u8; 32][..]).unwrap();
<T as pallet::Config>::Currency::mint_into(&account, (100000*UNIT_BALANCE).saturated_into()).unwrap();
}: _(RawOrigin::Root, account.clone(), UNIT_BALANCE)
verify {
assert_eq!(<T as pallet::Config>::Currency::balance(&account), (99999 * UNIT_BALANCE).saturated_into());
}

claim_deposit {
let r in 1 .. 1000;
let account = account::<T::AccountId>("alice", 1, r);
let asset_id: <T as pallet::Config>::AssetId = 100u128.into();
let deposits = create_deposit::<T>(account.clone());
let metadata = AssetMetadata::new(10).unwrap();
<Metadata<T>>::insert(100, metadata);
<T as pallet::Config>::Currency::mint_into(&account, 100_000_000_000_000u128.saturated_into()).unwrap();
<ApprovedDeposits<T>>::insert(account.clone(), deposits);
}: _(RawOrigin::Signed(account.clone()), 10,account.clone())
verify {
let current_balance = <T as pallet::Config>::Assets::balance(asset_id.into(), &account);
assert_eq!(current_balance, 1_000_000_000_000_000u128.saturated_into());
}
pending_deposits
}

#[cfg(test)]
Expand Down
Loading
Loading