Skip to content

Add Verification + Tracking Logic To Simplex Blocks #4052

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

Merged
merged 20 commits into from
Jul 17, 2025

Conversation

samliok
Copy link
Contributor

@samliok samliok commented Jul 3, 2025

Why this should be merged

In addition to calling Verify on the blocks inner vmBlock, we need to do some additional checks to ensure a simplex block can be verified. Furthermore, we need to ensure that any verified blocks are eventually accepted or rejected.

How this works

In simplex we do some pre-verification logic. However this is not enough, as we do not have access to the inner vmBlock pointed to by the prev field in the ProtocolMetadata. This means our verification logic in avalanchego must verify that prev for the block we are currently verifying points to that blocks parent. To understand more about why this important, see this test.

This PR also introduces a blockTracker struct to keep track of blocks that have been verified. When index is called on a digest, the blockTracker calls Accept on that block and Reject on any competing blocks.

How this was tested

Need to be documented in RELEASES.md?

@Copilot Copilot AI review requested due to automatic review settings July 3, 2025 21:34
@samliok samliok marked this pull request as draft July 3, 2025 21:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors change tracking in the Merkle DB view and history layers, replacing the old keyChanges+sortedKeys approach with a unified values map and a new recordValueChange method. It also updates the view iterator to reflect the map-based storage and overhauls history retrieval functions to collapse and filter changes via the new map structure.

  • Replaces keyChanges and sortedKeys with values map and recordValueChange in view.go
  • Updates NewIteratorWithStartAndPrefix to iterate over values and then sort the results in view_iterator.go
  • Refactors history functions (getValueChanges, getChangesToGetToRoot) to use the new map-based change summary in history.go and updates tests

Reviewed Changes

Copilot reviewed 89 out of 91 changed files in this pull request and generated 1 comment.

File Description
x/merkledb/view.go Introduced recordValueChange method and values map
x/merkledb/view_iterator.go Changed iterator to range over values and sort KeyChanges
x/merkledb/history.go Refactored history change accumulation to use changeSummary
x/merkledb/history_test.go Updated tests to assert on values instead of slices
Comments suppressed due to low confidence (2)

x/merkledb/view_iterator.go:27

  • [nitpick] The local variable changes shadows v.changes and may be confusing. Consider renaming it to something like result or filteredChanges.
		changes   = make([]KeyChange, 0, len(v.changes.values))

@samliok samliok force-pushed the simplex-tracker branch from 39129f0 to 99463d4 Compare July 3, 2025 21:36
@samliok samliok marked this pull request as ready for review July 3, 2025 21:36
@samliok samliok marked this pull request as draft July 3, 2025 21:36
@samliok samliok force-pushed the simplex-tracker branch from 99463d4 to 217daff Compare July 3, 2025 21:45
@samliok samliok force-pushed the simplex-tracker branch from 24727f8 to 152bc99 Compare July 7, 2025 19:44
@samliok samliok marked this pull request as ready for review July 7, 2025 19:45
yacovm
yacovm previously approved these changes Jul 10, 2025
@joshua-kim joshua-kim moved this to Ready 🚦 in avalanchego Jul 14, 2025
simplex/block.go Outdated
if b.blockTracker.isBlockAlreadyVerified(b.vmBlock) {
return b, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to grab the context lock here, because we're executing this function asynchronously.

@yacovm yacovm dismissed their stale review July 14, 2025 23:12

I think that there is something I overlooked, please see comment.

@samliok samliok force-pushed the simplex-tracker branch 2 times, most recently from ea7cae4 to 0b8baab Compare July 17, 2025 15:47
@StephenButtolph StephenButtolph added this pull request to the merge queue Jul 17, 2025
Merged via the queue into master with commit e6fc322 Jul 17, 2025
29 checks passed
@StephenButtolph StephenButtolph deleted the simplex-tracker branch July 17, 2025 17:13
@github-project-automation github-project-automation bot moved this from Ready 🚦 to Done 🎉 in avalanchego Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants