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

Minor gov improvements #3471

Merged
merged 8 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Minor improvements to governance and PGF code quality, including
template gov proposal jsons and a python script to attach wasm code.
([\#3471](https://github.com/anoma/namada/pull/3471))
4 changes: 2 additions & 2 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ pub mod cmds {

fn def() -> App {
App::new(Self::CMD)
.about(wrap!("Query pgf stewards and continuous funding."))
.about(wrap!("Query PGF stewards and continuous funding."))
.add_args::<args::QueryPgf<args::CliTypes>>()
}
}
Expand Down Expand Up @@ -5618,7 +5618,7 @@ pub mod args {
.def()
.help(wrap!(
"Flag if the proposal is of type pgf-funding. \
Used to control continuous/retro pgf fundings."
Used to control continuous/retro PGF fundings."
))
.conflicts_with_all([
PROPOSAL_ETH.name,
Expand Down
4 changes: 2 additions & 2 deletions crates/apps_lib/src/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,9 @@ pub struct GovernanceParams {
pub struct PgfParams<T: TemplateValidation> {
/// The set of stewards
pub stewards: BTreeSet<Address>,
/// The pgf funding inflation rate
/// The PGF funding inflation rate
pub pgf_inflation_rate: Dec,
/// The pgf stewards inflation rate
/// The PGF stewards inflation rate
pub stewards_inflation_rate: Dec,
/// The maximum allowed number of PGF stewards at any time
pub maximum_number_of_stewards: u64,
Expand Down
40 changes: 20 additions & 20 deletions crates/governance/src/cli/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct OnChainProposal {
pub activation_epoch: Epoch,
}

/// Pgf default proposal
/// PGF default proposal
#[derive(
Debug,
Clone,
Expand Down Expand Up @@ -119,16 +119,16 @@ impl TryFrom<&[u8]> for DefaultProposal {
}
}

/// Pgf stewards proposal
/// PGF stewards proposal
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PgfStewardProposal {
/// The proposal data
pub proposal: OnChainProposal,
/// The Pgf steward proposal extra data
/// The PGF steward proposal extra data
pub data: StewardsUpdate,
}

/// Pgf steward proposal extra data
/// PGF steward proposal extra data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StewardsUpdate {
/// The optional steward to add
Expand All @@ -138,7 +138,7 @@ pub struct StewardsUpdate {
}

impl PgfStewardProposal {
/// Validate a Pgf stewards proposal
/// Validate a PGF stewards proposal
pub fn validate(
self,
governance_parameters: &GovernanceParameters,
Expand Down Expand Up @@ -194,7 +194,7 @@ impl TryFrom<&[u8]> for PgfStewardProposal {
}
}

/// Pgf funding proposal
/// PGF funding proposal
#[derive(
Debug,
Clone,
Expand All @@ -207,12 +207,12 @@ impl TryFrom<&[u8]> for PgfStewardProposal {
pub struct PgfFundingProposal {
/// The proposal data
pub proposal: OnChainProposal,
/// The Pgf funding proposal extra data
/// The PGF funding proposal extra data
pub data: PgfFunding,
}

impl PgfFundingProposal {
/// Validate a Pgf funding proposal
/// Validate a PGF funding proposal
pub fn validate(
self,
governance_parameters: &GovernanceParameters,
Expand Down Expand Up @@ -263,7 +263,7 @@ impl TryFrom<&[u8]> for PgfFundingProposal {
}
}

/// Pgf stewards
/// PGF stewards
#[derive(
Debug,
Clone,
Expand All @@ -274,13 +274,13 @@ impl TryFrom<&[u8]> for PgfFundingProposal {
Deserialize,
)]
pub struct PgfSteward {
/// Pgf action
/// PGF action
pub action: PgfAction,
/// steward address
pub address: Address,
}

/// Pgf action
/// PGF action
#[derive(
Debug,
Clone,
Expand All @@ -298,13 +298,13 @@ pub enum PgfAction {
}

impl PgfAction {
/// Check if a pgf action is adding a steward
/// Check if a PGF action is adding a steward
pub fn is_add(&self) -> bool {
matches!(self, PgfAction::Add)
}
}

/// Pgf funding
/// PGF funding
#[derive(
Debug,
Clone,
Expand All @@ -315,9 +315,9 @@ impl PgfAction {
Deserialize,
)]
pub struct PgfFunding {
/// Pgf continuous funding
/// PGF continuous funding
pub continuous: Vec<PGFTarget>,
/// pgf retro fundings
/// PGF retro fundings
pub retro: Vec<PGFTarget>,
}

Expand All @@ -339,7 +339,7 @@ impl Display for PgfFunding {
}
}

/// Pgf continuous funding
/// PGF continuous funding
#[derive(
Debug,
Clone,
Expand All @@ -350,13 +350,13 @@ impl Display for PgfFunding {
Deserialize,
)]
pub struct PgfContinuous {
/// Pgf target
/// PGF target
pub target: PGFTarget,
/// Pgf action
/// PGF action
pub action: PgfAction,
}

/// Pgf retro funding
/// PGF retro funding
#[derive(
Debug,
Clone,
Expand All @@ -367,6 +367,6 @@ pub struct PgfContinuous {
Deserialize,
)]
pub struct PgfRetro {
/// Pgf retro target
/// PGF retro target
pub target: PGFTarget,
}
4 changes: 2 additions & 2 deletions crates/governance/src/cli/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ pub enum ProposalValidation {
({0}) is to big (max {1})"
)]
InvalidDefaultProposalExtraData(u64, u64),
/// The pgf stewards data is not valid
/// The PGF stewards data is not valid
#[error("Invalid proposal extra data: cannot be empty.")]
InvalidPgfStewardsExtraData,
/// The pgf funding data is not valid
/// The PGF funding data is not valid
#[error("invalid proposal extra data: cannot be empty.")]
InvalidPgfFundingExtraData,
#[error("Arithmetic {0}.")]
Expand Down
10 changes: 6 additions & 4 deletions crates/governance/src/pgf/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use namada_parameters::storage as params_storage;
use namada_storage::{Result, StorageRead, StorageWrite};
use namada_trans_token::{credit_tokens, get_effective_total_native_supply};

use crate::pgf::storage::{get_parameters, get_payments, get_stewards};
use crate::pgf::storage::{
get_continuous_pgf_payments, get_parameters, get_stewards,
};
use crate::storage::proposal::{PGFIbcTarget, PGFTarget};

/// Apply the PGF inflation.
Expand Down Expand Up @@ -44,8 +46,8 @@ where
total_supply.to_string_native()
);

let mut pgf_fundings = get_payments(storage)?;
// we want to pay first the oldest fundings
let mut pgf_fundings = get_continuous_pgf_payments(storage)?;
// prioritize the payments by oldest gov proposal ID
pgf_fundings.sort_by(|a, b| a.id.cmp(&b.id));

for funding in pgf_fundings {
Expand Down Expand Up @@ -82,7 +84,7 @@ where
}
}

// Pgf steward inflation
// PGF steward inflation
let stewards = get_stewards(storage)?;
let pgf_steward_inflation = total_supply
.mul_floor(pgf_parameters.stewards_inflation_rate)?
Expand Down
12 changes: 6 additions & 6 deletions crates/governance/src/pgf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//! Pgf library code
//! PGF library code

use namada_core::address::{Address, InternalAddress};

/// Pgf CLI
/// PGF CLI
pub mod cli;
/// Pgf inflation code
/// PGF inflation code
pub mod inflation;
/// Pgf parameters
/// PGF parameters
pub mod parameters;
/// Pgf storage
/// PGF storage
pub mod storage;

/// The Pgf internal address
/// The PGF internal address
pub const ADDRESS: Address = Address::Internal(InternalAddress::Pgf);

/// Upper limit on the number of reward distribution per steawrd
Expand Down
4 changes: 3 additions & 1 deletion crates/governance/src/pgf/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ where
}

/// Query the current pgf continuous payments
pub fn get_payments<S>(storage: &S) -> Result<Vec<StoragePgfFunding>>
pub fn get_continuous_pgf_payments<S>(
storage: &S,
) -> Result<Vec<StoragePgfFunding>>
where
S: StorageRead,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/governance/src/pgf/storage/steward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::pgf::REWARD_DISTRIBUTION_LIMIT;
#[derive(
Clone, Debug, BorshSerialize, BorshDeserialize, BorshDeserializer, PartialEq,
)]
/// Struct holding data about a pgf steward
/// Struct holding data about a PGF steward
pub struct StewardDetail {
/// The steward address
pub address: Address,
Expand Down
27 changes: 13 additions & 14 deletions crates/node/src/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ where
proposal_code.clone(),
)?;
tracing::info!(
"Default Governance proposal {} has been executed \
and passed.",
"Governance proposal #{} (default) has passed.",
id,
);

Expand All @@ -149,8 +148,8 @@ where
proposal_code.clone(),
)?;
tracing::info!(
"DefaultWithWasm Governance proposal {} has been \
executed and passed, wasm executiong was {}.",
"Governance proposal #{} (default with wasm) has \
passed and been executed, wasm execution: {}.",
id,
if result { "successful" } else { "unsuccessful" }
);
Expand Down Expand Up @@ -186,8 +185,8 @@ where
id,
)?;
tracing::info!(
"Governance proposal (pgf funding) {} has been \
executed and passed.",
"Governance proposal #{} for PGF funding has \
passed and been executed.",
id
);

Expand Down Expand Up @@ -529,8 +528,8 @@ where
StoragePgfFunding::new(target.clone(), proposal_id),
)?;
tracing::info!(
"Added/Updated ContinuousPgf from proposal id {}: set \
{} to {}.",
"Added/Updated Continuous PGF from proposal id {}: \
set {} to {}.",
proposal_id,
target.amount().to_string_native(),
target.target()
Expand All @@ -540,8 +539,8 @@ where
pgf_storage::fundings_handle()
.remove(state, &target.target())?;
tracing::info!(
"Removed ContinuousPgf from proposal id {}: set {} to \
{}.",
"Removed Continuous PGF from proposal id {}: set {} \
to {}.",
proposal_id,
target.amount().to_string_native(),
target.target()
Expand Down Expand Up @@ -593,17 +592,17 @@ where
match result {
Ok(()) => {
tracing::info!(
"Execute RetroPgf from proposal id {}: sent {} to \
{}.",
"Execute Retroactive PGF from proposal id {}: \
sent {} to {}.",
proposal_id,
target.amount().to_string_native(),
target.target()
);
events.emit(event);
}
Err(e) => tracing::warn!(
"Error in RetroPgf transfer from proposal id {}, \
amount {} to {}: {}",
"Error in Retroactive PGF transfer from proposal id \
{}, amount {} to {}: {}",
proposal_id,
target.amount().to_string_native(),
target.target(),
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/src/queries/vp/pgf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
{
namada_governance::pgf::storage::get_payments(ctx.state)
namada_governance::pgf::storage::get_continuous_pgf_payments(ctx.state)
}

/// Query the PGF parameters
Expand Down
2 changes: 0 additions & 2 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,6 @@ fn propose_funding(
let start_epoch = (epoch.0 + 6) / 3 * 3;
let proposal_json_path = prepare_proposal_data(
test_a.test_dir.path(),
0,
albert,
pgf_funding,
start_epoch,
Expand Down Expand Up @@ -2134,7 +2133,6 @@ fn propose_inflation(test: &Test) -> Result<Epoch> {
let start_epoch = (epoch.0 + 3) / 3 * 3;
let proposal_json = serde_json::json!({
"proposal": {
"id": 0,
"content": {
"title": "TheTitle",
"authors": "[email protected]",
Expand Down
3 changes: 0 additions & 3 deletions crates/tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,14 +1404,12 @@ fn test_epoch_sleep() -> Result<()> {
/// This can be submitted with "init-proposal" command.
pub fn prepare_proposal_data(
test_dir: impl AsRef<std::path::Path>,
id: u64,
source: Address,
data: impl serde::Serialize,
start_epoch: u64,
) -> PathBuf {
let valid_proposal_json = json!({
"proposal": {
"id": id,
"content": {
"title": "TheTitle",
"authors": "[email protected]",
Expand Down Expand Up @@ -1946,7 +1944,6 @@ fn proposal_change_shielded_reward() -> Result<()> {
let albert = find_address(&test, ALBERT)?;
let valid_proposal_json_path = prepare_proposal_data(
test.test_dir.path(),
0,
albert,
TestWasms::TxProposalMaspRewards.read_bytes(),
12,
Expand Down
Loading
Loading