Documentation
¶
Index ¶
- Constants
- Variables
- func GetNextStakerChangeTime(config validatorfee.Config, state Chain, nextTime time.Time) (time.Time, error)
- func NextBlockTime(config validatorfee.Config, state Chain, clk *mockable.Clock) (time.Time, bool, error)
- func PickFeeCalculator(config *config.Internal, state Chain) txfee.Calculator
- type Chain
- type CurrentStakers
- type Diff
- func (d *Diff) AddChain(createChainTx *platform.Tx)
- func (d *Diff) AddRewardUTXO(txID ids.ID, utxo *avax.UTXO)
- func (d *Diff) AddSubnet(subnetID ids.ID)
- func (d *Diff) AddSubnetTransformation(transformSubnetTxIntf *platform.Tx)
- func (d *Diff) AddTx(tx *platform.Tx, status status.Status)
- func (d *Diff) AddUTXO(utxo *avax.UTXO)
- func (d *Diff) Apply(baseState Chain) error
- func (d *Diff) DeleteCurrentDelegator(staker *Staker) error
- func (d *Diff) DeleteCurrentValidator(staker *Staker) error
- func (d *Diff) DeleteExpiry(entry ExpiryEntry)
- func (d *Diff) DeletePendingDelegator(staker *Staker)
- func (d *Diff) DeletePendingValidator(staker *Staker)
- func (d *Diff) DeleteUTXO(utxoID ids.ID)
- func (d *Diff) GetAccruedFees() uint64
- func (d *Diff) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error)
- func (d *Diff) GetCurrentDelegatorIterator(subnetID ids.ID, nodeID ids.NodeID) (iterator.Iterator[*Staker], error)
- func (d *Diff) GetCurrentStakerIterator() (iterator.Iterator[*Staker], error)
- func (d *Diff) GetCurrentSupply(subnetID ids.ID) (uint64, error)
- func (d *Diff) GetCurrentValidator(subnetID ids.ID, nodeID ids.NodeID) (*Staker, error)
- func (d *Diff) GetExpiryIterator() (iterator.Iterator[ExpiryEntry], error)
- func (d *Diff) GetFeeState() gas.State
- func (d *Diff) GetL1Validator(validationID ids.ID) (L1Validator, error)
- func (d *Diff) GetL1ValidatorExcess() gas.Gas
- func (d *Diff) GetPendingDelegatorIterator(subnetID ids.ID, nodeID ids.NodeID) (iterator.Iterator[*Staker], error)
- func (d *Diff) GetPendingStakerIterator() (iterator.Iterator[*Staker], error)
- func (d *Diff) GetPendingValidator(subnetID ids.ID, nodeID ids.NodeID) (*Staker, error)
- func (d *Diff) GetStakingInfo(subnetID ids.ID, nodeID ids.NodeID) (StakingInfo, error)
- func (d *Diff) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error)
- func (d *Diff) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error)
- func (d *Diff) GetSubnetTransformation(subnetID ids.ID) (*platform.Tx, error)
- func (d *Diff) GetTimestamp() time.Time
- func (d *Diff) GetTx(txID ids.ID) (*platform.Tx, status.Status, error)
- func (d *Diff) GetUTXO(utxoID ids.ID) (*avax.UTXO, error)
- func (d *Diff) HasExpiry(entry ExpiryEntry) (bool, error)
- func (d *Diff) HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error)
- func (d *Diff) NumActiveL1Validators() int
- func (d *Diff) PutCurrentDelegator(staker *Staker) error
- func (d *Diff) PutCurrentValidator(staker *Staker) error
- func (d *Diff) PutExpiry(entry ExpiryEntry)
- func (d *Diff) PutL1Validator(l1Validator L1Validator) error
- func (d *Diff) PutPendingDelegator(staker *Staker)
- func (d *Diff) PutPendingValidator(staker *Staker) error
- func (d *Diff) SetAccruedFees(accruedFees uint64)
- func (d *Diff) SetCurrentSupply(subnetID ids.ID, currentSupply uint64)
- func (d *Diff) SetFeeState(feeState gas.State)
- func (d *Diff) SetL1ValidatorExcess(excess gas.Gas)
- func (d *Diff) SetStakingInfo(subnetID ids.ID, nodeID ids.NodeID, stakingInfo StakingInfo) error
- func (d *Diff) SetSubnetOwner(subnetID ids.ID, owner fx.Owner)
- func (d *Diff) SetSubnetToL1Conversion(subnetID ids.ID, conv SubnetToL1Conversion)
- func (d *Diff) SetTimestamp(timestamp time.Time)
- func (d *Diff) WeightOfL1Validators(subnetID ids.ID) (uint64, error)
- type Expiry
- type ExpiryEntry
- type L1Validator
- type L1Validators
- type PendingStakers
- type Staker
- type StakerAdditionAfterDeletionLegality
- type StakerDiffIterator
- type Stakers
- type StakingInfo
- type State
- func (s *State) Abort()
- func (s *State) AddChain(createChainTxIntf *platform.Tx)
- func (s *State) AddRewardUTXO(txID ids.ID, utxo *avax.UTXO)
- func (s *State) AddStatelessBlock(block platform.Block)
- func (s *State) AddSubnet(subnetID ids.ID)
- func (s *State) AddSubnetTransformation(transformSubnetTxIntf *platform.Tx)
- func (s *State) AddTx(tx *platform.Tx, status status.Status)
- func (s *State) AddUTXO(utxo *avax.UTXO)
- func (s *State) ApplyAllValidatorPublicKeyDiffs(ctx context.Context, ...) error
- func (s *State) ApplyAllValidatorWeightDiffs(ctx context.Context, ...) error
- func (s *State) ApplyValidatorPublicKeyDiffs(ctx context.Context, validators map[ids.NodeID]*validators.GetValidatorOutput, ...) error
- func (s *State) ApplyValidatorWeightDiffs(ctx context.Context, validators map[ids.NodeID]*validators.GetValidatorOutput, ...) error
- func (s *State) Checksum() ids.ID
- func (s *State) Close() error
- func (s *State) Commit() error
- func (s *State) CommitBatch() (database.Batch, error)
- func (s *State) DeleteCurrentDelegator(staker *Staker) error
- func (s *State) DeleteCurrentValidator(staker *Staker) error
- func (s *State) DeleteExpiry(entry ExpiryEntry)
- func (s *State) DeletePendingDelegator(staker *Staker)
- func (s *State) DeletePendingValidator(staker *Staker)
- func (s *State) DeleteUTXO(utxoID ids.ID)
- func (s *State) GetAccruedFees() uint64
- func (s *State) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error)
- func (s *State) GetBlockIDAtHeight(height uint64) (ids.ID, error)
- func (s *State) GetChains(subnetID ids.ID) ([]*platform.Tx, error)
- func (s *State) GetCurrentDelegatorIterator(subnetID ids.ID, nodeID ids.NodeID) (iterator.Iterator[*Staker], error)
- func (s *State) GetCurrentStakerIterator() (iterator.Iterator[*Staker], error)
- func (s *State) GetCurrentSupply(subnetID ids.ID) (uint64, error)
- func (s *State) GetCurrentValidator(subnetID ids.ID, nodeID ids.NodeID) (*Staker, error)
- func (s *State) GetCurrentValidators(ctx context.Context, subnetID ids.ID) ([]*Staker, []L1Validator, uint64, error)
- func (s *State) GetExpiryIterator() (iterator.Iterator[ExpiryEntry], error)
- func (s *State) GetFeeState() gas.State
- func (s *State) GetL1Validator(validationID ids.ID) (L1Validator, error)
- func (s *State) GetL1ValidatorExcess() gas.Gas
- func (s *State) GetLastAccepted() ids.ID
- func (s *State) GetPendingDelegatorIterator(subnetID ids.ID, nodeID ids.NodeID) (iterator.Iterator[*Staker], error)
- func (s *State) GetPendingStakerIterator() (iterator.Iterator[*Staker], error)
- func (s *State) GetPendingValidator(subnetID ids.ID, nodeID ids.NodeID) (*Staker, error)
- func (s *State) GetRewardUTXOs(txID ids.ID) ([]*avax.UTXO, error)
- func (s *State) GetStakingInfo(subnetID ids.ID, vdrID ids.NodeID) (StakingInfo, error)
- func (s *State) GetStartTime(nodeID ids.NodeID) (time.Time, error)
- func (s *State) GetStatelessBlock(blockID ids.ID) (platform.Block, error)
- func (s *State) GetSubnetIDs() ([]ids.ID, error)
- func (s *State) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error)
- func (s *State) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error)
- func (s *State) GetSubnetTransformation(subnetID ids.ID) (*platform.Tx, error)
- func (s *State) GetTimestamp() time.Time
- func (s *State) GetTx(txID ids.ID) (*platform.Tx, status.Status, error)
- func (s *State) GetUTXO(utxoID ids.ID) (*avax.UTXO, error)
- func (s *State) GetUptime(vdrID ids.NodeID) (time.Duration, time.Time, error)
- func (s *State) HasExpiry(entry ExpiryEntry) (bool, error)
- func (s *State) HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error)
- func (s *State) NumActiveL1Validators() int
- func (s *State) PutCurrentDelegator(staker *Staker) error
- func (s *State) PutCurrentValidator(staker *Staker) error
- func (s *State) PutExpiry(entry ExpiryEntry)
- func (s *State) PutL1Validator(l1Validator L1Validator) error
- func (s *State) PutPendingDelegator(staker *Staker)
- func (s *State) PutPendingValidator(staker *Staker) error
- func (s *State) ReindexBlocks(lock sync.Locker, log logging.Logger) error
- func (s *State) SetAccruedFees(accruedFees uint64)
- func (s *State) SetCurrentSupply(subnetID ids.ID, cs uint64)
- func (s *State) SetFeeState(feeState gas.State)
- func (s *State) SetHeight(height uint64)
- func (s *State) SetL1ValidatorExcess(e gas.Gas)
- func (s *State) SetLastAccepted(lastAccepted ids.ID)
- func (s *State) SetStakingInfo(subnetID ids.ID, vdrID ids.NodeID, stakingInfo StakingInfo) error
- func (s *State) SetSubnetOwner(subnetID ids.ID, owner fx.Owner)
- func (s *State) SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion)
- func (s *State) SetTimestamp(tm time.Time)
- func (s *State) SetUptime(vdrID ids.NodeID, upDuration time.Duration, lastUpdated time.Time) error
- func (s *State) UTXOIDs(addr []byte, start ids.ID, limit int) ([]ids.ID, error)
- func (s *State) WeightOfL1Validators(subnetID ids.ID) (uint64, error)
- type SubnetToL1Conversion
- type ValidatorWeightDiff
- type Versions
Constants ¶
const ( CodecVersion0Tag = "v0" CodecVersion0 uint16 = 0 CodecVersion1Tag = "v1" CodecVersion1 uint16 = 1 )
Variables ¶
var ( ErrMutatedL1Validator = errors.New("L1 validator contains mutated constant fields") ErrConflictingL1Validator = errors.New("L1 validator contains conflicting subnetID + nodeID pair") ErrDuplicateL1Validator = errors.New("L1 validator contains duplicate subnetID + nodeID pair") )
var ( BlockIDPrefix = []byte("blockID") BlockPrefix = []byte("block") ValidatorsPrefix = []byte("validators") CurrentPrefix = []byte("current") PendingPrefix = []byte("pending") ValidatorPrefix = []byte("validator") DelegatorPrefix = []byte("delegator") SubnetValidatorPrefix = []byte("subnetValidator") SubnetDelegatorPrefix = []byte("subnetDelegator") ValidatorWeightDiffsBySubnetIDPrefix = []byte("flatValidatorDiffs") ValidatorWeightDiffsByHeightPrefix = []byte("flatValidatorDiffsByHeight") ValidatorPublicKeyDiffsBySubnetIDPrefix = []byte("flatPublicKeyDiffs") ValidatorPublicKeyDiffsByHeightPrefix = []byte("flatPublicKeyDiffsByHeight") TxPrefix = []byte("tx") RewardUTXOsPrefix = []byte("rewardUTXOs") UTXOPrefix = []byte("utxo") SubnetPrefix = []byte("subnet") SubnetOwnerPrefix = []byte("subnetOwner") SubnetToL1ConversionPrefix = []byte("subnetToL1Conversion") TransformedSubnetPrefix = []byte("transformedSubnet") SupplyPrefix = []byte("supply") ChainPrefix = []byte("chain") ExpiryReplayProtectionPrefix = []byte("expiryReplayProtection") L1Prefix = []byte("l1") WeightsPrefix = []byte("weights") SubnetIDNodeIDPrefix = []byte("subnetIDNodeID") ActivePrefix = []byte("active") InactivePrefix = []byte("inactive") SingletonPrefix = []byte("singleton") TimestampKey = []byte("timestamp") FeeStateKey = []byte("fee state") L1ValidatorExcessKey = []byte("l1Validator excess") AccruedFeesKey = []byte("accrued fees") CurrentSupplyKey = []byte("current supply") LastAcceptedKey = []byte("last accepted") HeightsIndexedKey = []byte("heights indexed") InitializedKey = []byte("initialized") BlocksReindexedKey = []byte("blocks reindexed.3") )
var (
ErrAddingStakerAfterDeletion = errors.New("attempted to add a staker after deleting it")
)
var (
ErrMissingParentState = errors.New("missing parent state")
)
var MetadataCodec codec.Manager
Functions ¶
func GetNextStakerChangeTime ¶ added in v1.11.9
func GetNextStakerChangeTime( config validatorfee.Config, state Chain, nextTime time.Time, ) (time.Time, error)
GetNextStakerChangeTime returns the next time a staker will be either added to or removed from the validator set. If the next staker change time is further in the future than [nextTime], then [nextTime] is returned.
func NextBlockTime ¶ added in v1.11.9
func PickFeeCalculator ¶ added in v1.11.10
func PickFeeCalculator(config *config.Internal, state Chain) txfee.Calculator
PickFeeCalculator creates either a simple or a dynamic fee calculator, depending on the active upgrade.
PickFeeCalculator does not modify state.
Types ¶
type Chain ¶
type Chain interface {
Expiry
L1Validators
Stakers
avax.UTXOAdder
avax.UTXOGetter
avax.UTXODeleter
GetTimestamp() time.Time
SetTimestamp(tm time.Time)
GetFeeState() gas.State
SetFeeState(f gas.State)
GetL1ValidatorExcess() gas.Gas
SetL1ValidatorExcess(e gas.Gas)
GetAccruedFees() uint64
SetAccruedFees(f uint64)
GetCurrentSupply(subnetID ids.ID) (uint64, error)
SetCurrentSupply(subnetID ids.ID, cs uint64)
AddRewardUTXO(txID ids.ID, utxo *avax.UTXO)
AddSubnet(subnetID ids.ID)
GetSubnetOwner(subnetID ids.ID) (fx.Owner, error)
SetSubnetOwner(subnetID ids.ID, owner fx.Owner)
GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error)
SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion)
GetSubnetTransformation(subnetID ids.ID) (*platform.Tx, error)
AddSubnetTransformation(transformSubnetTx *platform.Tx)
AddChain(createChainTx *platform.Tx)
GetTx(txID ids.ID) (*platform.Tx, status.Status, error)
AddTx(tx *platform.Tx, status status.Status)
}
Chain collects all methods to manage the state of the chain for block execution.
type CurrentStakers ¶
type CurrentStakers interface {
// GetCurrentValidator returns the Staker describing the validator on subnetID with nodeID.
// [database.ErrNotFound] is returned if the validator is not in the validator set.
GetCurrentValidator(subnetID ids.ID, nodeID ids.NodeID) (*Staker, error)
// PutCurrentValidator adds the Staker to the validator set.
//
// This returns an error if staker is already in the validator set.
PutCurrentValidator(staker *Staker) error
// DeleteCurrentValidator removes the Staker from the validator set.
//
// This returns an error if staker is not already in the validator set or if there are delegators
// for staker still present.
DeleteCurrentValidator(staker *Staker) error
// SetStakingInfo updates the mutable staking info for nodeID on subnetID.
//
// This returns an error if the validator is not in the validator set.
SetStakingInfo(subnetID ids.ID, nodeID ids.NodeID, stakingInfo StakingInfo) error
// GetStakingInfo returns the mutable staking info for nodeID on subnetID.
//
// This returns an error if the validator is not in the validator set.
GetStakingInfo(subnetID ids.ID, nodeID ids.NodeID) (StakingInfo, error)
// GetCurrentDelegatorIterator returns the delegators associated with the
// validator on subnetID with nodeID. Delegators are sorted by their
// removal from current staker set (i.e. Staker.NextTime).
//
// This returns an empty iterator if the validator is not in the validator set.
GetCurrentDelegatorIterator(subnetID ids.ID, nodeID ids.NodeID) (iterator.Iterator[*Staker], error)
// PutCurrentDelegator adds the staker describing a delegator to the
// staker set.
//
// This returns an error if the validator is not in the validator set.
//
// Invariant: staker is not currently a CurrentDelegator
// TODO error if the delegator is already present
PutCurrentDelegator(staker *Staker) error
// DeleteCurrentDelegator removes the staker describing a delegator from
// the staker set.
//
// This returns an error if the validator is not in the validator set.
//
// Invariant: staker is currently a CurrentDelegator
// TODO error if the delegator was not present
DeleteCurrentDelegator(staker *Staker) error
// GetCurrentStakerIterator returns stakers in order of their removal from
// the current staker set.
GetCurrentStakerIterator() (iterator.Iterator[*Staker], error)
}
type Diff ¶
type Diff struct {
// contains filtered or unexported fields
}
Diff is a copy-on-write layer on top of a parent Chain. It records mutations locally and applies them to the parent via Diff.Apply.
func NewDiff ¶
func NewDiff( parentID ids.ID, stateVersions Versions, allowAddingStakerAfterDeletion StakerAdditionAfterDeletionLegality, ) (*Diff, error)
NewDiff returns a new Diff whose parent is identified by parentID within stateVersions.
func NewDiffOn ¶ added in v1.10.18
func NewDiffOn(parentState Chain, allowAddingStakerAfterDeletion StakerAdditionAfterDeletionLegality) (*Diff, error)
func (*Diff) AddRewardUTXO ¶ added in v1.14.2
func (*Diff) AddSubnetTransformation ¶ added in v1.14.2
func (*Diff) DeleteCurrentDelegator ¶ added in v1.14.2
func (*Diff) DeleteCurrentValidator ¶ added in v1.14.2
func (*Diff) DeleteExpiry ¶ added in v1.14.2
func (d *Diff) DeleteExpiry(entry ExpiryEntry)
func (*Diff) DeletePendingDelegator ¶ added in v1.14.2
func (*Diff) DeletePendingValidator ¶ added in v1.14.2
func (*Diff) DeleteUTXO ¶ added in v1.14.2
func (*Diff) GetAccruedFees ¶ added in v1.14.2
func (*Diff) GetActiveL1ValidatorsIterator ¶ added in v1.14.2
func (d *Diff) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error)
func (*Diff) GetCurrentDelegatorIterator ¶ added in v1.14.2
func (*Diff) GetCurrentStakerIterator ¶ added in v1.14.2
func (*Diff) GetCurrentSupply ¶ added in v1.14.2
func (*Diff) GetCurrentValidator ¶ added in v1.14.2
func (*Diff) GetExpiryIterator ¶ added in v1.14.2
func (d *Diff) GetExpiryIterator() (iterator.Iterator[ExpiryEntry], error)
func (*Diff) GetFeeState ¶ added in v1.14.2
func (*Diff) GetL1Validator ¶ added in v1.14.2
func (d *Diff) GetL1Validator(validationID ids.ID) (L1Validator, error)
func (*Diff) GetL1ValidatorExcess ¶ added in v1.14.2
func (*Diff) GetPendingDelegatorIterator ¶ added in v1.14.2
func (*Diff) GetPendingStakerIterator ¶ added in v1.14.2
func (*Diff) GetPendingValidator ¶ added in v1.14.2
func (*Diff) GetStakingInfo ¶ added in v1.14.2
func (*Diff) GetSubnetOwner ¶ added in v1.14.2
func (*Diff) GetSubnetToL1Conversion ¶ added in v1.14.2
func (d *Diff) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error)
func (*Diff) GetSubnetTransformation ¶ added in v1.14.2
func (*Diff) GetTimestamp ¶ added in v1.14.2
func (*Diff) HasL1Validator ¶ added in v1.14.2
func (*Diff) NumActiveL1Validators ¶ added in v1.14.2
func (*Diff) PutCurrentDelegator ¶ added in v1.14.2
func (*Diff) PutCurrentValidator ¶ added in v1.14.2
func (*Diff) PutExpiry ¶ added in v1.14.2
func (d *Diff) PutExpiry(entry ExpiryEntry)
func (*Diff) PutL1Validator ¶ added in v1.14.2
func (d *Diff) PutL1Validator(l1Validator L1Validator) error
func (*Diff) PutPendingDelegator ¶ added in v1.14.2
func (*Diff) PutPendingValidator ¶ added in v1.14.2
func (*Diff) SetAccruedFees ¶ added in v1.14.2
func (*Diff) SetCurrentSupply ¶ added in v1.14.2
func (*Diff) SetFeeState ¶ added in v1.14.2
func (*Diff) SetL1ValidatorExcess ¶ added in v1.14.2
func (*Diff) SetStakingInfo ¶ added in v1.14.2
func (*Diff) SetSubnetOwner ¶ added in v1.14.2
func (*Diff) SetSubnetToL1Conversion ¶ added in v1.14.2
func (d *Diff) SetSubnetToL1Conversion(subnetID ids.ID, conv SubnetToL1Conversion)
func (*Diff) SetTimestamp ¶ added in v1.14.2
type Expiry ¶ added in v1.11.12
type Expiry interface {
// GetExpiryIterator returns an iterator of all the expiry entries in order
// of lowest to highest timestamp.
GetExpiryIterator() (iterator.Iterator[ExpiryEntry], error)
// HasExpiry returns true if the database has the specified entry.
HasExpiry(ExpiryEntry) (bool, error)
// PutExpiry adds the entry to the database. If the entry already exists, it
// is a noop.
PutExpiry(ExpiryEntry)
// DeleteExpiry removes the entry from the database. If the entry doesn't
// exist, it is a noop.
DeleteExpiry(ExpiryEntry)
}
type ExpiryEntry ¶ added in v1.11.12
func (ExpiryEntry) Compare ¶ added in v1.11.12
func (e ExpiryEntry) Compare(o ExpiryEntry) int
Invariant: Compare produces the same ordering as the marshalled bytes.
func (ExpiryEntry) Less ¶ added in v1.11.12
func (e ExpiryEntry) Less(o ExpiryEntry) bool
func (*ExpiryEntry) Marshal ¶ added in v1.11.12
func (e *ExpiryEntry) Marshal() []byte
func (*ExpiryEntry) Unmarshal ¶ added in v1.11.12
func (e *ExpiryEntry) Unmarshal(data []byte) error
type L1Validator ¶ added in v1.11.13
type L1Validator struct {
// ValidationID is not serialized because it is used as the key in the
// database, so it doesn't need to be stored in the value.
ValidationID ids.ID
SubnetID ids.ID `serialize:"true"`
NodeID ids.NodeID `serialize:"true"`
// PublicKey is the uncompressed BLS public key of the validator. It is
// guaranteed to be populated.
PublicKey []byte `serialize:"true"`
// RemainingBalanceOwner is the owner that will be used when returning the
// balance of the validator after removing accrued fees.
RemainingBalanceOwner []byte `serialize:"true"`
// DeactivationOwner is the owner that can manually deactivate the
// validator.
DeactivationOwner []byte `serialize:"true"`
// StartTime is the unix timestamp, in seconds, when this validator was
// added to the set.
StartTime uint64 `serialize:"true"`
// Weight of this validator. It can be updated when the MinNonce is
// increased. If the weight is being set to 0, the validator is being
// removed.
Weight uint64 `serialize:"true"`
// MinNonce is the smallest nonce that can be used to modify this
// validator's weight. It is initially set to 0 and is set to one higher
// than the last nonce used. It is not valid to use nonce MaxUint64 unless
// the weight is being set to 0, which removes the validator from the set.
MinNonce uint64 `serialize:"true"`
// EndAccumulatedFee is the amount of accumulated fees per validator that
// can accrue before this validator must be deactivated. It is equal to the
// amount of fees this validator is willing to pay plus the total amount of
// fees a validator would have needed to pay from the activation of the Etna
// upgrade until this validator was registered. Note that this relies on the
// fact that every validator is charged the same fee for each unit of time.
//
// If this value is 0, the validator is inactive.
EndAccumulatedFee uint64 `serialize:"true"`
}
L1Validator defines an ACP-77 validator. For a given ValidationID, it is expected for SubnetID, NodeID, PublicKey, RemainingBalanceOwner, DeactivationOwner, and StartTime to be constant.
func (L1Validator) Compare ¶ added in v1.11.13
func (v L1Validator) Compare(o L1Validator) int
Compare determines a canonical ordering of L1 validators based on their EndAccumulatedFees and ValidationIDs. Lower EndAccumulatedFees result in an earlier ordering.
func (L1Validator) IsActive ¶ added in v1.12.2
func (v L1Validator) IsActive() bool
func (L1Validator) Less ¶ added in v1.11.13
func (v L1Validator) Less(o L1Validator) bool
type L1Validators ¶ added in v1.11.13
type L1Validators interface {
// GetActiveL1ValidatorsIterator returns an iterator of all the active L1
// validators in increasing order of EndAccumulatedFee.
//
// It is the caller's responsibility to call [Release] on the iterator after
// use.
//
// It is not guaranteed to be safe to modify the state while using the
// iterator. After releasing the iterator, the state may be safely modified.
GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error)
// NumActiveL1Validators returns the number of currently active L1
// validators.
NumActiveL1Validators() int
// WeightOfL1Validators returns the total active and inactive weight of L1
// validators on [subnetID].
WeightOfL1Validators(subnetID ids.ID) (uint64, error)
// GetL1Validator returns the validator with [validationID] if it exists. If
// the validator does not exist, [err] will equal [database.ErrNotFound].
GetL1Validator(validationID ids.ID) (L1Validator, error)
// HasL1Validator returns the validator with [validationID] if it exists.
HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error)
// PutL1Validator inserts [l1Validator] as a validator. If the weight of the
// validator is 0, the validator is removed.
//
// If inserting this validator attempts to modify any of the constant fields
// of the L1 validator struct, an error will be returned.
//
// If inserting this validator would cause the total weight of L1 validators
// on a subnet to overflow MaxUint64, an error will be returned.
//
// If inserting this validator would cause there to be multiple validators
// with the same subnetID and nodeID pair to exist at the same time, an
// error will be returned.
//
// If an L1 validator is added with the same validationID as a previously
// removed L1 validator, the behavior is undefined.
PutL1Validator(l1Validator L1Validator) error
}
type PendingStakers ¶
type PendingStakers interface {
// GetPendingValidator returns the Staker describing the validator on
// [subnetID] with [nodeID]. If the validator does not exist,
// [database.ErrNotFound] is returned.
GetPendingValidator(subnetID ids.ID, nodeID ids.NodeID) (*Staker, error)
// PutPendingValidator adds the [staker] describing a validator to the
// staker set.
PutPendingValidator(staker *Staker) error
// DeletePendingValidator removes the [staker] describing a validator from
// the staker set.
DeletePendingValidator(staker *Staker)
// GetPendingDelegatorIterator returns the delegators associated with the
// validator on [subnetID] with [nodeID]. Delegators are sorted by their
// removal from pending staker set.
GetPendingDelegatorIterator(subnetID ids.ID, nodeID ids.NodeID) (iterator.Iterator[*Staker], error)
// PutPendingDelegator adds the [staker] describing a delegator to the
// staker set.
PutPendingDelegator(staker *Staker)
// DeletePendingDelegator removes the [staker] describing a delegator from
// the staker set.
DeletePendingDelegator(staker *Staker)
// GetPendingStakerIterator returns stakers in order of their removal from
// the pending staker set.
GetPendingStakerIterator() (iterator.Iterator[*Staker], error)
}
type Staker ¶ added in v1.7.15
type Staker struct {
TxID ids.ID
NodeID ids.NodeID
PublicKey *bls.PublicKey
SubnetID ids.ID
Weight uint64
StartTime time.Time
EndTime time.Time
PotentialReward uint64
// NextTime is the next time this staker will be moved from a validator set.
// If the staker is in the pending validator set, NextTime will equal
// StartTime. If the staker is in the current validator set, NextTime will
// equal EndTime.
NextTime time.Time
// Priority specifies how to break ties between stakers with the same
// NextTime. This ensures that stakers created by the same transaction type
// are grouped together. The ordering of these groups is documented in
// [priorities.go] and depends on if the stakers are in the pending or
// current validator set.
Priority platform.Priority
}
Staker contains all information required to represent a validator or delegator in the current and pending validator sets. Invariant: Staker's size is bounded to prevent OOM DoS attacks.
func NewCurrentStaker ¶ added in v1.8.0
func NewCurrentStaker( txID ids.ID, staker platform.Staker, startTime time.Time, endTime time.Time, weight uint64, potentialReward uint64, ) (*Staker, error)
NewCurrentStaker returns a current-priority Staker built from platform.Staker with the provided start time, end time, weight, and potential reward.
func NewPendingStaker ¶ added in v1.8.0
NewPendingStaker returns a pending Staker built from a platform.ScheduledStaker transaction.
func (*Staker) Equals ¶ added in v1.14.2
Equals returns true if this staker is equal to the provided staker. If s.Less(other) and other.Less(s) are both false, then it doesn't mean that s.Equals(other) is true.
func (*Staker) Less ¶ added in v1.7.15
A *Staker is considered to be less than another *Staker when:
- If its NextTime is before the other's.
- If the NextTimes are the same, the *Staker with the lesser priority is the lesser one.
- If the priorities are also the same, the one with the lesser txID is lesser.
type StakerAdditionAfterDeletionLegality ¶ added in v1.14.2
type StakerAdditionAfterDeletionLegality bool
StakerAdditionAfterDeletionLegality specifies whether a staker can be added after being deleted in the same diff. Pre Helicon it is forbidden, and post Helicon it is allowed.
const ( StakerAdditionAfterDeletionAllowed StakerAdditionAfterDeletionLegality = true StakerAdditionAfterDeletionForbidden StakerAdditionAfterDeletionLegality = false )
type StakerDiffIterator ¶ added in v1.7.15
type StakerDiffIterator interface {
Next() bool
// Returns:
// - The staker that is changing
// - True if the staker is being added to the current staker set, false if
// the staker is being removed from the current staker set
Value() (*Staker, bool)
Release()
}
StakerDiffIterator is an iterator that iterates over the events that will be performed on the current staker set.
There are two event types affecting current staker set, removal of an existing staker and addition of a new staker from the pending set.
The ordering of operations is:
- Staker operations are performed in order of their [NextTime].
- If operations have the same [NextTime], stakers are first added to the current staker set, then removed.
- Further ties are broken by *Staker.Less(), returning the lesser staker first.
func NewStakerDiffIterator ¶ added in v1.7.15
func NewStakerDiffIterator(currentIterator, pendingIterator iterator.Iterator[*Staker]) StakerDiffIterator
type Stakers ¶
type Stakers interface {
CurrentStakers
PendingStakers
}
type StakingInfo ¶ added in v1.14.2
type StakingInfo struct {
// DelegateeReward is the delegatee reward accrued during the current cycle.
DelegateeReward uint64
// Auto-renewed validators.
// AccruedValidationRewards is the sum of validation rewards restaked from previous cycles.
AccruedValidationRewards uint64
// AccruedDelegateeRewards is the sum of delegatee rewards restaked from previous cycles.
AccruedDelegateeRewards uint64
AutoCompoundRewardShares uint32
// NextPeriod is the next validation cycle duration, in seconds.
NextPeriod uint64
}
StakingInfo holds mutable validator data that can be modified.
type State ¶
type State struct {
// contains filtered or unexported fields
}
- VMDB
- |-. validators
- | |-. current
- | | |-. validator
- | | | '-. list
- | | | '-- txID -> uptime + potential reward + potential delegatee reward
- | | |-. delegator
- | | | '-. list
- | | | '-- txID -> potential reward
- | | |-. subnetValidator
- | | | '-. list
- | | | '-- txID -> uptime + potential reward + potential delegatee reward
- | | '-. subnetDelegator
- | | '-. list
- | | '-- txID -> potential reward
- | |-. pending
- | | |-. validator
- | | | '-. list
- | | | '-- txID -> nil
- | | |-. delegator
- | | | '-. list
- | | | '-- txID -> nil
- | | |-. subnetValidator
- | | | '-. list
- | | | '-- txID -> nil
- | | '-. subnetDelegator
- | | '-. list
- | | '-- txID -> nil
- | |-. l1
- | | |-. weights
- | | | '-- subnetID -> weight
- | | |-. subnetIDNodeID
- | | | '-- subnetID+nodeID -> validationID
- | | |-. active
- | | | '-- validationID -> l1Validator
- | | '-. inactive
- | | '-- validationID -> l1Validator
- | |-. weight diffs by subnet ID
- | | '-- subnet+height+nodeID -> weightChange
- | |-. weight diffs by height
- | | '-- height+subnet+nodeID -> weightChange
- | '-. pub key diffs by subnet ID
- | '-- subnet+height+nodeID -> uncompressed public key or nil
- | '-. pub key diffs by height
- | '-- height+subnet+nodeID -> uncompressed public key or nil
- |-. blockIDs
- | '-- height -> blockID
- |-. blocks
- | '-- blockID -> block bytes
- |-. txs
- | '-- txID -> tx bytes + tx status
- |- rewardUTXOs
- | '-. txID
- | '-. list
- | '-- utxoID -> utxo bytes
- |- utxos
- | '-- utxoDB
- |-. subnets
- | '-. list
- | '-- txID -> nil
- |-. subnetOwners
- | '-- subnetID -> owner
- |-. subnetToL1Conversions
- | '-- subnetID -> conversionID + chainID + addr
- |-. chains
- | '-. subnetID
- | '-. list
- | '-- txID -> nil
- |-. expiryReplayProtection
- | '-- timestamp + validationID -> nil
- '-. singletons
- |-- initializedKey -> nil
- |-- blocksReindexedKey -> nil
- |-- timestampKey -> timestamp
- |-- feeStateKey -> feeState
- |-- l1ValidatorExcessKey -> l1ValidatorExcess
- |-- accruedFeesKey -> accruedFees
- |-- currentSupplyKey -> currentSupply
- |-- lastAcceptedKey -> lastAccepted
- '-- heightsIndexKey -> startIndexHeight + endIndexHeight
State is the complete persisted state of the Platform chain.
func (*State) Abort ¶ added in v1.7.17
func (s *State) Abort()
Abort discards uncommitted changes to the database.
func (*State) AddRewardUTXO ¶ added in v1.14.2
func (*State) AddStatelessBlock ¶ added in v1.9.6
AddStatelessBlock stores block as an accepted block. Invariant: [block] is an accepted block.
func (*State) AddSubnetTransformation ¶ added in v1.14.2
func (*State) ApplyAllValidatorPublicKeyDiffs ¶ added in v1.14.0
func (s *State) ApplyAllValidatorPublicKeyDiffs( ctx context.Context, allValidators map[ids.ID]map[ids.NodeID]*validators.GetValidatorOutput, startHeight uint64, endHeight uint64, ) error
ApplyAllValidatorPublicKeyDiffs iterates from `startHeight` towards the genesis block until it has applied all of the diffs up to and including `endHeight`. Applying the diffs modifies `validators`.
Invariant: If attempting to generate the validator set for `endHeight - 1`, `validators` must initially contain the validator weights for `startHeight`.
Note: Because this function iterates towards the genesis, `startHeight` will typically be greater than or equal to `endHeight`. If `startHeight` is less than `endHeight`, no diffs will be applied.
func (*State) ApplyAllValidatorWeightDiffs ¶ added in v1.14.0
func (s *State) ApplyAllValidatorWeightDiffs( ctx context.Context, allValidators map[ids.ID]map[ids.NodeID]*validators.GetValidatorOutput, startHeight uint64, endHeight uint64, ) error
ApplyAllValidatorWeightDiffs iterates from `startHeight` towards the genesis block until it has applied all of the diffs up to and including `endHeight`. Applying the diffs modifies `validators`.
Invariant: If attempting to generate the validator set for `endHeight - 1`, `validators` must initially contain the validator weights for `startHeight`.
Note: Because this function iterates towards the genesis, `startHeight` will typically be greater than or equal to `endHeight`. If `startHeight` is less than `endHeight`, no diffs will be applied.
func (*State) ApplyValidatorPublicKeyDiffs ¶ added in v1.10.6
func (s *State) ApplyValidatorPublicKeyDiffs( ctx context.Context, validators map[ids.NodeID]*validators.GetValidatorOutput, startHeight uint64, endHeight uint64, subnetID ids.ID, ) error
ApplyValidatorPublicKeyDiffs iterates from `startHeight` towards the genesis block until it has applied all of the diffs up to and including `endHeight`. Applying the diffs modifies `validators`.
Invariant: If attempting to generate the validator set for `endHeight - 1`, `validators` must initially contain the validator weights for `startHeight`.
Note: Because this function iterates towards the genesis, `startHeight` will typically be greater than or equal to `endHeight`. If `startHeight` is less than `endHeight`, no diffs will be applied.
func (*State) ApplyValidatorWeightDiffs ¶ added in v1.10.6
func (s *State) ApplyValidatorWeightDiffs( ctx context.Context, validators map[ids.NodeID]*validators.GetValidatorOutput, startHeight uint64, endHeight uint64, subnetID ids.ID, ) error
ApplyValidatorWeightDiffs iterates from `startHeight` towards the genesis block until it has applied all of the diffs up to and including `endHeight`. Applying the diffs modifies `validators`.
Invariant: If attempting to generate the validator set for `endHeight - 1`, `validators` must initially contain the validator weights for `startHeight`.
Note: Because this function iterates towards the genesis, `startHeight` will typically be greater than or equal to `endHeight`. If `startHeight` is less than `endHeight`, no diffs will be applied.
func (*State) CommitBatch ¶ added in v1.7.17
CommitBatch returns a batch of unwritten changes that, when written, will commit all pending changes to the base database.
func (*State) DeleteCurrentDelegator ¶ added in v1.14.2
func (*State) DeleteCurrentValidator ¶ added in v1.14.2
func (*State) DeleteExpiry ¶ added in v1.14.2
func (s *State) DeleteExpiry(entry ExpiryEntry)
func (*State) DeletePendingDelegator ¶ added in v1.14.2
func (*State) DeletePendingValidator ¶ added in v1.14.2
func (*State) DeleteUTXO ¶ added in v1.14.2
func (*State) GetAccruedFees ¶ added in v1.14.2
func (*State) GetActiveL1ValidatorsIterator ¶ added in v1.14.2
func (s *State) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error)
func (*State) GetBlockIDAtHeight ¶ added in v1.10.8
func (*State) GetCurrentDelegatorIterator ¶ added in v1.14.2
func (*State) GetCurrentStakerIterator ¶ added in v1.14.2
func (*State) GetCurrentSupply ¶ added in v1.14.2
func (*State) GetCurrentValidator ¶ added in v1.14.2
func (*State) GetCurrentValidators ¶ added in v1.12.2
func (s *State) GetCurrentValidators(ctx context.Context, subnetID ids.ID) ([]*Staker, []L1Validator, uint64, error)
GetCurrentValidators returns subnet and L1 validators for the given subnetID along with the current P-chain height. This method works for both subnets and L1s. Depending of the requested subnet/L1 validator schema, the return values can include only subnet validator, only L1 validators or both if there are initial stakers in the L1 conversion.
func (*State) GetExpiryIterator ¶ added in v1.14.2
func (s *State) GetExpiryIterator() (iterator.Iterator[ExpiryEntry], error)
func (*State) GetFeeState ¶ added in v1.14.2
func (*State) GetL1Validator ¶ added in v1.14.2
func (s *State) GetL1Validator(validationID ids.ID) (L1Validator, error)
GetL1Validator allows for concurrent reads.
func (*State) GetL1ValidatorExcess ¶ added in v1.14.2
func (*State) GetLastAccepted ¶
func (*State) GetPendingDelegatorIterator ¶ added in v1.14.2
func (*State) GetPendingStakerIterator ¶ added in v1.14.2
func (*State) GetPendingValidator ¶ added in v1.14.2
func (*State) GetRewardUTXOs ¶ added in v1.10.17
func (*State) GetStakingInfo ¶ added in v1.14.2
func (*State) GetStartTime ¶ added in v1.14.2
func (*State) GetStatelessBlock ¶ added in v1.9.6
func (*State) GetSubnetOwner ¶ added in v1.14.2
func (*State) GetSubnetToL1Conversion ¶ added in v1.14.2
func (s *State) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error)
GetSubnetToL1Conversion allows for concurrent reads.
func (*State) GetSubnetTransformation ¶ added in v1.14.2
func (*State) GetTimestamp ¶ added in v1.14.2
GetTimestamp allows for concurrent reads.
func (*State) HasExpiry ¶ added in v1.14.2
func (s *State) HasExpiry(entry ExpiryEntry) (bool, error)
HasExpiry allows for concurrent reads.
func (*State) HasL1Validator ¶ added in v1.14.2
func (*State) NumActiveL1Validators ¶ added in v1.14.2
func (*State) PutCurrentDelegator ¶ added in v1.14.2
func (*State) PutCurrentValidator ¶ added in v1.14.2
func (*State) PutExpiry ¶ added in v1.14.2
func (s *State) PutExpiry(entry ExpiryEntry)
func (*State) PutL1Validator ¶ added in v1.14.2
func (s *State) PutL1Validator(l1Validator L1Validator) error
func (*State) PutPendingDelegator ¶ added in v1.14.2
func (*State) PutPendingValidator ¶ added in v1.14.2
func (*State) ReindexBlocks ¶ added in v1.11.4
ReindexBlocks converts any block indices using the legacy storage format to the new format. If this database has already updated the indices, this function will return immediately, without iterating over the database.
TODO: Remove after v1.14.x is activated
func (*State) SetAccruedFees ¶ added in v1.14.2
func (*State) SetCurrentSupply ¶ added in v1.14.2
func (*State) SetFeeState ¶ added in v1.14.2
func (*State) SetL1ValidatorExcess ¶ added in v1.14.2
func (*State) SetLastAccepted ¶
func (*State) SetStakingInfo ¶ added in v1.14.2
func (*State) SetSubnetOwner ¶ added in v1.14.2
func (*State) SetSubnetToL1Conversion ¶ added in v1.14.2
func (s *State) SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion)
func (*State) SetTimestamp ¶ added in v1.14.2
type SubnetToL1Conversion ¶ added in v1.11.13
type ValidatorWeightDiff ¶
type ValidatorWeightDiff struct {
Decrease bool `serialize:"true"`
Amount uint64 `serialize:"true"`
}
func (*ValidatorWeightDiff) Add ¶ added in v1.7.15
func (v *ValidatorWeightDiff) Add(amount uint64) error
func (*ValidatorWeightDiff) Sub ¶ added in v1.11.13
func (v *ValidatorWeightDiff) Sub(amount uint64) error