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

Governance Abstain vote #2128

Merged
merged 8 commits into from
Nov 11, 2023
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/SDK/2128-governance-abstain-vote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updated the `LedgerProposalVote` display method to account for the new
`Abstain` vote variant. ([\#2128](https://github.com/anoma/namada/pull/2128))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added the option to abstain from voting a governance proposal.
([\#2128](https://github.com/anoma/namada/pull/2128))
2 changes: 1 addition & 1 deletion apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ pub async fn query_proposal_result<'a>(
let proposal_result = compute_proposal_result(
proposal_votes,
total_voting_power,
TallyType::TwoThird,
TallyType::TwoThirds,
);

display_line!(
Expand Down
7 changes: 4 additions & 3 deletions apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,17 @@ where
}
TallyResult::Rejected => {
if let ProposalType::PGFPayment(_) = proposal_type {
let two_third_nay = proposal_result.two_third_nay();
if two_third_nay {
if proposal_result.two_thirds_nay_over_two_thirds_total() {
pgf::remove_steward(
&mut shell.wl_storage,
&proposal_author,
)?;

tracing::info!(
"Governance proposal {} was rejected with 2/3 of \
nay votes. Removing {} from stewards set.",
nay votes over 2/3 of the total voting power. If \
{} is a steward, it's being removed from the \
stewards set.",
id,
proposal_author
);
Expand Down
15 changes: 15 additions & 0 deletions core/src/ledger/governance/cli/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@ impl OfflineVote {
self.vote.is_yay()
}

/// Check if the vote is nay
pub fn is_nay(&self) -> bool {
self.vote.is_nay()
}

/// Check if the vote is abstain
pub fn is_abstain(&self) -> bool {
self.vote.is_abstain()
}

/// Check if two votes are equal
pub fn is_same_side(&self, other: &Self) -> bool {
self.vote.is_same_side(&other.vote)
}

/// compute the hash of a proposal
pub fn compute_hash(&self) -> Hash {
let proposal_hash_data = self.proposal_hash.serialize_to_vec();
Expand Down
28 changes: 22 additions & 6 deletions core/src/ledger/governance/cli/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub struct PgfFundingTarget {
pub address: Address,
}

/// Rappresent an proposal vote
/// Represent an proposal vote
#[derive(
Debug,
Clone,
Expand All @@ -324,12 +324,12 @@ pub struct PgfFundingTarget {
PartialEq,
)]
pub enum ProposalVote {
/// Rappresent an yay proposal vote
/// Represent an yay proposal vote
Yay,
/// Rappresent an nay proposal vote
/// Represent an nay proposal vote
Nay,
/// Rappresent an invalid proposal vote
Invalid,
/// Represent an abstain proposal vote
Abstain,
}

impl TryFrom<String> for ProposalVote {
Expand All @@ -339,14 +339,30 @@ impl TryFrom<String> for ProposalVote {
match value.trim().to_lowercase().as_str() {
"yay" => Ok(ProposalVote::Yay),
"nay" => Ok(ProposalVote::Nay),
"abstain" => Ok(ProposalVote::Abstain),
_ => Err("invalid vote".to_string()),
}
}
}

impl ProposalVote {
/// Check if the proposal type is yay
/// Check if the vote type is yay
pub fn is_yay(&self) -> bool {
matches!(self, ProposalVote::Yay)
}

/// Check if the vote type is nay
pub fn is_nay(&self) -> bool {
matches!(self, ProposalVote::Nay)
}

/// Check if the vote type is abstain
pub fn is_abstain(&self) -> bool {
matches!(self, ProposalVote::Abstain)
}

/// Check if two votes are equal
pub fn is_same_side(&self, other: &Self) -> bool {
std::mem::discriminant(self) == std::mem::discriminant(other)
}
}
19 changes: 19 additions & 0 deletions core/src/ledger/governance/storage/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum StorageProposalVote {
Yay(VoteType),
/// No
Nay,
/// Abstain
Abstain,
}

impl StorageProposalVote {
Expand All @@ -50,6 +52,21 @@ impl StorageProposalVote {
matches!(self, StorageProposalVote::Yay(_))
}

/// Check if a vote is nay
pub fn is_nay(&self) -> bool {
matches!(self, StorageProposalVote::Nay)
}

/// Check if a vote is abstain
pub fn is_abstain(&self) -> bool {
matches!(self, StorageProposalVote::Abstain)
}

/// Check if two votes are equal
pub fn is_same_side(&self, other: &Self) -> bool {
std::mem::discriminant(self) == std::mem::discriminant(other)
}

/// Check if vote is of type default
pub fn is_default_vote(&self) -> bool {
matches!(
Expand All @@ -64,6 +81,7 @@ impl StorageProposalVote {
match self {
StorageProposalVote::Yay(vote_type) => proposal_type.eq(vote_type),
StorageProposalVote::Nay => true,
StorageProposalVote::Abstain => true,
}
}

Expand Down Expand Up @@ -106,6 +124,7 @@ impl Display for StorageProposalVote {
},

StorageProposalVote::Nay => write!(f, "nay"),
StorageProposalVote::Abstain => write!(f, "abstain"),
}
}
}
Expand Down
Loading
Loading