diff --git a/common/utils.go b/common/utils.go index 1c806c55..cc0dbb7d 100644 --- a/common/utils.go +++ b/common/utils.go @@ -224,6 +224,9 @@ func AccumulateRewards(header *types.Header, uncles []*types.Header) (minerBaseR if params.MainnetChainConfig.ByzantiumBlock.Cmp(header.Number) <= 0 { minerBaseReward = ethash.ByzantiumBlockReward } + if params.MainnetChainConfig.ConstantinopleBlock.Cmp(header.Number) <= 0 { + minerBaseReward = ethash.ConstantinopleBlockReward + } // Accumulate the rewards for the miner and any included uncles r := new(big.Int) diff --git a/common/utils_test.go b/common/utils_test.go index 717353bb..e739400a 100644 --- a/common/utils_test.go +++ b/common/utils_test.go @@ -24,49 +24,73 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/params" "github.com/stretchr/testify/assert" ) func TestAccumulateRewards(t *testing.T) { - blockNum := big.NewInt(5862127) - minerBaseReward := ethash.FrontierBlockReward - if params.MainnetChainConfig.ByzantiumBlock.Cmp(blockNum) <= 0 { - minerBaseReward = ethash.ByzantiumBlockReward - } - header := &types.Header{Number: blockNum} - + byzantiumBlock := big.NewInt(5862127) + constantinopleBlock := big.NewInt(7162127) tests := []struct { description string uncleHeaders []*types.Header + blockNum *big.Int uncleInclusionReward *big.Int minerBaseReward *big.Int unclesReward []*big.Int }{ { - description: "no uncles", + description: "no uncles on byzantium", uncleHeaders: []*types.Header{}, + blockNum: byzantiumBlock, uncleInclusionReward: big.NewInt(0), - minerBaseReward: minerBaseReward, + minerBaseReward: ethash.ByzantiumBlockReward, unclesReward: []*big.Int{}, }, { - description: "two uncles in same block number", - uncleHeaders: []*types.Header{{Number: big.NewInt(blockNum.Int64() - 1), Coinbase: common.HexToAddress("uncle1")}, {Number: big.NewInt(blockNum.Int64() - 1), Coinbase: common.HexToAddress("uncle2")}}, + description: "two uncles in same block number on byzantium", + uncleHeaders: []*types.Header{{Number: big.NewInt(byzantiumBlock.Int64() - 1), Coinbase: common.HexToAddress("uncle1")}, {Number: big.NewInt(byzantiumBlock.Int64() - 1), Coinbase: common.HexToAddress("uncle2")}}, + blockNum: byzantiumBlock, uncleInclusionReward: big.NewInt(187500000000000000), - minerBaseReward: minerBaseReward, + minerBaseReward: ethash.ByzantiumBlockReward, unclesReward: []*big.Int{big.NewInt(2625000000000000000), big.NewInt(2625000000000000000)}, }, { - description: "two uncles in different block number", - uncleHeaders: []*types.Header{{Number: big.NewInt(blockNum.Int64() - 1), Coinbase: common.HexToAddress("uncle1")}, {Number: big.NewInt(blockNum.Int64() - 2), Coinbase: common.HexToAddress("uncle2")}}, + description: "two uncles in different block number on byzantium", + uncleHeaders: []*types.Header{{Number: big.NewInt(byzantiumBlock.Int64() - 1), Coinbase: common.HexToAddress("uncle1")}, {Number: big.NewInt(byzantiumBlock.Int64() - 2), Coinbase: common.HexToAddress("uncle2")}}, + blockNum: byzantiumBlock, uncleInclusionReward: big.NewInt(187500000000000000), - minerBaseReward: minerBaseReward, + minerBaseReward: ethash.ByzantiumBlockReward, unclesReward: []*big.Int{big.NewInt(2625000000000000000), big.NewInt(2250000000000000000)}, }, + + { + description: "no uncles on constantinople", + uncleHeaders: []*types.Header{}, + blockNum: constantinopleBlock, + uncleInclusionReward: big.NewInt(0), + minerBaseReward: ethash.ConstantinopleBlockReward, + unclesReward: []*big.Int{}, + }, + { + description: "two uncles in same block number on constantinople", + uncleHeaders: []*types.Header{{Number: big.NewInt(constantinopleBlock.Int64() - 1), Coinbase: common.HexToAddress("uncle1")}, {Number: big.NewInt(constantinopleBlock.Int64() - 1), Coinbase: common.HexToAddress("uncle2")}}, + blockNum: constantinopleBlock, + uncleInclusionReward: big.NewInt(125000000000000000), + minerBaseReward: ethash.ConstantinopleBlockReward, + unclesReward: []*big.Int{big.NewInt(1750000000000000000), big.NewInt(1750000000000000000)}, + }, + { + description: "two uncles in different block number on constantinople", + uncleHeaders: []*types.Header{{Number: big.NewInt(constantinopleBlock.Int64() - 1), Coinbase: common.HexToAddress("uncle1")}, {Number: big.NewInt(constantinopleBlock.Int64() - 2), Coinbase: common.HexToAddress("uncle2")}}, + blockNum: constantinopleBlock, + uncleInclusionReward: big.NewInt(125000000000000000), + minerBaseReward: ethash.ConstantinopleBlockReward, + unclesReward: []*big.Int{big.NewInt(1750000000000000000), big.NewInt(1500000000000000000)}, + }, } for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { + header := &types.Header{Number: tt.blockNum} minerBaseReward, uncleInclusionReward, unclesCoinbase, unclesReward, _ := AccumulateRewards(header, tt.uncleHeaders) assert.Equal(t, tt.minerBaseReward, minerBaseReward)