-
Notifications
You must be signed in to change notification settings - Fork 777
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
Conversation
There was a problem hiding this 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
andsortedKeys
withvalues
map andrecordValueChange
inview.go
- Updates
NewIteratorWithStartAndPrefix
to iterate overvalues
and then sort the results inview_iterator.go
- Refactors history functions (
getValueChanges
,getChangesToGetToRoot
) to use the new map-based change summary inhistory.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
shadowsv.changes
and may be confusing. Consider renaming it to something likeresult
orfilteredChanges
.
changes = make([]KeyChange, 0, len(v.changes.values))
simplex/block.go
Outdated
if b.blockTracker.isBlockAlreadyVerified(b.vmBlock) { | ||
return b, nil | ||
} | ||
|
There was a problem hiding this comment.
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.
I think that there is something I overlooked, please see comment.
ea7cae4
to
0b8baab
Compare
Signed-off-by: Sam Liokumovich <[email protected]>
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 theprev
field in theProtocolMetadata
. This means our verification logic in avalanchego must verify thatprev
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. Whenindex
is called on a digest, theblockTracker
callsAccept
on that block andReject
on any competing blocks.How this was tested
Need to be documented in RELEASES.md?