Skip to content

Commit

Permalink
add baseblockerror
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarreif committed Nov 5, 2024
1 parent 58ac5fd commit e3f4c04
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/astria-auctioneer/src/auction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl Auction {
let submission_result = select! {
biased;

// TODO: should this be Ok(())?
// TODO: should this be Ok(())? or Ok("received shutdown signal")?
() = self.shutdown_token.cancelled() => Err(eyre!("received shutdown signal")),

// submit the transaction to the sequencer
Expand Down
8 changes: 1 addition & 7 deletions crates/astria-auctioneer/src/block/executed_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,8 @@ pub(crate) fn make_execution_requests_stream(
let (blocks_to_execute_tx, blocks_to_execute_rx) = mpsc::channel(16);
let blocks_to_execute_stream_rx = ReceiverStream::new(blocks_to_execute_rx);

// TODO: dont skip empty blocks
let requests = blocks_to_execute_stream_rx.filter_map(move |block: Optimistic| async move {
let base_block = block
.try_into_base_block(rollup_id)
.wrap_err("failed to create BaseBlock from FilteredSequencerBlock");

// skip blocks which fail to produce a BaseBlock for the given rollup_id
match base_block {
match block.try_into_base_block(rollup_id) {
Ok(base_block) => Some(ExecuteOptimisticBlockStreamRequest {
base_block: Some(base_block),
}),
Expand Down
35 changes: 29 additions & 6 deletions crates/astria-auctioneer/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use astria_eyre::eyre::{
OptionExt,
};
use bytes::Bytes;
use prost::Message as _;
use prost::{
DecodeError,
Message as _,
};

pub(crate) mod block_commitment_stream;
pub(crate) mod executed_stream;
Expand Down Expand Up @@ -62,7 +65,7 @@ impl Optimistic {
pub(crate) fn try_into_base_block(
self,
rollup_id: RollupId,
) -> eyre::Result<raw_bundle::BaseBlock> {
) -> Result<raw_bundle::BaseBlock, BaseBlockError> {
let FilteredSequencerBlockParts {
block_hash,
header,
Expand All @@ -72,17 +75,15 @@ impl Optimistic {

let serialized_transactions = rollup_transactions
.swap_remove(&rollup_id)
.ok_or_eyre(
"FilteredSequencerBlock does not contain transactions for the given rollup",
)?
.ok_or_else(|| BaseBlockError::rollup_id_not_found(rollup_id))?
.into_parts();

let transactions = serialized_transactions
.transactions
.into_iter()
.map(raw_sequencer_block::RollupData::decode)
.collect::<Result<_, _>>()
.wrap_err("failed to decode RollupData")?;
.map_err(BaseBlockError::decode_rollup_data)?;

let timestamp = Some(convert_tendermint_time_to_protobuf_timestamp(header.time()));

Expand All @@ -102,6 +103,28 @@ impl Optimistic {
}
}

#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub(crate) struct BaseBlockError(BaseBlockErrorKind);

#[derive(Debug, thiserror::Error)]
enum BaseBlockErrorKind {
#[error("RollupId not found: {0}")]
RollupIdNotFound(RollupId),
#[error("failed to decode RollupData")]
DecodeRollupData(DecodeError),
}

impl BaseBlockError {
pub(crate) fn rollup_id_not_found(rollup_id: RollupId) -> Self {
Self(BaseBlockErrorKind::RollupIdNotFound(rollup_id))
}

fn decode_rollup_data(error: DecodeError) -> Self {
Self(BaseBlockErrorKind::DecodeRollupData(error))
}
}

#[derive(Debug, Clone)]
pub(crate) struct Executed {
block: execution::v1::Block,
Expand Down

0 comments on commit e3f4c04

Please sign in to comment.