From 07d0a023f810817b194f39bbb5c7b8087f8e60e3 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 9 May 2022 15:43:01 +0000 Subject: [PATCH] added london fork patch, from jamescoxon/open-ethereum-pool@77ccc6a --- payouts/unlocker.go | 20 ++++++++++++++++++++ rpc/rpc.go | 1 + util/util.go | 25 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/payouts/unlocker.go b/payouts/unlocker.go index a98438f1..3176f62e 100644 --- a/payouts/unlocker.go +++ b/payouts/unlocker.go @@ -225,6 +225,26 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage reward.Add(reward, extraTxReward) } + + // Remove Burnt Fees, post London (Base Fee Per Gas * Gas Used) + baseFeePerGas := new(big.Int) + bigBaseFeePerGas := util.DecodeValueHex(block.BaseFeePerGas) + baseFeePerGas.SetString(bigBaseFeePerGas, 10) + log.Println("baseFeePerGas: ", baseFeePerGas) + log.Println("block.BaseFeePerGas: ", block.BaseFeePerGas) + + //gasUsed := big.NewInt(int64(block.GasUsed)) + gasUsed := new(big.Int) + bigGasUsed := util.DecodeValueHex(block.GasUsed) + gasUsed.SetString(bigGasUsed, 10) + log.Println("gasUsed: ", gasUsed) + + burntFees := new(big.Int).Mul(baseFeePerGas, gasUsed) + log.Println("BurntFees: ", burntFees) + reward.Sub(reward, burntFees) + + + // Add reward for including uncles uncleReward := getRewardForUncle(candidate.Height) rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles)))) diff --git a/rpc/rpc.go b/rpc/rpc.go index 2ef11d7b..3615a7cd 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -35,6 +35,7 @@ type GetBlockReply struct { Difficulty string `json:"difficulty"` GasLimit string `json:"gasLimit"` GasUsed string `json:"gasUsed"` + BaseFeePerGas string `json:"baseFeePerGas"` Transactions []Tx `json:"transactions"` Uncles []string `json:"uncles"` // https://github.com/ethereum/EIPs/issues/95 diff --git a/util/util.go b/util/util.go index fe96a98c..906f8e6b 100644 --- a/util/util.go +++ b/util/util.go @@ -18,6 +18,31 @@ var pow256 = math.BigPow(2, 256) var addressPattern = regexp.MustCompile("^0x[0-9a-fA-F]{40}$") var zeroHash = regexp.MustCompile("^0?x?0+$") +//https://github.com/octanolabs/go-spectrum/blob/21ca5a2f3fec6c4bd12d5cc0a93b40cd305036fc/util/util.go +func DecodeValueHex(val string) string { + + if len(val) < 2 || val == "0x0" { + return "0" + } + + if val[:2] == "0x" { + x, err := hexutil.DecodeBig(val) + + if err != nil { +// log.Error("errorDecodeValueHex", "str", val, "err", err) + } + return x.String() + } else { + x, ok := big.NewInt(0).SetString(val, 16) + + if !ok { +// log.Error("errorDecodeValueHex", "str", val, "ok", ok) + } + + return x.String() + } +} + func IsValidHexAddress(s string) bool { if IsZeroHash(s) || !addressPattern.MatchString(s) { return false