Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Nov 8, 2024
1 parent 2f17c08 commit 3e7f64a
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 52 deletions.
16 changes: 8 additions & 8 deletions crates/astria-auctioneer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-auctioneer/src/auction/allocation_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-auctioneer/src/auction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -77,8 +77,8 @@ impl Builder {

(
Handle {
new_bundles_tx,
commands_tx,
new_bundles_tx,
},
auction,
)
Expand Down
28 changes: 12 additions & 16 deletions crates/astria-auctioneer/src/auction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,25 +119,22 @@ 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")?;

Ok(())
}

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")?;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 }))
};
}
Expand All @@ -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"
);
Expand Down Expand Up @@ -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")
},
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions crates/astria-auctioneer/src/auctioneer/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
};

Expand All @@ -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);
}
}
}
Expand All @@ -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");
}
Expand Down
1 change: 0 additions & 1 deletion crates/astria-auctioneer/src/auctioneer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
let shutdown_token = CancellationToken::new();
let inner = inner::Auctioneer::new(cfg, metrics, shutdown_token.child_token())?;
Expand Down
7 changes: 3 additions & 4 deletions crates/astria-auctioneer/src/block/commitment_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ impl Stream for BlockCommitmentStream {
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
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
Expand All @@ -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");

Expand Down
5 changes: 2 additions & 3 deletions crates/astria-auctioneer/src/block/executed_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ impl Stream for ExecutedBlockStream {
mut self: Pin<&mut Self>,
cx: &mut std::task::Context,
) -> std::task::Poll<Option<Self::Item>> {
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")?;
Expand Down
25 changes: 15 additions & 10 deletions crates/astria-auctioneer/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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| {
Expand All @@ -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 {
Expand Down Expand Up @@ -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<Self> {
Ok(Self {
sequencer_height: raw.height,
Expand Down Expand Up @@ -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.
Expand All @@ -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 \
Expand Down
5 changes: 2 additions & 3 deletions crates/astria-auctioneer/src/block/optimistic_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ impl Stream for OptimisticBlockStream {
mut self: Pin<&mut Self>,
cx: &mut std::task::Context,
) -> std::task::Poll<Option<Self::Item>> {
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
Expand Down

0 comments on commit 3e7f64a

Please sign in to comment.