-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polygon/sync: milestone headers verifier (#10466)
Fixes: ``` [DBUG] [05-24|00:54:02.436] [sync] issue downloading waypoint blocks - will try again err="VerifyAccumulatedHeaders: bad headers root hash" start=7412843 end=7412895 rootHash=0x78a48a8d01ef08ba73edeef11f8c6b85aace76723ea53301a5732f69b21beee3 kind=*heimdall.Milestone peerId=c3a4ece91b544f27f2b01822bcdac0afd66df311abf8f76d6d23cba8d5ee1670f711312283b5636adda83f514b7f5badd499dc652a840d8abbb5c7649ae98ef1 ``` Waypoint root hash verification is different for checkpoints and milestones: - checkpoints use merkle root hash of all the headers - milestones use the last header hash
- Loading branch information
Showing
8 changed files
with
180 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package sync | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ledgerwatch/erigon-lib/common" | ||
"github.com/ledgerwatch/erigon/core/types" | ||
"github.com/ledgerwatch/erigon/polygon/bor" | ||
"github.com/ledgerwatch/erigon/polygon/heimdall" | ||
) | ||
|
||
var ( | ||
ErrFailedToComputeHeadersRootHash = errors.New("failed to compute headers root hash") | ||
ErrBadHeadersRootHash = errors.New("bad headers root hash") | ||
) | ||
|
||
type WaypointHeadersVerifier func(waypoint heimdall.Waypoint, headers []*types.Header) error | ||
|
||
func VerifyCheckpointHeaders(waypoint heimdall.Waypoint, headers []*types.Header) error { | ||
rootHash, err := bor.ComputeHeadersRootHash(headers) | ||
if err != nil { | ||
return fmt.Errorf("VerifyCheckpointHeaders: %w: %w", ErrFailedToComputeHeadersRootHash, err) | ||
} | ||
if !bytes.Equal(rootHash, waypoint.RootHash().Bytes()) { | ||
return fmt.Errorf("VerifyCheckpointHeaders: %w", ErrBadHeadersRootHash) | ||
} | ||
return nil | ||
} | ||
|
||
func VerifyMilestoneHeaders(waypoint heimdall.Waypoint, headers []*types.Header) error { | ||
var hash common.Hash | ||
if len(headers) > 0 { | ||
hash = headers[len(headers)-1].Hash() | ||
} | ||
if hash != waypoint.RootHash() { | ||
return fmt.Errorf("VerifyMilestoneHeaders: %w", ErrBadHeadersRootHash) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.