/
fork.go
33 lines (28 loc) · 1008 Bytes
/
fork.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package utils
import "math/big"
// IsForked returns whether a fork scheduled at block s is active at the given head block.
// Note: [s] and [head] can be either a block number or a block timestamp.
func IsForked(s, head *big.Int) bool {
if s == nil || head == nil {
return false
}
return s.Cmp(head) <= 0
}
// IsForkTransition returns true if [fork] activates during the transition from [parent]
// to [current].
// Note: this works for both block number and timestamp activated forks.
func IsForkTransition(fork *big.Int, parent *big.Int, current *big.Int) bool {
parentForked := IsForked(fork, parent)
currentForked := IsForked(fork, current)
return !parentForked && currentForked
}
// BigNumEqual returns true if x and y are equivalent ie. both nil or both
// contain the same value.
func BigNumEqual(x, y *big.Int) bool {
if x == nil || y == nil {
return x == y
}
return x.Cmp(y) == 0
}