diff --git a/crates/astria-auctioneer/Cargo.toml b/crates/astria-auctioneer/Cargo.toml index 2d7fe56a72..77e9b6ca58 100644 --- a/crates/astria-auctioneer/Cargo.toml +++ b/crates/astria-auctioneer/Cargo.toml @@ -18,7 +18,7 @@ astria-eyre = { path = "../astria-eyre" } config = { package = "astria-config", path = "../astria-config" } sequencer_client = { package = "astria-sequencer-client", path = "../astria-sequencer-client" } telemetry = { package = "astria-telemetry", path = "../astria-telemetry", features = [ - "display", + "display", ] } async-trait = { workspace = true } @@ -36,11 +36,11 @@ serde_json = { workspace = true } sha2 = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = [ - "macros", - "rt-multi-thread", - "sync", - "time", - "signal", + "macros", + "rt-multi-thread", + "sync", + "time", + "signal", ] } tokio-util = { workspace = true, features = ["rt"] } tracing = { workspace = true, features = ["attributes"] } @@ -51,12 +51,12 @@ tokio-stream = { workspace = true, features = ["net"] } [dev-dependencies] astria-core = { path = "../astria-core", features = ["client"] } config = { package = "astria-config", path = "../astria-config", features = [ - "tests", + "tests", ] } insta = { workspace = true, features = ["json"] } tempfile = { workspace = true } test_utils = { package = "astria-test-utils", path = "../astria-test-utils", features = [ - "geth", + "geth", ] } tokio-test = { workspace = true } wiremock = { workspace = true } diff --git a/crates/astria-auctioneer/src/auction/allocation_rule.rs b/crates/astria-auctioneer/src/auction/allocation_rule.rs index 3bae574daa..4eab5a23d5 100644 --- a/crates/astria-auctioneer/src/auction/allocation_rule.rs +++ b/crates/astria-auctioneer/src/auction/allocation_rule.rs @@ -17,7 +17,7 @@ impl FirstPrice { /// /// Returns `true` if the bid is accepted as the highest bid. pub(crate) fn bid(&mut self, bundle: Bundle) -> bool { - if bundle.bid() > self.highest_bid.as_ref().map_or(0, |b| b.bid()) { + if bundle.bid() > self.highest_bid.as_ref().map_or(0, Bundle::bid) { self.highest_bid = Some(bundle); true } else { diff --git a/crates/astria-auctioneer/src/auction/builder.rs b/crates/astria-auctioneer/src/auction/builder.rs index ae5bf8464e..9038fb76f9 100644 --- a/crates/astria-auctioneer/src/auction/builder.rs +++ b/crates/astria-auctioneer/src/auction/builder.rs @@ -67,8 +67,8 @@ impl Builder { sequencer_abci_client, commands_rx, new_bundles_rx, - auction_id, latency_margin, + id: auction_id, sequencer_key, fee_asset_denomination, sequencer_chain_id, @@ -77,8 +77,8 @@ impl Builder { ( Handle { - new_bundles_tx, commands_tx, + new_bundles_tx, }, auction, ) diff --git a/crates/astria-auctioneer/src/auction/mod.rs b/crates/astria-auctioneer/src/auction/mod.rs index 8bedeadb17..d6769b98f7 100644 --- a/crates/astria-auctioneer/src/auction/mod.rs +++ b/crates/astria-auctioneer/src/auction/mod.rs @@ -13,8 +13,8 @@ //! `Command::Abort`. This will cause the auction to return early without submitting a winner, //! effectively discarding any bundles that were processed. //! This is used for leveraging optimsitic execution, running an auction for block data that has -//! been proposed in the sequencer network's CometBFT but not yet finalized. -//! We assume that most proposals are adopted in CometBFT, allowing us to buy a few hundred +//! been proposed in the sequencer network's cometBFT but not yet finalized. +//! We assume that most proposals are adopted in cometBFT, allowing us to buy a few hundred //! milliseconds before they are finalized. However, if multiple rounds of voting invalidate a //! proposal, we can abort the auction and avoid submitting a potentially invalid bundle. In this //! case, the auction will abort and a new one will be created for the newly processed proposal @@ -119,8 +119,7 @@ pub(crate) struct Handle { impl Handle { pub(crate) fn try_abort(&mut self) -> eyre::Result<()> { - let _ = self - .commands_tx + self.commands_tx .try_send(Command::Abort) .wrap_err("unable to send abort command to auction")?; @@ -128,16 +127,14 @@ impl Handle { } pub(crate) fn start_processing_bids(&mut self) -> eyre::Result<()> { - let _ = self - .commands_tx + self.commands_tx .try_send(Command::StartProcessingBids) .wrap_err("unable to send command to start processing bids to auction")?; Ok(()) } pub(crate) fn start_timer(&mut self) -> eyre::Result<()> { - let _ = self - .commands_tx + self.commands_tx .try_send(Command::StartTimer) .wrap_err("unable to send command to start time to auction")?; @@ -169,7 +166,7 @@ pub(crate) struct Auction { /// The time between receiving a block commitment latency_margin: Duration, /// The ID of the auction - auction_id: Id, + id: Id, /// The key used to sign transactions on the sequencer sequencer_key: SequencerKey, /// Fee asset for submitting transactions @@ -205,7 +202,7 @@ impl Auction { Command::Abort => { // abort the auction early // TODO: should this be an error? - break Err(eyre!("auction {id} received abort signal", id = base64(&self.auction_id))); + break Err(eyre!("auction {id} received abort signal", id = base64(&self.id))); }, Command::StartProcessingBids => { if auction_is_open { @@ -224,7 +221,7 @@ impl Auction { // we wait for commit because we want the pending nonce from the committed block nonce_fetch = { let client = self.sequencer_grpc_client.clone(); - let address = self.sequencer_key.address().clone(); + let &address = self.sequencer_key.address(); Some(tokio::task::spawn(async move { get_pending_nonce(client, address, self.metrics).await })) }; } @@ -234,13 +231,13 @@ impl Auction { Some(bundle) = self.new_bundles_rx.recv(), if auction_is_open => { if allocation_rule.bid(bundle.clone()) { info!( - auction.id = %base64(self.auction_id), + auction.id = %base64(self.id), bundle.bid = %bundle.bid(), "received new highest bid" ); } else { debug!( - auction.id = %base64(self.auction_id), + auction.id = %base64(self.id), bundle.bid = %bundle.bid(), "received bid lower than current highest bid, discarding" ); @@ -286,11 +283,11 @@ impl Auction { match result { Ok(resp) => { // TODO: handle failed submission instead of just logging the result - info!(auction.id = %base64(self.auction_id), auction.result = %resp.log, "auction result submitted to sequencer"); + info!(auction.id = %base64(self.id), auction.result = %resp.log, "auction result submitted to sequencer"); Ok(()) }, Err(e) => { - error!(auction.id = %base64(self.auction_id), err = %e, "failed to submit auction result to sequencer"); + error!(auction.id = %base64(self.id), err = %e, "failed to submit auction result to sequencer"); Err(e).wrap_err("failed to submit auction result to sequencer") }, } @@ -329,7 +326,6 @@ async fn get_pending_nonce( let nonce = tryhard::retry_fn(|| { let mut client = client.clone(); - let address = address.clone(); async move { client diff --git a/crates/astria-auctioneer/src/auctioneer/inner.rs b/crates/astria-auctioneer/src/auctioneer/inner.rs index f34d44bf49..e2da31f057 100644 --- a/crates/astria-auctioneer/src/auctioneer/inner.rs +++ b/crates/astria-auctioneer/src/auctioneer/inner.rs @@ -113,7 +113,7 @@ impl Auctioneer { Some((name, res)) = self.tasks.join_next() => { flatten_result(res) .wrap_err_with(|| format!("task `{name}` failed")) - .map(|_| "task `{name}` exited unexpectedly") + .map(|()| "task `{name}` exited unexpectedly") } }; @@ -135,10 +135,10 @@ impl Auctioneer { let message = "task shut down"; match flatten_result(res) { Ok(()) => { - info!(name, message) + info!(name, message); } Err(err) => { - error!(name, %err, message) + error!(name, %err, message); } } } @@ -153,7 +153,7 @@ impl Auctioneer { warn!( tasks = format_args!("[{tasks}]"), "aborting all tasks that have not yet shut down" - ) + ); } else { info!("all tasks have shut down regularly"); } diff --git a/crates/astria-auctioneer/src/auctioneer/mod.rs b/crates/astria-auctioneer/src/auctioneer/mod.rs index aed31d40bd..cce3a43586 100644 --- a/crates/astria-auctioneer/src/auctioneer/mod.rs +++ b/crates/astria-auctioneer/src/auctioneer/mod.rs @@ -32,7 +32,6 @@ impl Auctioneer { /// /// # Errors /// Returns an error if the Auctioneer cannot be initialized. - #[must_use] pub fn spawn(cfg: Config, metrics: &'static Metrics) -> eyre::Result { let shutdown_token = CancellationToken::new(); let inner = inner::Auctioneer::new(cfg, metrics, shutdown_token.child_token())?; diff --git a/crates/astria-auctioneer/src/block/commitment_stream.rs b/crates/astria-auctioneer/src/block/commitment_stream.rs index a6c6bcd814..aa603ab074 100644 --- a/crates/astria-auctioneer/src/block/commitment_stream.rs +++ b/crates/astria-auctioneer/src/block/commitment_stream.rs @@ -45,9 +45,8 @@ impl Stream for BlockCommitmentStream { mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>, ) -> std::task::Poll> { - let res = match futures::ready!(self.client.poll_next_unpin(cx)) { - Some(res) => res, - None => return std::task::Poll::Ready(None), + let Some(res) = futures::ready!(self.client.poll_next_unpin(cx)) else { + return std::task::Poll::Ready(None); }; let raw = res @@ -56,7 +55,7 @@ impl Stream for BlockCommitmentStream { .ok_or_eyre("response did not contain block commitment")?; let commitment = - Commitment::try_from_raw(raw).wrap_err("failed to parse raw to BlockCommitment")?; + Commitment::try_from_raw(&raw).wrap_err("failed to parse raw to BlockCommitment")?; debug!(block_commitment.sequencer_block_hash = %base64(&commitment.sequencer_block_hash()), "received block commitment"); diff --git a/crates/astria-auctioneer/src/block/executed_stream.rs b/crates/astria-auctioneer/src/block/executed_stream.rs index 184d9f02ed..bea5db6ed4 100644 --- a/crates/astria-auctioneer/src/block/executed_stream.rs +++ b/crates/astria-auctioneer/src/block/executed_stream.rs @@ -82,9 +82,8 @@ impl Stream for ExecutedBlockStream { mut self: Pin<&mut Self>, cx: &mut std::task::Context, ) -> std::task::Poll> { - let res = match futures::ready!(self.client.poll_next_unpin(cx)) { - Some(res) => res, - None => return std::task::Poll::Ready(None), + let Some(res) = futures::ready!(self.client.poll_next_unpin(cx)) else { + return std::task::Poll::Ready(None); }; let raw = res.wrap_err("received gRPC Error")?; diff --git a/crates/astria-auctioneer/src/block/mod.rs b/crates/astria-auctioneer/src/block/mod.rs index 0fd30b99c3..3d087241de 100644 --- a/crates/astria-auctioneer/src/block/mod.rs +++ b/crates/astria-auctioneer/src/block/mod.rs @@ -4,13 +4,18 @@ use astria_core::{ bundle::v1alpha1 as raw_bundle, sequencerblock::{ optimisticblock::v1alpha1 as raw_optimistic_block, - v1 as raw_sequencer_block, + v1::{ + self as raw_sequencer_block, + }, }, }, primitive::v1::RollupId, - sequencerblock::v1::block::{ - FilteredSequencerBlock, - FilteredSequencerBlockParts, + sequencerblock::v1::{ + block::{ + FilteredSequencerBlock, + FilteredSequencerBlockParts, + }, + RollupTransactions, }, Protobuf, }; @@ -79,7 +84,7 @@ impl Optimistic { let maybe_serialized_transactions = rollup_transactions .swap_remove(&rollup_id) - .map(|transactions| transactions.into_parts()); + .map(RollupTransactions::into_parts); let transactions = maybe_serialized_transactions.map_or(Ok(vec![]), |serialized_transactions| { @@ -101,7 +106,7 @@ impl Optimistic { } pub(crate) fn sequencer_block_hash(&self) -> [u8; 32] { - self.filtered_sequencer_block.block_hash().clone() + *self.filtered_sequencer_block.block_hash() } pub(crate) fn sequencer_height(&self) -> u64 { @@ -170,7 +175,7 @@ pub(crate) struct Commitment { impl Commitment { pub(crate) fn try_from_raw( - raw: raw_optimistic_block::SequencerBlockCommit, + raw: &raw_optimistic_block::SequencerBlockCommit, ) -> eyre::Result { Ok(Self { sequencer_height: raw.height, @@ -238,10 +243,10 @@ impl Current { self.optimistic.sequencer_block_hash() } - pub(crate) fn rollup_parent_block_hash(&self) -> Option<[u8; 32]> { + pub(crate) fn parent_rollup_block_hash(&self) -> Option<[u8; 32]> { self.executed .as_ref() - .map(|executed| executed.parent_rollup_block_hash()) + .map(Executed::parent_rollup_block_hash) } /// Ensures that the given `bundle` is valid for the current block state. @@ -254,7 +259,7 @@ impl Current { current_hash = base64(self.sequencer_block_hash()) ); - if let Some(rollup_parent_block_hash) = self.rollup_parent_block_hash() { + if let Some(rollup_parent_block_hash) = self.parent_rollup_block_hash() { ensure!( bundle.parent_rollup_block_hash() == rollup_parent_block_hash, "bundle's rollup parent block hash {bundle_hash} does not match current rollup \ diff --git a/crates/astria-auctioneer/src/block/optimistic_stream.rs b/crates/astria-auctioneer/src/block/optimistic_stream.rs index 6bbb995422..76c384dd21 100644 --- a/crates/astria-auctioneer/src/block/optimistic_stream.rs +++ b/crates/astria-auctioneer/src/block/optimistic_stream.rs @@ -69,9 +69,8 @@ impl Stream for OptimisticBlockStream { mut self: Pin<&mut Self>, cx: &mut std::task::Context, ) -> std::task::Poll> { - let res = match futures::ready!(self.client.poll_next_unpin(cx)) { - Some(raw) => raw, - None => return std::task::Poll::Ready(None), + let Some(res) = futures::ready!(self.client.poll_next_unpin(cx)) else { + return std::task::Poll::Ready(None); }; let raw = res