Skip to content

Commit

Permalink
updated parent and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
varun-doshi committed Jan 16, 2025
1 parent d40511c commit 6cc6b76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion miden-tx/src/testing/mock_chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,9 @@ impl MockChain {
/// This will also make all the objects currently pending available for use.
/// If `block_num` is `Some(number)`, blocks will be generated up to `number`.
pub fn seal_block(&mut self, block_num: Option<u32>) -> Block {
let next_block_num = self.blocks.last().map_or(0, |b| b.header().block_num().child());
let next_block_num =
self.blocks.last().map_or(0, |b| b.header().block_num().child().as_u32());

let target_block_num = block_num.unwrap_or(next_block_num);

if target_block_num < next_block_num {
Expand Down
13 changes: 8 additions & 5 deletions objects/src/block/block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ impl BlockNumber {
/// exponent.
pub const EPOCH_LENGTH_EXPONENT: u8 = 16;

/// Genesis BlockNumber
pub const GENESIS: Self = Self(0);

/// Returns the previous block number
pub fn parent(&self) -> u32 {
self.checked_sub(1).expect("Cannot go below Genesis block!").0
pub fn parent(self) -> Option<BlockNumber> {
self.checked_sub(1)
}

/// Returns the next block number
pub fn child(&mut self) -> u32 {
self.0 + 1
pub fn child(self) -> BlockNumber {
self + 1
}

/// Creates the [`BlockNumber`] corresponding to the epoch block for the provided `epoch`.
Expand Down Expand Up @@ -62,7 +65,7 @@ impl BlockNumber {
self.0 as usize
}

/// Checked integer subtraction. Computes `self - rhs`, returning `None` if overflow occurred.
/// Checked integer subtraction. Computes `self - rhs`, returning `None` if underflow occurred.
pub fn checked_sub(&self, rhs: u32) -> Option<Self> {
self.0.checked_sub(rhs).map(Self)
}
Expand Down
2 changes: 1 addition & 1 deletion objects/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub enum TransactionInputError {
#[error("block in which input note with id {0} was created is not in chain mmr")]
InputNoteBlockNotInChainMmr(NoteId),
#[error("input note with id {0} was not created in block {1}")]
InputNoteNotInBlock(NoteId, u32),
InputNoteNotInBlock(NoteId, BlockNumber),
#[error("account ID computed from seed is invalid")]
InvalidAccountIdSeed(#[source] AccountIdError),
#[error(
Expand Down
5 changes: 1 addition & 4 deletions objects/src/transaction/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,7 @@ fn validate_is_in_block(
.note_path()
.verify(note_index, note_hash, &block_header.note_root())
.map_err(|_| {
TransactionInputError::InputNoteNotInBlock(
note.id(),
proof.location().block_num().as_u32(),
)
TransactionInputError::InputNoteNotInBlock(note.id(), proof.location().block_num())
})
}

Expand Down

0 comments on commit 6cc6b76

Please sign in to comment.