-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Borevent snapshot validation #9436
Conversation
@@ -220,19 +217,21 @@ func fetchAndWriteHeimdallStateSyncEvents( | |||
continue | |||
} | |||
|
|||
if lastStateSyncEventID+1 != eventRecord.ID || eventRecord.ChainID != chainID || !eventRecord.Time.Before(to) { | |||
if lastStateSyncEventID+1 != eventRecord.ID || eventRecord.ChainID != chainID || | |||
!(eventRecord.Time.After(from) && eventRecord.Time.Before(to)) { |
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'd suggest to add a new unit test for this error path - it should be fairly easy to add.
You can have a look at TestBorHeimdallForwardPersistsStateSyncEvents
and stagedsynctest.Harness.mockHeimdallClient
. For this you will need to pass in a new function to h.heimdallClient.EXPECT().FetchStateSyncEvents(...).DoAndReturn()
.
A clean way to do this may be to add an optional MockFetchStateSyncEventsCallback
to the HarnessCfg
and check if it is present use that inside the DoAndReturn otherwise use the current one.
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.
ok I'll look at this tomorrow.
for i := uint64(0); i < maxBlockNum; i += 10_000 { | ||
|
||
if to != 0 && maxBlockNum > to { | ||
maxBlockNum = 2 |
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.
out of curiosity - why is this necessary? is it worth leaving a comment?
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.
hmm - should say: maxBlockNum = to
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.
@mh0lt this typo still needs fixing
did try this "integrity" check, see:
for all events |
…gerwatch/erigon into borevent_snapshot_validation
I'm only just testing this now. I need to validate that the check is actually correctly configured - which I'm talking through with Polygon. As there is no spec for the start of a window its going to take some adjustment to get right. |
eth/integrity/no_gaps_bor_events.go
Outdated
return err | ||
} | ||
|
||
fmt.Println("LAST Event", lastEventId, "BH", borHeimdallProgress, "B", bodyProgress) |
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.
looks like leftover print from debugging? should we remove and/or use a logger?
"github.com/erigontech/erigon-lib/log/v3" | ||
) | ||
|
||
func TestOver50EventBlockFetch(t *testing.T) { |
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.
this test should maybe be removed since it is calling an external service https://heimdall-api.polygon.technology/
and may fail our CI or alternatively we can add t.Skip
with info why we skip it and why it is left behind in the code base
@@ -131,3 +131,29 @@ type StateSyncEventResponse struct { | |||
Height string `json:"height"` | |||
Result EventRecordWithTime `json:"result"` | |||
} | |||
|
|||
var methodId []byte = borabi.StateReceiverContractABI().Methods["commitState"].ID |
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.
[]byte
type can be omitted in the declaration
|
||
fmt.Println("LAST Event", lastEventId, "BH", borHeimdallProgress, "B", bodyProgress) | ||
|
||
if bodyProgress > borHeimdallProgress { |
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.
this if and for loop don't seem to do anything?
probably the whole if db != nil
if branch above on line 89 can be removed?
This adds integrity checking for borevents in the following places
It also adds an external integrity checker which runs on snapshots checking for continuity and timeliness of events. This can be called using the following command:
erigon snapshots integrity --datadir=~/snapshots/bor-mainnet-patch-1 --from=45500000
(--to specifies an end block)
This also now fixes the long running issue with bor events causing unexpected fails in executions:
the problem event validation uncovered was a follows:
The kv.BorEventNums mapping table currently keeps the mapping first event id->block. The code which produces bor-event snapshots to determine which events to put into the snapshot.
however if no additional blocks have events by the time the block is stored in the snapshot, the snapshot creation code does not know which events to include - so drops them.
This causes problems in two places:
The code change in this PR fixes that bug.
It has been tested by running:
with validation in place and the confimed by running the following:
To recreate the chain from snapshots.
It has also been checked with: