diff --git a/consensus/block.go b/consensus/block.go index 5c230b4..2f20298 100644 --- a/consensus/block.go +++ b/consensus/block.go @@ -159,14 +159,14 @@ func ValidateBlockReward(minerTx *types.Transaction, height, blockSize, medianSi return nil } -// ExpectedBlockMajorVersion returns the expected block major version for a +// expectedBlockMajorVersion returns the expected block major version for a // given height and fork schedule. This maps hardfork eras to block versions: // // HF0 (genesis) -> 0 // HF1 -> 1 // HF3 -> 2 // HF4+ -> 3 -func ExpectedBlockMajorVersion(forks []config.HardFork, height uint64) uint8 { +func expectedBlockMajorVersion(forks []config.HardFork, height uint64) uint8 { if config.IsHardForkActive(forks, config.HF4Zarcanum, height) { return config.CurrentBlockMajorVersion // 3 } @@ -179,10 +179,10 @@ func ExpectedBlockMajorVersion(forks []config.HardFork, height uint64) uint8 { return config.BlockMajorVersionInitial // 0 } -// CheckBlockVersion validates that the block's major version matches +// checkBlockVersion validates that the block's major version matches // what is expected at the given height in the fork schedule. -func CheckBlockVersion(majorVersion uint8, forks []config.HardFork, height uint64) error { - expected := ExpectedBlockMajorVersion(forks, height) +func checkBlockVersion(majorVersion uint8, forks []config.HardFork, height uint64) error { + expected := expectedBlockMajorVersion(forks, height) if majorVersion != expected { return coreerr.E("CheckBlockVersion", fmt.Sprintf("got %d, want %d at height %d", majorVersion, expected, height), ErrBlockMajorVersion) @@ -198,7 +198,7 @@ func ValidateBlock(blk *types.Block, height, blockSize, medianSize, totalFees, a recentTimestamps []uint64, forks []config.HardFork) error { // Block major version check. - if err := CheckBlockVersion(blk.MajorVersion, forks, height); err != nil { + if err := checkBlockVersion(blk.MajorVersion, forks, height); err != nil { return err } diff --git a/consensus/block_test.go b/consensus/block_test.go index 3655815..aba41a0 100644 --- a/consensus/block_test.go +++ b/consensus/block_test.go @@ -431,9 +431,9 @@ func TestExpectedBlockMajorVersion_Good(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := ExpectedBlockMajorVersion(tt.forks, tt.height) + got := expectedBlockMajorVersion(tt.forks, tt.height) if got != tt.want { - t.Errorf("ExpectedBlockMajorVersion(%d) = %d, want %d", tt.height, got, tt.want) + t.Errorf("expectedBlockMajorVersion(%d) = %d, want %d", tt.height, got, tt.want) } }) } @@ -462,7 +462,7 @@ func TestCheckBlockVersion_Good(t *testing.T) { Flags: 0, }, } - err := CheckBlockVersion(blk.MajorVersion, tt.forks, tt.height) + err := checkBlockVersion(blk.MajorVersion, tt.forks, tt.height) require.NoError(t, err) }) } @@ -491,7 +491,7 @@ func TestCheckBlockVersion_Bad(t *testing.T) { Flags: 0, }, } - err := CheckBlockVersion(blk.MajorVersion, tt.forks, tt.height) + err := checkBlockVersion(blk.MajorVersion, tt.forks, tt.height) assert.ErrorIs(t, err, ErrBlockVersion) }) } @@ -504,17 +504,17 @@ func TestCheckBlockVersion_Ugly(t *testing.T) { blk := &types.Block{ BlockHeader: types.BlockHeader{MajorVersion: 255, Timestamp: now}, } - err := CheckBlockVersion(blk.MajorVersion, config.MainnetForks, 0) + err := checkBlockVersion(blk.MajorVersion, config.MainnetForks, 0) assert.ErrorIs(t, err, ErrBlockVersion) - err = CheckBlockVersion(blk.MajorVersion, config.MainnetForks, 10081) + err = checkBlockVersion(blk.MajorVersion, config.MainnetForks, 10081) assert.ErrorIs(t, err, ErrBlockVersion) // Version 0 at the exact HF1 boundary (height 10080 -- fork not yet active). blk0 := &types.Block{ BlockHeader: types.BlockHeader{MajorVersion: config.BlockMajorVersionInitial, Timestamp: now}, } - err = CheckBlockVersion(blk0.MajorVersion, config.MainnetForks, 10080) + err = checkBlockVersion(blk0.MajorVersion, config.MainnetForks, 10080) require.NoError(t, err) }