Skip to content

Commit

Permalink
rename bundle apis
Browse files Browse the repository at this point in the history
migrate all of auctioneer to bundle -> auction API
  • Loading branch information
itamarreif authored and SuperFluffy committed Jan 14, 2025
1 parent e08dd0e commit 7ba8503
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 331 deletions.
2 changes: 1 addition & 1 deletion crates/astria-auctioneer/local.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ASTRIA_AUCTIONEER_FEE_ASSET_DENOMINATION="nria"
# The prefix that will be used to construct bech32m sequencer addresses.
ASTRIA_AUCTIONEER_SEQUENCER_ADDRESS_PREFIX=astria

# Address of the gRPC server for the rollup's Optimistic Execution and Bundle services
# Address of the gRPC server for the rollup's Auction and Optimistic Execution services.
ASTRIA_AUCTIONEER_ROLLUP_GRPC_ENDPOINT="http://127.0.0.1:50051"

# The rollup ID to post the auction result to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use tracing::{
instrument,
};

use super::Bundle;
use super::Bid;

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

impl FirstPrice {
Expand All @@ -20,15 +20,15 @@ impl FirstPrice {
}
}

/// Submit a bundle with a bid.
/// Submit a bid with a bid.
///
/// Returns `true` if the bid is accepted as the highest bid.
// TODO: identify the incumbant and candidate by their hash?
#[instrument(skip_all, fields(
current_winner.bid = self.highest_bid.as_ref().map(|bundle| bundle.bid()),
current_winner.bid = self.highest_bid.as_ref().map(|bid| bid.bid()),
candidate.bid = candidate.bid(),
))]
pub(super) fn bid(&mut self, candidate: &Arc<Bundle>) {
pub(super) fn bid(&mut self, candidate: &Arc<Bid>) {
let winner = if let Some(current) = self.highest_bid.as_mut() {
if candidate.bid() > current.bid() {
*current = candidate.clone();
Expand All @@ -44,7 +44,7 @@ impl FirstPrice {
}

/// Returns the winner of the auction, if one exists.
pub(super) fn winner(self) -> Option<Arc<Bundle>> {
pub(super) fn winner(self) -> Option<Arc<Bid>> {
self.highest_bid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ impl Factory {
// TODO: get the capacities from config or something instead of using a magic number
let (start_bids_tx, start_bids_rx) = oneshot::channel();
let (start_timer_tx, start_timer_rx) = oneshot::channel();
let (bundles_tx, bundles_rx) = mpsc::unbounded_channel();
let (bids_tx, bids_rx) = mpsc::unbounded_channel();

let cancellation_token = self.cancellation_token.child_token();
let auction = Worker {
sequencer_abci_client: self.sequencer_abci_client.clone(),
sequencer_channel: self.sequencer_channel.clone(),
start_bids: Some(start_bids_rx),
start_timer: Some(start_timer_rx),
bundles: bundles_rx,
bids: bids_rx,
latency_margin: self.latency_margin,
id,
sequencer_key: self.sequencer_key.clone(),
Expand All @@ -76,7 +76,7 @@ impl Factory {
hash_of_executed_block_on_rollup: None,
start_bids: Some(start_bids_tx),
start_timer: Some(start_timer_tx),
bundles: bundles_tx,
bids: bids_tx,
cancellation_token,
worker: tokio::task::spawn(auction.run()),
}
Expand Down
37 changes: 19 additions & 18 deletions crates/astria-auctioneer/src/auctioneer/inner/auction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use astria_eyre::eyre::{
bail,
ensure,
eyre,
Context,
WrapErr as _,
};
use futures::{
Future,
Expand All @@ -70,7 +70,7 @@ use tokio_util::sync::CancellationToken;
use tracing::instrument;

use crate::{
bundle::Bundle,
bid::Bid,
sequencer_key::SequencerKey,
};

Expand Down Expand Up @@ -106,7 +106,7 @@ pub(super) struct Auction {
hash_of_executed_block_on_rollup: Option<[u8; 32]>,
start_bids: Option<oneshot::Sender<()>>,
start_timer: Option<oneshot::Sender<()>>,
bundles: mpsc::UnboundedSender<Arc<Bundle>>,
bids: mpsc::UnboundedSender<Arc<Bid>>,
cancellation_token: CancellationToken,
worker: JoinHandle<Result<Summary, worker::Error>>,
}
Expand Down Expand Up @@ -183,35 +183,36 @@ impl Auction {
// TODO: Use a refinement type for the parente rollup block hash
#[instrument(skip_all, fields(
id = %self.id,
bundle.sequencer_block_hash = %bundle.base_sequencer_block_hash(),
bundle.parent_roll_block_hash = %base64(bundle.parent_rollup_block_hash()),
bid.sequencer_block_hash = %bid.sequencer_parent_block_hash(),
bid.parent_roll_block_hash = %base64(bid.rollup_parent_block_hash()),
), err)]
pub(in crate::auctioneer::inner) fn forward_bundle_to_auction(
pub(in crate::auctioneer::inner) fn forward_bid_to_auction(
&mut self,
bundle: Arc<Bundle>,
bid: Arc<Bid>,
) -> eyre::Result<()> {
// TODO: emit some more information about auctoin ID, expected vs actual parent block hash,
// tacked block hash, provided block hash, etc.
let Some(block_hash_of_executed) = self.hash_of_executed_block_on_rollup else {
eyre::bail!(
"received a new bundle but the current auction has not yet
received an execute block from the rollup; dropping the bundle"
"received a new bid but the current auction has not yet
received an execute block from the rollup; dropping the bid"
);
};
ensure!(
&self.block_hash == bundle.base_sequencer_block_hash()
&& block_hash_of_executed == bundle.parent_rollup_block_hash(),
"bundle does not match auction; auction.sequenecer_block_hash = `{}`, \
auction.parent_block_hash = `{}`, bundle. = `{}`, bundle.height = `{}`",
&self.block_hash == bid.sequencer_parent_block_hash()
&& block_hash_of_executed == bid.rollup_parent_block_hash(),
"bid does not match auction; auction.sequencer_parent_block_hash = `{}`, \
auction.rollup_parent_block_hash = `{}`, bid.sequencer_parent_block_hash = `{}`, \
bid.rollup_parent_block_hash = `{}`",
self.block_hash,
base64(block_hash_of_executed),
bundle.base_sequencer_block_hash(),
base64(bundle.parent_rollup_block_hash()),
bid.sequencer_parent_block_hash(),
base64(bid.rollup_parent_block_hash()),
);
self.bundles
.send(bundle)
.wrap_err("failed to submit bundle to auction; the bundle is lost")
self.bids
.send(bid)
.wrap_err("failed to submit bid to auction; the bid is lost")
}
}

Expand Down
14 changes: 7 additions & 7 deletions crates/astria-auctioneer/src/auctioneer/inner/auction/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use super::{
Summary,
};
use crate::{
bundle::Bundle,
bid::Bid,
sequencer_channel::SequencerChannel,
sequencer_key::SequencerKey,
};
Expand All @@ -96,8 +96,8 @@ pub(super) struct Worker {
pub(super) sequencer_channel: SequencerChannel,
pub(super) start_bids: Option<oneshot::Receiver<()>>,
pub(super) start_timer: Option<oneshot::Receiver<()>>,
/// Channel for receiving new bundles
pub(super) bundles: tokio::sync::mpsc::UnboundedReceiver<Arc<Bundle>>,
/// Channel for receiving new bids.
pub(super) bids: tokio::sync::mpsc::UnboundedReceiver<Arc<Bid>>,
/// The time between receiving a block commitment
pub(super) latency_margin: Duration,
/// The ID of the auction
Expand Down Expand Up @@ -230,7 +230,7 @@ impl Worker {
.unwrap()
.await
}, if latency_margin_timer.is_some() => {
info!("timer is up; bids left unprocessed: {}", self.bundles.len());
info!("timer is up; bids left unprocessed: {}", self.bids.len());
break Ok(AuctionItems {
winner: allocation_rule.winner(),
nonce_fetch,
Expand Down Expand Up @@ -277,8 +277,8 @@ impl Worker {
}

// TODO: this is an unbounded channel. Can we process multiple bids at a time?
Some(bundle) = self.bundles.recv(), if auction_is_open => {
allocation_rule.bid(&bundle);
Some(bid) = self.bids.recv(), if auction_is_open => {
allocation_rule.bid(&bid);
}

else => break Err(Error::ChannelsClosed),
Expand Down Expand Up @@ -319,7 +319,7 @@ where
}

struct AuctionItems {
winner: Option<Arc<Bundle>>,
winner: Option<Arc<Bid>>,
nonce_fetch: Option<AbortJoinHandle<u32>>,
}

Expand Down
24 changes: 12 additions & 12 deletions crates/astria-auctioneer/src/auctioneer/inner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use tracing::{

use crate::{
rollup_channel::{
BundleStream,
BidStream,
ExecuteOptimisticBlockStream,
},
sequencer_channel::{
Expand All @@ -50,7 +50,7 @@ mod auction;
pub(super) struct Inner {
auction_factory: auction::Factory,
block_commitments: BlockCommitmentStream,
bundles: BundleStream,
bids: BidStream,
cancelled_auctions: FuturesUnordered<auction::Auction>,
executed_blocks: ExecuteOptimisticBlockStream,
running_auction: Option<auction::Auction>,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Inner {
Ok(Self {
auction_factory,
block_commitments: sequencer_channel.open_get_block_commitment_stream(),
bundles: rollup_channel.open_bundle_stream(),
bids: rollup_channel.open_bid_stream(),
cancelled_auctions: FuturesUnordered::new(),
executed_blocks: rollup_channel.open_execute_optimistic_block_stream(),
optimistic_blocks: sequencer_channel.open_get_optimistic_block_stream(rollup_id),
Expand Down Expand Up @@ -167,8 +167,8 @@ impl Inner {
let _ = self.handle_completed_auction(id, res);
}

Some(res) = self.bundles.next() => {
let _ = self.handle_bundle(res);
Some(res) = self.bids.next() => {
let _ = self.handle_bids(res);
}

Some((id, res)) = self.cancelled_auctions.next() => {
Expand Down Expand Up @@ -296,23 +296,23 @@ impl Inner {
}

#[instrument(skip_all, fields(block_hash = field::Empty), err)]
fn handle_bundle(&mut self, bundle: eyre::Result<crate::bundle::Bundle>) -> eyre::Result<()> {
let bundle = Arc::new(bundle.wrap_err("received problematic bundle")?);
fn handle_bids(&mut self, bid: eyre::Result<crate::bid::Bid>) -> eyre::Result<()> {
let bid = Arc::new(bid.wrap_err("received problematic bid")?);
Span::current().record(
"block_hash",
field::display(bundle.base_sequencer_block_hash()),
field::display(bid.sequencer_parent_block_hash()),
);
if let Some(running_auction) = &mut self.running_auction {
running_auction
.forward_bundle_to_auction(bundle)
.wrap_err("failed to forward bundle to auction")?;
.forward_bid_to_auction(bid)
.wrap_err("failed to forward bid to auction")?;
info!(
auction_id = %running_auction.id(),
"forwarded bundle to auction"
"forwarded bid auction"
);
} else {
info!(
"received a bundle but did not forward it to the auction because no auction was \
"received a bid but did not forward it to the auction because no auction was \
running",
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use astria_core::{
Signature,
VerificationKey,
},
generated::astria::bundle::v1alpha1 as raw,
generated::astria::auction::v1alpha1 as raw,
primitive::v1::{
asset,
RollupId,
Expand All @@ -23,51 +23,50 @@ use prost::Message as _;

use crate::sequencer_key::SequencerKey;

// TODO: this should probably be moved to astria_core::bundle?
// TODO: this should probably be moved to astria_core::auction?
#[derive(Debug, Clone)]
pub(crate) struct Bundle {
/// The fee that will be charged for this bundle
pub(crate) struct Bid {
/// The fee that will be charged for this bid.
fee: u64,
/// The byte list of transactions fto be included.
transactions: Vec<Bytes>,
/// The hash of the rollup block that this bundle is based on.
// TODO: rename this to `parent_rollup_block_hash` to match execution api
prev_rollup_block_hash: [u8; 32],
/// The hash of the sequencer block used to derive the rollup block that this bundle is based
/// The hash of the rollup block that this bid is based on.
rollup_parent_block_hash: [u8; 32],
/// The hash of the sequencer block used to derive the rollup block that this bid is based
/// on.
base_sequencer_block_hash: block::Hash,
sequencer_parent_block_hash: block::Hash,
}

impl Bundle {
pub(crate) fn try_from_raw(raw: raw::Bundle) -> eyre::Result<Self> {
let raw::Bundle {
impl Bid {
pub(crate) fn try_from_raw(raw: raw::Bid) -> eyre::Result<Self> {
let raw::Bid {
fee,
transactions,
base_sequencer_block_hash,
prev_rollup_block_hash,
sequencer_parent_block_hash,
rollup_parent_block_hash,
} = raw;
Ok(Self {
fee,
transactions,
prev_rollup_block_hash: prev_rollup_block_hash
rollup_parent_block_hash: rollup_parent_block_hash
.as_ref()
.try_into()
.wrap_err("invalid prev_rollup_block_hash")?,
base_sequencer_block_hash: base_sequencer_block_hash
sequencer_parent_block_hash: sequencer_parent_block_hash
.as_ref()
.try_into()
.wrap_err("invalid base_sequencer_block_hash")?,
})
}

fn into_raw(self) -> raw::Bundle {
raw::Bundle {
fn into_raw(self) -> raw::Bid {
raw::Bid {
fee: self.fee,
transactions: self.transactions,
base_sequencer_block_hash: Bytes::copy_from_slice(
self.base_sequencer_block_hash.as_bytes(),
sequencer_parent_block_hash: Bytes::copy_from_slice(
self.sequencer_parent_block_hash.as_bytes(),
),
prev_rollup_block_hash: Bytes::copy_from_slice(&self.prev_rollup_block_hash),
rollup_parent_block_hash: Bytes::copy_from_slice(&self.rollup_parent_block_hash),
}
}

Expand Down Expand Up @@ -101,31 +100,31 @@ impl Bundle {
self.fee
}

pub(crate) fn parent_rollup_block_hash(&self) -> [u8; 32] {
self.prev_rollup_block_hash
pub(crate) fn rollup_parent_block_hash(&self) -> [u8; 32] {
self.rollup_parent_block_hash
}

pub(crate) fn base_sequencer_block_hash(&self) -> &block::Hash {
&self.base_sequencer_block_hash
pub(crate) fn sequencer_parent_block_hash(&self) -> &block::Hash {
&self.sequencer_parent_block_hash
}
}

#[derive(Debug)]
pub(crate) struct Allocation {
signature: Signature,
verification_key: VerificationKey,
payload: Bundle,
payload: Bid,
}

impl Allocation {
fn new(bundle: Bundle, sequencer_key: &SequencerKey) -> Self {
let bundle_data = bundle.clone().into_raw().encode_to_vec();
let signature = sequencer_key.signing_key().sign(&bundle_data);
fn new(bid: Bid, sequencer_key: &SequencerKey) -> Self {
let bid_data = bid.clone().into_raw().encode_to_vec();
let signature = sequencer_key.signing_key().sign(&bid_data);
let verification_key = sequencer_key.signing_key().verification_key();
Self {
signature,
verification_key,
payload: bundle,
payload: bid,
}
}

Expand Down
Loading

0 comments on commit 7ba8503

Please sign in to comment.