Skip to content

Commit

Permalink
wip: move governance out of the app crate to its component crate
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Sep 18, 2023
1 parent a8928f8 commit a0b0126
Show file tree
Hide file tree
Showing 26 changed files with 444 additions and 402 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/core/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub use mock_client::MockClient;
pub use temp_storage_ext::TempStorageExt;

pub mod app;
pub mod governance;

#[cfg(test)]
mod tests;
Expand Down
7 changes: 6 additions & 1 deletion crates/core/component/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ component = [
"penumbra-storage",
"penumbra-proto/penumbra-storage",
"penumbra-chain/component",
"penumbra-sct/component"
"penumbra-sct/component",
"penumbra-stake/component",
]
proving-keys = ["penumbra-proof-params/proving-keys"]
default = ["std", "component", "proving-keys"]
Expand All @@ -28,9 +29,11 @@ penumbra-proof-params = { path = "../../../crypto/proof-params", default-feature
penumbra-sct = { path = "../sct", default-features = false }
penumbra-component = { path = "../component", optional = true }
penumbra-shielded-pool = { path = "../shielded-pool", default-features = false }
penumbra-stake = { path = "../stake", default-features = false }
penumbra-chain = { path = "../chain", default-features = false }
penumbra-asset = { path = "../../../core/asset", default-features = false }
penumbra-keys = { path = "../../../core/keys", default-features = false }
penumbra-num = { path = "../../../core/num", default-features = false }

# Penumbra dependencies
decaf377-rdsa = { version = "0.7" }
Expand All @@ -56,6 +59,8 @@ rand_core = { version = "0.6.3", features = ["getrandom"] }
rand = "0.8"
im = "15.1"
regex = "1.5"
futures = "0.3"

[dev-dependencies]
proptest = "1"
proptest-derive = "0.3"
1 change: 1 addition & 0 deletions crates/core/component/governance/src/action_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use penumbra_component::ActionHandler;
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ use anyhow::{Context, Result};
use async_trait::async_trait;
use penumbra_chain::component::StateReadExt;
use penumbra_storage::StateWrite;
use penumbra_transaction::proposal;
use tendermint::v0_34::abci;
use tracing::instrument;

use super::{tally, StateReadExt as _, StateWriteExt as _};
use penumbra_component::Component;

use crate::{
proposal_state::{
Outcome as ProposalOutcome, State as ProposalState, Withdrawn as ProposalWithdrawn,
},
tally,
view::{StateReadExt as _, StateWriteExt},
};

pub struct Governance {}

#[async_trait]
Expand Down Expand Up @@ -84,7 +90,7 @@ pub async fn enact_all_passed_proposals<S: StateWrite>(mut state: S) -> Result<(
.context("proposal has id")?;

let outcome = match current_state {
proposal::State::Voting => {
ProposalState::Voting => {
// If the proposal is still in the voting state, tally and conclude it (this will
// automatically remove it from the list of unfinished proposals)
let outcome = state.current_tally(proposal_id).await?.outcome(
Expand Down Expand Up @@ -126,22 +132,22 @@ pub async fn enact_all_passed_proposals<S: StateWrite>(mut state: S) -> Result<(

outcome.into()
}
proposal::State::Withdrawn { reason } => {
ProposalState::Withdrawn { reason } => {
tracing::info!(proposal = %proposal_id, reason = ?reason, "proposal concluded after being withdrawn");
proposal::Outcome::Failed {
withdrawn: proposal::Withdrawn::WithReason { reason },
ProposalOutcome::Failed {
withdrawn: ProposalWithdrawn::WithReason { reason },
}
}
proposal::State::Finished { outcome: _ } => {
ProposalState::Finished { outcome: _ } => {
anyhow::bail!("proposal {proposal_id} is already finished, and should have been removed from the active set");
}
proposal::State::Claimed { outcome: _ } => {
ProposalState::Claimed { outcome: _ } => {
anyhow::bail!("proposal {proposal_id} is already claimed, and should have been removed from the active set");
}
};

// Update the proposal state to reflect the outcome
state.put_proposal_state(proposal_id, proposal::State::Finished { outcome });
state.put_proposal_state(proposal_id, ProposalState::Finished { outcome });
}

Ok(())
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions crates/core/component/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@ mod delegator_vote;
pub use delegator_vote::proof::{DelegatorVoteCircuit, DelegatorVoteProof};

pub mod proposal_nft;
pub mod proposal_state;
pub mod voting_receipt_token;

pub use proposal_nft::ProposalNft;
pub use voting_receipt_token::VotingReceiptToken;

mod metrics;
mod state_key;
mod tally;
mod view;

#[cfg_attr(docsrs, doc(cfg(feature = "component")))]
#[cfg(feature = "component")]
pub mod component;

#[cfg_attr(docsrs, doc(cfg(feature = "component")))]
#[cfg(feature = "component")]
mod action_handler;

#[cfg_attr(docsrs, doc(cfg(feature = "component")))]
#[cfg(feature = "component")]
pub use component::StateReadExt;

pub mod proposal;
pub mod vote;
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a0b0126

Please sign in to comment.