Skip to content
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
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/3442-limit-pgf-stewards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Enforce an upper limit on the number of PGF stewards allowed to exist at a
given time. ([\#3442](https://github.com/anoma/namada/pull/3442))
1 change: 1 addition & 0 deletions crates/apps_lib/src/config/genesis/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ impl FinalizedParameters {
stewards: pgf_params.stewards,
pgf_inflation_rate: pgf_params.pgf_inflation_rate,
stewards_inflation_rate: pgf_params.stewards_inflation_rate,
maximum_number_of_stewards: pgf_params.maximum_number_of_stewards,
};
Self {
parameters,
Expand Down
4 changes: 4 additions & 0 deletions crates/apps_lib/src/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ pub struct PgfParams<T: TemplateValidation> {
pub pgf_inflation_rate: Dec,
/// 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,
#[serde(default)]
#[serde(skip_serializing)]
#[cfg(test)]
Expand Down Expand Up @@ -913,6 +915,8 @@ pub fn validate_parameters(
stewards: pgf_params.stewards,
pgf_inflation_rate: pgf_params.pgf_inflation_rate,
stewards_inflation_rate: pgf_params.stewards_inflation_rate,
maximum_number_of_stewards: pgf_params
.maximum_number_of_stewards,
valid: Default::default(),
},
eth_bridge_params,
Expand Down
11 changes: 10 additions & 1 deletion crates/governance/src/pgf/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct PgfParameters {
pub pgf_inflation_rate: Dec,
/// The pgf stewards inflation rate
pub stewards_inflation_rate: Dec,
/// The maximum number of pgf stewards at once
pub maximum_number_of_stewards: u64,
}

impl Default for PgfParameters {
Expand All @@ -42,6 +44,7 @@ impl Default for PgfParameters {
stewards: BTreeSet::default(),
pgf_inflation_rate: Dec::new(10, 2).unwrap(),
stewards_inflation_rate: Dec::new(1, 2).unwrap(),
maximum_number_of_stewards: 5,
}
}
}
Expand All @@ -56,6 +59,7 @@ impl PgfParameters {
stewards,
pgf_inflation_rate,
stewards_inflation_rate,
maximum_number_of_stewards,
} = self;

for steward in stewards {
Expand All @@ -71,6 +75,11 @@ impl PgfParameters {

let steward_inflation_rate_key =
pgf_storage::get_steward_inflation_rate_key();
storage.write(&steward_inflation_rate_key, stewards_inflation_rate)
storage.write(&steward_inflation_rate_key, stewards_inflation_rate)?;

let maximum_number_of_stewards_key =
pgf_storage::get_maximum_number_of_pgf_steward_key();
storage
.write(&maximum_number_of_stewards_key, maximum_number_of_stewards)
}
}
8 changes: 8 additions & 0 deletions crates/governance/src/pgf/storage/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Keys {
fundings: &'static str,
pgf_inflation_rate: &'static str,
steward_inflation_rate: &'static str,
maximum_number_of_stewards: &'static str,
}

/// Obtain a storage key for stewards key
Expand Down Expand Up @@ -94,6 +95,13 @@ pub fn get_pgf_inflation_rate_key() -> Key {
.expect("Cannot obtain a storage key")
}

/// Get key for maximum number of pgf stewards
pub fn get_maximum_number_of_pgf_steward_key() -> Key {
Key::from(ADDRESS.to_db_key())
.push(&Keys::VALUES.maximum_number_of_stewards.to_owned())
.expect("Cannot obtain a storage key")
}

/// Get key for inflation rate key
pub fn get_steward_inflation_rate_key() -> Key {
Key::from(ADDRESS.to_db_key())
Expand Down
61 changes: 45 additions & 16 deletions crates/node/src/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,20 @@ where
GovernanceEvent::passed_proposal(id, true, result)
}
ProposalType::PGFSteward(stewards) => {
let _result = execute_pgf_steward_proposal(
let result = execute_pgf_steward_proposal(
&mut shell.state,
stewards,
)?;
tracing::info!(
"Governance proposal (pgf stewards){} has been \
executed and passed.",
id
"Governance proposal #{} for PGF stewards has \
been executed. {}.",
id,
if result {
"State changes have been applied successfully"
} else {
"FAILURE trying to apply the state changes - \
no state change occurred"
}
);

GovernanceEvent::passed_proposal(id, false, false)
Expand Down Expand Up @@ -461,18 +467,41 @@ fn execute_pgf_steward_proposal<S>(
where
S: StorageRead + StorageWrite,
{
for action in stewards {
match action {
AddRemove::Add(address) => {
pgf_storage::stewards_handle().insert(
storage,
address.to_owned(),
StewardDetail::base(address),
)?;
}
AddRemove::Remove(address) => {
pgf_storage::stewards_handle().remove(storage, &address)?;
}
let maximum_number_of_pgf_steward_key =
pgf_storage::get_maximum_number_of_pgf_steward_key();
let maximum_number_of_pgf_steward = storage
.read::<u64>(&maximum_number_of_pgf_steward_key)?
.expect(
"Pgf parameter maximum_number_of_pgf_steward must be in storage",
);

// First, remove the appropriate addresses
for address in stewards.iter().filter_map(|action| match action {
AddRemove::Add(_) => None,
AddRemove::Remove(address) => Some(address),
}) {
pgf_storage::stewards_handle().remove(storage, address)?;
}

// Then add new addresses
let mut steward_count = pgf_storage::stewards_handle().len(storage)?;
for address in stewards.iter().filter_map(|action| match action {
AddRemove::Add(address) => Some(address),
AddRemove::Remove(_) => None,
}) {
#[allow(clippy::arithmetic_side_effects)]
if steward_count + 1 > maximum_number_of_pgf_steward {
return Ok(false);
}
pgf_storage::stewards_handle().insert(
storage,
address.to_owned(),
StewardDetail::base(address.to_owned()),
)?;

#[allow(clippy::arithmetic_side_effects)]
{
steward_count += 1;
}
}

Expand Down
2 changes: 2 additions & 0 deletions genesis/localnet/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ stewards = [
pgf_inflation_rate = "0.1"
# The pgf stewards inflation rate
stewards_inflation_rate = "0.01"
# The maximum number of pgf stewards
maximum_number_of_stewards = 5

# IBC parameters
[ibc_params]
Expand Down
2 changes: 2 additions & 0 deletions genesis/starter/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ stewards = []
pgf_inflation_rate = "0.1"
# The pgf stewards inflation rate
stewards_inflation_rate = "0.01"
# The maximum number of pgf stewards
maximum_number_of_stewards = 5

# IBC parameters
[ibc_params]
Expand Down