From 2a81ac83c3a72de0e5dd19393dd5d64fb67107a3 Mon Sep 17 00:00:00 2001 From: Erwan Or Date: Tue, 30 Apr 2024 15:07:56 -0400 Subject: [PATCH] auction: another pass at txv/txp for DAs --- Cargo.lock | 1 + crates/core/asset/src/asset/cache.rs | 28 ------------ .../auction/src/auction/dutch/actions/view.rs | 34 +++++++++------ .../core/component/shielded-pool/Cargo.toml | 1 + crates/core/transaction/src/action.rs | 10 ++--- crates/core/transaction/src/is_action.rs | 17 ++++++-- .../core/transaction/src/view/action_view.rs | 15 ++++--- ...enumbra.core.component.auction.v1alpha1.rs | 40 +++++++++--------- .../src/gen/penumbra.core.transaction.v1.rs | 4 +- .../proto/src/gen/proto_descriptor.bin.no_lfs | Bin 401773 -> 401781 bytes crates/view/src/service.rs | 6 +++ .../core/transaction/v1/transaction.proto | 4 +- 12 files changed, 81 insertions(+), 79 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f78dbb6bee..f9990f6c60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5506,6 +5506,7 @@ dependencies = [ "tap", "tendermint", "thiserror", + "tokio", "tonic", "tracing", ] diff --git a/crates/core/asset/src/asset/cache.rs b/crates/core/asset/src/asset/cache.rs index c6e333486a..e41643682c 100644 --- a/crates/core/asset/src/asset/cache.rs +++ b/crates/core/asset/src/asset/cache.rs @@ -25,34 +25,6 @@ impl Cache { self.units.get(raw_denom).cloned() } - fn _try_populate(&mut self, _raw_denom: &str) -> anyhow::Result> { - // First try to parse the raw denom string as a specific denom unit of some kind, to see if already present in the cache - - // Ok(if let Some(unit) = self._get_unit(raw_denom) { - // // If the raw denom returns an associated unit, the denom metadata should already be present in the cache as well, so retrieve that. - // self._get_by_id(unit.id()) - // } else { - // // If the raw denom isn't present in the cache, what should we do here in the typical case? simply return None to indicate population failed? - // // In some cases, there will be countless possible denoms of a specific type/in a specific denom family (i.e. all the possible DelegationTokens), - // // so we can't reasonably populate the cache with all of them or necessarily provide all metadata for them, but we can & should still parse the raw denom - // // to determine whether the newly-witnessed denom is of a type we are familiar with. - - // // TODO: Before returning None, attempt to parse the raw denom to determine whether it is of a known type. - // // If so, return some kind of "empty" or default denom metadata for that type, which can be used to populate the cache with the raw denom as the base denom - // // and with whatever useful information we may otherwise be able to interpolate. - - // // Types: - // // - DelegationToken - // // - IbcToken - // // - UnbondingToken - // // - whatever else? - - // None - // }) - - unimplemented!("try_populate") - } - pub fn with_known_assets() -> Self { let mut cache = Cache::default(); diff --git a/crates/core/component/auction/src/auction/dutch/actions/view.rs b/crates/core/component/auction/src/auction/dutch/actions/view.rs index 28b340276e..bee10a6329 100644 --- a/crates/core/component/auction/src/auction/dutch/actions/view.rs +++ b/crates/core/component/auction/src/auction/dutch/actions/view.rs @@ -19,8 +19,8 @@ use serde::{Deserialize, Serialize}; pub struct ActionDutchAuctionScheduleView { pub action: ActionDutchAuctionSchedule, pub auction_id: AuctionId, - pub input_metadata: Metadata, - pub output_metadata: Metadata, + pub input_metadata: Option, + pub output_metadata: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -35,6 +35,20 @@ pub struct ActionDutchAuctionWithdrawView { pub reserves: Vec, } +/* Conversion back to an action */ + +impl From for ActionDutchAuctionSchedule { + fn from(value: ActionDutchAuctionScheduleView) -> Self { + value.action + } +} + +impl From for ActionDutchAuctionWithdraw { + fn from(value: ActionDutchAuctionWithdrawView) -> Self { + value.action + } +} + /* Protobuf impls */ impl DomainType for ActionDutchAuctionScheduleView { type Proto = pb::ActionDutchAuctionScheduleView; @@ -45,8 +59,8 @@ impl From for pb::ActionDutchAuctionScheduleView pb::ActionDutchAuctionScheduleView { action: Some(domain.action.into()), auction_id: Some(domain.auction_id.into()), - input_metadata: Some(domain.input_metadata.into()), - output_metadata: Some(domain.output_metadata.into()), + input_metadata: domain.input_metadata.map(Into::into), + output_metadata: domain.output_metadata.map(Into::into), } } } @@ -70,16 +84,12 @@ impl TryFrom for ActionDutchAuctionScheduleV .try_into()?, input_metadata: msg .input_metadata - .ok_or_else(|| { - anyhow!("ActionDutchAuctionScheduleView message is missing an input_metadata") - })? - .try_into()?, + .map(|input| input.try_into()) + .transpose()?, output_metadata: msg .output_metadata - .ok_or_else(|| { - anyhow!("ActionDutchAuctionScheduleView message is missing an output_metadata") - })? - .try_into()?, + .map(|output| output.try_into()) + .transpose()?, }) } } diff --git a/crates/core/component/shielded-pool/Cargo.toml b/crates/core/component/shielded-pool/Cargo.toml index bf573f4fb9..0ca3bbda95 100644 --- a/crates/core/component/shielded-pool/Cargo.toml +++ b/crates/core/component/shielded-pool/Cargo.toml @@ -72,6 +72,7 @@ tendermint = {workspace = true} thiserror = {workspace = true} tonic = {workspace = true, optional = true} tracing = {workspace = true} +tokio = {workspace = true} [dev-dependencies] proptest = {workspace = true} diff --git a/crates/core/transaction/src/action.rs b/crates/core/transaction/src/action.rs index d56330b854..9cfdb8174a 100644 --- a/crates/core/transaction/src/action.rs +++ b/crates/core/transaction/src/action.rs @@ -184,13 +184,9 @@ impl IsAction for Action { Action::CommunityPoolDeposit(x) => x.view_from_perspective(txp), Action::ValidatorDefinition(x) => ActionView::ValidatorDefinition(x.to_owned()), Action::IbcRelay(x) => ActionView::IbcRelay(x.to_owned()), - Action::ActionDutchAuctionSchedule(x) => { - ActionView::ActionDutchAuctionSchedule(x.to_owned()) - } - Action::ActionDutchAuctionEnd(x) => ActionView::ActionDutchAuctionEnd(x.to_owned()), - Action::ActionDutchAuctionWithdraw(x) => { - ActionView::ActionDutchAuctionWithdraw(x.to_owned()) - } + Action::ActionDutchAuctionSchedule(x) => x.view_from_perspective(txp), + Action::ActionDutchAuctionEnd(x) => x.view_from_perspective(txp), + Action::ActionDutchAuctionWithdraw(x) => x.view_from_perspective(txp), } } } diff --git a/crates/core/transaction/src/is_action.rs b/crates/core/transaction/src/is_action.rs index d1921a4327..9663bce511 100644 --- a/crates/core/transaction/src/is_action.rs +++ b/crates/core/transaction/src/is_action.rs @@ -2,6 +2,7 @@ use ark_ff::Zero; use decaf377::Fr; use penumbra_asset::{balance, Value}; use penumbra_auction::auction::dutch::actions::{ + view::{ActionDutchAuctionScheduleView, ActionDutchAuctionWithdrawView}, ActionDutchAuctionEnd, ActionDutchAuctionSchedule, ActionDutchAuctionWithdraw, }; use penumbra_community_pool::{CommunityPoolDeposit, CommunityPoolOutput, CommunityPoolSpend}; @@ -467,8 +468,14 @@ impl IsAction for ActionDutchAuctionSchedule { self.balance().commit(Fr::zero()) } - fn view_from_perspective(&self, _txp: &TransactionPerspective) -> ActionView { - ActionView::ActionDutchAuctionSchedule(self.to_owned()) + fn view_from_perspective(&self, txp: &TransactionPerspective) -> ActionView { + let view = ActionDutchAuctionScheduleView { + action: self.to_owned(), + auction_id: self.description.id(), + input_metadata: txp.denoms.get_by_id(self.description.input.asset_id), + output_metadata: txp.denoms.get_by_id(self.description.output_id), + }; + ActionView::ActionDutchAuctionSchedule(view) } } @@ -488,6 +495,10 @@ impl IsAction for ActionDutchAuctionWithdraw { } fn view_from_perspective(&self, _txp: &TransactionPerspective) -> ActionView { - ActionView::ActionDutchAuctionWithdraw(self.to_owned()) + let view = ActionDutchAuctionWithdrawView { + action: self.to_owned(), + reserves: vec![], + }; + ActionView::ActionDutchAuctionWithdraw(view) } } diff --git a/crates/core/transaction/src/view/action_view.rs b/crates/core/transaction/src/view/action_view.rs index ef00229838..4ed7ecb537 100644 --- a/crates/core/transaction/src/view/action_view.rs +++ b/crates/core/transaction/src/view/action_view.rs @@ -1,5 +1,6 @@ use penumbra_auction::auction::dutch::{ - ActionDutchAuctionEnd, ActionDutchAuctionSchedule, ActionDutchAuctionWithdraw, + actions::view::{ActionDutchAuctionScheduleView, ActionDutchAuctionWithdrawView}, + ActionDutchAuctionEnd, }; use penumbra_community_pool::{CommunityPoolDeposit, CommunityPoolOutput, CommunityPoolSpend}; use penumbra_dex::{ @@ -47,9 +48,9 @@ pub enum ActionView { CommunityPoolDeposit(CommunityPoolDeposit), CommunityPoolSpend(CommunityPoolSpend), CommunityPoolOutput(CommunityPoolOutput), - ActionDutchAuctionSchedule(ActionDutchAuctionSchedule), + ActionDutchAuctionSchedule(ActionDutchAuctionScheduleView), ActionDutchAuctionEnd(ActionDutchAuctionEnd), - ActionDutchAuctionWithdraw(ActionDutchAuctionWithdraw), + ActionDutchAuctionWithdraw(ActionDutchAuctionWithdrawView), } impl DomainType for ActionView { @@ -166,9 +167,13 @@ impl From for Action { ActionView::CommunityPoolDeposit(x) => Action::CommunityPoolDeposit(x), ActionView::CommunityPoolSpend(x) => Action::CommunityPoolSpend(x), ActionView::CommunityPoolOutput(x) => Action::CommunityPoolOutput(x), - ActionView::ActionDutchAuctionSchedule(x) => Action::ActionDutchAuctionSchedule(x), + ActionView::ActionDutchAuctionSchedule(x) => { + Action::ActionDutchAuctionSchedule(x.into()) + } ActionView::ActionDutchAuctionEnd(x) => Action::ActionDutchAuctionEnd(x), - ActionView::ActionDutchAuctionWithdraw(x) => Action::ActionDutchAuctionWithdraw(x), + ActionView::ActionDutchAuctionWithdraw(x) => { + Action::ActionDutchAuctionWithdraw(x.into()) + } } } } diff --git a/crates/proto/src/gen/penumbra.core.component.auction.v1alpha1.rs b/crates/proto/src/gen/penumbra.core.component.auction.v1alpha1.rs index 9cb11332f5..0c98e133b0 100644 --- a/crates/proto/src/gen/penumbra.core.component.auction.v1alpha1.rs +++ b/crates/proto/src/gen/penumbra.core.component.auction.v1alpha1.rs @@ -307,19 +307,21 @@ impl ::prost::Name for ActionDutchAuctionWithdraw { ) } } -/// An `ActionDutchAuctionWithdraw` augmented with additional metadata. +/// A plan to a `ActionDutchAuctionWithdraw` which contains both private and public data. #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] -pub struct ActionDutchAuctionWithdrawView { +pub struct ActionDutchAuctionWithdrawPlan { #[prost(message, optional, tag = "1")] - pub action: ::core::option::Option, - /// A sequence of values that sum together to the provided - /// reserves commitment. - #[prost(message, repeated, tag = "2")] - pub reserves: ::prost::alloc::vec::Vec, + pub auction_id: ::core::option::Option, + #[prost(uint64, tag = "2")] + pub seq: u64, + #[prost(message, optional, tag = "3")] + pub reserves_input: ::core::option::Option, + #[prost(message, optional, tag = "4")] + pub reserves_output: ::core::option::Option, } -impl ::prost::Name for ActionDutchAuctionWithdrawView { - const NAME: &'static str = "ActionDutchAuctionWithdrawView"; +impl ::prost::Name for ActionDutchAuctionWithdrawPlan { + const NAME: &'static str = "ActionDutchAuctionWithdrawPlan"; const PACKAGE: &'static str = "penumbra.core.component.auction.v1alpha1"; fn full_name() -> ::prost::alloc::string::String { ::prost::alloc::format!( @@ -351,21 +353,19 @@ impl ::prost::Name for ActionDutchAuctionScheduleView { ) } } -/// A plan to a `ActionDutchAuctionWithdraw` which contains both private and public data. +/// An `ActionDutchAuctionWithdraw` augmented with additional metadata. #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] -pub struct ActionDutchAuctionWithdrawPlan { +pub struct ActionDutchAuctionWithdrawView { #[prost(message, optional, tag = "1")] - pub auction_id: ::core::option::Option, - #[prost(uint64, tag = "2")] - pub seq: u64, - #[prost(message, optional, tag = "3")] - pub reserves_input: ::core::option::Option, - #[prost(message, optional, tag = "4")] - pub reserves_output: ::core::option::Option, + pub action: ::core::option::Option, + /// A sequence of values that sum together to the provided + /// reserves commitment. + #[prost(message, repeated, tag = "2")] + pub reserves: ::prost::alloc::vec::Vec, } -impl ::prost::Name for ActionDutchAuctionWithdrawPlan { - const NAME: &'static str = "ActionDutchAuctionWithdrawPlan"; +impl ::prost::Name for ActionDutchAuctionWithdrawView { + const NAME: &'static str = "ActionDutchAuctionWithdrawView"; const PACKAGE: &'static str = "penumbra.core.component.auction.v1alpha1"; fn full_name() -> ::prost::alloc::string::String { ::prost::alloc::format!( diff --git a/crates/proto/src/gen/penumbra.core.transaction.v1.rs b/crates/proto/src/gen/penumbra.core.transaction.v1.rs index 98b0852670..5cab6232f1 100644 --- a/crates/proto/src/gen/penumbra.core.transaction.v1.rs +++ b/crates/proto/src/gen/penumbra.core.transaction.v1.rs @@ -470,7 +470,7 @@ pub mod action_view { /// Dutch auctions #[prost(message, tag = "53")] ActionDutchAuctionSchedule( - super::super::super::component::auction::v1alpha1::ActionDutchAuctionSchedule, + super::super::super::component::auction::v1alpha1::ActionDutchAuctionScheduleView, ), #[prost(message, tag = "54")] ActionDutchAuctionEnd( @@ -478,7 +478,7 @@ pub mod action_view { ), #[prost(message, tag = "55")] ActionDutchAuctionWithdraw( - super::super::super::component::auction::v1alpha1::ActionDutchAuctionWithdraw, + super::super::super::component::auction::v1alpha1::ActionDutchAuctionWithdrawView, ), /// TODO: we have no way to recover the opening of the undelegate_claim's /// balance commitment, and can only infer the value from looking at the rest diff --git a/crates/proto/src/gen/proto_descriptor.bin.no_lfs b/crates/proto/src/gen/proto_descriptor.bin.no_lfs index 4057b3c8428cc9392575c71081b478834ff49e67..e70942f8dc941e0859ec633a81bec38e8589e364 100644 GIT binary patch delta 953 zcmZvaPe@cz6vpS=d*7S!y~*B;IXa_`!#wkU5*TWs)uKfZQ50l@m1FczMNtZgEHXvi z)M^$7Qv(++62@E<*FZM|LM^1EeIi4Fib%FhM9|{F{oU_;-#PER_aj&OGgmtH z7Dl=;x6Dsvj*LWc=7b1kHrf;NcQ-5s!Z~2;fS>xH9CPeo7x%NAAmD1KUI9H0pcoe9NDpb{RzhXvWSxgl zLaA=CT_v*qW2QQ z8y>~SDN%`?EBqpADRC6PHS-p^l@fOX$))IvH%G4C7rXwF|3|bF|9LMMP-fzbB?Yhmby6L8lIA*4s7?!CJSY3jk$PQ*HTauATxn@NmqHU6KYnfjB2*?_qUqT-mmxXw%E@d0>hR()lnLXNNSxZ3E4 zQ(#UL`+?LZNBR01{8ZTixC;+)I~J-H`GRpC<(A>9(d*E|5?Cxk!bHXlE6U?opb3b= zwkA^Ig+{REspLTe-dCj2DLLl`XAn2SP1jYjG-1N-aL$NO*wf_*fS9ku4b zSeEHDTpF_}J_mss`T#_m8Bv@Ew#So+s5N0wBW33y6w^qp=b<$2t5jS77V(QJmgM zb=3>I)xB2g=HRWtCb2rzHwpAG)i=q5weUj?E%V={@J`)$!w2%zffYUt>h?PCJOn-R zgNc<+tJh1gB5J(_ZJipa^%h*{mLUsIHuU&!V>C_{P&+Ylvj3bIIazX4+QR-0dA18X zWao3$dFP*wn`yLoOP0F|&H7g48SUzFFTS#X3 diff --git a/crates/view/src/service.rs b/crates/view/src/service.rs index 327f90707b..5a2b078549 100644 --- a/crates/view/src/service.rs +++ b/crates/view/src/service.rs @@ -10,6 +10,7 @@ use async_stream::try_stream; use camino::Utf8Path; use decaf377::Fq; use futures::stream::{self, StreamExt, TryStreamExt}; +use penumbra_auction::auction::dutch::actions::view::ActionDutchAuctionWithdrawView; use rand::Rng; use rand_core::OsRng; use tokio::sync::{watch, RwLock}; @@ -960,6 +961,11 @@ impl ViewService for ViewServer { address_views.insert(address.clone(), fvk.view_address(address)); asset_ids.insert(note.asset_id()); } + ActionView::ActionDutchAuctionWithdraw(ActionDutchAuctionWithdrawView { + action: _, + reserves: _, + }) => { /* no-op for now - i'm not totally sure we have all the necessary data to attribute specific note openings to this view */ + } _ => {} } } diff --git a/proto/penumbra/penumbra/core/transaction/v1/transaction.proto b/proto/penumbra/penumbra/core/transaction/v1/transaction.proto index bc4ee0e20a..1e0564ead0 100644 --- a/proto/penumbra/penumbra/core/transaction/v1/transaction.proto +++ b/proto/penumbra/penumbra/core/transaction/v1/transaction.proto @@ -223,9 +223,9 @@ message ActionView { component.governance.v1.CommunityPoolOutput community_pool_output = 51; component.governance.v1.CommunityPoolDeposit community_pool_deposit = 52; // Dutch auctions - component.auction.v1alpha1.ActionDutchAuctionSchedule action_dutch_auction_schedule = 53; + component.auction.v1alpha1.ActionDutchAuctionScheduleView action_dutch_auction_schedule = 53; component.auction.v1alpha1.ActionDutchAuctionEnd action_dutch_auction_end = 54; - component.auction.v1alpha1.ActionDutchAuctionWithdraw action_dutch_auction_withdraw = 55; + component.auction.v1alpha1.ActionDutchAuctionWithdrawView action_dutch_auction_withdraw = 55; // TODO: we have no way to recover the opening of the undelegate_claim's // balance commitment, and can only infer the value from looking at the rest