refactor(consensus): unexport block version helpers
Some checks are pending
Security Scan / security (push) Waiting to run
Test / Test (push) Waiting to run

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Virgil 2026-04-04 21:48:36 +00:00
parent 2e92407233
commit 219aeae540
2 changed files with 13 additions and 13 deletions

View file

@ -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
}

View file

@ -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)
}