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

PoS inflation and rewards #714

Merged
merged 27 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fb5f758
core: refactor gov address
tzemanovic Mar 23, 2023
8060564
shared/pos: re-use PoS address from address mod
tzemanovic Mar 23, 2023
65b8e3f
inflation and rewards modules
brentstone Feb 8, 2023
1704095
storage types and keys for inflation
brentstone Feb 8, 2023
17b60dc
log block rewards with accumulator LazyMaps and apply inflation with …
brentstone Feb 8, 2023
c36710e
trigger 2-block countdown to new epoch for Tendermint
brentstone Feb 9, 2023
2b2e86b
apps/lib: configure genesis to set up any number of validators
brentstone Feb 9, 2023
50eb906
tests for inflation
brentstone Feb 9, 2023
25c66e7
pos misc: cargo files, debugging, test parameters
brentstone Feb 9, 2023
321e46f
upgrade total token supply tracking and balance tracking at genesis
brentstone Feb 9, 2023
c7b118b
core/token/credit_tokens: handle overflows
tzemanovic Mar 24, 2023
e5fd80c
fixes/upgrades for tests
brentstone Feb 9, 2023
3870f6f
core/ledger: fix `value` types in functions that update parameters st…
brentstone Mar 14, 2023
962b820
pos: use the native token address as staking token
tzemanovic Mar 16, 2023
7d77def
pos: update tests for validator sets updates
tzemanovic Mar 17, 2023
1e5319d
upgrade and refactor vp_token + related logic
tzemanovic Mar 24, 2023
68879ca
various import, comment and print clean-ups
tzemanovic Mar 24, 2023
bc02625
changelog: add #714
brentstone Feb 9, 2023
02c6e5a
[ci] wasm checksums update
github-actions[bot] Mar 24, 2023
bf85965
test/e2e: set PoS param tm_votes_per_token = 0.1
tzemanovic Apr 5, 2023
e5d8505
core/token: add unscaled decimal conversions
tzemanovic Apr 5, 2023
799b174
pos: fix debug assertion checking validator voting power
tzemanovic Apr 5, 2023
11b48fa
pos: improve inflation rewards error type
tzemanovic Apr 5, 2023
422a34c
pos: fix token conversion in rewards calculation
tzemanovic Apr 5, 2023
20cae15
pos: add debug log for rewards
tzemanovic Apr 5, 2023
7faef3d
pos: fix token conversion in rewards products
tzemanovic Apr 5, 2023
12dc220
[ci] wasm checksums update
github-actions[bot] Apr 5, 2023
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
6 changes: 6 additions & 0 deletions .changelog/unreleased/features/714-pos-inflation-rewards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Infrastructure for PoS inflation and rewards. Includes inflation
using the PD controller mechanism and rewards based on validator block voting
behavior. Rewards are tracked and effectively distributed using the F1 fee
mechanism. In this PR, rewards are calculated and stored, but they are not
yet applied to voting powers or considered when unbonding and withdrawing.
([#714](https://github.com/anoma/namada/pull/714))
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2407,7 +2407,7 @@ pub async fn submit_unbond(ctx: Context, args: args::Unbond) {
let data = pos::Unbond {
validator: validator.clone(),
amount: args.amount,
source,
source: Some(bond_source.clone()),
};
let data = data.try_to_vec().expect("Encoding tx data shouldn't fail");

Expand Down
45 changes: 41 additions & 4 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ pub fn genesis(base_dir: impl AsRef<Path>, chain_id: &ChainId) -> Genesis {
genesis_config::read_genesis_config(path)
}
#[cfg(feature = "dev")]
pub fn genesis() -> Genesis {
pub fn genesis(num_validators: u64) -> Genesis {
use namada::types::address;
use rust_decimal_macros::dec;

Expand All @@ -888,6 +888,9 @@ pub fn genesis() -> Genesis {
// NOTE When the validator's key changes, tendermint must be reset with
// `namada reset` command. To generate a new validator, use the
// `tests::gen_genesis_validator` below.
let mut validators = Vec::<Validator>::new();

// Use hard-coded keys for the first validator to avoid breaking other code
let consensus_keypair = wallet::defaults::validator_keypair();
let account_keypair = wallet::defaults::validator_keypair();
let address = wallet::defaults::validator_address();
Expand All @@ -908,6 +911,37 @@ pub fn genesis() -> Genesis {
validator_vp_code_path: vp_user_path.into(),
validator_vp_sha256: Default::default(),
};
validators.push(validator);

// Add other validators with randomly generated keys if needed
for _ in 0..(num_validators - 1) {
let consensus_keypair: common::SecretKey =
testing::gen_keypair::<ed25519::SigScheme>()
.try_to_sk()
.unwrap();
let account_keypair = consensus_keypair.clone();
let address = address::gen_established_address("validator account");
let (protocol_keypair, dkg_keypair) =
wallet::defaults::validator_keys();
let validator = Validator {
pos_data: GenesisValidator {
address,
tokens: token::Amount::whole(200_000),
consensus_key: consensus_keypair.ref_to(),
commission_rate: dec!(0.05),
max_commission_rate_change: dec!(0.01),
},
account_key: account_keypair.ref_to(),
protocol_key: protocol_keypair.ref_to(),
dkg_public_key: dkg_keypair.public(),
non_staked_balance: token::Amount::whole(100_000),
// TODO replace with https://github.com/anoma/namada/issues/25)
validator_vp_code_path: vp_user_path.into(),
validator_vp_sha256: Default::default(),
};
validators.push(validator);
}

let parameters = Parameters {
epoch_duration: EpochDuration {
min_num_of_blocks: 10,
Expand Down Expand Up @@ -960,7 +994,7 @@ pub fn genesis() -> Genesis {
}];
let default_user_tokens = token::Amount::whole(1_000_000);
let default_key_tokens = token::Amount::whole(1_000);
let balances: HashMap<Address, token::Amount> = HashMap::from_iter([
let mut balances: HashMap<Address, token::Amount> = HashMap::from_iter([
// established accounts' balances
(wallet::defaults::albert_address(), default_user_tokens),
(wallet::defaults::bertha_address(), default_user_tokens),
Expand All @@ -980,8 +1014,11 @@ pub fn genesis() -> Genesis {
christel.public_key.as_ref().unwrap().into(),
default_key_tokens,
),
((&validator.account_key).into(), default_key_tokens),
]);
for validator in &validators {
balances.insert((&validator.account_key).into(), default_key_tokens);
}

let token_accounts = address::tokens()
.into_keys()
.map(|address| TokenAccount {
Expand All @@ -993,7 +1030,7 @@ pub fn genesis() -> Genesis {
.collect();
Genesis {
genesis_time: DateTimeUtc::now(),
validators: vec![validator],
validators,
established_accounts: vec![albert, bertha, christel, masp],
implicit_accounts,
token_accounts,
Expand Down
9 changes: 7 additions & 2 deletions apps/src/lib/node/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ impl Shell {
match req {
Request::InitChain(init) => {
tracing::debug!("Request InitChain");
self.init_chain(init).map(Response::InitChain)
self.init_chain(
init,
#[cfg(feature = "dev")]
1,
)
.map(Response::InitChain)
}
Request::Info(_) => Ok(Response::Info(self.last_state())),
Request::Query(query) => Ok(Response::Query(self.query(query))),
Expand Down Expand Up @@ -446,7 +451,7 @@ fn start_abci_broadcaster_shell(
#[cfg(not(feature = "dev"))]
let genesis = genesis::genesis(&config.shell.base_dir, &config.chain_id);
#[cfg(feature = "dev")]
let genesis = genesis::genesis();
let genesis = genesis::genesis(1);
let (shell, abci_service) = AbcippShim::new(
config,
wasm_dir,
Expand Down
Loading