mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 09:37:38 +00:00
2793ef6ec1
* move mocks to the owner packages * squash single file packages * move types to more appropriate files * remove unused mocks
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package bor
|
|
|
|
import (
|
|
"github.com/ledgerwatch/erigon/polygon/bor/borcfg"
|
|
)
|
|
|
|
const (
|
|
spanLength = 6400 // Number of blocks in a span
|
|
zerothSpanEnd = 255 // End block of 0th span
|
|
)
|
|
|
|
// SpanIDAt returns the corresponding span id for the given block number.
|
|
func SpanIDAt(blockNum uint64) uint64 {
|
|
if blockNum > zerothSpanEnd {
|
|
return 1 + (blockNum-zerothSpanEnd-1)/spanLength
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// SpanEndBlockNum returns the number of the last block in the given span.
|
|
func SpanEndBlockNum(spanID uint64) uint64 {
|
|
if spanID > 0 {
|
|
return spanID*spanLength + zerothSpanEnd
|
|
}
|
|
return zerothSpanEnd
|
|
}
|
|
|
|
// IsBlockInLastSprintOfSpan returns true if a block num is within the last sprint of a span and false otherwise.
|
|
func IsBlockInLastSprintOfSpan(blockNum uint64, config *borcfg.BorConfig) bool {
|
|
spanNum := SpanIDAt(blockNum)
|
|
endBlockNum := SpanEndBlockNum(spanNum)
|
|
sprintLen := config.CalculateSprintLength(blockNum)
|
|
startBlockNum := endBlockNum - sprintLen + 1
|
|
return startBlockNum <= blockNum && blockNum <= endBlockNum
|
|
}
|