diff --git a/Cargo.lock b/Cargo.lock index cf7fe0b2f9..7f66be38c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5548,6 +5548,7 @@ dependencies = [ "penumbra-dao", "penumbra-dex", "penumbra-fee", + "penumbra-governance", "penumbra-ibc", "penumbra-keys", "penumbra-num", @@ -5592,6 +5593,7 @@ dependencies = [ "penumbra-custody", "penumbra-dex", "penumbra-fee", + "penumbra-governance", "penumbra-keys", "penumbra-num", "penumbra-proto", @@ -5627,6 +5629,7 @@ dependencies = [ "penumbra-compact-block", "penumbra-dex", "penumbra-fee", + "penumbra-governance", "penumbra-keys", "penumbra-num", "penumbra-proto", diff --git a/crates/bin/pcli/Cargo.toml b/crates/bin/pcli/Cargo.toml index 0772b7ed40..b242532155 100644 --- a/crates/bin/pcli/Cargo.toml +++ b/crates/bin/pcli/Cargo.toml @@ -27,6 +27,7 @@ penumbra-asset = { path = "../../core/asset", default-features=false } penumbra-keys = { path = "../../core/keys", default-features=false } penumbra-chain = { path = "../../core/component/chain", default-features = false } penumbra-shielded-pool = { path = "../../core/component/shielded-pool", default-features = false } +penumbra-governance = { path = "../../core/component/governance", default-features = false } penumbra-stake = { path = "../../core/component/stake", default-features = false } penumbra-sct = { path = "../../core/component/sct", default-features = false } penumbra-fee = { path = "../../core/component/fee", default-features = false } diff --git a/crates/bin/pcli/src/command/query/governance.rs b/crates/bin/pcli/src/command/query/governance.rs index ef1c365dc8..360b6ebb66 100644 --- a/crates/bin/pcli/src/command/query/governance.rs +++ b/crates/bin/pcli/src/command/query/governance.rs @@ -6,13 +6,10 @@ use std::{ use anyhow::{Context, Result}; use futures::{StreamExt, TryStreamExt}; -use penumbra_app::governance::{self, state_key::*}; +use penumbra_governance::state_key::*; +use penumbra_governance::{proposal_state::State as ProposalState, Proposal, Vote}; use penumbra_proto::client::v1alpha1::{PrefixValueRequest, PrefixValueResponse}; use penumbra_stake::IdentityKey; -use penumbra_transaction::{ - proposal::{self, Proposal}, - vote::Vote, -}; use serde::Serialize; use serde_json::json; @@ -91,7 +88,7 @@ impl GovernanceCmd { let proposal_title = proposal.title; - let proposal_state: proposal::State = client + let proposal_state: ProposalState = client .key_domain(proposal_state(proposal_id)) .await? .context(format!("proposal state for {} not found", proposal_id))?; @@ -114,7 +111,7 @@ impl GovernanceCmd { toml(&proposal)?; } State => { - let state: proposal::State = client + let state: ProposalState = client .key_domain(proposal_state(*proposal_id)) .await? .context(format!( @@ -169,24 +166,25 @@ impl GovernanceCmd { validator_votes_and_power.insert(*identity_key, (*vote, power)); } - let mut delegator_tallies: BTreeMap = client - .prefix_domain::( - all_tallied_delegator_votes_for_proposal(*proposal_id), - ) - .await? - .and_then(|r| async move { - Ok(( - IdentityKey::from_str( - r.0.rsplit('/').next().context("invalid key")?, - )?, - r.1, - )) - }) - .try_collect() - .await?; + let mut delegator_tallies: BTreeMap = + client + .prefix_domain::( + all_tallied_delegator_votes_for_proposal(*proposal_id), + ) + .await? + .and_then(|r| async move { + Ok(( + IdentityKey::from_str( + r.0.rsplit('/').next().context("invalid key")?, + )?, + r.1, + )) + }) + .try_collect() + .await?; // Combine the two mappings - let mut total = governance::Tally::default(); + let mut total = penumbra_governance::Tally::default(); let mut all_votes_and_power: BTreeMap = BTreeMap::new(); for (identity_key, (vote, power)) in validator_votes_and_power.into_iter() { @@ -207,9 +205,10 @@ impl GovernanceCmd { }; // Subtract delegator total from validator power, then add delegator // tally in to get the total tally for this validator: - let sub_total = - governance::Tally::from((vote, power - delegator_tally.total())) - + delegator_tally; + let sub_total = penumbra_governance::Tally::from(( + vote, + power - delegator_tally.total(), + )) + delegator_tally; map.insert("sub_total".to_string(), json_tally(&sub_total)); total += sub_total; map.into() @@ -245,7 +244,7 @@ fn json(value: &T) -> Result<()> { Ok(()) } -fn json_tally(tally: &governance::Tally) -> serde_json::Value { +fn json_tally(tally: &penumbra_governance::Tally) -> serde_json::Value { let mut map = serde_json::Map::new(); if tally.yes() > 0 { map.insert("yes".to_string(), tally.yes().into()); diff --git a/crates/bin/pcli/src/command/tx.rs b/crates/bin/pcli/src/command/tx.rs index 5ee17dc54b..bd3cfe2d4d 100644 --- a/crates/bin/pcli/src/command/tx.rs +++ b/crates/bin/pcli/src/command/tx.rs @@ -13,6 +13,7 @@ use ibc_types::core::channel::ChannelId; use penumbra_asset::{asset, asset::DenomMetadata, Value, STAKING_TOKEN_ASSET_ID}; use penumbra_dex::{lp::position, swap_claim::SwapClaimPlan}; use penumbra_fee::Fee; +use penumbra_governance::{proposal::ProposalToml, proposal_state::State as ProposalState, Vote}; use penumbra_ibc::Ics20Withdrawal; use penumbra_keys::keys::AddressIndex; use penumbra_num::Amount; @@ -25,7 +26,7 @@ use penumbra_proto::{ }; use penumbra_stake::rate::RateData; use penumbra_stake::{DelegationToken, IdentityKey, Penalty, UnbondingToken, UndelegateClaimPlan}; -use penumbra_transaction::{memo::MemoPlaintext, proposal::ProposalToml, vote::Vote}; +use penumbra_transaction::memo::MemoPlaintext; use penumbra_view::ViewClient; use penumbra_wallet::plan::{self, Planner}; use rand_core::OsRng; @@ -654,7 +655,7 @@ impl TxCmd { // Find out what the latest proposal ID is so we can include the next ID in the template: let mut client = app.specific_client().await?; let next_proposal_id: u64 = client - .key_proto(penumbra_app::governance::state_key::next_proposal_id()) + .key_proto(penumbra_governance::state_key::next_proposal_id()) .await? .context(format!("there are no proposals yet"))?; @@ -676,13 +677,12 @@ impl TxCmd { proposal_id, source, }) => { - use penumbra_app::governance::state_key; - use penumbra_transaction::proposal; + use penumbra_governance::state_key; let fee = Fee::from_staking_token_amount((*fee).into()); let mut client = app.specific_client().await?; - let state: proposal::State = client + let state: ProposalState = client .key_domain(state_key::proposal_state(*proposal_id)) .await? .context(format!( @@ -691,15 +691,15 @@ impl TxCmd { ))?; let outcome = match state { - proposal::State::Voting => anyhow::bail!( + ProposalState::Voting => anyhow::bail!( "proposal {} is still voting, so the deposit cannot yet be claimed", proposal_id ), - proposal::State::Withdrawn { reason: _ } => { + ProposalState::Withdrawn { reason: _ } => { anyhow::bail!("proposal {} has been withdrawn but voting has not yet concluded, so the deposit cannot yet be claimed", proposal_id); } - proposal::State::Finished { outcome } => outcome.map(|_| ()), - proposal::State::Claimed { outcome: _ } => { + ProposalState::Finished { outcome } => outcome.map(|_| ()), + ProposalState::Claimed { outcome: _ } => { anyhow::bail!("proposal {} has already been claimed", proposal_id) } }; diff --git a/crates/bin/pcli/src/command/tx/proposal.rs b/crates/bin/pcli/src/command/tx/proposal.rs index 2a5f8ecead..65d996fe80 100644 --- a/crates/bin/pcli/src/command/tx/proposal.rs +++ b/crates/bin/pcli/src/command/tx/proposal.rs @@ -1,10 +1,9 @@ use anyhow::{Context, Result}; use penumbra_chain::params::ChainParameters; -use penumbra_transaction::{ - plan::TransactionPlan, - proposal::{Proposal, ProposalPayload}, -}; +use penumbra_governance::{Proposal, ProposalPayload}; +use penumbra_proto::DomainType; +use penumbra_transaction::plan::TransactionPlan; #[derive(Debug, clap::Subcommand)] pub enum ProposalCmd { @@ -108,7 +107,7 @@ impl ProposalKindCmd { } } else { ProposalPayload::DaoSpend { - transaction_plan: TransactionPlan::default(), + transaction_plan: TransactionPlan::default().encode_to_vec(), } } } diff --git a/crates/bin/pcli/src/command/validator.rs b/crates/bin/pcli/src/command/validator.rs index f6f3c50d57..bed5a26a3b 100644 --- a/crates/bin/pcli/src/command/validator.rs +++ b/crates/bin/pcli/src/command/validator.rs @@ -5,6 +5,7 @@ use std::{ use anyhow::{Context, Result}; use penumbra_fee::Fee; +use penumbra_governance::{ValidatorVote, ValidatorVoteBody, Vote}; use penumbra_keys::keys::AddressIndex; use penumbra_proto::{core::stake::v1alpha1::Validator as ProtoValidator, DomainType, Message}; use penumbra_stake::{ @@ -12,7 +13,6 @@ use penumbra_stake::{ validator::{Validator, ValidatorToml}, FundingStream, FundingStreams, GovernanceKey, IdentityKey, }; -use penumbra_transaction::action::{ValidatorVote, ValidatorVoteBody, Vote}; use penumbra_wallet::plan; use rand_core::OsRng; use serde_json::Value; diff --git a/crates/bin/pd/src/info/specific.rs b/crates/bin/pd/src/info/specific.rs index 0e2c033dd9..a072b06c94 100644 --- a/crates/bin/pd/src/info/specific.rs +++ b/crates/bin/pd/src/info/specific.rs @@ -4,7 +4,6 @@ use std::sync::Arc; use async_stream::try_stream; use futures::StreamExt; use futures::TryStreamExt; -use penumbra_app::governance::StateReadExt as _; use penumbra_asset::{asset, Value}; use penumbra_chain::component::AppHashRead; use penumbra_chain::component::StateReadExt as _; @@ -15,6 +14,7 @@ use penumbra_dex::{ lp::{position, position::Position}, DirectedTradingPair, SwapExecution, TradingPair, }; +use penumbra_governance::StateReadExt as _; use penumbra_proto::{ self as proto, client::v1alpha1::{ @@ -747,7 +747,7 @@ impl SpecificQueryService for Info { .map_err(|e| tonic::Status::unknown(format!("chain_id not OK: {e}")))?; let proposal_id = request.into_inner().proposal_id; - use penumbra_app::governance::state_key; + use penumbra_governance::state_key; let s = state.prefix(&state_key::all_rate_data_at_proposal_start(proposal_id)); Ok(tonic::Response::new( diff --git a/crates/core/component/governance/src/metrics.rs b/crates/core/component/governance/src/metrics.rs index 8f5131ec82..6a897cfe75 100644 --- a/crates/core/component/governance/src/metrics.rs +++ b/crates/core/component/governance/src/metrics.rs @@ -13,6 +13,7 @@ pub use metrics::*; +#[allow(dead_code)] /// Registers all metrics used by this crate. pub fn register_metrics() { /* diff --git a/crates/view/Cargo.toml b/crates/view/Cargo.toml index 222756feb6..ceba12c006 100644 --- a/crates/view/Cargo.toml +++ b/crates/view/Cargo.toml @@ -29,6 +29,7 @@ penumbra-chain = { path = "../core/component/chain" } penumbra-shielded-pool = { path = "../core/component/shielded-pool", default-features = false, features = [ "proving-keys", ] } +penumbra-governance = { path = "../core/component/governance", default-features = false } penumbra-stake = { path = "../core/component/stake", default-features = false } penumbra-ibc = { path = "../core/component/ibc", default-features = false } penumbra-dao = { path = "../core/component/dao", default-features = false } diff --git a/crates/view/src/planner.rs b/crates/view/src/planner.rs index f0c4780397..634ba5647a 100644 --- a/crates/view/src/planner.rs +++ b/crates/view/src/planner.rs @@ -20,6 +20,10 @@ use penumbra_dex::{ TradingPair, }; use penumbra_fee::Fee; +use penumbra_governance::{ + proposal_state, DelegatorVotePlan, Proposal, ProposalDepositClaim, ProposalSubmit, + ProposalWithdraw, ValidatorVote, Vote, +}; use penumbra_ibc::{IbcAction, Ics20Withdrawal}; use penumbra_keys::{ keys::{AccountGroupId, AddressIndex}, @@ -32,12 +36,8 @@ use penumbra_stake::{rate::RateData, validator}; use penumbra_stake::{IdentityKey, UndelegateClaimPlan}; use penumbra_tct as tct; use penumbra_transaction::{ - action::{ - Proposal, ProposalDepositClaim, ProposalSubmit, ProposalWithdraw, ValidatorVote, Vote, - }, memo::MemoPlaintext, - plan::{ActionPlan, DelegatorVotePlan, MemoPlan, TransactionPlan}, - proposal, + plan::{ActionPlan, MemoPlan, TransactionPlan}, }; use rand::{CryptoRng, RngCore}; use tracing::instrument; @@ -320,7 +320,7 @@ impl Planner { &mut self, proposal: u64, deposit_amount: Amount, - outcome: proposal::Outcome<()>, + outcome: proposal_state::Outcome<()>, ) -> &mut Self { self.action(ActionPlan::ProposalDepositClaim(ProposalDepositClaim { proposal, diff --git a/crates/wallet/Cargo.toml b/crates/wallet/Cargo.toml index 639e8d3ddd..2af0cfee9b 100644 --- a/crates/wallet/Cargo.toml +++ b/crates/wallet/Cargo.toml @@ -23,6 +23,7 @@ penumbra-dex = { path = "../core/component/dex" } penumbra-transaction = { path = "../core/transaction" } penumbra-app = { path = "../core/app" } penumbra-stake = { path = "../core/component/stake" } +penumbra-governance = { path = "../core/component/governance" } penumbra-fee = { path = "../core/component/fee" } penumbra-view = { path = "../view" } penumbra-custody = { path = "../custody" } diff --git a/crates/wallet/src/plan.rs b/crates/wallet/src/plan.rs index b6f54ffc5e..39527ba64a 100644 --- a/crates/wallet/src/plan.rs +++ b/crates/wallet/src/plan.rs @@ -11,6 +11,7 @@ use ark_std::UniformRand; use decaf377::Fq; use penumbra_asset::Value; use penumbra_fee::Fee; +use penumbra_governance::{proposal_state, Proposal, ValidatorVote}; use penumbra_keys::{ keys::{AccountGroupId, AddressIndex}, Address, @@ -18,12 +19,7 @@ use penumbra_keys::{ use penumbra_num::Amount; use penumbra_stake::rate::RateData; use penumbra_stake::validator; -use penumbra_transaction::{ - action::{Proposal, ValidatorVote}, - memo::MemoPlaintext, - plan::TransactionPlan, - proposal, -}; +use penumbra_transaction::{memo::MemoPlaintext, plan::TransactionPlan}; use penumbra_view::{SpendableNoteRecord, ViewClient}; use rand_core::{CryptoRng, RngCore}; use tracing::instrument; @@ -328,7 +324,7 @@ pub async fn proposal_deposit_claim( rng: R, proposal_id: u64, deposit_amount: Amount, - outcome: proposal::Outcome<()>, + outcome: proposal_state::Outcome<()>, fee: Fee, source_address: AddressIndex, ) -> Result diff --git a/crates/wasm/Cargo.toml b/crates/wasm/Cargo.toml index f6daa4e1d0..49ab7ee802 100644 --- a/crates/wasm/Cargo.toml +++ b/crates/wasm/Cargo.toml @@ -25,6 +25,7 @@ penumbra-proto = { path = "../proto", default-features = false } penumbra-sct = { path = "../core/component/sct", default-features = false } penumbra-shielded-pool = { path = "../core/component/shielded-pool", default-features = false, features = ["proving-keys"] } penumbra-stake = { path = "../core/component/stake", default-features = false } +penumbra-governance = { path = "../core/component/governance", default-features = false, features = ["proving-keys"] } penumbra-tct = { path = "../crypto/tct" } penumbra-transaction = { path = "../core/transaction", default-features = false } diff --git a/crates/wasm/src/planner.rs b/crates/wasm/src/planner.rs index 861b05b5c8..b031274f7b 100644 --- a/crates/wasm/src/planner.rs +++ b/crates/wasm/src/planner.rs @@ -11,15 +11,17 @@ use penumbra_asset::{asset::DenomMetadata, Balance, Value}; use penumbra_chain::params::{ChainParameters, FmdParameters}; use penumbra_dex::{swap::SwapPlaintext, swap::SwapPlan, swap_claim::SwapClaimPlan, TradingPair}; use penumbra_fee::Fee; +use penumbra_governance::{ + DelegatorVotePlan, Proposal, ProposalSubmit, ProposalWithdraw, ValidatorVote, Vote, +}; use penumbra_keys::{keys::AddressIndex, Address, FullViewingKey}; use penumbra_num::Amount; use penumbra_shielded_pool::{Note, OutputPlan, SpendPlan}; use penumbra_stake::{IdentityKey, UndelegateClaimPlan}; use penumbra_tct as tct; use penumbra_transaction::{ - action::{Proposal, ProposalSubmit, ProposalWithdraw, ValidatorVote, Vote}, memo::MemoPlaintext, - plan::{ActionPlan, DelegatorVotePlan, MemoPlan, TransactionPlan}, + plan::{ActionPlan, MemoPlan, TransactionPlan}, }; // use penumbra_view::{SpendableNoteRecord, ViewClient};