Skip to content

Commit

Permalink
Fixes check for replay protection keys
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Oct 13, 2023
1 parent 1e06990 commit 37a6602
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 6 additions & 0 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,7 @@ mod test_finalize_block {
.wl_storage
.write_log
.has_replay_protection_entry(&decrypted_tx.header_hash())
.unwrap_or_default()
);
// Check that the hash is present in the merkle tree
assert!(
Expand Down Expand Up @@ -2472,24 +2473,28 @@ mod test_finalize_block {
.wl_storage
.write_log
.has_replay_protection_entry(&invalid_wrapper_hash)
.unwrap_or_default()
);
assert!(
!shell
.wl_storage
.write_log
.has_replay_protection_entry(&decrypted_3_hash)
.unwrap_or_default()
);
assert!(
!shell
.wl_storage
.write_log
.has_replay_protection_entry(&decrypted_hash)
.unwrap_or_default()
);
assert!(
shell
.wl_storage
.write_log
.has_replay_protection_entry(&wrapper_hash)
.unwrap_or_default()
);
assert!(
shell
Expand All @@ -2503,6 +2508,7 @@ mod test_finalize_block {
.wl_storage
.write_log
.has_replay_protection_entry(&wrapper_2_hash)
.unwrap_or_default()
);
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/ledger/storage/wl_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ where
&self,
hash: &Hash,
) -> Result<bool, super::Error> {
if self.write_log.has_replay_protection_entry(hash) {
return Ok(true);
if let Some(present) = self.write_log.has_replay_protection_entry(hash)
{
return Ok(present);
}

self.storage.has_replay_protection_entry(hash)
Expand Down
14 changes: 7 additions & 7 deletions core/src/ledger/storage/write_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,12 @@ impl WriteLog {
PrefixIter { iter }
}

/// Check if the given tx hash has already been processed
pub fn has_replay_protection_entry(&self, hash: &Hash) -> bool {
match self.replay_protection.get(hash) {
Some(v) => !matches!(v, ReProtStorageModification::Delete),
None => false,
}
/// Check if the given tx hash has already been processed. Returns `None` if
/// the key is not known.
pub fn has_replay_protection_entry(&self, hash: &Hash) -> Option<bool> {
self.replay_protection
.get(hash)
.map(|action| !matches!(action, ReProtStorageModification::Delete))
}

/// Write the transaction hash
Expand Down Expand Up @@ -714,7 +714,7 @@ impl WriteLog {

/// Move the transaction hash of the previous block to the list of all
/// blocks. This functions should be called at the beginning of the block
/// processing
/// processing, before any other replay protection operation is done
pub fn finalize_tx_hash(&mut self, hash: Hash) -> Result<()> {
if self
.replay_protection
Expand Down

0 comments on commit 37a6602

Please sign in to comment.