Skip to content

Commit

Permalink
rename grace_epoch to activation_epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Feb 28, 2024
1 parent 51f7f35 commit 30317de
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 125 deletions.
2 changes: 1 addition & 1 deletion crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Default for BenchShell {
r#type: ProposalType::Default(None),
voting_start_epoch,
voting_end_epoch: voting_start_epoch + 3_u64,
grace_epoch: voting_start_epoch + 9_u64,
activation_epoch: voting_start_epoch + 9_u64,

Check warning on line 258 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L258

Added line #L258 was not covered by tests
},
None,
Some(vec![content_section]),
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ pub struct GovernanceParams {
pub max_proposal_period: u64,
/// Maximum number of characters in the proposal content
pub max_proposal_content_size: u64,
/// Minimum number of epoch between end and grace epoch
/// Minimum number of epochs between the end and activation epochs
pub min_proposal_grace_epochs: u64,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ mod test_finalize_block {
author: validator.clone(),
voting_start_epoch: Epoch::default(),
voting_end_epoch: Epoch::default().next(),
grace_epoch: Epoch::default().next(),
activation_epoch: Epoch::default().next(),
r#type: ProposalType::Default(None),
};

Expand Down
6 changes: 3 additions & 3 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn governance(c: &mut Criterion) {
r#type: ProposalType::Default(None),
voting_start_epoch,
voting_end_epoch: voting_start_epoch + 3_u64,
grace_epoch: voting_start_epoch + 9_u64,
activation_epoch: voting_start_epoch + 9_u64,
},
None,
Some(vec![content_section]),
Expand Down Expand Up @@ -179,7 +179,7 @@ fn governance(c: &mut Criterion) {
)),
voting_start_epoch,
voting_end_epoch: voting_start_epoch + 3_u64,
grace_epoch: voting_start_epoch + 9_u64,
activation_epoch: voting_start_epoch + 9_u64,
},
None,
Some(vec![content_section, wasm_code_section]),
Expand Down Expand Up @@ -251,7 +251,7 @@ fn governance(c: &mut Criterion) {
// r#type: ProposalType::Default(None),
// voting_start_epoch: 12.into(),
// voting_end_epoch: 15.into(),
// grace_epoch: 18.into(),
// activation_epoch: 18.into(),
// },
// None,
// Some(vec![content_section]),
Expand Down
4 changes: 2 additions & 2 deletions crates/benches/txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ fn init_proposal(c: &mut Criterion) {
r#type: ProposalType::Default(None),
voting_start_epoch: 12.into(),
voting_end_epoch: 15.into(),
grace_epoch: 18.into(),
activation_epoch: 18.into(),
},
None,
Some(vec![content_section]),
Expand Down Expand Up @@ -517,7 +517,7 @@ fn init_proposal(c: &mut Criterion) {
)),
voting_start_epoch: 12.into(),
voting_end_epoch: 15.into(),
grace_epoch: 18.into(),
activation_epoch: 18.into(),
},
None,
Some(vec![content_section, wasm_code_section]),
Expand Down
34 changes: 17 additions & 17 deletions crates/governance/src/cli/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use namada_core::token;
use serde::{Deserialize, Serialize};

use super::validation::{
is_valid_author_balance, is_valid_content, is_valid_default_proposal_data,
is_valid_end_epoch, is_valid_grace_epoch, is_valid_pgf_funding_data,
is_valid_pgf_stewards_data, is_valid_proposal_period, is_valid_start_epoch,
ProposalValidation,
is_valid_activation_epoch, is_valid_author_balance, is_valid_content,
is_valid_default_proposal_data, is_valid_end_epoch,
is_valid_pgf_funding_data, is_valid_pgf_stewards_data,
is_valid_proposal_period, is_valid_start_epoch, ProposalValidation,
};
use crate::parameters::GovernanceParameters;
use crate::storage::proposal::PGFTarget;
Expand All @@ -27,12 +27,12 @@ pub struct OnChainProposal {
pub content: BTreeMap<String, String>,
/// The proposal author address
pub author: Address,
/// The epoch from which voting is allowed
/// The epoch in which voting begins
pub voting_start_epoch: Epoch,
/// The epoch from which voting is stopped
/// The final epoch in which voting is allowed
pub voting_end_epoch: Epoch,
/// The epoch from which this changes are executed
pub grace_epoch: Epoch,
/// The epoch in which any changes are executed and become active
pub activation_epoch: Epoch,
}

/// Pgf default proposal
Expand Down Expand Up @@ -71,14 +71,14 @@ impl DefaultProposal {
governance_parameters.min_proposal_voting_period,
governance_parameters.max_proposal_period,
)?;
is_valid_grace_epoch(
self.proposal.grace_epoch,
is_valid_activation_epoch(
self.proposal.activation_epoch,

Check warning on line 75 in crates/governance/src/cli/onchain.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/onchain.rs#L74-L75

Added lines #L74 - L75 were not covered by tests
self.proposal.voting_end_epoch,
governance_parameters.min_proposal_grace_epochs,
)?;
is_valid_proposal_period(
self.proposal.voting_start_epoch,
self.proposal.grace_epoch,
self.proposal.activation_epoch,

Check warning on line 81 in crates/governance/src/cli/onchain.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/onchain.rs#L81

Added line #L81 was not covered by tests
governance_parameters.max_proposal_period,
)?;
is_valid_author_balance(
Expand Down Expand Up @@ -149,14 +149,14 @@ impl PgfStewardProposal {
governance_parameters.min_proposal_voting_period,
governance_parameters.max_proposal_period,
)?;
is_valid_grace_epoch(
self.proposal.grace_epoch,
is_valid_activation_epoch(
self.proposal.activation_epoch,

Check warning on line 153 in crates/governance/src/cli/onchain.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/onchain.rs#L152-L153

Added lines #L152 - L153 were not covered by tests
self.proposal.voting_end_epoch,
governance_parameters.min_proposal_grace_epochs,
)?;
is_valid_proposal_period(
self.proposal.voting_start_epoch,
self.proposal.grace_epoch,
self.proposal.activation_epoch,

Check warning on line 159 in crates/governance/src/cli/onchain.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/onchain.rs#L159

Added line #L159 was not covered by tests
governance_parameters.max_proposal_period,
)?;
is_valid_author_balance(
Expand Down Expand Up @@ -216,14 +216,14 @@ impl PgfFundingProposal {
governance_parameters.min_proposal_voting_period,
governance_parameters.max_proposal_period,
)?;
is_valid_grace_epoch(
self.proposal.grace_epoch,
is_valid_activation_epoch(
self.proposal.activation_epoch,

Check warning on line 220 in crates/governance/src/cli/onchain.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/onchain.rs#L219-L220

Added lines #L219 - L220 were not covered by tests
self.proposal.voting_end_epoch,
governance_parameters.min_proposal_grace_epochs,
)?;
is_valid_proposal_period(
self.proposal.voting_start_epoch,
self.proposal.grace_epoch,
self.proposal.activation_epoch,

Check warning on line 226 in crates/governance/src/cli/onchain.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/onchain.rs#L226

Added line #L226 was not covered by tests
governance_parameters.max_proposal_period,
)?;
is_valid_content(
Expand Down
32 changes: 16 additions & 16 deletions crates/governance/src/cli/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ pub enum ProposalValidation {
a multiple of {0}"
)]
InvalidStartEndDifference(u64, u64),
/// The proposal difference between end and grace epoch is invalid
/// The proposal difference between end and activation epoch is invalid
#[error(
"Invalid proposal grace epoch: difference between proposal grace and \
end epoch must be at least {0}, but found {1}"
"Invalid proposal activation epoch: difference between proposal \
activation and end epoch must be at least {0}, but found {1}"
)]
InvalidEndGraceDifference(u64, u64),
/// The proposal difference between end and grace epoch is invalid
InvalidEndActivationDifference(u64, u64),
/// The proposal difference between end and activation epoch is invalid
#[error(
"Invalid proposal period: difference between proposal start and grace \
epoch must be at most {1}, but found {0}"
"Invalid proposal period: difference between proposal start and \
activation epoch must be at most {1}, but found {0}"
)]
InvalidProposalPeriod(u64, u64),
/// The proposal author does not have enough balance to pay for proposal
Expand Down Expand Up @@ -130,29 +130,29 @@ pub fn is_valid_end_epoch(
}
}

pub fn is_valid_grace_epoch(
proposal_grace_epoch: Epoch,
pub fn is_valid_activation_epoch(
proposal_activation_epoch: Epoch,

Check warning on line 134 in crates/governance/src/cli/validation.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/validation.rs#L133-L134

Added lines #L133 - L134 were not covered by tests
proposal_end_epoch: Epoch,
min_proposal_grace_epoch: u64,
min_proposal_grace_epochs: u64,

Check warning on line 136 in crates/governance/src/cli/validation.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/validation.rs#L136

Added line #L136 was not covered by tests
) -> Result<(), ProposalValidation> {
let grace_period = proposal_grace_epoch.0 - proposal_end_epoch.0;
let grace_period = proposal_activation_epoch.0 - proposal_end_epoch.0;

Check warning on line 138 in crates/governance/src/cli/validation.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/validation.rs#L138

Added line #L138 was not covered by tests

if grace_period > 0 && grace_period >= min_proposal_grace_epoch {
if grace_period > 0 && grace_period >= min_proposal_grace_epochs {

Check warning on line 140 in crates/governance/src/cli/validation.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/validation.rs#L140

Added line #L140 was not covered by tests
Ok(())
} else {
Err(ProposalValidation::InvalidEndGraceDifference(
min_proposal_grace_epoch,
Err(ProposalValidation::InvalidEndActivationDifference(
min_proposal_grace_epochs,

Check warning on line 144 in crates/governance/src/cli/validation.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/validation.rs#L143-L144

Added lines #L143 - L144 were not covered by tests
grace_period,
))
}
}

pub fn is_valid_proposal_period(
proposal_start_epoch: Epoch,
proposal_grace_epoch: Epoch,
proposal_activation_epoch: Epoch,

Check warning on line 152 in crates/governance/src/cli/validation.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/validation.rs#L152

Added line #L152 was not covered by tests
max_proposal_period: u64,
) -> Result<(), ProposalValidation> {
let proposal_period = proposal_grace_epoch.0 - proposal_start_epoch.0;
let proposal_period = proposal_activation_epoch.0 - proposal_start_epoch.0;

Check warning on line 155 in crates/governance/src/cli/validation.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/cli/validation.rs#L155

Added line #L155 was not covered by tests

if proposal_period > 0 && proposal_period <= max_proposal_period {
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions crates/governance/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct GovernanceParameters {
pub max_proposal_period: u64,
/// Maximum number of characters for proposal content
pub max_proposal_content_size: u64,
/// Minimum epochs between end and grace epochs
/// Minimum number of epochs between the end and activation epochs
pub min_proposal_grace_epochs: u64,
}

Expand Down Expand Up @@ -83,10 +83,10 @@ impl GovernanceParameters {
storage
.write(&max_proposal_content_size_key, max_proposal_content_size)?;

let min_proposal_grace_epoch_key =
goverance_storage::get_min_proposal_grace_epoch_key();
let min_proposal_grace_epochs_key =
goverance_storage::get_min_proposal_grace_epochs_key();
storage
.write(&min_proposal_grace_epoch_key, min_proposal_grace_epochs)?;
.write(&min_proposal_grace_epochs_key, min_proposal_grace_epochs)?;

let counter_key = goverance_storage::get_counter_key();
storage.write(&counter_key, u64::MIN)
Expand Down
34 changes: 17 additions & 17 deletions crates/governance/src/storage/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Keys {
content: &'static str,
start_epoch: &'static str,
end_epoch: &'static str,
grace_epoch: &'static str,
activation_epoch: &'static str,
funds: &'static str,
proposal_code: &'static str,
committing_epoch: &'static str,
Expand All @@ -23,7 +23,7 @@ struct Keys {
min_period: &'static str,
max_period: &'static str,
max_content: &'static str,
min_grace_epoch: &'static str,
min_grace_epochs: &'static str,
counter: &'static str,
pending: &'static str,
result: &'static str,
Expand Down Expand Up @@ -90,17 +90,17 @@ pub fn is_proposal_code_key(key: &Key) -> bool {
}
}

/// Check if key is grace epoch key
pub fn is_grace_epoch_key(key: &Key) -> bool {
/// Check if key is activation epoch key
pub fn is_activation_epoch_key(key: &Key) -> bool {

Check warning on line 94 in crates/governance/src/storage/keys.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/keys.rs#L94

Added line #L94 was not covered by tests
match &key.segments[..] {
[
DbKeySeg::AddressSeg(addr),
DbKeySeg::StringSeg(prefix),
DbKeySeg::StringSeg(id),
DbKeySeg::StringSeg(grace_epoch),
DbKeySeg::StringSeg(activation_epoch),

Check warning on line 100 in crates/governance/src/storage/keys.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/keys.rs#L100

Added line #L100 was not covered by tests
] if addr == &ADDRESS
&& prefix == Keys::VALUES.proposal
&& grace_epoch == Keys::VALUES.grace_epoch =>
&& activation_epoch == Keys::VALUES.activation_epoch =>

Check warning on line 103 in crates/governance/src/storage/keys.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/keys.rs#L103

Added line #L103 was not covered by tests
{
id.parse::<u64>().is_ok()
}
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn is_max_proposal_period_key(key: &Key) -> bool {
&& max_proposal_period_param == Keys::VALUES.max_period)
}

/// Check if key is a min grace epoch key
/// Check if key is a min grace epochs key
pub fn is_commit_proposal_key(key: &Key) -> bool {
matches!(&key.segments[..], [
DbKeySeg::AddressSeg(addr),
Expand All @@ -262,12 +262,12 @@ pub fn is_commit_proposal_key(key: &Key) -> bool {
}

/// Check if key is a commit proposal key
pub fn is_min_grace_epoch_key(key: &Key) -> bool {
pub fn is_min_grace_epochs_key(key: &Key) -> bool {

Check warning on line 265 in crates/governance/src/storage/keys.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/keys.rs#L265

Added line #L265 was not covered by tests
matches!(&key.segments[..], [
DbKeySeg::AddressSeg(addr),
DbKeySeg::StringSeg(min_grace_epoch_param),
DbKeySeg::StringSeg(min_grace_epochs_param),

Check warning on line 268 in crates/governance/src/storage/keys.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/keys.rs#L268

Added line #L268 was not covered by tests
] if addr == &ADDRESS
&& min_grace_epoch_param == Keys::VALUES.min_grace_epoch)
&& min_grace_epochs_param == Keys::VALUES.min_grace_epochs)

Check warning on line 270 in crates/governance/src/storage/keys.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/keys.rs#L270

Added line #L270 was not covered by tests
}

/// Check if key is parameter key
Expand All @@ -277,7 +277,7 @@ pub fn is_parameter_key(key: &Key) -> bool {
|| is_max_proposal_code_size_key(key)
|| is_min_proposal_voting_period_key(key)
|| is_max_proposal_period_key(key)
|| is_min_grace_epoch_key(key)
|| is_min_grace_epochs_key(key)

Check warning on line 280 in crates/governance/src/storage/keys.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/keys.rs#L280

Added line #L280 was not covered by tests
}

/// Check if key is start epoch or end epoch key
Expand Down Expand Up @@ -327,10 +327,10 @@ pub fn get_max_proposal_content_key() -> Key {
.expect("Cannot obtain a storage key")
}

/// Get min grace epoch proposal key
pub fn get_min_proposal_grace_epoch_key() -> Key {
/// Get min grace epochs proposal key
pub fn get_min_proposal_grace_epochs_key() -> Key {
Key::from(ADDRESS.to_db_key())
.push(&Keys::VALUES.min_grace_epoch.to_owned())
.push(&Keys::VALUES.min_grace_epochs.to_owned())
.expect("Cannot obtain a storage key")
}

Expand Down Expand Up @@ -395,12 +395,12 @@ pub fn get_funds_key(id: u64) -> Key {
.expect("Cannot obtain a storage key")
}

/// Get proposal grace epoch key
pub fn get_grace_epoch_key(id: u64) -> Key {
/// Get proposal activation epoch key
pub fn get_activation_epoch_key(id: u64) -> Key {
proposal_prefix()
.push(&id.to_string())
.expect("Cannot obtain a storage key")
.push(&Keys::VALUES.grace_epoch.to_owned())
.push(&Keys::VALUES.activation_epoch.to_owned())
.expect("Cannot obtain a storage key")
}

Expand Down
Loading

0 comments on commit 30317de

Please sign in to comment.