Skip to content

Commit

Permalink
refactor: make extended commit info third injected tx (#1791)
Browse files Browse the repository at this point in the history
## Summary
make extended commit info third injected tx, and update
`SequencerBlock::try_from_block_info_and_data` to handle whether the
extended commit info is in the block or not.

## Background
it makes more sense to append to the existing list of injected txs which
are the two commitments at the start of the block.

## Changes
- make extended commit info the third injected tx instead of the first
- update `SequencerBlock::try_from_block_info_and_data` to handle
whether the extended commit info is in the block or not
- cleanup of related unit tests

## Testing
unit tests

## Breaking Changelist
- unbreaks `SequencerBlock::try_from_block_info_and_data`
  • Loading branch information
noot authored Nov 18, 2024
1 parent 1b162c2 commit 5f8dae6
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 278 deletions.
43 changes: 28 additions & 15 deletions crates/astria-core/src/protocol/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use crate::{
},
protocol::transaction::v1::TransactionBody,
sequencerblock::v1::{
block::Deposit,
block::{
Deposit,
SequencerBlockBuilder,
},
SequencerBlock,
},
Protobuf as _,
Expand Down Expand Up @@ -53,13 +56,15 @@ pub struct ConfigureSequencerBlock {
pub sequence_data: Vec<(RollupId, Vec<u8>)>,
pub deposits: Vec<Deposit>,
pub unix_timestamp: UnixTimeStamp,
pub with_extended_commit_info: bool,
}

impl ConfigureSequencerBlock {
/// Construct a [`SequencerBlock`] with the configured parameters.
#[must_use]
#[expect(
clippy::missing_panics_doc,
clippy::too_many_lines,
reason = "This should only be used in tests, so everything here is unwrapped"
)]
pub fn make(self) -> SequencerBlock {
Expand All @@ -79,6 +84,7 @@ impl ConfigureSequencerBlock {
sequence_data,
unix_timestamp,
deposits,
with_extended_commit_info,
} = self;

let block_hash = block_hash.unwrap_or_default();
Expand Down Expand Up @@ -142,35 +148,42 @@ impl ConfigureSequencerBlock {
rollup_transactions.sort_unstable_keys();
let rollup_transactions_tree = derive_merkle_tree_from_rollup_txs(&rollup_transactions);

let extended_commit_info: tendermint_proto::abci::ExtendedCommitInfo = ExtendedCommitInfo {
round: 0u16.into(),
votes: vec![],
}
.into();
let extended_commit_info_bytes = extended_commit_info.encode_to_vec();

let rollup_ids_root = merkle::Tree::from_leaves(
rollup_transactions
.keys()
.map(|rollup_id| rollup_id.as_ref().to_vec()),
)
.root();
let mut data = vec![
extended_commit_info_bytes,
rollup_transactions_tree.root().to_vec(),
rollup_ids_root.to_vec(),
];

if with_extended_commit_info {
let extended_commit_info: tendermint_proto::abci::ExtendedCommitInfo =
ExtendedCommitInfo {
round: 0u16.into(),
votes: vec![],
}
.into();
let extended_commit_info_bytes = extended_commit_info.encode_to_vec();
data.push(extended_commit_info_bytes);
}

data.extend(txs.into_iter().map(|tx| tx.into_raw().encode_to_vec()));
let data = data.into_iter().map(Bytes::from).collect();
SequencerBlock::try_from_block_info_and_data(

SequencerBlockBuilder {
block_hash,
chain_id.try_into().unwrap(),
height.into(),
Time::from_unix_timestamp(unix_timestamp.secs, unix_timestamp.nanos).unwrap(),
chain_id: chain_id.try_into().unwrap(),
height: height.into(),
time: Time::from_unix_timestamp(unix_timestamp.secs, unix_timestamp.nanos).unwrap(),
proposer_address,
data,
deposits_map,
)
deposits: deposits_map,
with_extended_commit_info,
}
.try_build()
.unwrap()
}
}
Loading

0 comments on commit 5f8dae6

Please sign in to comment.