From ee5965e9909c16c4e193a933a334ceaf90682ad2 Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Sun, 7 May 2023 21:28:04 +0200 Subject: [PATCH] ethw test --- payouts/unlocker.go | 17 +++++++++++++++++ rpc/rpc.go | 21 +++++++++++---------- util/util.go | 25 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/payouts/unlocker.go b/payouts/unlocker.go index c5e1808..4948cae 100644 --- a/payouts/unlocker.go +++ b/payouts/unlocker.go @@ -337,6 +337,23 @@ 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) + candidate.Orphan = false candidate.Hash = block.Hash candidate.Reward = reward diff --git a/rpc/rpc.go b/rpc/rpc.go index 07ba2db..9a4f1b0 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -28,16 +28,17 @@ type RPCClient struct { } type GetBlockReply struct { - Number string `json:"number"` - Hash string `json:"hash"` - Nonce string `json:"nonce"` - Miner string `json:"miner"` - Difficulty string `json:"difficulty"` - GasLimit string `json:"gasLimit"` - GasUsed string `json:"gasUsed"` - Timestamp string `json:"timestamp"` - Transactions []Tx `json:"transactions"` - Uncles []string `json:"uncles"` + Number string `json:"number"` + Hash string `json:"hash"` + Nonce string `json:"nonce"` + Miner string `json:"miner"` + Difficulty string `json:"difficulty"` + GasLimit string `json:"gasLimit"` + BaseFeePerGas string `json:"baseFeePerGas"` + GasUsed string `json:"gasUsed"` + Timestamp string `json:"timestamp"` + Transactions []Tx `json:"transactions"` + Uncles []string `json:"uncles"` // https://github.com/ethereum/EIPs/issues/95 SealFields []string `json:"sealFields"` } diff --git a/util/util.go b/util/util.go index 0431ef8..fd5a11c 100644 --- a/util/util.go +++ b/util/util.go @@ -94,3 +94,28 @@ func DiffIntToFloat(diffInt int64) (diffFloat float64) { func ToHex1(n int64) string { return strconv.FormatInt(n, 10) } + +// 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() + } +}