From 57f9e3a2581cee81f00b34c85ac0ea70ba6e4628 Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Thu, 9 Dec 2021 10:13:12 +0800 Subject: [PATCH] add support for eip4345 (#86) --- common/config/config.go | 10 ++++++++++ common/constants/constants.go | 3 +++ native/service/header_sync/eth/header1559.go | 8 ++++++++ native/service/header_sync/eth/header_sync.go | 4 +++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/common/config/config.go b/common/config/config.go index 0d1108ad..e738470f 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -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, @@ -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 { diff --git a/common/constants/constants.go b/common/constants/constants.go index 9930020a..1fb90494 100644 --- a/common/constants/constants.go +++ b/common/constants/constants.go @@ -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 diff --git a/native/service/header_sync/eth/header1559.go b/native/service/header_sync/eth/header1559.go index c48d842f..f8ec817f 100644 --- a/native/service/header_sync/eth/header1559.go +++ b/native/service/header_sync/eth/header1559.go @@ -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 { diff --git a/native/service/header_sync/eth/header_sync.go b/native/service/header_sync/eth/header_sync.go index 6da14f8c..0ec14fa4 100644 --- a/native/service/header_sync/eth/header_sync.go +++ b/native/service/header_sync/eth/header_sync.go @@ -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)