Skip to content

Commit

Permalink
effecthash: clean up split impls into new crate
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence committed Dec 30, 2023
1 parent 165659f commit d640c21
Show file tree
Hide file tree
Showing 38 changed files with 588 additions and 592 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/core/component/dao/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ penumbra-sct = { path = "../sct", default-features = false }
penumbra-asset = { path = "../../../core/asset", default-features = false }
penumbra-num = { path = "../../../core/num", default-features = false }
penumbra-keys = { path = "../../../core/keys", default-features = false }
penumbra-effecthash = { path = "../../../core/effecthash", default-features = false }

# Crates.io deps
ark-ff = { version = "0.4", default_features = false }
Expand Down
7 changes: 7 additions & 0 deletions crates/core/component/dao/src/action/dao_deposit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{Context, Error};
use penumbra_effecthash::{EffectHash, EffectingData};
use serde::{Deserialize, Serialize};
use std::convert::{TryFrom, TryInto};

Expand All @@ -19,6 +20,12 @@ impl DaoDeposit {
}
}

impl EffectingData for DaoDeposit {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl DomainType for DaoDeposit {
type Proto = pb::DaoDeposit;
}
Expand Down
7 changes: 7 additions & 0 deletions crates/core/component/dao/src/action/dao_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
use std::convert::{TryFrom, TryInto};

use penumbra_asset::{Balance, Value};
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_keys::Address;
use penumbra_proto::{penumbra::core::component::governance::v1alpha1 as pb, DomainType};

Expand All @@ -20,6 +21,12 @@ impl DaoOutput {
}
}

impl EffectingData for DaoOutput {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl DomainType for DaoOutput {
type Proto = pb::DaoOutput;
}
Expand Down
7 changes: 7 additions & 0 deletions crates/core/component/dao/src/action/dao_spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

use penumbra_asset::{Balance, Value};
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_proto::{penumbra::core::component::governance::v1alpha1 as pb, DomainType};

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -11,6 +12,12 @@ pub struct DaoSpend {
pub value: Value,
}

impl EffectingData for DaoSpend {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl DaoSpend {
pub fn balance(&self) -> Balance {
// Spends from the DAO produce value
Expand Down
1 change: 1 addition & 0 deletions crates/core/component/dex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ penumbra-proof-params = { path = "../../../crypto/proof-params" }
penumbra-asset = { path = "../../../core/asset", default-features = false }
penumbra-num = { path = "../../../core/num", default-features = false }
penumbra-keys = { path = "../../../core/keys", default-features = false }
penumbra-effecthash = { path = "../../../core/effecthash", default-features = false }
decaf377-ka = { path = "../../../crypto/decaf377-ka/" }
decaf377-fmd = { path = "../../../crypto/decaf377-fmd/" }

Expand Down
27 changes: 27 additions & 0 deletions crates/core/component/dex/src/lp/action.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};

use penumbra_asset::{balance, Balance, Value};
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_proto::{penumbra::core::component::dex::v1alpha1 as pb, DomainType};

use super::{position, position::Position, LpNft};
Expand All @@ -19,6 +20,14 @@ pub struct PositionOpen {
pub position: Position,
}

impl EffectingData for PositionOpen {
fn effect_hash(&self) -> EffectHash {
// The position open action consists only of the position, which
// we consider effecting data.
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl PositionOpen {
/// Compute a commitment to the value this action contributes to its transaction.
pub fn balance(&self) -> Balance {
Expand Down Expand Up @@ -49,6 +58,12 @@ pub struct PositionClose {
pub position_id: position::Id,
}

impl EffectingData for PositionClose {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl PositionClose {
/// Compute the value this action contributes to its transaction.
pub fn balance(&self) -> Balance {
Expand Down Expand Up @@ -82,6 +97,12 @@ pub struct PositionWithdraw {
pub reserves_commitment: balance::Commitment,
}

impl EffectingData for PositionWithdraw {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

/// A transaction action that claims retroactive rewards for a historical
/// position.
///
Expand All @@ -97,6 +118,12 @@ pub struct PositionRewardClaim {
pub rewards_commitment: balance::Commitment,
}

impl EffectingData for PositionRewardClaim {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl DomainType for PositionOpen {
type Proto = pb::PositionOpen;
}
Expand Down
15 changes: 15 additions & 0 deletions crates/core/component/dex/src/swap/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Context;
use ark_ff::Zero;
use decaf377::Fr;
use penumbra_asset::{balance, Balance, Value};
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_num::Amount;
use penumbra_proto::{
core::component::dex::v1alpha1 as pbc, penumbra::core::component::dex::v1alpha1 as pb,
Expand Down Expand Up @@ -39,6 +40,14 @@ impl Swap {
}
}

impl EffectingData for Swap {
fn effect_hash(&self) -> EffectHash {
// The effecting data is in the body of the swap, so we can
// just use hash the proto-encoding of the body.
self.body.effect_hash()
}
}

impl DomainType for Swap {
type Proto = pb::Swap;
}
Expand Down Expand Up @@ -81,6 +90,12 @@ pub struct Body {
pub payload: SwapPayload,
}

impl EffectingData for Body {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl DomainType for Body {
type Proto = pb::SwapBody;
}
Expand Down
15 changes: 15 additions & 0 deletions crates/core/component/dex/src/swap_claim/action.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Context;
use penumbra_asset::Balance;
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_fee::Fee;
use penumbra_proof_params::GROTH16_PROOF_LENGTH_BYTES;
use penumbra_proto::{penumbra::core::component::dex::v1alpha1 as pb, DomainType};
Expand All @@ -26,6 +27,14 @@ impl SwapClaim {
}
}

impl EffectingData for SwapClaim {
fn effect_hash(&self) -> EffectHash {
// The effecting data is in the body of the swap claim, so we can
// just use hash the proto-encoding of the body.
self.body.effect_hash()
}
}

impl DomainType for SwapClaim {
type Proto = pb::SwapClaim;
}
Expand Down Expand Up @@ -72,6 +81,12 @@ pub struct Body {
pub output_data: BatchSwapOutputData,
}

impl EffectingData for Body {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl DomainType for Body {
type Proto = pb::SwapClaimBody;
}
Expand Down
1 change: 1 addition & 0 deletions crates/core/component/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ penumbra-distributions = { path = "../distributions", 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-effecthash = { path = "../../../core/effecthash", default-features = false }
penumbra-num = { path = "../../../core/num", default-features = false }

# Penumbra dependencies
Expand Down
13 changes: 13 additions & 0 deletions crates/core/component/governance/src/delegator_vote/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use anyhow::Context;
use crate::{vote::Vote, DelegatorVoteProof};
use decaf377_rdsa::{Signature, SpendAuth, VerificationKey};
use penumbra_asset::Value;
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_num::Amount;
use penumbra_proto::{core::component::governance::v1alpha1 as pb, DomainType};
use penumbra_sct::Nullifier;
Expand All @@ -15,6 +16,12 @@ pub struct DelegatorVote {
pub proof: DelegatorVoteProof,
}

impl EffectingData for DelegatorVote {
fn effect_hash(&self) -> EffectHash {
self.body.effect_hash()
}
}

/// The body of a delegator vote.
#[derive(Debug, Clone)]
pub struct DelegatorVoteBody {
Expand All @@ -34,6 +41,12 @@ pub struct DelegatorVoteBody {
pub rk: VerificationKey<SpendAuth>,
}

impl EffectingData for DelegatorVoteBody {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl From<DelegatorVoteBody> for pb::DelegatorVoteBody {
fn from(value: DelegatorVoteBody) -> Self {
pb::DelegatorVoteBody {
Expand Down
9 changes: 9 additions & 0 deletions crates/core/component/governance/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ pub struct Proposal {
pub payload: ProposalPayload,
}

/*
// TODO: is this needed?
impl EffectingData for Proposal {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}
*/

/// The protobuf type URL for a transaction plan.
pub const TRANSACTION_PLAN_TYPE_URL: &str = "/penumbra.core.transaction.v1alpha1.TransactionPlan";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use penumbra_asset::{
asset::{self, DenomMetadata},
Balance, Value, STAKING_TOKEN_ASSET_ID,
};
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_num::Amount;
use penumbra_proto::penumbra::core::component::governance::v1alpha1 as pb;
use penumbra_proto::{penumbra::core::component::governance::v1alpha1 as pb, DomainType};

use crate::proposal_state::{Outcome, Withdrawn};

Expand All @@ -26,6 +27,16 @@ pub struct ProposalDepositClaim {
pub outcome: Outcome<()>,
}

impl EffectingData for ProposalDepositClaim {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl DomainType for ProposalDepositClaim {
type Proto = pb::ProposalDepositClaim;
}

impl From<ProposalDepositClaim> for pb::ProposalDepositClaim {
fn from(value: ProposalDepositClaim) -> pb::ProposalDepositClaim {
pb::ProposalDepositClaim {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};

use penumbra_asset::{Balance, Value, STAKING_TOKEN_ASSET_ID};
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_num::Amount;
use penumbra_proto::{penumbra::core::component::governance::v1alpha1 as pb, DomainType};

Expand All @@ -20,6 +21,12 @@ pub struct ProposalSubmit {
pub deposit_amount: Amount,
}

impl EffectingData for ProposalSubmit {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl ProposalSubmit {
/// Compute a commitment to the value contributed to a transaction by this proposal submission.
pub fn balance(&self) -> Balance {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};

use penumbra_asset::{Balance, Value};
use penumbra_effecthash::{EffectHash, EffectingData};
use penumbra_num::Amount;
use penumbra_proto::{penumbra::core::component::governance::v1alpha1 as pb, DomainType};

Expand All @@ -16,6 +17,12 @@ pub struct ProposalWithdraw {
pub reason: String,
}

impl EffectingData for ProposalWithdraw {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

impl From<ProposalWithdraw> for pb::ProposalWithdraw {
fn from(value: ProposalWithdraw) -> pb::ProposalWithdraw {
pb::ProposalWithdraw {
Expand Down
Loading

0 comments on commit d640c21

Please sign in to comment.