-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: impl block rewards #1198
Merged
Merged
feat: impl block rewards #1198
Changes from 58 commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
b9bd2c4
chore: init block rewards from liquidity rewards clone
wischli a69bb5e
feat: adjust extrinsics, add SessionManager
wischli a2f9a79
refactor: use OneSessionHandler, handle minting, add docs
wischli 1c81915
chore: remove admin deposit/withdraw_stake
wischli c4dbe47
chore: impl BlockRewards for dev runtime
wischli 795036d
feat: make reward source configurable
wischli 664eee6
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli 020ec78
feat: mint remainder
wischli ccae5c6
feat: finalize session handling
wischli a99a583
feat: init rewards at genesis
wischli 1ee21af
fix: collator, treasury reward split
wischli 257308d
refactor: use OnUnbalanced instead of PalletId
wischli bdb6d12
fix: beneficiary reward currency
wischli 97292e2
chore: remove dummy bench, mock, tests
wischli 4c48350
fix: session + collator selection benches
wischli 6fa7c4a
refactor: hardcode many ATs
wischli 0d73cf3
refactor: reward source v2
wischli a5ac903
refactor: issuance of rewards
wischli 910139a
tests: apply RewardIssuance
wischli 8b8c40f
refactor: total_rewards instead of beneficiary
wischli c5340dd
tests: add mock
wischli 70bcdc9
fix: reward_to_mint
wischli 4ad2bb0
tests: extend mock
wischli ce7d9d2
fix: new session handler, genesis setup
wischli e94c1d0
tests: almost done
wischli df29f21
feat: init new rewards instance in dev runtime
wischli 9ccc965
tests: finish
wischli 00fb722
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli 6ecd801
fix: clippy
wischli 12a1f6f
tests: add pallet_restricted_tokens
wischli 70b46bb
tests: add ci
wischli 6a23f9a
refactor: split up ci tests
wischli 95770df
chore: add block_rewards to dev genesis cfg
wischli bce628a
feat: add benchmarks
wischli 8aad4b0
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli c03962a
fix: add missing encoding to rewards currency
wischli b21e10a
fix: clippy
wischli 2de4fb6
chore: bump nix
wischli 48fd15e
ci: add fast-runtime flag to integration tests
wischli 0a5c366
chore: remove open TODOs
wischli 6971b5a
fmt: taplo
wischli 17b6c67
refactor: replace epoch with session for b rewards
wischli 69f703c
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli cec502e
tests: temp fix pools env
wischli f8044e5
feat: add block rewards init migration
wischli 55b0272
fix: migration
wischli 373a5ed
fix: add missing try-runtime feat to all tomls
wischli 1d3da74
chore: update codeowners
wischli 34a7c57
style: fmt
wischli 60194a9
chore: apply self-review
wischli 404e564
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli 144ed20
fix: issues after rebasing
wischli c1304aa
chore: add session fail event
wischli 78deabb
chore: add benches for session, collator selection
wischli 5556b2c
fix: benchmarks
wischli 5597f73
refactor: move pallet consts
wischli fdcd632
chore: add saturated conversion comment
wischli 5f84538
refactor: remove unused Rewards requirement
wischli 7070475
refactor: re-add staking currency
wischli 43f6127
refactor: move block rewards consts
wischli 7d4251c
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli 19fb92a
chore: nix
wischli dd50f66
chore: provide conversion for StakingCurrency
wischli b2cbf25
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli ae05055
fix: lint
wischli b936c39
docs: improvements
wischli d5a4f1a
chore: bump nix
wischli 93a481c
refactor: add StakeCurrency as associated type
wischli 684dc68
fix: integration tests
wischli 3f44316
refactor: collator stk
wischli cb72de4
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli 7c64b8d
chore: bump nix
wischli 27e4653
feat: add check to set_collator_rewards
wischli 7223a31
chore: update CODEOWNERS
wischli 02060eb
refactor: stake amt, group id via associated type
wischli 5be160c
chore: move dev rewards config closer to prod
wischli ecd49de
refactor: abstract CfgCurrencyId
wischli 8650cc8
Merge remote-tracking branch 'origin/main' into feat/impl-block-rewards
wischli 69de861
Merge remote-tracking branch 'origin/main' into feat/impl-block-rewards
wischli 97a0dbe
fix: bench errors after rebase
wischli 5a3a6ad
fix: dev try-runtime
wischli 572d9e2
fix: benchmarks
wischli cbb10b1
Merge branch 'main' into feat/impl-block-rewards
wischli 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ case $TARGET in | |
;; | ||
|
||
integration) | ||
RUST_MIN_STACK=8388608 cargo test --release --package runtime-integration-tests | ||
RUST_MIN_STACK=8388608 cargo test --release --package runtime-integration-tests --features fast-runtime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required for newly added |
||
;; | ||
|
||
fmt) | ||
|
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
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
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 @@ | ||
[package] | ||
name = "pallet-block-rewards" | ||
version = "0.1.0" | ||
authors = ["Centrifuge <admin@centrifuge.io>"] | ||
description = "Block Rewards pallet" | ||
edition = "2021" | ||
homepage = "https://centrifuge.io" | ||
license = "LGPL-3.0" | ||
repository = "https://github.com/centrifuge/centrifuge-chain" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
cfg-primitives = { path = "../../libs/primitives", default-features = false} | ||
cfg-traits = { path = "../../libs/traits", default-features = false } | ||
cfg-types = { path = "../../libs/types", default-features = false } | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } | ||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.32" } | ||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.32" } | ||
log = { version = "0.4.17", default-features = false } | ||
mustermeiszer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
num-traits = { version = "0.2", default-features = false } | ||
pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.32" } | ||
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.32" } | ||
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] } | ||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.32" } | ||
sp-staking = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.32" } | ||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.32" } | ||
|
||
# optional dependencies for benchmarking | ||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.32" } | ||
|
||
[dev-dependencies] | ||
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.32" } | ||
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.32" } | ||
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.32" } | ||
pallet-restricted-tokens = { path = "../restricted-tokens", default-features = false } | ||
pallet-rewards = { path = "../rewards", default-features = false } | ||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.32" } | ||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.32" } | ||
|
||
[features] | ||
default = ["std"] | ||
try-runtime = [ | ||
"cfg-primitives/try-runtime", | ||
"cfg-traits/try-runtime", | ||
"frame-support/try-runtime", | ||
"cfg-types/try-runtime", | ||
"frame-system/try-runtime", | ||
"pallet-collator-selection/try-runtime", | ||
"pallet-session/try-runtime", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking", | ||
"cfg-traits/runtime-benchmarks", | ||
"cfg-types/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"pallet-collator-selection/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
"sp-staking/runtime-benchmarks", | ||
"cfg-primitives/runtime-benchmarks", | ||
] | ||
std = [ | ||
"frame-benchmarking/std", | ||
"num-traits/std", | ||
"scale-info/std", | ||
"cfg-primitives/std", | ||
"cfg-traits/std", | ||
"cfg-types/std", | ||
"codec/std", | ||
"log/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"pallet-collator-selection/std", | ||
"pallet-rewards/std", | ||
"pallet-session/std", | ||
"sp-runtime/std", | ||
"sp-staking/std", | ||
"sp-std/std", | ||
] |
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,67 @@ | ||
use cfg_primitives::CFG; | ||
use cfg_types::tokens::CurrencyId; | ||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; | ||
use frame_support::{ | ||
assert_ok, | ||
traits::{fungibles::Inspect, Currency as CurrencyT}, | ||
}; | ||
use frame_system::RawOrigin; | ||
use sp_runtime::traits::{One, Zero}; | ||
|
||
use super::*; | ||
use crate::{pallet::Config, Pallet as BlockRewards}; | ||
|
||
const REWARD: u128 = 1 * CFG; | ||
const SEED: u32 = 0; | ||
|
||
benchmarks! { | ||
where_clause { | ||
where | ||
T::Balance: From<u128>, | ||
T::BlockNumber: From<u32> + One, | ||
T::Weight: From<u32>, | ||
<T as Config>::Currency: frame_support::traits::fungibles::Inspect<T::AccountId> + CurrencyT<T::AccountId>, | ||
} | ||
|
||
claim_reward { | ||
let caller = whitelisted_caller(); | ||
let beneficiary: T::AccountId = account("collator", 0, SEED); | ||
|
||
assert_ok!(BlockRewards::<T>::do_init_collator(&beneficiary)); | ||
assert_ok!(T::Rewards::reward_group(COLLATOR_GROUP_ID, REWARD.into())); | ||
assert!(T::Rewards::is_ready(COLLATOR_GROUP_ID)); | ||
assert!( | ||
!T::Rewards::compute_reward( | ||
( | ||
T::Domain::get(), | ||
CurrencyId::BlockRewards, | ||
), | ||
&beneficiary, | ||
).unwrap().is_zero() | ||
); | ||
let before = <T as Config>::Currency::balance(CurrencyId::Native, &beneficiary); | ||
|
||
}: _(RawOrigin::Signed(caller), beneficiary.clone()) | ||
verify { | ||
// Does not get entire reward since another collator is auto-staked via genesis config | ||
assert_eq!(<T as Config>::Currency::balance(CurrencyId::Native, &beneficiary).saturating_sub(before), (REWARD / 2).into()); | ||
} | ||
|
||
set_collator_reward { | ||
}: _(RawOrigin::Root, REWARD.into()) | ||
verify { | ||
assert_eq!(BlockRewards::<T>::next_session_changes().collator_reward, Some(REWARD.into())); | ||
} | ||
|
||
set_total_reward { | ||
}: _(RawOrigin::Root, u128::MAX.into()) | ||
verify { | ||
assert_eq!(BlockRewards::<T>::next_session_changes().total_reward, Some(u128::MAX.into())); | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
BlockRewards, | ||
crate::mock::ExtBuilder::default().build(), | ||
crate::mock::Test, | ||
); |
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.
Could you remove
gruberb
from this file since you are touching it? :)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.
7223a31