Skip to content

Commit

Permalink
add auction manager
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Nov 7, 2024
1 parent 2447dd4 commit 3c4403c
Show file tree
Hide file tree
Showing 21 changed files with 1,067 additions and 412 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.

1 change: 1 addition & 0 deletions crates/astria-auctioneer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async-trait = { workspace = true }
axum = { workspace = true }
bytes = { workspace = true }
futures = { workspace = true }
hex = { workspace = true }
humantime = { workspace = true }
itertools = { workspace = true }
pbjson-types = { workspace = true }
Expand Down
26 changes: 26 additions & 0 deletions crates/astria-auctioneer/src/auction/allocation_rule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use super::Bundle;

pub(super) struct FirstPrice {
highest_bid: Option<Bundle>,
}

impl FirstPrice {
pub(super) fn new() -> Self {
Self {
highest_bid: None,
}
}

pub(crate) fn bid(&mut self, bundle: Bundle) -> bool {
if bundle.bid() > self.highest_bid.as_ref().map_or(0, |b| b.bid()) {
self.highest_bid = Some(bundle);
true
} else {
false
}
}

pub(crate) fn highest_bid(self) -> Option<Bundle> {
self.highest_bid
}
}
57 changes: 0 additions & 57 deletions crates/astria-auctioneer/src/auction/bid.rs

This file was deleted.

74 changes: 47 additions & 27 deletions crates/astria-auctioneer/src/auction/builder.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
use std::time::Duration;

use astria_eyre::eyre;
use astria_core::{
generated::sequencerblock::v1::sequencer_service_client::SequencerServiceClient,
primitive::v1::{
asset,
RollupId,
},
};
use tokio::sync::{
mpsc,
oneshot,
};
use tokio_util::sync::CancellationToken;

use super::{
BundlesHandle,
Driver,
Auction,
Handle,
Id,
OptimisticExecutionHandle,
SequencerKey,
};
use crate::Metrics;

Expand All @@ -20,56 +26,70 @@ pub(crate) struct Builder {
pub(crate) shutdown_token: CancellationToken,

/// The endpoint for the sequencer gRPC service used to get pending nonces
pub(crate) sequencer_grpc_endpoint: String,
pub(crate) sequencer_grpc_client: SequencerServiceClient<tonic::transport::Channel>,
/// The endpoint for the sequencer ABCI service used to submit transactions
pub(crate) sequencer_abci_endpoint: String,
pub(crate) sequencer_abci_client: sequencer_client::HttpClient,
/// The amount of time to wait after a commit before closing the auction for bids and
/// submitting the resulting transaction
pub(crate) latency_margin: Duration,
/// The ID of the auction to be run
pub(crate) auction_id: Id,
/// The key used to sign sequencer transactions
pub(crate) sequencer_key: SequencerKey,
/// The denomination of the fee asset used in the sequencer transactions
pub(crate) fee_asset_denomination: asset::Denom,
/// The chain ID used for sequencer transactions
pub(crate) sequencer_chain_id: String,
/// The rollup ID used for `RollupDataSubmission` with the auction result
pub(crate) rollup_id: RollupId,
}

impl Builder {
pub(crate) fn build(self) -> eyre::Result<(Driver, OptimisticExecutionHandle, BundlesHandle)> {
pub(crate) fn build(self) -> (Handle, Auction) {
let Self {
metrics,
shutdown_token,
sequencer_grpc_endpoint,
sequencer_abci_endpoint,
sequencer_grpc_client,
sequencer_abci_client,
latency_margin,
auction_id,
fee_asset_denomination,
rollup_id,
sequencer_key,
sequencer_chain_id,
} = self;

let (executed_block_tx, executed_block_rx) = oneshot::channel();
let (block_commitment_tx, block_commitment_rx) = oneshot::channel();
let (reorg_tx, reorg_rx) = oneshot::channel();
// TODO: get the capacity from config or something instead of using a magic number
let (new_bids_tx, new_bids_rx) = mpsc::channel(16);
let (new_bundles_tx, new_bundles_rx) = mpsc::channel(16);

let driver = Driver {
let auction = Auction {
metrics,
shutdown_token,
sequencer_grpc_endpoint,
sequencer_abci_endpoint,
executed_block_rx,
block_commitment_rx,
reorg_rx,
new_bids_rx,
sequencer_grpc_client,
sequencer_abci_client,
start_processing_bids_rx: executed_block_rx,
start_timer_rx: block_commitment_rx,
abort_rx: reorg_rx,
new_bundles_rx,
auction_id,
latency_margin,
sequencer_key,
fee_asset_denomination,
sequencer_chain_id,
rollup_id,
};

Ok((
driver,
OptimisticExecutionHandle {
executed_block_tx: Some(executed_block_tx),
block_commitment_tx: Some(block_commitment_tx),
reorg_tx: Some(reorg_tx),
},
BundlesHandle {
new_bids_tx,
(
Handle {
new_bundles_tx,
start_processing_bids_tx: Some(executed_block_tx),
start_timer_tx: Some(block_commitment_tx),
abort_tx: Some(reorg_tx),
},
))
auction,
)
}
}
Loading

0 comments on commit 3c4403c

Please sign in to comment.