Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replay protection refactor #2956

Merged
merged 11 commits into from Apr 27, 2024
Merged

Replay protection refactor #2956

merged 11 commits into from Apr 27, 2024

Conversation

grarco
Copy link
Contributor

@grarco grarco commented Mar 25, 2024

Describe your changes

Closes #2922.

Since there's no more need to keep track and possibly act on tx cases from different block, this PR removes the ReProtStorageModification enum and uses a simple HashSet to keep track of the transaction hashes.

Also improves replay protection unit tests.

Indicate on which release or other PRs this topic is based on

v0.33.0

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

grarco added a commit that referenced this pull request Mar 25, 2024
@grarco grarco marked this pull request as ready for review March 25, 2024 17:58
@grarco grarco requested a review from batconjurer March 25, 2024 17:58
//! - `all`: the hashes included up to the last block
//! - `last`: the hashes included in the last block
//! - `replay_protection`: hashes of processed tx for replay protection purposes
//! - `current/{hash}`: an hash included in the current block
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! - `current/{hash}`: an hash included in the current block
//! - `current/{hash}`: a hash included in the current block

//! - `last`: the hashes included in the last block
//! - `replay_protection`: hashes of processed tx for replay protection purposes
//! - `current/{hash}`: an hash included in the current block
//! - `{hash}`: an hash included in previous blocks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! - `{hash}`: an hash included in previous blocks
//! - `{hash}`: a hash included in previous blocks

// deleted, this is fine, in this case just continue
let all_key = replay_protection::all_key(&hash);
batch.delete_cf(reprot_cf, all_key.to_string());
// Remove the "current" tx hashes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we also need to remove the replay_protection::key(_) entries committed by the previous block as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Let's say we are at block 10 and we have tx1, tx2, tx3 committed in the previous blocks and tx4, tx5 committed in 10. Say that we want to rollback to 9, then we need to remove the transactions committed in 10 (tx4, tx5) which live under the current subkey.

We could think about bringing the tx committed in block 9 back under the new current subkey but I believe this is not needed because these keys are known anyway and the validation doesn't change if the hash lives under the current subkey or not. Also, replay protection is not merklized so this is not needed

@Fraccaman Fraccaman mentioned this pull request Apr 15, 2024
grarco added a commit that referenced this pull request Apr 16, 2024
Copy link

codecov bot commented Apr 16, 2024

Codecov Report

Attention: Patch coverage is 96.72131% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 59.37%. Comparing base (97ec5b4) to head (bed0517).
Report is 10 commits behind head on main.

Files Patch % Lines
crates/state/src/write_log.rs 92.59% 2 Missing ⚠️
crates/storage/src/mockdb.rs 93.54% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2956      +/-   ##
==========================================
- Coverage   59.39%   59.37%   -0.02%     
==========================================
  Files         298      298              
  Lines       92771    92685      -86     
==========================================
- Hits        55104    55036      -68     
+ Misses      37667    37649      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brentstone
Copy link
Contributor

is this still just awaiting a final review?

.expect("Test failed");

// the merkle tree root should not change after finalize_block
let root_post = shell.shell.state.in_mem().block.tree.root();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably me forgetting details, but since the second tx should pass, wouldn't its hash be added to replay prot and change the merkle tree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reprot entries of the db are not merklized

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right.

@batconjurer batconjurer self-requested a review April 23, 2024 09:49
brentstone added a commit that referenced this pull request Apr 23, 2024
* grarco/refactor-reprot:
  Changelog #2956
  Rebase fixes
  Fixes typos in rocksdb documentation
  Removes `ReProtStorageModification`
  Updates rocksdb layout docs
  Fixes bug in replay protection iterator
  Removes unused reprot action and adds one to mark tx hashes as redundant. Updates tests
  `has_replay_protection_entry` returns a bool instead of result
  Renames reprot action `Delete` to `Redundant`
  Removes `Finalize` replay protection action. Improves replay protection api
  Adds replay protection unit test
@brentstone brentstone merged commit 614e905 into main Apr 27, 2024
18 of 19 checks passed
@brentstone brentstone deleted the grarco/refactor-reprot branch April 27, 2024 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor replay protection
3 participants