github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/priorities.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package txs
     5  
     6  const (
     7  	// First primary network apricot delegators are moved from the pending to
     8  	// the current validator set,
     9  	PrimaryNetworkDelegatorApricotPendingPriority Priority = iota + 1
    10  	// then primary network validators,
    11  	PrimaryNetworkValidatorPendingPriority
    12  	// then primary network banff delegators,
    13  	PrimaryNetworkDelegatorBanffPendingPriority
    14  	// then permissionless subnet validators,
    15  	SubnetPermissionlessValidatorPendingPriority
    16  	// then permissionless subnet delegators.
    17  	SubnetPermissionlessDelegatorPendingPriority
    18  	// then permissioned subnet validators,
    19  	SubnetPermissionedValidatorPendingPriority
    20  
    21  	// First permissioned subnet validators are removed from the current
    22  	// validator set,
    23  	// Invariant: All permissioned stakers must be removed first because they
    24  	//            are removed by the advancement of time. Permissionless stakers
    25  	//            are removed with a RewardValidatorTx after time has advanced.
    26  	SubnetPermissionedValidatorCurrentPriority
    27  	// then permissionless subnet delegators,
    28  	SubnetPermissionlessDelegatorCurrentPriority
    29  	// then permissionless subnet validators,
    30  	SubnetPermissionlessValidatorCurrentPriority
    31  	// then primary network delegators,
    32  	PrimaryNetworkDelegatorCurrentPriority
    33  	// then primary network validators.
    34  	PrimaryNetworkValidatorCurrentPriority
    35  )
    36  
    37  var PendingToCurrentPriorities = []Priority{
    38  	PrimaryNetworkDelegatorApricotPendingPriority: PrimaryNetworkDelegatorCurrentPriority,
    39  	PrimaryNetworkValidatorPendingPriority:        PrimaryNetworkValidatorCurrentPriority,
    40  	PrimaryNetworkDelegatorBanffPendingPriority:   PrimaryNetworkDelegatorCurrentPriority,
    41  	SubnetPermissionlessValidatorPendingPriority:  SubnetPermissionlessValidatorCurrentPriority,
    42  	SubnetPermissionlessDelegatorPendingPriority:  SubnetPermissionlessDelegatorCurrentPriority,
    43  	SubnetPermissionedValidatorPendingPriority:    SubnetPermissionedValidatorCurrentPriority,
    44  }
    45  
    46  type Priority byte
    47  
    48  func (p Priority) IsCurrent() bool {
    49  	return p.IsCurrentValidator() || p.IsCurrentDelegator()
    50  }
    51  
    52  func (p Priority) IsPending() bool {
    53  	return p.IsPendingValidator() || p.IsPendingDelegator()
    54  }
    55  
    56  func (p Priority) IsValidator() bool {
    57  	return p.IsCurrentValidator() || p.IsPendingValidator()
    58  }
    59  
    60  func (p Priority) IsPermissionedValidator() bool {
    61  	return p == SubnetPermissionedValidatorCurrentPriority ||
    62  		p == SubnetPermissionedValidatorPendingPriority
    63  }
    64  
    65  func (p Priority) IsDelegator() bool {
    66  	return p.IsCurrentDelegator() || p.IsPendingDelegator()
    67  }
    68  
    69  func (p Priority) IsCurrentValidator() bool {
    70  	return p == PrimaryNetworkValidatorCurrentPriority ||
    71  		p == SubnetPermissionedValidatorCurrentPriority ||
    72  		p == SubnetPermissionlessValidatorCurrentPriority
    73  }
    74  
    75  func (p Priority) IsCurrentDelegator() bool {
    76  	return p == PrimaryNetworkDelegatorCurrentPriority ||
    77  		p == SubnetPermissionlessDelegatorCurrentPriority
    78  }
    79  
    80  func (p Priority) IsPendingValidator() bool {
    81  	return p == PrimaryNetworkValidatorPendingPriority ||
    82  		p == SubnetPermissionedValidatorPendingPriority ||
    83  		p == SubnetPermissionlessValidatorPendingPriority
    84  }
    85  
    86  func (p Priority) IsPendingDelegator() bool {
    87  	return p == PrimaryNetworkDelegatorBanffPendingPriority ||
    88  		p == PrimaryNetworkDelegatorApricotPendingPriority ||
    89  		p == SubnetPermissionlessDelegatorPendingPriority
    90  }