Skip to content

Commit

Permalink
Merge pull request etclabscore#6 from ethpool-update-project/london_f…
Browse files Browse the repository at this point in the history
…ork_patch

added london fork patch, from
  • Loading branch information
phatblinkie authored May 9, 2022
2 parents 69b79b3 + 07d0a02 commit 170c3a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions payouts/unlocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
1 change: 1 addition & 0 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 170c3a4

Please sign in to comment.