Skip to content

Commit

Permalink
feat: Log block ID and add TxID to missing witness index error variant
Browse files Browse the repository at this point in the history
  • Loading branch information
netrome committed Feb 21, 2025
1 parent 4a3e513 commit d934c0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
8 changes: 7 additions & 1 deletion crates/proof_system/global_merkle_root/storage/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ pub enum InvalidBlock {
/// A transaction already exists.
DuplicateTransaction(TxId),
/// A transaction is missing a referenced witness.
MissingWitness(usize),
#[display(fmt = "missing witness at index {witness_index} in tx {txid}")]
MissingWitness {
/// Transaction ID
txid: TxId,
/// Index of missing witness
witness_index: usize,
},
/// A create transaction is missing a contract created output.
ContractCreatedOutputNotFound,
/// An upload transaction tries to upload code that has already been completely uploaded.
Expand Down
28 changes: 18 additions & 10 deletions crates/proof_system/global_merkle_root/storage/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ where
#[tracing::instrument(skip(self, block))]
pub fn process_block(&mut self, block: &Block) -> crate::Result<()> {
let block_height = *block.header().height();
tracing::info!(%block_height, "processing block");

for (tx_idx, tx) in block.transactions().iter().enumerate() {
let tx_idx: u16 =
Expand Down Expand Up @@ -340,8 +341,9 @@ where
let witnesses = tx.witnesses();
let bytecode = witnesses
.get(usize::from(*bytecode_witness_index))
.ok_or_else(|| {
InvalidBlock::MissingWitness(usize::from(*bytecode_witness_index))
.ok_or_else(|| InvalidBlock::MissingWitness {
txid: tx.id(&self.chain_id),
witness_index: usize::from(*bytecode_witness_index),
})?
.as_vec();

Expand Down Expand Up @@ -448,10 +450,13 @@ where
};

let witness_index = usize::from(*tx.bytecode_witness_index());
let new_bytecode = tx
.witnesses()
.get(witness_index)
.ok_or(InvalidBlock::MissingWitness(witness_index))?;
let new_bytecode =
tx.witnesses()
.get(witness_index)
.ok_or(InvalidBlock::MissingWitness {
txid: tx.id(&self.chain_id),
witness_index,
})?;

bytecode.extend_from_slice(new_bytecode.as_ref());

Expand Down Expand Up @@ -485,10 +490,13 @@ where
} = tx.body();

let witness_index = usize::from(*witness_index);
let blob = tx
.witnesses()
.get(witness_index)
.ok_or(InvalidBlock::MissingWitness(witness_index))?;
let blob =
tx.witnesses()
.get(witness_index)
.ok_or(InvalidBlock::MissingWitness {
txid: tx.id(&self.chain_id),
witness_index,
})?;

tracing::debug!("storing blob");
self.storage
Expand Down

0 comments on commit d934c0d

Please sign in to comment.