Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/forkid: refactor nextForkHash #1177

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions core/forkid/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down