Skip to content

Commit

Permalink
fix sequencer block construction
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Jul 3, 2024
1 parent 536fd2c commit d3ba1fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
14 changes: 14 additions & 0 deletions crates/astria-core/src/sequencerblock/v1alpha1/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ impl SequencerBlockError {
Self(SequencerBlockErrorKind::IdProofInvalid(source))
}

fn no_extended_commit_info() -> Self {
Self(SequencerBlockErrorKind::NoExtendedCommitInfo)
}

fn no_rollup_transactions_root() -> Self {
Self(SequencerBlockErrorKind::NoRollupTransactionsRoot)
}
Expand Down Expand Up @@ -262,6 +266,10 @@ enum SequencerBlockErrorKind {
TransactionProofInvalid(#[source] merkle::audit::InvalidProof),
#[error("failed constructing a rollup ID proof from the raw protobuf rollup ID proof")]
IdProofInvalid(#[source] merkle::audit::InvalidProof),
#[error(
"the cometbft block.data field was too short and did not contain the extended commit info"
)]
NoExtendedCommitInfo,
#[error(
"the cometbft block.data field was too short and did not contain the rollup transaction \
root"
Expand Down Expand Up @@ -713,6 +721,12 @@ impl SequencerBlock {
let data_hash = tree.root();

let mut data_list = data.into_iter();

// TODO: this needs to go into the block header
let _extended_commit_info = data_list
.next()
.ok_or(SequencerBlockError::no_extended_commit_info())?;

let rollup_transactions_root: [u8; 32] = data_list
.next()
.ok_or(SequencerBlockError::no_rollup_transactions_root())?
Expand Down
11 changes: 6 additions & 5 deletions crates/astria-sequencer/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,16 @@ impl App {
}

ensure!(
finalize_block.txs.len() >= 2,
"block must contain at least two transactions: the rollup transactions commitment and
finalize_block.txs.len() >= 3,
"block must contain at least three transactions: the extended commit info, the rollup \
transactions commitment and
rollup IDs commitment"
);

// cometbft expects a result for every tx in the block, so we need to return a
// tx result for the commitments, even though they're not actually user txs.
let mut tx_results: Vec<ExecTxResult> = Vec::with_capacity(finalize_block.txs.len());
tx_results.extend(std::iter::repeat(ExecTxResult::default()).take(2));
tx_results.extend(std::iter::repeat(ExecTxResult::default()).take(3));

// When the hash is not empty, we have already executed and cached the results
if self.executed_proposal_hash.is_empty() {
Expand All @@ -887,8 +888,8 @@ impl App {
.await
.context("failed to execute block")?;

// skip the first two transactions, as they are the rollup data commitments
for tx in finalize_block.txs.iter().skip(2) {
// skip the first three transactions, as they are injected transactions
for tx in finalize_block.txs.iter().skip(3) {
// remove any included txs from the mempool
let tx_hash = Sha256::digest(tx).into();
self.mempool.remove(tx_hash).await;
Expand Down
15 changes: 15 additions & 0 deletions crates/astria-sequencer/src/app/vote_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ impl ProposalHandler {
height: u64,
mut extended_commit_info: ExtendedCommitInfo,
) -> anyhow::Result<ExtendedCommitInfo> {
if height == 1 {
// we're proposing block 1, so nothing to validate
return Ok(extended_commit_info);
}

for vote in extended_commit_info.votes.iter_mut() {
let oracle_vote_extension =
RawOracleVoteExtension::decode(vote.vote_extension.clone())?.into();
Expand All @@ -212,6 +217,7 @@ impl ProposalHandler {
validate_vote_extensions(state, height, &extended_commit_info)
.await
.context("failed to validate vote extensions in prepare_proposal")?;

Ok(extended_commit_info)
}

Expand All @@ -222,6 +228,11 @@ impl ProposalHandler {
last_commit: &CommitInfo,
extended_commit_info: &ExtendedCommitInfo,
) -> anyhow::Result<()> {
if height == 1 {
// we're processing block 1, so nothing to validate (no last commit yet)
return Ok(());
}

// inside process_proposal, we must validate the vote extensions proposed against the last
// commit proposed
validate_extended_commit_against_last_commit(last_commit, extended_commit_info)?;
Expand Down Expand Up @@ -345,6 +356,10 @@ async fn validate_vote_extensions<S: StateReadExt>(
"submitted voting power is less than required voting power",
);

debug!(
submitted_voting_power,
total_voting_power, "validated extended commit info"
);
Ok(())
}

Expand Down

0 comments on commit d3ba1fa

Please sign in to comment.