Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auction: connect auction component to application #4259

Merged
merged 12 commits into from
Apr 23, 2024
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.

1 change: 1 addition & 0 deletions crates/bin/pcli/src/command/tx/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl ProposalKindCmd {
ProposalKindCmd::ParameterChange => ProposalPayload::ParameterChange {
old: Box::new(app_params.as_changed_params()),
new: Box::new(ChangedAppParameters {
auction_params: None,
community_pool_params: None,
distributions_params: None,
ibc_params: None,
Expand Down
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
12 changes: 12 additions & 0 deletions crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cnidarium::{ArcStateDeltaExt, Snapshot, StateDelta, StateRead, StateWrite, S
use cnidarium_component::Component;
use ibc_types::core::connection::ChainId;
use jmt::RootHash;
use penumbra_auction::component::{Auction, StateReadExt as _, StateWriteExt as _};
use penumbra_community_pool::component::{CommunityPool, StateWriteExt as _};
use penumbra_community_pool::StateReadExt as _;
use penumbra_compact_block::component::CompactBlockManager;
Expand Down Expand Up @@ -118,6 +119,7 @@ impl App {
)
.await;
Ibc::init_chain(&mut state_tx, Some(&genesis.ibc_content)).await;
Auction::init_chain(&mut state_tx, Some(&genesis.auction_content)).await;
Dex::init_chain(&mut state_tx, Some(&genesis.dex_content)).await;
CommunityPool::init_chain(&mut state_tx, Some(&genesis.community_pool_content))
.await;
Expand Down Expand Up @@ -245,6 +247,9 @@ impl App {
if let Some(dex_params) = app_params.new.dex_params {
state_tx.put_dex_params(dex_params);
}
if let Some(auction_params) = app_params.new.auction_params {
state_tx.put_auction_params(auction_params);
}
}

// Run each of the begin block handlers for each component, in sequence:
Expand All @@ -257,6 +262,7 @@ impl App {
begin_block,
)
.await;
Auction::begin_block(&mut arc_state_tx, begin_block).await;
Dex::begin_block(&mut arc_state_tx, begin_block).await;
CommunityPool::begin_block(&mut arc_state_tx, begin_block).await;
Governance::begin_block(&mut arc_state_tx, begin_block).await;
Expand Down Expand Up @@ -387,6 +393,7 @@ impl App {
ShieldedPool::end_block(&mut arc_state_tx, end_block).await;
Distributions::end_block(&mut arc_state_tx, end_block).await;
Ibc::end_block(&mut arc_state_tx, end_block).await;
Auction::end_block(&mut arc_state_tx, end_block).await;
Dex::end_block(&mut arc_state_tx, end_block).await;
CommunityPool::end_block(&mut arc_state_tx, end_block).await;
Governance::end_block(&mut arc_state_tx, end_block).await;
Expand Down Expand Up @@ -496,6 +503,9 @@ impl App {
Ibc::end_epoch(&mut arc_state_tx)
.await
.expect("able to call end_epoch on IBC component");
Auction::end_epoch(&mut arc_state_tx)
.await
.expect("able to call end_epoch on auction component");
Dex::end_epoch(&mut arc_state_tx)
.await
.expect("able to call end_epoch on dex component");
Expand Down Expand Up @@ -691,9 +701,11 @@ pub trait StateReadExt: StateRead {
let shielded_pool_params = self.get_shielded_pool_params().await?;
let stake_params = self.get_stake_params().await?;
let dex_params = self.get_dex_params().await?;
let auction_params = self.get_auction_params().await?;

Ok(AppParameters {
chain_id,
auction_params,
community_pool_params,
distributions_params,
fee_params,
Expand Down
8 changes: 8 additions & 0 deletions crates/core/app/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use penumbra_auction::genesis::Content as AuctionContent;
use penumbra_community_pool::genesis::Content as CommunityPoolContent;
use penumbra_dex::genesis::Content as DexContent;
use penumbra_distributions::genesis::Content as DistributionsContent;
Expand Down Expand Up @@ -47,6 +48,8 @@ pub struct Content {
pub stake_content: StakeContent,
/// Dex component genesis state.
pub dex_content: DexContent,
/// Auction component genesis state.
pub auction_content: AuctionContent,
}

impl DomainType for Content {
Expand Down Expand Up @@ -78,6 +81,7 @@ impl From<Content> for pb::GenesisContent {
fn from(genesis: Content) -> Self {
pb::GenesisContent {
chain_id: genesis.chain_id,
auction_content: Some(genesis.auction_content.into()),
community_pool_content: Some(genesis.community_pool_content.into()),
distributions_content: Some(genesis.distributions_content.into()),
fee_content: Some(genesis.fee_content.into()),
Expand Down Expand Up @@ -116,6 +120,10 @@ impl TryFrom<pb::GenesisContent> for Content {
fn try_from(msg: pb::GenesisContent) -> Result<Self, Self::Error> {
Ok(Content {
chain_id: msg.chain_id,
auction_content: msg
.auction_content
.ok_or_else(|| anyhow::anyhow!("proto response missing Auction content"))?
.try_into()?,
community_pool_content: msg
.community_pool_content
.ok_or_else(|| anyhow::anyhow!("proto response missing Community Pool content"))?
Expand Down
7 changes: 7 additions & 0 deletions crates/core/app/src/params.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use penumbra_auction::params::AuctionParameters;
use penumbra_community_pool::params::CommunityPoolParameters;
use penumbra_dex::DexParameters;
use penumbra_distributions::DistributionsParameters;
Expand All @@ -19,6 +20,7 @@ pub mod change;
#[serde(try_from = "pb::AppParameters", into = "pb::AppParameters")]
pub struct AppParameters {
pub chain_id: String,
pub auction_params: AuctionParameters,
pub community_pool_params: CommunityPoolParameters,
pub distributions_params: DistributionsParameters,
pub dex_params: DexParameters,
Expand All @@ -41,6 +43,10 @@ impl TryFrom<pb::AppParameters> for AppParameters {
fn try_from(msg: pb::AppParameters) -> anyhow::Result<Self> {
Ok(AppParameters {
chain_id: msg.chain_id,
auction_params: msg
.auction_params
.ok_or_else(|| anyhow::anyhow!("proto response missing auction params"))?
.try_into()?,
community_pool_params: msg
.community_pool_params
.ok_or_else(|| anyhow::anyhow!("proto response missing community pool params"))?
Expand Down Expand Up @@ -89,6 +95,7 @@ impl From<AppParameters> for pb::AppParameters {
fn from(params: AppParameters) -> Self {
pb::AppParameters {
chain_id: params.chain_id,
auction_params: Some(params.auction_params.into()),
community_pool_params: Some(params.community_pool_params.into()),
distributions_params: Some(params.distributions_params.into()),
fee_params: Some(params.fee_params.into()),
Expand Down
12 changes: 11 additions & 1 deletion crates/core/app/src/params/change.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

use anyhow::Result;
use penumbra_auction::params::AuctionParameters;
use penumbra_community_pool::params::CommunityPoolParameters;
use penumbra_dex::DexParameters;
use penumbra_distributions::params::DistributionsParameters;
Expand All @@ -27,6 +28,7 @@ impl AppParameters {
// Tracked by #3593
let AppParameters {
chain_id,
auction_params: AuctionParameters {},
community_pool_params:
CommunityPoolParameters {
community_pool_spend_proposals_enabled: _,
Expand Down Expand Up @@ -122,6 +124,7 @@ impl AppParameters {
pub fn check_valid(&self) -> Result<()> {
let AppParameters {
chain_id,
auction_params: AuctionParameters {},
community_pool_params:
CommunityPoolParameters {
community_pool_spend_proposals_enabled: _,
Expand Down Expand Up @@ -252,6 +255,7 @@ impl AppParameters {
/// Converts an `AppParameters` instance to a complete `ChangedAppParameters`.
pub fn as_changed_params(&self) -> ChangedAppParameters {
ChangedAppParameters {
auction_params: Some(self.auction_params.clone()),
community_pool_params: Some(self.community_pool_params.clone()),
distributions_params: Some(self.distributions_params.clone()),
fee_params: Some(self.fee_params.clone()),
Expand Down Expand Up @@ -283,7 +287,8 @@ impl AppParameters {
|| new.ibc_params.is_none()
|| new.sct_params.is_none()
|| new.shielded_pool_params.is_none()
|| new.stake_params.is_none())
|| new.stake_params.is_none()
|| new.auction_params.is_none())
{
anyhow::bail!("all parameters must be specified if no old parameters are provided");
}
Expand All @@ -296,6 +301,11 @@ impl AppParameters {
.expect("old should be set if new has any None values")
.chain_id
.clone(),
auction_params: new.auction_params.clone().unwrap_or_else(|| {
old.expect("old should be set if new has any None values")
.auction_params
.clone()
}),
community_pool_params: new.community_pool_params.clone().unwrap_or_else(|| {
old.expect("old should be set if new has any None values")
.community_pool_params
Expand Down
36 changes: 30 additions & 6 deletions crates/core/component/auction/src/component/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@ use anyhow::Result;
use async_trait::async_trait;
use cnidarium::{StateRead, StateWrite};
use cnidarium_component::Component;
use penumbra_proto::StateReadProto;
use penumbra_proto::StateWriteProto;
use std::sync::Arc;
use tendermint::v0_37::abci;
use tracing::instrument;

use crate::{params::AuctionParameters, state_key};

pub struct Auction {}

#[async_trait]
impl Component for Auction {
type AppState = ();
// Note: this is currently empty, but will make future
// addition easy to do.
type AppState = crate::genesis::Content;

#[instrument(name = "auction", skip(_state, app_state))]
async fn init_chain<S: StateWrite>(_state: S, app_state: Option<&Self::AppState>) {
#[instrument(name = "auction", skip(state, app_state))]
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
match app_state {
None => { /* perform upgrade specific check */ }
Some(&()) => {}
Some(content) => {
state.put_auction_params(content.auction_params.clone());
}
}
}

Expand All @@ -43,14 +51,30 @@ impl Component for Auction {
/// Extension trait providing read access to auction data.
#[async_trait]
pub trait StateReadExt: StateRead {
// Params accessors
async fn get_auction_params(&self) -> Result<AuctionParameters> {
self.get(state_key::parameters::key())
.await
.expect("no deserialization errors")
.ok_or_else(|| anyhow::anyhow!("Missing AuctionParameters"))
}

fn auction_params_updated(&self) -> bool {
self.object_get::<()>(state_key::parameters::updated_flag())
.is_some()
}
}

impl<T: StateRead + ?Sized> StateReadExt for T {}

/// Extension trait providing write access to auction data.
#[async_trait]
pub trait StateWriteExt: StateWrite {}
pub trait StateWriteExt: StateWrite {
/// Writes the provided auction parameters to the chain state.
fn put_auction_params(&mut self, params: AuctionParameters) {
self.object_put(state_key::parameters::updated_flag(), ());
self.put(state_key::parameters::key().into(), params)
}
}

impl<T: StateWrite + ?Sized> StateWriteExt for T {}

Expand Down
1 change: 1 addition & 0 deletions crates/core/component/auction/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod dutch_auction;
pub mod metrics;
pub mod rpc;

pub use auction::Auction;
pub use auction::{StateReadExt, StateWriteExt};
pub(crate) use auction_store::AuctionStoreRead;
pub(crate) use dutch_auction::DutchAuctionManager;
4 changes: 2 additions & 2 deletions crates/core/component/auction/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl DomainType for Content {
impl From<Content> for pb::GenesisContent {
fn from(value: Content) -> Self {
pb::GenesisContent {
auction_params: Some(value.auction_params.into()),
params: Some(value.auction_params.into()),
}
}
}
Expand All @@ -29,7 +29,7 @@ impl TryFrom<pb::GenesisContent> for Content {
fn try_from(msg: pb::GenesisContent) -> Result<Self, Self::Error> {
Ok(Content {
auction_params: msg
.auction_params
.params
.context("auction params not present in protobuf message")?
.try_into()?,
})
Expand Down
1 change: 1 addition & 0 deletions crates/core/component/auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![deny(clippy::unwrap_used)]

pub mod auction;
pub mod genesis;
pub mod params;
pub mod state_key;

Expand Down
6 changes: 6 additions & 0 deletions crates/core/component/auction/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ impl TryFrom<pb::AuctionParameters> for AuctionParameters {
Ok(AuctionParameters {})
}
}

impl Default for AuctionParameters {
fn default() -> Self {
AuctionParameters {}
}
}
1 change: 1 addition & 0 deletions crates/core/component/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ metrics = {workspace = true}
once_cell = {workspace = true}
pbjson-types = {workspace = true}
penumbra-asset = {workspace = true, default-features = false}
penumbra-auction = {workspace = true, default-features = false}
penumbra-community-pool = {workspace = true, default-features = false}
penumbra-distributions = {workspace = true, default-features = false}
penumbra-fee = {workspace = true, default-features = false}
Expand Down
4 changes: 4 additions & 0 deletions crates/core/component/governance/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
use std::str::FromStr;

use crate::params::GovernanceParameters;
use penumbra_auction::params::AuctionParameters;
use penumbra_community_pool::params::CommunityPoolParameters;
use penumbra_dex::DexParameters;
use penumbra_distributions::params::DistributionsParameters;
Expand Down Expand Up @@ -436,6 +437,7 @@ impl ProposalPayload {
into = "pb::ChangedAppParameters"
)]
pub struct ChangedAppParameters {
pub auction_params: Option<AuctionParameters>,
pub community_pool_params: Option<CommunityPoolParameters>,
pub distributions_params: Option<DistributionsParameters>,
pub ibc_params: Option<IBCParameters>,
Expand All @@ -457,6 +459,7 @@ impl TryFrom<pb::ChangedAppParameters> for ChangedAppParameters {

fn try_from(msg: pb::ChangedAppParameters) -> anyhow::Result<Self> {
Ok(ChangedAppParameters {
auction_params: msg.auction_params.map(TryInto::try_into).transpose()?,
community_pool_params: msg
.community_pool_params
.map(TryInto::try_into)
Expand All @@ -483,6 +486,7 @@ impl TryFrom<pb::ChangedAppParameters> for ChangedAppParameters {
impl From<ChangedAppParameters> for pb::ChangedAppParameters {
fn from(params: ChangedAppParameters) -> Self {
pb::ChangedAppParameters {
auction_params: params.auction_params.map(Into::into),
community_pool_params: params.community_pool_params.map(Into::into),
distributions_params: params.distributions_params.map(Into::into),
fee_params: params.fee_params.map(Into::into),
Expand Down
10 changes: 10 additions & 0 deletions crates/proto/src/gen/penumbra.core.app.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ pub struct AppParameters {
pub dex_params: ::core::option::Option<
super::super::component::dex::v1::DexParameters,
>,
/// Auction module parameters.
#[prost(message, optional, tag = "12")]
pub auction_params: ::core::option::Option<
super::super::component::auction::v1alpha1::AuctionParameters,
>,
}
impl ::prost::Name for AppParameters {
const NAME: &'static str = "AppParameters";
Expand Down Expand Up @@ -201,6 +206,11 @@ pub struct GenesisContent {
pub dex_content: ::core::option::Option<
super::super::component::dex::v1::GenesisContent,
>,
/// Auction component genesis state.
#[prost(message, optional, tag = "12")]
pub auction_content: ::core::option::Option<
super::super::component::auction::v1alpha1::GenesisContent,
>,
}
impl ::prost::Name for GenesisContent {
const NAME: &'static str = "GenesisContent";
Expand Down
Loading
Loading