Skip to content

Commit

Permalink
fixup! Merge branch 'tiago/uniquely-identify-inner-txs' (#3416)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Jul 3, 2024
1 parent b747e9a commit e366e80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
28 changes: 5 additions & 23 deletions crates/node/src/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5911,16 +5911,10 @@ mod test_finalize_block {

// multiple tx results (2)
let tx_results = event.read_attribute::<Batch<'_>>().unwrap();
assert_eq!(tx_results.batch_results.0.len(), 2);
assert_eq!(tx_results.batch_results.len(), 2);

// all txs should have succeeded
assert!(
tx_results
.batch_results
.0
.values()
.all(|result| result.is_ok())
);
assert!(tx_results.batch_results.are_results_ok());
}

#[test]
Expand Down Expand Up @@ -5990,22 +5984,10 @@ mod test_finalize_block {

// multiple tx results (2)
let tx_results = event.read_attribute::<Batch<'_>>().unwrap();
assert_eq!(tx_results.batch_results.0.len(), 2);
assert_eq!(tx_results.batch_results.len(), 2);

// check one succeeded and the other failed
assert!(
tx_results
.batch_results
.0
.values()
.any(|result| result.is_ok())
);
assert!(
tx_results
.batch_results
.0
.values()
.any(|result| result.is_err())
);
assert!(tx_results.batch_results.are_any_ok());
assert!(tx_results.batch_results.are_any_err());
}
}
18 changes: 18 additions & 0 deletions crates/tx/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@ impl<T> BatchResults<T> {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}

/// Check if the collecction of inner tx results contains no errors.
#[inline]
pub fn are_results_ok(&self) -> bool {
self.iter().all(|(_, res)| res.is_ok())
}

/// Check if the collecction of inner tx results contains any ok results.
#[inline]
pub fn are_any_ok(&self) -> bool {
self.iter().any(|(_, res)| res.is_ok())
}

/// Check if the collecction of inner tx results contains any errors.
#[inline]
pub fn are_any_err(&self) -> bool {
self.iter().any(|(_, res)| res.is_err())
}
}

/// Compute the hash of the some inner tx in a batch.
Expand Down

0 comments on commit e366e80

Please sign in to comment.