diff --git a/.changelog/unreleased/improvements/3471-remove-gov-prop-id-input.md b/.changelog/unreleased/improvements/3471-remove-gov-prop-id-input.md new file mode 100644 index 00000000000..cb70c2a2496 --- /dev/null +++ b/.changelog/unreleased/improvements/3471-remove-gov-prop-id-input.md @@ -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)) \ No newline at end of file diff --git a/crates/apps_lib/src/cli.rs b/crates/apps_lib/src/cli.rs index 2ddab6dfb46..02e6a09aa2c 100644 --- a/crates/apps_lib/src/cli.rs +++ b/crates/apps_lib/src/cli.rs @@ -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::>() } } @@ -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, diff --git a/crates/apps_lib/src/config/genesis/templates.rs b/crates/apps_lib/src/config/genesis/templates.rs index 75aea239171..253fda82680 100644 --- a/crates/apps_lib/src/config/genesis/templates.rs +++ b/crates/apps_lib/src/config/genesis/templates.rs @@ -465,9 +465,9 @@ pub struct GovernanceParams { pub struct PgfParams { /// The set of stewards pub stewards: BTreeSet
, - /// 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, diff --git a/crates/governance/src/cli/onchain.rs b/crates/governance/src/cli/onchain.rs index 9c4a1d84525..f904ef00945 100644 --- a/crates/governance/src/cli/onchain.rs +++ b/crates/governance/src/cli/onchain.rs @@ -42,7 +42,7 @@ pub struct OnChainProposal { pub activation_epoch: Epoch, } -/// Pgf default proposal +/// PGF default proposal #[derive( Debug, Clone, @@ -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 @@ -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, @@ -194,7 +194,7 @@ impl TryFrom<&[u8]> for PgfStewardProposal { } } -/// Pgf funding proposal +/// PGF funding proposal #[derive( Debug, Clone, @@ -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, @@ -263,7 +263,7 @@ impl TryFrom<&[u8]> for PgfFundingProposal { } } -/// Pgf stewards +/// PGF stewards #[derive( Debug, Clone, @@ -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, @@ -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, @@ -315,9 +315,9 @@ impl PgfAction { Deserialize, )] pub struct PgfFunding { - /// Pgf continuous funding + /// PGF continuous funding pub continuous: Vec, - /// pgf retro fundings + /// PGF retro fundings pub retro: Vec, } @@ -339,7 +339,7 @@ impl Display for PgfFunding { } } -/// Pgf continuous funding +/// PGF continuous funding #[derive( Debug, Clone, @@ -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, @@ -367,6 +367,6 @@ pub struct PgfContinuous { Deserialize, )] pub struct PgfRetro { - /// Pgf retro target + /// PGF retro target pub target: PGFTarget, } diff --git a/crates/governance/src/cli/validation.rs b/crates/governance/src/cli/validation.rs index e2dea7f907c..90982a6077e 100644 --- a/crates/governance/src/cli/validation.rs +++ b/crates/governance/src/cli/validation.rs @@ -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}.")] diff --git a/crates/governance/src/pgf/inflation.rs b/crates/governance/src/pgf/inflation.rs index da0154d3829..e3c2e64a66d 100644 --- a/crates/governance/src/pgf/inflation.rs +++ b/crates/governance/src/pgf/inflation.rs @@ -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. @@ -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 { @@ -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)? diff --git a/crates/governance/src/pgf/mod.rs b/crates/governance/src/pgf/mod.rs index 22592625cf2..f0de680e7c6 100644 --- a/crates/governance/src/pgf/mod.rs +++ b/crates/governance/src/pgf/mod.rs @@ -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 diff --git a/crates/governance/src/pgf/storage/mod.rs b/crates/governance/src/pgf/storage/mod.rs index 7dbd54f2c1d..df81e6974e1 100644 --- a/crates/governance/src/pgf/storage/mod.rs +++ b/crates/governance/src/pgf/storage/mod.rs @@ -61,7 +61,9 @@ where } /// Query the current pgf continuous payments -pub fn get_payments(storage: &S) -> Result> +pub fn get_continuous_pgf_payments( + storage: &S, +) -> Result> where S: StorageRead, { diff --git a/crates/governance/src/pgf/storage/steward.rs b/crates/governance/src/pgf/storage/steward.rs index 3d14aa74264..d0363cbcc7d 100644 --- a/crates/governance/src/pgf/storage/steward.rs +++ b/crates/governance/src/pgf/storage/steward.rs @@ -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, diff --git a/crates/node/src/shell/governance.rs b/crates/node/src/shell/governance.rs index fefa43fa55f..39a01c049ea 100644 --- a/crates/node/src/shell/governance.rs +++ b/crates/node/src/shell/governance.rs @@ -132,8 +132,7 @@ where proposal_code.clone(), )?; tracing::info!( - "Default Governance proposal {} has been executed \ - and passed.", + "Governance proposal #{} (default) has passed.", id, ); @@ -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" } ); @@ -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 ); @@ -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() @@ -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() @@ -593,8 +592,8 @@ 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() @@ -602,8 +601,8 @@ where 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(), diff --git a/crates/sdk/src/queries/vp/pgf.rs b/crates/sdk/src/queries/vp/pgf.rs index 7a4dbf06731..6276043a50a 100644 --- a/crates/sdk/src/queries/vp/pgf.rs +++ b/crates/sdk/src/queries/vp/pgf.rs @@ -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 diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 808288b812a..2a5b4908caf 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -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, @@ -2134,7 +2133,6 @@ fn propose_inflation(test: &Test) -> Result { let start_epoch = (epoch.0 + 3) / 3 * 3; let proposal_json = serde_json::json!({ "proposal": { - "id": 0, "content": { "title": "TheTitle", "authors": "test@test.com", diff --git a/crates/tests/src/e2e/ledger_tests.rs b/crates/tests/src/e2e/ledger_tests.rs index 0521f5e82a2..fc012b8b18e 100644 --- a/crates/tests/src/e2e/ledger_tests.rs +++ b/crates/tests/src/e2e/ledger_tests.rs @@ -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, - id: u64, source: Address, data: impl serde::Serialize, start_epoch: u64, ) -> PathBuf { let valid_proposal_json = json!({ "proposal": { - "id": id, "content": { "title": "TheTitle", "authors": "test@test.com", @@ -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, diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 293c81d973e..fef77e521bb 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -704,7 +704,6 @@ fn proposal_submission() -> Result<()> { let albert = defaults::albert_address(); let valid_proposal_json_path = prepare_proposal_data( node.test_dir.path(), - 0, albert.clone(), TestWasms::TxProposalCode.read_bytes(), 12, @@ -772,7 +771,6 @@ fn proposal_submission() -> Result<()> { // proposal is invalid due to voting_end_epoch - voting_start_epoch < 3 let invalid_proposal_json = prepare_proposal_data( node.test_dir.path(), - 1, albert, TestWasms::TxProposalCode.read_bytes(), 1, @@ -1041,13 +1039,8 @@ fn pgf_governance_proposal() -> Result<()> { remove: vec![], }; - let valid_proposal_json_path = prepare_proposal_data( - node.test_dir.path(), - 0, - albert, - pgf_stewards, - 12, - ); + let valid_proposal_json_path = + prepare_proposal_data(node.test_dir.path(), albert, pgf_stewards, 12); let submit_proposal_args = vec![ "init-proposal", "--pgf-stewards", @@ -1222,7 +1215,7 @@ fn pgf_governance_proposal() -> Result<()> { })], }; let valid_proposal_json_path = - prepare_proposal_data(node.test_dir.path(), 1, albert, pgf_funding, 36); + prepare_proposal_data(node.test_dir.path(), albert, pgf_funding, 36); let submit_proposal_args = vec![ "init-proposal", @@ -1365,7 +1358,6 @@ fn implicit_account_reveal_pk() -> Result<()> { let author = find_address(&node, source).unwrap(); let valid_proposal_json_path = prepare_proposal_data( node.test_dir.path(), - 0, author, TestWasms::TxProposalCode.read_bytes(), 12, diff --git a/scripts/add_proposal_wasm_code.py b/scripts/add_proposal_wasm_code.py new file mode 100755 index 00000000000..1ee2a45b036 --- /dev/null +++ b/scripts/add_proposal_wasm_code.py @@ -0,0 +1,25 @@ +import json +import argparse + +parser = argparse.ArgumentParser(description='Bingbong') +parser.add_argument('--proposal-path', type=str, help='Path to the proposal json file') +parser.add_argument('--wasm-path', type=str, help='Path to the wasm code to attach as proposal data') + +args = parser.parse_args() + +wasm_path = args.wasm_path +with open(wasm_path, 'rb') as f: + wasm_bytes = list(f.read()) + +proposal_path = args.proposal_path.strip().replace(" ", "") + +print("Proposal path: ", proposal_path) +with open(proposal_path, 'r') as f: + proposal = json.load(f) + +proposal['data'] = wasm_bytes +new_proposal_path = proposal_path.replace(".json", "_edited.json") +with open(new_proposal_path, 'w') as f: + json.dump(proposal, f) + +print(f"Add wasm to {proposal_path}") \ No newline at end of file diff --git a/scripts/default_proposal_template.json b/scripts/default_proposal_template.json new file mode 100644 index 00000000000..af529aa5ebd --- /dev/null +++ b/scripts/default_proposal_template.json @@ -0,0 +1,19 @@ +{ + "proposal": { + "content": { + "title": "XXX", + "authors": "XXX, XXX", + "discussions-to": "XXX@YYY.ZZZ", + "created": "YYYY-MM-DDTHH:MM:SSZ", + "abstract": "XXX", + "motivation": "XXX", + "details": "XXX", + "requires": "0" + }, + "author": "tnamXXX", + "voting_start_epoch": 0, + "voting_end_epoch": 0, + "activation_epoch": 0 + }, + "data": [] +} \ No newline at end of file diff --git a/scripts/funding_proposal_template.json b/scripts/funding_proposal_template.json new file mode 100644 index 00000000000..9e8b288e184 --- /dev/null +++ b/scripts/funding_proposal_template.json @@ -0,0 +1,36 @@ +{ + "proposal": { + "content": { + "title": "XXX", + "authors": "XXX, XXX", + "discussions-to": "XXX@YYY.ZZZ", + "created": "YYYY-MM-DDTHH:MM:SSZ", + "abstract": "XXX", + "motivation": "XXX", + "details": "XXX", + "requires": "0" + }, + "author": "tnamXXX", + "voting_start_epoch": 0, + "voting_end_epoch": 0, + "activation_epoch": 0 + }, + "data": { + "continuous/retro": [ + { + "Internal": { + "amount": "0", + "target": "tnamXXX" + } + }, + { + "IBC": { + "amount": "0", + "target": "", + "port_id": "", + "channel_id": "" + } + } + ] + } +} \ No newline at end of file diff --git a/scripts/steward_proposal_template.json b/scripts/steward_proposal_template.json new file mode 100644 index 00000000000..e50a57c1885 --- /dev/null +++ b/scripts/steward_proposal_template.json @@ -0,0 +1,22 @@ +{ + "proposal": { + "content": { + "title": "XXX", + "authors": "XXX, XXX", + "discussions-to": "XXX@YYY.ZZZ", + "created": "YYYY-MM-DDTHH:MM:SSZ", + "abstract": "XXX", + "motivation": "XXX", + "details": "XXX", + "requires": "0" + }, + "author": "tnamXXX", + "voting_start_epoch": 0, + "voting_end_epoch": 0, + "activation_epoch": 0 + }, + "data": { + "add": "", + "remove": [] + } +} \ No newline at end of file