Skip to content

Commit

Permalink
move Auctioneer frontend to lib.rs, flatten business logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFluffy committed Jan 14, 2025
1 parent 7ba8503 commit ea52399
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/// associated handles.
use astria_core::{
primitive::v1::{
asset,
RollupId,
asset,
},
sequencerblock::v1::block::FilteredSequencerBlock,
};
Expand All @@ -20,29 +20,26 @@ use super::{
};
use crate::sequencer_channel::SequencerChannel;

pub(in crate::auctioneer::inner) struct Factory {
pub(in crate::auctioneer) struct Factory {
#[allow(dead_code)]
pub(in crate::auctioneer::inner) metrics: &'static crate::Metrics,
pub(in crate::auctioneer::inner) sequencer_abci_client: sequencer_client::HttpClient,
pub(in crate::auctioneer::inner) sequencer_channel: SequencerChannel,
pub(in crate::auctioneer::inner) latency_margin: std::time::Duration,
pub(in crate::auctioneer::inner) sequencer_key: SequencerKey,
pub(in crate::auctioneer::inner) fee_asset_denomination: asset::Denom,
pub(in crate::auctioneer::inner) sequencer_chain_id: String,
pub(in crate::auctioneer::inner) rollup_id: RollupId,
pub(in crate::auctioneer::inner) cancellation_token: CancellationToken,
pub(in crate::auctioneer) metrics: &'static crate::Metrics,
pub(in crate::auctioneer) sequencer_abci_client: sequencer_client::HttpClient,
pub(in crate::auctioneer) sequencer_channel: SequencerChannel,
pub(in crate::auctioneer) latency_margin: std::time::Duration,
pub(in crate::auctioneer) sequencer_key: SequencerKey,
pub(in crate::auctioneer) fee_asset_denomination: asset::Denom,
pub(in crate::auctioneer) sequencer_chain_id: String,
pub(in crate::auctioneer) rollup_id: RollupId,
pub(in crate::auctioneer) cancellation_token: CancellationToken,
/// `last_successful_nonce + 1` is used for submitting an auction winner to Sequencer
/// if an auction worker was not able to receive the last pending
/// nonce from Sequencer in time. Starts unset at the beginning of the program and
/// is set externally via Factory::set_last_succesful_nonce`.
pub(in crate::auctioneer::inner) last_successful_nonce: Option<u32>,
pub(in crate::auctioneer) last_successful_nonce: Option<u32>,
}

impl Factory {
pub(in crate::auctioneer::inner) fn start_new(
&self,
block: &FilteredSequencerBlock,
) -> Auction {
pub(in crate::auctioneer) fn start_new(&self, block: &FilteredSequencerBlock) -> Auction {
let id = super::Id::from_sequencer_block_hash(block.block_hash());
let block_hash = *block.block_hash();
let height = block.height().into();
Expand Down Expand Up @@ -82,7 +79,7 @@ impl Factory {
}
}

pub(in crate::auctioneer::inner) fn set_last_successful_nonce(&mut self, nonce: u32) {
pub(in crate::auctioneer) fn set_last_successful_nonce(&mut self, nonce: u32) {
self.last_successful_nonce.replace(nonce);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ use astria_core::{
};
use astria_eyre::eyre::{
self,
WrapErr as _,
bail,
ensure,
eyre,
WrapErr as _,
};
use futures::{
Future,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl Auction {
self.cancellation_token.cancel();
}

pub(in crate::auctioneer::inner) fn id(&self) -> &Id {
pub(in crate::auctioneer) fn id(&self) -> &Id {
&self.id
}

Expand Down Expand Up @@ -152,7 +152,7 @@ impl Auction {

// TODO: identify the executed block in the span fields
#[instrument(skip_all, fields(id = %self.id), err)]
pub(in crate::auctioneer::inner) fn start_bids(
pub(in crate::auctioneer) fn start_bids(
&mut self,
block: crate::block::Executed,
) -> eyre::Result<()> {
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Auction {
bid.parent_roll_block_hash = %base64(bid.rollup_parent_block_hash()),
), err)]
pub(in crate::auctioneer::inner) fn forward_bid_to_auction(
pub(in crate::auctioneer) fn forward_bid_to_auction(
&mut self,
bid: Arc<Bid>,
) -> eyre::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ use std::{

use astria_core::{
primitive::v1::{
asset,
Address,
RollupId,
asset,
},
protocol::transaction::v1::Transaction,
};
use futures::FutureExt as _;
use sequencer_client::{
tendermint_rpc::endpoint::broadcast::tx_sync,
SequencerClientExt as _,
tendermint_rpc::endpoint::broadcast::tx_sync,
};
use tokio::{
select,
Expand All @@ -65,22 +65,22 @@ use tokio::{
JoinHandle,
},
time::{
sleep,
Sleep,
sleep,
},
};
use tokio_util::sync::CancellationToken;
use tracing::{
Instrument as _,
Level,
error,
info,
instrument,
Instrument as _,
Level,
};

use super::{
allocation_rule::FirstPrice,
Summary,
allocation_rule::FirstPrice,
};
use crate::{
bid::Bid,
Expand Down Expand Up @@ -288,7 +288,7 @@ impl Worker {
}

#[derive(Debug, thiserror::Error)]
pub(in crate::auctioneer::inner) enum Error {
pub(in crate::auctioneer) enum Error {
#[error("all channels to the auction worker are closed; the auction cannot continue")]
ChannelsClosed,
// TODO: Is there a way to identify the winning bid? Do we need it?
Expand Down
Loading

0 comments on commit ea52399

Please sign in to comment.