forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forkid.go
34 lines (28 loc) · 1.05 KB
/
forkid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package state
import "github.com/0xPolygonHermez/zkevm-node/log"
// ForkIDInterval is a fork id interval
type ForkIDInterval struct {
FromBatchNumber uint64
ToBatchNumber uint64
ForkId uint64
Version string
}
// UpdateForkIDIntervals updates the forkID intervals
func (s *State) UpdateForkIDIntervals(intervals []ForkIDInterval) {
log.Infof("Updating forkIDs. Setting %d forkIDs", len(intervals))
s.cfg.ForkIDIntervals = intervals
}
// GetForkIDByBatchNumber returns the fork id for a given batch number
func GetForkIDByBatchNumber(intervals []ForkIDInterval, batchNumber uint64) uint64 {
for _, interval := range intervals {
if batchNumber >= interval.FromBatchNumber && batchNumber <= interval.ToBatchNumber {
return interval.ForkId
}
}
// If not found return the last fork id
return intervals[len(intervals)-1].ForkId
}
// GetForkIDByBatchNumber returns the fork id for the given batch number
func (s *State) GetForkIDByBatchNumber(batchNumber uint64) uint64 {
return GetForkIDByBatchNumber(s.cfg.ForkIDIntervals, batchNumber)
}