-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starlight <> Ethereum: Rewards mapping (#761)
* WIP does not compile, needs cherry pick AggregateMessageOrigin * Add eth outbound queue and system pallets * Use fork branch tomasz-generic-aggregate-message-origin * Update Cargo.lock * Fix outdated fork branches * Fix tests and benchmarks * Fix compilation and toml * WIP root_test_send_msg_to_eth * Use custom Command enum and do_process_message impl * Create validate trait * Fix tests * Fix unused variable * Fix toml * Add integration test * pnpm lint and fmt * typescript-api * Also support original Command enum * typescript-api * Add test using snowbridge message * Add different origin for custom snowbridge messages vs original ones * add initial ReportSlashes variant * PR review * Fix tests * polkadot-sdk branch merged, use stable2407 again * typescript-api * small PoC for sending slashes message on_initialize * minor fixes * Test message limits: max numMsg and msgSize * Add benchmarks * fmt * Fix accidental refactor * typescript-api * only map rewards * PR comments * Copy * refactor mapping and add test * fix match pattern * start adding runtime-api * more progress on runtime apis * add test for merkle proofs * fmt * fix external-validators-rewards mock * toml fmt * rust fmt * add more checks to rust test * add TS test for runtime apis * fix test * add some docs * add EraInflationProvider * PR suggestion * add benchmark for on_era_end * add benchmark for on_era_end * remove comment * pr comments * add TODO for gas cost
- Loading branch information
Showing
19 changed files
with
857 additions
and
52 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
28 changes: 28 additions & 0 deletions
28
pallets/external-validators-rewards/runtime-api/Cargo.toml
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,28 @@ | ||
[package] | ||
name = "pallet-external-validators-rewards-runtime-api" | ||
authors = { workspace = true } | ||
description = "Runtime API definition of pallet-external-validators-rewards" | ||
edition = "2021" | ||
license = "GPL-3.0-only" | ||
version = "0.1.0" | ||
|
||
[package.metadata.docs.rs] | ||
targets = [ "x86_64-unknown-linux-gnu" ] | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true } | ||
snowbridge-outbound-queue-merkle-tree = { workspace = true } | ||
sp-api = { workspace = true } | ||
sp-core = { workspace = true } | ||
|
||
[features] | ||
default = [ "std" ] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"snowbridge-outbound-queue-merkle-tree/std", | ||
"sp-api/std", | ||
"sp-core/std", | ||
] |
32 changes: 32 additions & 0 deletions
32
pallets/external-validators-rewards/runtime-api/src/lib.rs
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,32 @@ | ||
// Copyright (C) Moondance Labs Ltd. | ||
// This file is part of Tanssi. | ||
|
||
// Tanssi 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. | ||
|
||
// Tanssi 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. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Tanssi. If not, see <http://www.gnu.org/licenses/> | ||
|
||
//! Runtime API for External Validators Rewards pallet | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use snowbridge_outbound_queue_merkle_tree::MerkleProof; | ||
|
||
sp_api::decl_runtime_apis! { | ||
pub trait ExternalValidatorsRewardsApi<AccountId, EraIndex> | ||
where | ||
AccountId: parity_scale_codec::Codec, | ||
EraIndex: parity_scale_codec::Codec, | ||
{ | ||
fn generate_rewards_merkle_proof(account_id: AccountId, era_index: EraIndex) -> Option<MerkleProof>; | ||
fn verify_rewards_merkle_proof(merkle_proof: MerkleProof) -> bool; | ||
} | ||
} |
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,81 @@ | ||
// Copyright (C) Moondance Labs Ltd. | ||
// This file is part of Tanssi. | ||
|
||
// Tanssi 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. | ||
|
||
// Tanssi 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. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Tanssi. If not, see <http://www.gnu.org/licenses/> | ||
|
||
//! Benchmarking setup for pallet_external_validators_rewards | ||
use super::*; | ||
|
||
#[allow(unused)] | ||
use crate::Pallet as ExternalValidatorsRewards; | ||
use { | ||
frame_benchmarking::{account, v2::*, BenchmarkError}, | ||
frame_support::traits::{Currency, Get}, | ||
sp_std::prelude::*, | ||
tp_traits::OnEraEnd, | ||
}; | ||
|
||
const SEED: u32 = 0; | ||
|
||
fn create_funded_user<T: Config + pallet_balances::Config>( | ||
string: &'static str, | ||
n: u32, | ||
balance_factor: u32, | ||
) -> T::AccountId { | ||
let user = account(string, n, SEED); | ||
let balance = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::minimum_balance() | ||
* balance_factor.into(); | ||
let _ = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::make_free_balance_be( | ||
&user, balance, | ||
); | ||
user | ||
} | ||
|
||
#[allow(clippy::multiple_bound_locations)] | ||
#[benchmarks(where T: pallet_balances::Config)] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
// worst case for the end of an era. | ||
#[benchmark] | ||
fn on_era_end() -> Result<(), BenchmarkError> { | ||
frame_system::Pallet::<T>::set_block_number(0u32.into()); | ||
|
||
let mut era_reward_points = EraRewardPoints::default(); | ||
era_reward_points.total = T::BackingPoints::get() * 1000; | ||
|
||
for i in 0..1000 { | ||
let account_id = create_funded_user::<T>("candidate", i, 100); | ||
era_reward_points | ||
.individual | ||
.insert(account_id, T::BackingPoints::get()); | ||
} | ||
|
||
<RewardPointsForEra<T>>::insert(1u32, era_reward_points); | ||
|
||
#[block] | ||
{ | ||
<ExternalValidatorsRewards<T> as OnEraEnd>::on_era_end(1u32); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
ExternalValidatorsRewards, | ||
crate::mock::new_test_ext(), | ||
crate::mock::Test, | ||
); | ||
} |
Oops, something went wrong.