diff --git a/core/forkid/forkid.go b/core/forkid/forkid.go index 88a7bc1c4f..d8fef09a7c 100644 --- a/core/forkid/forkid.go +++ b/core/forkid/forkid.go @@ -84,26 +84,20 @@ func NewID(config *params.ChainConfig, genesis common.Hash, head uint64) ID { return ID{Hash: checksumToBytes(hash), Next: next} } +//NextForkHash calculates the forkHash from genesis to the next fork block number func NextForkHash(config *params.ChainConfig, genesis common.Hash, head uint64) [4]byte { // Calculate the starting checksum from the genesis hash hash := crc32.ChecksumIEEE(genesis[:]) - // Calculate the current fork checksum and the next fork block - var next uint64 for _, fork := range gatherForks(config) { - if fork <= head { - // Fork already passed, checksum the previous hash and the fork number - hash = checksumUpdate(hash, fork) - continue + if fork > head { + // Checksum the previous hash and nextFokr number and return + return checksumToBytes(checksumUpdate(hash, fork)) } - next = fork - break - } - if next == 0 { - return checksumToBytes(hash) - } else { - return checksumToBytes(checksumUpdate(hash, next)) + // Fork already passed, checksum the previous hash and the fork number + hash = checksumUpdate(hash, fork) } + return checksumToBytes(hash) } // NewIDWithChain calculates the Ethereum fork ID from an existing chain instance.