From a89e14bf2d766fbba553a809179adf41d5ffbb5b Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:59:07 +0200 Subject: [PATCH] london hard fork --- payouts/unlocker.go | 52 ++++++++++++++++++++++++++++++++------------- rpc/rpc.go | 2 ++ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/payouts/unlocker.go b/payouts/unlocker.go index f64350f..0e92dab 100644 --- a/payouts/unlocker.go +++ b/payouts/unlocker.go @@ -1,6 +1,7 @@ package payouts import ( + "errors" "fmt" "log" "math/big" @@ -17,24 +18,28 @@ import ( ) type UnlockerConfig struct { - Enabled bool `json:"enabled"` - PoolFee float64 `json:"poolFee"` - PoolFeeAddress string `json:"poolFeeAddress"` - Depth int64 `json:"depth"` - ImmatureDepth int64 `json:"immatureDepth"` - KeepTxFees bool `json:"keepTxFees"` - Interval string `json:"interval"` - Daemon string `json:"daemon"` - Timeout string `json:"timeout"` - Ecip1017FBlock int64 `json:"ecip1017FBlock"` - Ecip1017EraRounds *big.Int `json:"ecip1017EraRounds"` - ByzantiumFBlock *big.Int `json:"byzantiumFBlock"` - ConstantinopleFBlock *big.Int `json:"constantinopleFBlock"` - Network string `json:"network"` + Enabled bool `json:"enabled"` + PoolFee float64 `json:"poolFee"` + PoolFeeAddress string `json:"poolFeeAddress"` + Depth int64 `json:"depth"` + ImmatureDepth int64 `json:"immatureDepth"` + KeepTxFees bool `json:"keepTxFees"` + Interval string `json:"interval"` + Daemon string `json:"daemon"` + Timeout string `json:"timeout"` + Ecip1017FBlock int64 `json:"ecip1017FBlock"` + Ecip1017EraRounds *big.Int `json:"ecip1017EraRounds"` + ByzantiumFBlock *big.Int `json:"byzantiumFBlock"` + ConstantinopleFBlock *big.Int `json:"constantinopleFBlock"` + Network string `json:"network"` + IsLondonHardForkEnabled bool `json:"isLondonHardForkEnabled"` } const minDepth = 16 +// London hark fork +const londonHardForkHeight = 12965000 + // Universal block reward ethash const UniversalHardForkHeight = 0 @@ -927,14 +932,31 @@ func getUncleRewardEthereum(uHeight *big.Int, height *big.Int, reward *big.Int) func (u *BlockUnlocker) getExtraRewardForTx(block *rpc.GetBlockReply) (*big.Int, error) { amount := new(big.Int) + blockHeight, err := strconv.ParseInt(strings.Replace(block.Number, "0x", "", -1), 16, 64) + if err != nil { + return nil, err + } + baseFeePerGas := util.String2Big(block.BaseFeePerGas) + + config := UnlockerConfig{ + IsLondonHardForkEnabled: blockHeight >= londonHardForkHeight, + } + for _, tx := range block.Transactions { receipt, err := u.rpc.GetTxReceipt(tx.Hash) if err != nil { - return nil, err + log.Println("Error getting transaction receipt:", err) + continue } if receipt != nil { gasUsed := util.String2Big(receipt.GasUsed) gasPrice := util.String2Big(tx.GasPrice) + if config.IsLondonHardForkEnabled { + gasPrice = new(big.Int).Sub(gasPrice, baseFeePerGas) + if gasPrice.Cmp(big.NewInt(0)) < 0 { + return nil, errors.New("gasPrice less than baseFeePerGas") + } + } fee := new(big.Int).Mul(gasUsed, gasPrice) amount.Add(amount, fee) } diff --git a/rpc/rpc.go b/rpc/rpc.go index 2c72c48..21505a6 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -40,6 +40,8 @@ type GetBlockReply struct { Uncles []string `json:"uncles"` // https://github.com/ethereum/EIPs/issues/95 SealFields []string `json:"sealFields"` + // london hard fork + BaseFeePerGas string `json:"baseFeePerGas"` } type GetBlockReplyPart struct {