Skip to content

Commit b76268c

Browse files
authored
fix polygon snap (#65)
* fix * upgrade with chainid instead of height
1 parent 1df5961 commit b76268c

4 files changed

Lines changed: 181 additions & 1 deletion

File tree

common/config/config.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ var ETH1559_HEIGHT = map[uint32]uint64{
109109
NETWORK_ID_TEST_NET: constants.ETH1559_HEIGHT_TESTNET,
110110
}
111111

112-
var EXTRA_INFO_HEIGHT_FORK_CHECK bool
112+
var POLYGON_SNAP_CHAINID = map[uint32]uint32{
113+
NETWORK_ID_MAIN_NET: constants.POLYGON_SNAP_CHAINID_MAINNET,
114+
}
115+
116+
var (
117+
EXTRA_INFO_HEIGHT_FORK_CHECK bool
118+
)
113119

114120
func GetNetworkMagic(id uint32) uint32 {
115121
nid, ok := NETWORK_MAGIC[id]
@@ -119,6 +125,11 @@ func GetNetworkMagic(id uint32) uint32 {
119125
return id
120126
}
121127

128+
func GetPolygonSnapChainID(id uint32) uint32 {
129+
height := POLYGON_SNAP_CHAINID[id]
130+
return height
131+
}
132+
122133
func GetEth1559Height(id uint32) uint64 {
123134
height := ETH1559_HEIGHT[id]
124135
if height == 0 {

common/constants/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ const EXTRA_INFO_HEIGHT_TESTNET = 1664798
4747
// eth 1559 heigh
4848
const ETH1559_HEIGHT_MAINNET = 12965000
4949
const ETH1559_HEIGHT_TESTNET = 10499401
50+
51+
const POLYGON_SNAP_CHAINID_MAINNET = 16

native/service/header_sync/polygon/bor_header_sync.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/ethereum/go-ethereum/crypto"
3434
"github.com/ethereum/go-ethereum/rlp"
3535
"github.com/polynetwork/poly/common"
36+
"github.com/polynetwork/poly/common/config"
3637
"github.com/polynetwork/poly/common/log"
3738
cstates "github.com/polynetwork/poly/core/states"
3839
"github.com/polynetwork/poly/native"
@@ -608,7 +609,13 @@ func validateHeaderExtraFieldWithSpan(native *native.NativeService, headerWOP *H
608609
return nil
609610
}
610611

612+
// only used for test
613+
var skipVerifySpan bool
614+
611615
func validateHeaderExtraField(native *native.NativeService, headerWOP *HeaderWithOptionalProof, ctx *Context) (err error) {
616+
if skipVerifySpan {
617+
return
618+
}
612619
if headerWOP.Proof == nil {
613620
var span *Span
614621
span, err = getSpan(native, ctx)
@@ -715,9 +722,17 @@ func validatorContains(a []*Validator, x *Validator) (*Validator, bool) {
715722
return nil, false
716723
}
717724

725+
func shouldApplyFix(currentChainID uint64) bool {
726+
chainID := config.GetPolygonSnapChainID(config.DefConfig.P2PNode.NetworkId)
727+
return uint32(currentChainID) != chainID
728+
}
729+
718730
func getSnapshot(native *native.NativeService, parent *HeaderWithDifficultySum, ctx *Context) (s *Snapshot, err error) {
719731
if parent.HeaderWithOptionalSnap.Snapshot != nil {
720732
s = parent.HeaderWithOptionalSnap.Snapshot
733+
if shouldApplyFix(ctx.ChainID) {
734+
err = s.ValidatorSet.updateTotalVotingPower()
735+
}
721736
return
722737
}
723738

@@ -736,6 +751,9 @@ func getSnapshot(native *native.NativeService, parent *HeaderWithDifficultySum,
736751
}
737752

738753
s = snapHeader.HeaderWithOptionalSnap.Snapshot
754+
if shouldApplyFix(ctx.ChainID) {
755+
err = s.ValidatorSet.updateTotalVotingPower()
756+
}
739757
return
740758
}
741759

native/service/header_sync/polygon/header_sync_test.go

Lines changed: 149 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)