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

feat: impl block rewards #1198

Merged
merged 83 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 80 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 Feb 6, 2023
a69bb5e
feat: adjust extrinsics, add SessionManager
wischli Feb 7, 2023
a2f9a79
refactor: use OneSessionHandler, handle minting, add docs
wischli Feb 10, 2023
1c81915
chore: remove admin deposit/withdraw_stake
wischli Feb 10, 2023
c4dbe47
chore: impl BlockRewards for dev runtime
wischli Feb 10, 2023
795036d
feat: make reward source configurable
wischli Feb 13, 2023
664eee6
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli Feb 13, 2023
020ec78
feat: mint remainder
wischli Feb 13, 2023
ccae5c6
feat: finalize session handling
wischli Feb 13, 2023
a99a583
feat: init rewards at genesis
wischli Feb 14, 2023
1ee21af
fix: collator, treasury reward split
wischli Feb 14, 2023
257308d
refactor: use OnUnbalanced instead of PalletId
wischli Feb 14, 2023
bdb6d12
fix: beneficiary reward currency
wischli Feb 15, 2023
97292e2
chore: remove dummy bench, mock, tests
wischli Feb 15, 2023
4c48350
fix: session + collator selection benches
wischli Feb 15, 2023
6fa7c4a
refactor: hardcode many ATs
wischli Feb 15, 2023
0d73cf3
refactor: reward source v2
wischli Feb 16, 2023
a5ac903
refactor: issuance of rewards
wischli Feb 16, 2023
910139a
tests: apply RewardIssuance
wischli Feb 17, 2023
8b8c40f
refactor: total_rewards instead of beneficiary
wischli Feb 17, 2023
c5340dd
tests: add mock
wischli Feb 17, 2023
70bcdc9
fix: reward_to_mint
wischli Feb 21, 2023
4ad2bb0
tests: extend mock
wischli Feb 21, 2023
ce7d9d2
fix: new session handler, genesis setup
wischli Feb 21, 2023
e94c1d0
tests: almost done
wischli Feb 21, 2023
df29f21
feat: init new rewards instance in dev runtime
wischli Feb 21, 2023
9ccc965
tests: finish
wischli Feb 22, 2023
00fb722
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli Feb 22, 2023
6ecd801
fix: clippy
wischli Feb 22, 2023
12a1f6f
tests: add pallet_restricted_tokens
wischli Feb 22, 2023
70b46bb
tests: add ci
wischli Feb 27, 2023
6a23f9a
refactor: split up ci tests
wischli Feb 27, 2023
95770df
chore: add block_rewards to dev genesis cfg
wischli Feb 28, 2023
bce628a
feat: add benchmarks
wischli Feb 28, 2023
8aad4b0
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli Feb 28, 2023
c03962a
fix: add missing encoding to rewards currency
wischli Feb 28, 2023
b21e10a
fix: clippy
wischli Feb 28, 2023
2de4fb6
chore: bump nix
wischli Feb 28, 2023
48fd15e
ci: add fast-runtime flag to integration tests
wischli Feb 28, 2023
0a5c366
chore: remove open TODOs
wischli Feb 28, 2023
6971b5a
fmt: taplo
wischli Feb 28, 2023
17b6c67
refactor: replace epoch with session for b rewards
wischli Feb 28, 2023
69f703c
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli Feb 28, 2023
cec502e
tests: temp fix pools env
wischli Mar 1, 2023
f8044e5
feat: add block rewards init migration
wischli Mar 1, 2023
55b0272
fix: migration
wischli Mar 2, 2023
373a5ed
fix: add missing try-runtime feat to all tomls
wischli Mar 2, 2023
1d3da74
chore: update codeowners
wischli Mar 3, 2023
34a7c57
style: fmt
wischli Mar 3, 2023
60194a9
chore: apply self-review
wischli Mar 3, 2023
404e564
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli Mar 6, 2023
144ed20
fix: issues after rebasing
wischli Mar 6, 2023
c1304aa
chore: add session fail event
wischli Mar 7, 2023
78deabb
chore: add benches for session, collator selection
wischli Mar 9, 2023
5556b2c
fix: benchmarks
wischli Mar 10, 2023
5597f73
refactor: move pallet consts
wischli Mar 10, 2023
fdcd632
chore: add saturated conversion comment
wischli Mar 10, 2023
5f84538
refactor: remove unused Rewards requirement
wischli Mar 10, 2023
7070475
refactor: re-add staking currency
wischli Mar 16, 2023
43f6127
refactor: move block rewards consts
wischli Mar 16, 2023
7d4251c
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli Mar 16, 2023
19fb92a
chore: nix
wischli Mar 16, 2023
dd50f66
chore: provide conversion for StakingCurrency
wischli Mar 16, 2023
b2cbf25
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli Mar 16, 2023
ae05055
fix: lint
wischli Mar 16, 2023
b936c39
docs: improvements
wischli Mar 16, 2023
d5a4f1a
chore: bump nix
wischli Mar 16, 2023
93a481c
refactor: add StakeCurrency as associated type
wischli Mar 16, 2023
684dc68
fix: integration tests
wischli Mar 17, 2023
3f44316
refactor: collator stk
wischli Mar 20, 2023
cb72de4
Merge remote-tracking branch 'origin' into feat/impl-block-rewards
wischli Mar 20, 2023
7c64b8d
chore: bump nix
wischli Mar 20, 2023
27e4653
feat: add check to set_collator_rewards
wischli Mar 27, 2023
7223a31
chore: update CODEOWNERS
wischli Mar 27, 2023
02060eb
refactor: stake amt, group id via associated type
wischli Mar 27, 2023
5be160c
chore: move dev rewards config closer to prod
wischli Mar 27, 2023
ecd49de
refactor: abstract CfgCurrencyId
wischli Mar 28, 2023
8650cc8
Merge remote-tracking branch 'origin/main' into feat/impl-block-rewards
wischli Apr 13, 2023
69de861
Merge remote-tracking branch 'origin/main' into feat/impl-block-rewards
wischli Apr 14, 2023
97a0dbe
fix: bench errors after rebase
wischli Apr 14, 2023
5a3a6ad
fix: dev try-runtime
wischli Apr 14, 2023
572d9e2
fix: benchmarks
wischli Apr 17, 2023
cbb10b1
Merge branch 'main' into feat/impl-block-rewards
wischli Apr 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -19,6 +19,7 @@ pallets/connectors/* @NunoAlexandre @offerijns
## Rewards related logic
pallets/rewards/* @lemunozm @mikiquantum
pallets/liquidity-rewards/* @lemunozm @mikiquantum
pallets/block-rewards/* @wischli @lemunozm
Copy link
Contributor

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? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


## Nft-sales related logic
pallets/nft-sales/* @NunoAlexandre
Expand All @@ -27,7 +28,7 @@ pallets/nft-sales/* @NunoAlexandre
pallets/keystore/* @cdamian @mikiquantum

## Pallet Registry
pallets/pool-registry/* @gruberb @mustermeiszer
pallets/pool-registry/* @mustermeiszer

## Pallet Pool-System
pallets/pool-system/* @mustermeiszer @branan @offerijns
Expand Down Expand Up @@ -71,5 +72,8 @@ runtime/centrifuge/* @branan @mikiquantum @mustermeiszer @NunoAlexandre @offerij
### Changes to runtime/integration-tests
runtime/integration-tests/* @mustermeiszer @NunoAlexandre

### Changes to runtime/integration-tests/rewards
runtime/integration-tests/rewards/* @wischli

### Changes to runtime/integration-tests/xcm/
runtime/integration-tests/xcm/* @NunoAlexandre
49 changes: 49 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Expand Up @@ -37,6 +37,7 @@ members = [
"libs/utils",
"pallets/anchors",
"pallets/bridge",
"pallets/block-rewards",
"pallets/connectors",
"pallets/claims",
"pallets/collator-allowlist",
Expand Down Expand Up @@ -124,6 +125,7 @@ cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus",
cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
Expand Down Expand Up @@ -207,6 +209,7 @@ std = [
"sp-timestamp/std",
"sp-transaction-pool/std",
"xcm/std",
"cumulus-pallet-session-benchmarking/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand All @@ -218,6 +221,7 @@ runtime-benchmarks = [
"polkadot-cli/runtime-benchmarks",
"cfg-primitives/runtime-benchmarks",
"cfg-types/runtime-benchmarks",
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
"pallet-anchors/runtime-benchmarks",
"pallet-pool-system/runtime-benchmarks",
Expand Down Expand Up @@ -249,6 +253,8 @@ try-runtime = [
fast-runtime = [
"altair-runtime/fast-runtime",
"centrifuge-runtime/fast-runtime",
"development-runtime/fast-runtime",
"runtime-integration-tests/fast-runtime",
]

#
Expand Down
2 changes: 1 addition & 1 deletion ci/script.sh
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required for newly added pallet-block-rewards integration tests which need to iterate at least four sessions (20 blocks/~2 min with fast-runtime)

;;

fmt)
Expand Down
2 changes: 2 additions & 0 deletions libs/mocks/Cargo.toml
Expand Up @@ -50,4 +50,6 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"cfg-types/try-runtime",
"cfg-primitives/try-runtime",
"cfg-traits/try-runtime",
]
8 changes: 7 additions & 1 deletion libs/test-utils/Cargo.toml
Expand Up @@ -53,4 +53,10 @@ runtime-benchmarks = [
"cfg-traits/runtime-benchmarks",
"cfg-types/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime", "frame-system/try-runtime", "cfg-types/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"cfg-types/try-runtime",
"cfg-primitives/try-runtime",
"cfg-traits/try-runtime",
]
9 changes: 9 additions & 0 deletions libs/types/src/consts.rs
Expand Up @@ -25,3 +25,12 @@ pub mod pools {
pub const MaxTrancheSymbolLengthBytes: u32 = 32;
}
}

// Rewards-related constants
pub mod rewards {
use cfg_primitives::{Balance, CFG};

/// The default amount of stake for CurrencyId::Staking(StakingCurrency::BlockRewards) which is inherently
/// assigned to any member of the only group in block rewards.
pub const DEFAULT_COLLATOR_STAKE: Balance = CFG;
}
4 changes: 4 additions & 0 deletions libs/types/src/ids.rs
Expand Up @@ -36,3 +36,7 @@ pub const STAKE_POT_PALLET_ID: PalletId = PalletId(*b"PotStake");
// Other ids
pub const CHAIN_BRIDGE_HASH_ID: [u8; 13] = *b"cent_nft_hash";
pub const CHAIN_BRIDGE_NATIVE_TOKEN_ID: [u8; 4] = *b"xCFG";

// Reward related
/// The identifier of the group eligible to receive block rewards.
pub const COLLATOR_GROUP_ID: u32 = 1;
2 changes: 2 additions & 0 deletions libs/types/src/permissions.rs
Expand Up @@ -471,6 +471,7 @@ mod tests {

///! Tests for some types in the common section for our runtimes
use super::*;
use crate::tokens::StakingCurrency;

parameter_types! {
pub const MinDelay: u64 = 4;
Expand Down Expand Up @@ -694,6 +695,7 @@ mod tests {
KSM => vec![2],
AUSD => vec![3],
ForeignAsset(id) => vec![4, id as u64, 0, 0, 0],
Staking(StakingCurrency::BlockRewards) => vec![5, 1, 0, 0, 0],
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions libs/types/src/tokens.rs
Expand Up @@ -41,6 +41,19 @@ pub enum CurrencyId {

/// A foreign asset
ForeignAsset(ForeignAssetId),

/// A staking token
Staking(StakingCurrency),
}

#[derive(
Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum StakingCurrency {
mustermeiszer marked this conversation as resolved.
Show resolved Hide resolved
/// An emulated internal, non-transferrable currency
/// Its issuance and holding is handled inherently
BlockRewards,
}

pub type ForeignAssetId = u32;
Expand All @@ -59,6 +72,13 @@ impl From<u32> for CurrencyId {
}
}

// A shortcut anchoring the assumption made about `StakingCurrency`.
impl From<StakingCurrency> for CurrencyId {
fn from(inner: StakingCurrency) -> Self {
CurrencyId::Staking(inner)
}
}

/// A Currency that is solely used by tranches.
///
/// We distinguish here between the enum variant CurrencyId::Tranche(PoolId, TranchId)
Expand Down
81 changes: 81 additions & 0 deletions pallets/block-rewards/Cargo.toml
@@ -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.37" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" }
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.37" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" }
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.37" }
sp-staking = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.37" }

# optional dependencies for benchmarking
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.37" }

[dev-dependencies]
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.37" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.37" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
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.37" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }

[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",
]