Skip to content

Commit

Permalink
transaction: finalize auction integration (#4237)
Browse files Browse the repository at this point in the history
## Describe your changes

This PR:
- adds an action plan for withdrawing DA auctions
- plugs in `GasCost` and `IsAction` impls
- add basic TxV/TxP support/definitions

## Issue ticket number and link
Part of #4212 + #4219

## Checklist before requesting a review

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

  > Consensus breaking
  • Loading branch information
erwanor authored Apr 19, 2024
1 parent 7a90283 commit 971006e
Show file tree
Hide file tree
Showing 24 changed files with 633 additions and 78 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,9 @@ impl TxCmd {
.await?;
app.build_and_submit_transaction(plan).await?;
}
TxCmd::Position(PositionCmd::RewardClaim {}) => todo!(),
TxCmd::Position(PositionCmd::RewardClaim {}) => {
unimplemented!("deprecated, remove this")
}
TxCmd::Position(PositionCmd::Replicate(replicate_cmd)) => {
replicate_cmd.exec(app).await?;
}
Expand Down
7 changes: 7 additions & 0 deletions crates/bin/pcli/src/transaction_view_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ impl TransactionViewExt for TransactionView {
penumbra_transaction::ActionView::Delegate(_) => ["Delegation", ""],
penumbra_transaction::ActionView::Undelegate(_) => ["Undelegation", ""],
penumbra_transaction::ActionView::UndelegateClaim(_) => ["Undelegation Claim", ""],
penumbra_transaction::ActionView::ActionDutchAuctionSchedule(_) => todo!(),
penumbra_transaction::ActionView::ActionDutchAuctionEnd(_) => {
todo!()
}
penumbra_transaction::ActionView::ActionDutchAuctionWithdraw(_) => {
todo!()
}
};

actions_table.add_row(row);
Expand Down
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
1 change: 1 addition & 0 deletions crates/core/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ metrics = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
penumbra-asset = { workspace = true, default-features = true }
penumbra-auction = { workspace = true, default-features = true }
penumbra-community-pool = { workspace = true, default-features = true }
penumbra-compact-block = { workspace = true, default-features = true }
penumbra-dex = { workspace = true, default-features = true }
Expand Down
18 changes: 9 additions & 9 deletions crates/core/app/src/action_handler/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ impl AppActionHandler for Action {
Action::CommunityPoolSpend(action) => action.check_stateless(()).await,
Action::CommunityPoolOutput(action) => action.check_stateless(()).await,
Action::CommunityPoolDeposit(action) => action.check_stateless(()).await,
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(action) => action.check_stateless(()).await,
Action::ActionDutchAuctionEnd(action) => action.check_stateless(()).await,
Action::ActionDutchAuctionWithdraw(action) => action.check_stateless(()).await,
}
}

Expand Down Expand Up @@ -95,9 +95,9 @@ impl AppActionHandler for Action {
Action::CommunityPoolSpend(action) => action.check_historical(state).await,
Action::CommunityPoolOutput(action) => action.check_historical(state).await,
Action::CommunityPoolDeposit(action) => action.check_historical(state).await,
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(action) => action.check_historical(state).await,
Action::ActionDutchAuctionEnd(action) => action.check_historical(state).await,
Action::ActionDutchAuctionWithdraw(action) => action.check_historical(state).await,
}
}

Expand Down Expand Up @@ -130,9 +130,9 @@ impl AppActionHandler for Action {
Action::CommunityPoolSpend(action) => action.check_and_execute(state).await,
Action::CommunityPoolOutput(action) => action.check_and_execute(state).await,
Action::CommunityPoolDeposit(action) => action.check_and_execute(state).await,
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(action) => action.check_and_execute(state).await,
Action::ActionDutchAuctionEnd(action) => action.check_and_execute(state).await,
Action::ActionDutchAuctionWithdraw(action) => action.check_and_execute(state).await,
}
}
}
8 changes: 4 additions & 4 deletions crates/core/app/src/action_handler/actions/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ impl AppActionHandler for ProposalSubmit {
| CommunityPoolSpend(_)
| CommunityPoolOutput(_)
| Ics20Withdrawal(_)
| CommunityPoolDeposit(_) => {}
ActionDutchAuctionSchedule(_) => todo!(),
ActionDutchAuctionEnd(_) => todo!(),
ActionDutchAuctionWithdraw(_) => todo!(),
| CommunityPoolDeposit(_)
| ActionDutchAuctionSchedule(_)
| ActionDutchAuctionEnd(_)
| ActionDutchAuctionWithdraw(_) => {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::anyhow;
use penumbra_asset::{Balance, Value};
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use penumbra_txhash::{EffectHash, EffectingData};
use serde::{Deserialize, Serialize};

use crate::auction::{id::AuctionId, AuctionNft};
Expand Down Expand Up @@ -39,6 +40,12 @@ impl ActionDutchAuctionEnd {
}
}

/* Effect hash */
impl EffectingData for ActionDutchAuctionEnd {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}
/* Protobuf impls */
impl DomainType for ActionDutchAuctionEnd {
type Proto = pb::ActionDutchAuctionEnd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pub use end::ActionDutchAuctionEnd;

pub mod withdraw;
pub use withdraw::ActionDutchAuctionWithdraw;

pub mod plan;
pub use plan::ActionDutchAuctionWithdrawPlan;
100 changes: 100 additions & 0 deletions crates/core/component/auction/src/auction/dutch/actions/plan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use ark_ff::Zero;
use decaf377::Fr;
use penumbra_asset::{balance, Balance, Value};
use penumbra_proto::{penumbra::core::component::auction::v1alpha1 as pb, DomainType};
use serde::{Deserialize, Serialize};

use crate::auction::{dutch::ActionDutchAuctionWithdraw, AuctionId, AuctionNft};

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(
try_from = "pb::ActionDutchAuctionWithdrawPlan",
into = "pb::ActionDutchAuctionWithdrawPlan"
)]
pub struct ActionDutchAuctionWithdrawPlan {
pub auction_id: AuctionId,
pub seq: u64,
pub reserves_input: Value,
pub reserves_output: Value,
}

impl ActionDutchAuctionWithdrawPlan {
pub fn to_action(&self) -> ActionDutchAuctionWithdraw {
ActionDutchAuctionWithdraw {
auction_id: self.auction_id,
reserves_commitment: self.reserves_commitment(),
seq: self.seq,
}
}

pub fn reserves_balance(&self) -> Balance {
Balance::from(self.reserves_input) + Balance::from(self.reserves_output)
}

pub fn reserves_commitment(&self) -> balance::Commitment {
self.reserves_balance().commit(Fr::zero())
}

pub fn balance(&self) -> Balance {
let reserves_balance = self.reserves_balance();
let prev_auction_nft = Balance::from(Value {
amount: 1u128.into(),
asset_id: AuctionNft::new(self.auction_id, self.seq.saturating_sub(1)).asset_id(),
});

let next_auction_nft = Balance::from(Value {
amount: 1u128.into(),
asset_id: AuctionNft::new(self.auction_id, self.seq).asset_id(),
});

reserves_balance + next_auction_nft - prev_auction_nft
}
}

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

impl From<ActionDutchAuctionWithdrawPlan> for pb::ActionDutchAuctionWithdrawPlan {
fn from(domain: ActionDutchAuctionWithdrawPlan) -> Self {
Self {
auction_id: Some(domain.auction_id.into()),
seq: domain.seq,
reserves_input: Some(domain.reserves_input.into()),
reserves_output: Some(domain.reserves_output.into()),
}
}
}

impl TryFrom<pb::ActionDutchAuctionWithdrawPlan> for ActionDutchAuctionWithdrawPlan {
type Error = anyhow::Error;
fn try_from(msg: pb::ActionDutchAuctionWithdrawPlan) -> Result<Self, Self::Error> {
Ok(Self {
auction_id: msg
.auction_id
.ok_or_else(|| {
anyhow::anyhow!(
"ActionDutchAuctionWithdrawPlan message is missing an auction id"
)
})?
.try_into()?,
seq: msg.seq,
reserves_input: msg
.reserves_input
.ok_or_else(|| {
anyhow::anyhow!(
"ActionDutchAuctionWithdrawPlan message is missing a reserves input"
)
})?
.try_into()?,
reserves_output: msg
.reserves_output
.ok_or_else(|| {
anyhow::anyhow!(
"ActionDutchAuctionWithdrawPlan message is missing a reserves output"
)
})?
.try_into()?,
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::auction::{dutch::DutchAuctionDescription, nft::AuctionNft};
use anyhow::anyhow;
use penumbra_asset::{Balance, Value};
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use penumbra_txhash::{EffectHash, EffectingData};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -37,6 +38,13 @@ impl ActionDutchAuctionSchedule {
}
}

/* Effect hash */
impl EffectingData for ActionDutchAuctionSchedule {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

/* Protobuf impls */
impl DomainType for ActionDutchAuctionSchedule {
type Proto = pb::ActionDutchAuctionSchedule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ark_ff::Zero;
use decaf377_rdsa::Fr;
use penumbra_asset::{balance, Balance, Value};
use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use penumbra_txhash::{EffectHash, EffectingData};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -55,6 +56,13 @@ impl ActionDutchAuctionWithdraw {
}
}

/* Effect hash */
impl EffectingData for ActionDutchAuctionWithdraw {
fn effect_hash(&self) -> EffectHash {
EffectHash::from_proto_effecting_data(&self.to_proto())
}
}

/* Protobuf impls */
impl DomainType for ActionDutchAuctionWithdraw {
type Proto = pb::ActionDutchAuctionWithdraw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{ensure, Result};
use async_trait::async_trait;
use cnidarium::StateWrite;
use cnidarium_component::ActionHandler;
use penumbra_sct::component::clock::EpochRead; // AuctionRead?
use penumbra_sct::component::clock::EpochRead;

use crate::auction::dutch::ActionDutchAuctionSchedule;
use crate::component::DutchAuctionManager;
Expand Down
48 changes: 31 additions & 17 deletions crates/core/transaction/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ impl EffectingData for Action {
Action::CommunityPoolSpend(d) => d.effect_hash(),
Action::CommunityPoolOutput(d) => d.effect_hash(),
Action::CommunityPoolDeposit(d) => d.effect_hash(),
// TODO: fill in skeleton
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(a) => a.effect_hash(),
Action::ActionDutchAuctionEnd(a) => a.effect_hash(),
Action::ActionDutchAuctionWithdraw(a) => a.effect_hash(),
}
}
}
Expand Down Expand Up @@ -119,10 +118,13 @@ impl Action {
Action::CommunityPoolDeposit(_) => tracing::info_span!("CommunityPoolDeposit", ?idx),
Action::CommunityPoolSpend(_) => tracing::info_span!("CommunityPoolSpend", ?idx),
Action::CommunityPoolOutput(_) => tracing::info_span!("CommunityPoolOutput", ?idx),
// TODO: fill in skeleton
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(_) => {
tracing::info_span!("ActionDutchAuctionSchedule", ?idx)
}
Action::ActionDutchAuctionEnd(_) => tracing::info_span!("ActionDutchAuctionEnd", ?idx),
Action::ActionDutchAuctionWithdraw(_) => {
tracing::info_span!("ActionDutchAuctionWithdraw", ?idx)
}
}
}
}
Expand Down Expand Up @@ -154,9 +156,9 @@ impl IsAction for Action {
Action::IbcRelay(x) => x.balance_commitment(),
Action::ValidatorDefinition(_) => balance::Commitment::default(),
// TODO: fill in skeleton
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(action) => action.balance_commitment(),
Action::ActionDutchAuctionEnd(action) => action.balance_commitment(),
Action::ActionDutchAuctionWithdraw(action) => action.balance_commitment(),
}
}

Expand All @@ -181,10 +183,8 @@ impl IsAction for Action {
Action::CommunityPoolSpend(x) => x.view_from_perspective(txp),
Action::CommunityPoolOutput(x) => x.view_from_perspective(txp),
Action::CommunityPoolDeposit(x) => x.view_from_perspective(txp),
// TODO: figure out where to implement the actual decryption methods for these? where are their action definitions?
Action::ValidatorDefinition(x) => ActionView::ValidatorDefinition(x.to_owned()),
Action::IbcRelay(x) => ActionView::IbcRelay(x.to_owned()),
// TODO: fill in skeleton
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Expand Down Expand Up @@ -262,10 +262,15 @@ impl From<Action> for pb::Action {
Action::CommunityPoolDeposit(inner) => pb::Action {
action: Some(pb::action::Action::CommunityPoolDeposit(inner.into())),
},
// TODO: fill in skeleton
Action::ActionDutchAuctionSchedule(_) => todo!(),
Action::ActionDutchAuctionEnd(_) => todo!(),
Action::ActionDutchAuctionWithdraw(_) => todo!(),
Action::ActionDutchAuctionSchedule(inner) => pb::Action {
action: Some(pb::action::Action::ActionDutchAuctionSchedule(inner.into())),
},
Action::ActionDutchAuctionEnd(inner) => pb::Action {
action: Some(pb::action::Action::ActionDutchAuctionEnd(inner.into())),
},
Action::ActionDutchAuctionWithdraw(inner) => pb::Action {
action: Some(pb::action::Action::ActionDutchAuctionWithdraw(inner.into())),
},
}
}
}
Expand Down Expand Up @@ -331,6 +336,15 @@ impl TryFrom<pb::Action> for Action {
pb::action::Action::CommunityPoolDeposit(inner) => {
Ok(Action::CommunityPoolDeposit(inner.try_into()?))
}
pb::action::Action::ActionDutchAuctionSchedule(inner) => {
Ok(Action::ActionDutchAuctionSchedule(inner.try_into()?))
}
pb::action::Action::ActionDutchAuctionEnd(inner) => {
Ok(Action::ActionDutchAuctionEnd(inner.try_into()?))
}
pb::action::Action::ActionDutchAuctionWithdraw(inner) => {
Ok(Action::ActionDutchAuctionWithdraw(inner.try_into()?))
}
}
}
}
6 changes: 3 additions & 3 deletions crates/core/transaction/src/is_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl IsAction for ActionDutchAuctionSchedule {
}

fn view_from_perspective(&self, _txp: &TransactionPerspective) -> ActionView {
todo!()
ActionView::ActionDutchAuctionSchedule(self.to_owned())
}
}

Expand All @@ -426,7 +426,7 @@ impl IsAction for ActionDutchAuctionEnd {
}

fn view_from_perspective(&self, _txp: &TransactionPerspective) -> ActionView {
todo!()
ActionView::ActionDutchAuctionEnd(self.to_owned())
}
}

Expand All @@ -436,6 +436,6 @@ impl IsAction for ActionDutchAuctionWithdraw {
}

fn view_from_perspective(&self, _txp: &TransactionPerspective) -> ActionView {
todo!()
ActionView::ActionDutchAuctionWithdraw(self.to_owned())
}
}
Loading

0 comments on commit 971006e

Please sign in to comment.