Skip to content

consensus/ethash/consensus_etc_test.go — Version Comparison

v1.17.3 v1.17.4
Branch etc/v1.17.3-full-node etc/v1.17.4-full-node
Delta +398 -0 +426 -0

Diff between branches

diff --git a/consensus/ethash/consensus_etc_test.go b/consensus/ethash/consensus_etc_test.go
index 3e774894d..d65b41255 100644
--- a/consensus/ethash/consensus_etc_test.go
+++ b/consensus/ethash/consensus_etc_test.go
@@ -146,6 +146,33 @@ func TestECIP1017GetBlockWinnerRewardByBlock(t *testing.T) {
    }
 }

+// TestECIP1017RewardSingleDivision checks the ECIP-1017 era reward equals
+// baseReward * 4^era / 5^era with a single final division, against a big.Int
+// reference, plus ground-truth values for high eras where accumulated rounding
+// from per-era division would drift.
+func TestECIP1017RewardSingleDivision(t *testing.T) {
+   baseReward := uint256.NewInt(5e+18)
+   base := baseReward.ToBig()
+   for e := int64(0); e <= 40; e++ {
+       era := big.NewInt(e)
+       want := new(big.Int).Mul(base, new(big.Int).Exp(big.NewInt(4), era, nil))
+       want.Div(want, new(big.Int).Exp(big.NewInt(5), era, nil))
+
+       got := getBlockWinnerRewardByEra(era, baseReward).ToBig()
+       if got.Cmp(want) != 0 {
+           t.Errorf("era %d reward: got %s, want %s", e, got, want)
+       }
+   }
+
+   // Explicit ground-truth values for eras 20 and 21, independent of the formula above.
+   if got := getBlockWinnerRewardByEra(big.NewInt(20), baseReward).ToBig().String(); got != "57646075230342348" {
+       t.Errorf("era 20 reward: got %s, want 57646075230342348", got)
+   }
+   if got := getBlockWinnerRewardByEra(big.NewInt(21), baseReward).ToBig().String(); got != "46116860184273879" {
+       t.Errorf("era 21 reward: got %s, want 46116860184273879", got)
+   }
+}
+
 // TestECIP1017GetBlockUncleRewardByEra tests uncle reward calculation.
 // Era 0: standard sliding scale (uncle_number + 8 - header_number) / 8 * blockReward.
 // Era 1+: flat 1/32 of era-adjusted winner reward.
@@ -254,7 +281,8 @@ func (m *mockStateDB) AddLog(*types.Log)
 func (m *mockStateDB) AddPreimage(common.Hash, []byte)                            {}
 func (m *mockStateDB) Witness() *stateless.Witness                                { return nil }
 func (m *mockStateDB) AccessEvents() *state.AccessEvents                          { return nil }
-func (m *mockStateDB) Finalise(bool) *bal.StateAccessList                         { return nil }
+func (m *mockStateDB) Finalise(bool) *bal.ConstructionBlockAccessList             { return nil }
+func (m *mockStateDB) SetTxContext(common.Hash, int, uint32)                      {}
 func (m *mockStateDB) LogsForBurnAccounts() []*types.Log                          { return nil }
 func (m *mockStateDB) Prepare(rules params.Rules, sender, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList) {
 }
← Back to Version Comparison