Skip to content

Commit

Permalink
app: connect auction component to application
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Apr 23, 2024
1 parent b66a2c6 commit a3a6cbe
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
11 changes: 10 additions & 1 deletion crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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::{StateReadExt as _, StateWriteExt as _};
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 @@ -119,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 @@ -246,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 @@ -258,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 @@ -388,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 @@ -497,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
6 changes: 6 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 @@ -80,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 @@ -118,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
6 changes: 4 additions & 2 deletions crates/core/component/auction/src/component/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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>) {
match app_state {
None => { /* perform upgrade specific check */ }
Some(&()) => {}
Some(_) => {}
}
}

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
2 changes: 1 addition & 1 deletion crates/core/component/auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#![deny(clippy::unwrap_used)]

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

#[cfg(feature = "component")]
Expand Down

0 comments on commit a3a6cbe

Please sign in to comment.