Skip to content

Commit

Permalink
add support for eip4345 (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu committed Dec 9, 2021
1 parent 07408cf commit 57f9e3a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ var ETH1559_HEIGHT = map[uint32]uint64{
NETWORK_ID_TEST_NET: constants.ETH1559_HEIGHT_TESTNET,
}

var ETH4345_HEIGHT = map[uint32]uint64{
NETWORK_ID_MAIN_NET: constants.ETH4345_HEIGHT_MAINNET,
}

var HECO120_HEIGHT = map[uint32]uint64{
NETWORK_ID_MAIN_NET: constants.HECO120_HEIGHT_MAINNET,
NETWORK_ID_TEST_NET: constants.HECO120_HEIGHT_TESTNET,
Expand All @@ -135,6 +139,12 @@ func GetPolygonSnapChainID(id uint32) uint32 {
return height
}

func GetEth4345Height(id uint32) uint64 {
height := ETH4345_HEIGHT[id]

return height
}

func GetEth1559Height(id uint32) uint64 {
height := ETH1559_HEIGHT[id]
if height == 0 {
Expand Down
3 changes: 3 additions & 0 deletions common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ const HECO120_HEIGHT_MAINNET = 8577000
const HECO120_HEIGHT_TESTNET = 8290000

const POLYGON_SNAP_CHAINID_MAINNET = 16

// eth arrow glacier upgrade
const ETH4345_HEIGHT_MAINNET = 13_773_000
8 changes: 8 additions & 0 deletions native/service/header_sync/eth/header1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ func isLondon(h *Header) bool {
return h.BaseFee != nil || h.Number.Uint64() >= config.GetEth1559Height(config.DefConfig.P2PNode.NetworkId)
}

func isArrowGlacier(h *Header) bool {
forkHeight := config.GetEth4345Height(config.DefConfig.P2PNode.NetworkId)
if forkHeight == 0 {
return false
}
return h.Number.Uint64() >= forkHeight
}

// VerifyGaslimit verifies the header gas limit according increase/decrease
// in relation to the parent gas limit.
func VerifyGaslimit(parentGasLimit, headerGasLimit uint64) error {
Expand Down
4 changes: 3 additions & 1 deletion native/service/header_sync/eth/header_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ func (this *ETHHandler) SyncBlockHeader(native *native.NativeService) error {

//verify difficulty
var expected *big.Int
if isLondon(&header) {
if isArrowGlacier(&header) {
expected = makeDifficultyCalculator(big.NewInt(10_700_000))(header.Time, parentHeader)
} else if isLondon(&header) {
expected = makeDifficultyCalculator(big.NewInt(9700000))(header.Time, parentHeader)
} else {
expected = difficultyCalculator(new(big.Int).SetUint64(header.Time), parentHeader)
Expand Down

0 comments on commit 57f9e3a

Please sign in to comment.