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

feat(tree): schedule block removal on disk reorgs #10603

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

Rjected
Copy link
Member

@Rjected Rjected commented Aug 29, 2024

This introduces is_disk_reorg, and adds a field to PersistenceState that tracks whether or not a block removal operation has been requested due to an on-disk reorg.

The persistence task has been modified to return the hash of the new tip number, so that the engine can track the last persisted block and hash in a consistent way.

@Rjected Rjected added C-enhancement New feature or request A-blockchain-tree Related to sidechains, reorgs and pending blocks labels Aug 29, 2024
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this complexity is still manageable and easy to follow,

although the edge case described is problematic, but
a) unlikely
b) can be solved by tracking the pending new disk height currently in progress.

can be solved in a followup

Comment on lines -872 to +1057
debug!(target: "engine", "Returned empty set of blocks to persist");
} else {
if !self.persistence_state.in_progress() {
if let Some(new_tip_num) = self.persistence_state.remove_above_state.take() {
debug!(target: "engine", ?new_tip_num, "Removing blocks using persistence task");
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we also track the distance here: last_persisted - new_tip

Comment on lines +2104 to +2382
// TODO: what about multiple on-disk reorgs in a row?
self.remove_above_state = Some(new_tip_num);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could happen if there's a reorg immediately followed by another reorg while we're reorging on disk, right?

I assume what we'd need to do here is tracking the in progress remove_above_state and compare the new_tip_num against this, if the new_tip_num is lower, only then do we need a followup?

but perhaps this should instead be checked in on_disk_reorg function?

Copy link
Member

Choose a reason for hiding this comment

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

here we should take a min of existing target block and incoming

crates/engine/tree/src/tree/mod.rs Outdated Show resolved Hide resolved
Comment on lines +2104 to +2382
// TODO: what about multiple on-disk reorgs in a row?
self.remove_above_state = Some(new_tip_num);
Copy link
Member

Choose a reason for hiding this comment

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

here we should take a min of existing target block and incoming

@Rjected
Copy link
Member Author

Rjected commented Sep 4, 2024

Going to merge this as I end up improving on this in #10678

@Rjected Rjected added this pull request to the merge queue Sep 4, 2024
Merged via the queue into main with commit 98b214f Sep 4, 2024
35 checks passed
@Rjected Rjected deleted the dan/remove-blocks-reorg branch September 4, 2024 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-blockchain-tree Related to sidechains, reorgs and pending blocks C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants