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

Fix governance bugs #2133

Merged
merged 5 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
25 changes: 11 additions & 14 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,17 +800,7 @@ where
let pgf_pd_rate =
pgf_parameters.pgf_inflation_rate / Dec::from(epochs_per_year);
let pgf_inflation = Dec::from(total_tokens) * pgf_pd_rate;

let stewards = pgf::get_stewards(&self.wl_storage)?;
let pgf_stewards_pd_rate =
pgf_parameters.stewards_inflation_rate / Dec::from(epochs_per_year);
let pgf_steward_inflation =
Dec::from(total_tokens) * pgf_stewards_pd_rate;
let total_pgf_stewards_inflation =
pgf_steward_inflation * Dec::from(stewards.len());

let pgf_inflation_amount =
token::Amount::from(pgf_inflation + total_pgf_stewards_inflation);
let pgf_inflation_amount = token::Amount::from(pgf_inflation);

credit_tokens(
&mut self.wl_storage,
Expand All @@ -830,29 +820,36 @@ where
pgf_fundings.sort_by(|a, b| a.id.cmp(&b.id));

for funding in pgf_fundings {
if credit_tokens(
if storage_api::token::transfer(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is complete, we also need to update/change https://github.com/anoma/namada/blob/main/apps/src/lib/node/ledger/shell/finalize_block.rs#L858 - I think we can actually use credit_tokens there, but then we shouldn't send the steward inflation to the PGF account in the first place (https://github.com/anoma/namada/blob/main/apps/src/lib/node/ledger/shell/finalize_block.rs#L812)

&mut self.wl_storage,
&staking_token,
&pgf_address,
&funding.detail.target,
funding.detail.amount,
)
.is_ok()
{
tracing::info!(
"Minted {} tokens for {} project.",
"Paying {} tokens for {} project.",
funding.detail.amount.to_string_native(),
&funding.detail.target,
);
} else {
tracing::warn!(
"Failed Minting {} tokens for {} project.",
"Failed to pay {} tokens for {} project.",
funding.detail.amount.to_string_native(),
&funding.detail.target,
);
}
}

// Pgf steward inflation
let stewards = pgf::get_stewards(&self.wl_storage)?;
let pgf_stewards_pd_rate =
pgf_parameters.stewards_inflation_rate / Dec::from(epochs_per_year);
let pgf_steward_inflation =
Dec::from(total_tokens) * pgf_stewards_pd_rate;

for steward in stewards {
for (address, percentage) in steward.reward_distribution {
let pgf_steward_reward = pgf_steward_inflation
Expand Down
2 changes: 1 addition & 1 deletion proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ pub fn is_delegator<S>(
epoch: Option<namada_core::types::storage::Epoch>,
) -> storage_api::Result<bool>
where
S: StorageRead + StorageWrite,
S: StorageRead,
{
let prefix = bonds_for_source_prefix(address);
match epoch {
Expand Down
20 changes: 7 additions & 13 deletions shared/src/ledger/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,19 +671,13 @@ where
address: &Address,
delegation_address: &Address,
) -> Result<bool> {
let bond_handle = pos::namada_proof_of_stake::bond_handle(
address,
delegation_address,
);
let params =
pos::namada_proof_of_stake::read_pos_params(&self.ctx.pre())?;
let bond = bond_handle.get_sum(&self.ctx.pre(), epoch, &params)?;

if bond.is_some() && verifiers.contains(address) {
Ok(true)
} else {
Ok(false)
}
Ok(address != delegation_address
&& verifiers.contains(address)
&& pos::namada_proof_of_stake::is_delegator(
&self.ctx.pre(),
address,
Some(epoch),
)?)
}
}

Expand Down
Loading