github.com/MetalBlockchain/subnet-evm@v0.4.9/utils/fork.go (about)

     1  // (c) 2019-2020, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package utils
     5  
     6  import "math/big"
     7  
     8  // IsForked returns whether a fork scheduled at block s is active at the given head block.
     9  // Note: [s] and [head] can be either a block number or a block timestamp.
    10  func IsForked(s, head *big.Int) bool {
    11  	if s == nil || head == nil {
    12  		return false
    13  	}
    14  	return s.Cmp(head) <= 0
    15  }
    16  
    17  // IsForkTransition returns true if [fork] activates during the transition from [parent]
    18  // to [current].
    19  // Note: this works for both block number and timestamp activated forks.
    20  func IsForkTransition(fork *big.Int, parent *big.Int, current *big.Int) bool {
    21  	parentForked := IsForked(fork, parent)
    22  	currentForked := IsForked(fork, current)
    23  	return !parentForked && currentForked
    24  }
    25  
    26  // BigNumEqual returns true if x and y are equivalent ie. both nil or both
    27  // contain the same value.
    28  func BigNumEqual(x, y *big.Int) bool {
    29  	if x == nil || y == nil {
    30  		return x == y
    31  	}
    32  	return x.Cmp(y) == 0
    33  }