executor

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2025 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Maximum future start time for staking/delegating
	MaxFutureStartTime = 24 * 7 * 2 * time.Hour

	// SyncBound is the synchrony bound used for safe decision making
	SyncBound = 10 * time.Second
)

Variables

View Source
var (
	ErrRemoveStakerTooEarly          = errors.New("attempting to remove staker before their end time")
	ErrRemoveWrongStaker             = errors.New("attempting to remove wrong staker")
	ErrChildBlockNotAfterParent      = errors.New("proposed timestamp not after current chain time")
	ErrInvalidState                  = errors.New("generated output isn't valid state")
	ErrShouldBePermissionlessStaker  = errors.New("expected permissionless staker")
	ErrWrongTxType                   = errors.New("wrong transaction type")
	ErrInvalidID                     = errors.New("invalid ID")
	ErrProposedAddStakerTxAfterBanff = errors.New("staker transaction proposed after Banff")
	ErrAdvanceTimeTxIssuedAfterBanff = errors.New("AdvanceTimeTx issued after Banff")
)
View Source
var (
	ErrWeightTooSmall                  = errors.New("weight of this validator is too low")
	ErrWeightTooLarge                  = errors.New("weight of this validator is too large")
	ErrInsufficientDelegationFee       = errors.New("staker charges an insufficient delegation fee")
	ErrTooLargeDelegationFee           = errors.New("staker charges a too large delegation fee")
	ErrStakeTooShort                   = errors.New("staking period is too short")
	ErrStakeTooLong                    = errors.New("staking period is too long")
	ErrFlowCheckFailed                 = errors.New("flow check failed")
	ErrNotValidator                    = errors.New("isn't a current or pending validator")
	ErrRemovePermissionlessValidator   = errors.New("attempting to remove permissionless validator")
	ErrStakeOverflow                   = errors.New("validator stake exceeds limit")
	ErrPeriodMismatch                  = errors.New("proposed staking period is not inside dependant staking period")
	ErrOverDelegated                   = errors.New("validator would be over delegated")
	ErrIsNotTransformSupernetTx        = errors.New("is not a transform supernet tx")
	ErrTimestampNotBeforeStartTime     = errors.New("chain timestamp not before start time")
	ErrAlreadyValidator                = errors.New("already a validator")
	ErrDuplicateValidator              = errors.New("duplicate validator")
	ErrDelegateToPermissionedValidator = errors.New("delegation to permissioned validator")
	ErrWrongStakedAssetID              = errors.New("incorrect staked assetID")
	ErrDurangoUpgradeNotActive         = errors.New("attempting to use a Durango-upgrade feature prior to activation")
	ErrDonationUpgradeNotActive        = errors.New("attempting to use a Donation-upgrade feature prior to activation")
	ErrAddValidatorTxPostDurango       = errors.New("AddValidatorTx is not permitted post-Durango")
	ErrAddDelegatorTxPostDurango       = errors.New("AddDelegatorTx is not permitted post-Durango")
)
View Source
var (
	ErrChildBlockAfterStakerChangeTime = errors.New("proposed timestamp later than next staker change time")
	ErrChildBlockBeyondSyncBound       = errors.New("proposed timestamp is too far in the future relative to local time")
)

Functions

func AdvanceTimeTo

func AdvanceTimeTo(
	backend *Backend,
	parentState state.Chain,
	newChainTime time.Time,
) (bool, error)

AdvanceTimeTo applies all state changes to [parentState] resulting from advancing the chain time to [newChainTime]. Returns true iff the validator set changed.

func GetMaxWeight

func GetMaxWeight(
	chainState state.Chain,
	validator *state.Staker,
	startTime time.Time,
	endTime time.Time,
) (uint64, error)

GetMaxWeight returns the maximum total weight of the [validator], including its own weight, between [startTime] and [endTime]. The weight changes are applied in the order they will be applied as chain time advances. Invariant: - [validator.StartTime] <= [startTime] < [endTime] <= [validator.EndTime]

func GetNextStakerChangeTime

func GetNextStakerChangeTime(state state.Chain) (time.Time, error)

GetNextStakerChangeTime returns the next time a staker will be either added or removed to/from the current validator set.

func GetRewardsCalculator

func GetRewardsCalculator(
	backend *Backend,
	parentState state.Chain,
	supernetID ids.ID,
) (reward.Calculator, error)

func GetTransformSupernetTx

func GetTransformSupernetTx(chain state.Chain, supernetID ids.ID) (*txs.TransformSupernetTx, error)

func GetValidator

func GetValidator(state state.Chain, supernetID ids.ID, nodeID ids.NodeID) (*state.Staker, error)

GetValidator returns information about the given validator, which may be a current validator or pending validator.

func NextBlockTime

func NextBlockTime(state state.Chain, clk *mockable.Clock) (time.Time, bool, error)

func VerifyNewChainTime

func VerifyNewChainTime(
	newChainTime,
	nextStakerChangeTime,
	now time.Time,
) error

VerifyNewChainTime returns nil if the [newChainTime] is a valid chain time given the wall clock time ([now]) and when the next staking set change occurs ([nextStakerChangeTime]). Requires:

  • [newChainTime] <= [nextStakerChangeTime]: so that no staking set changes are skipped.
  • [newChainTime] <= [now] + SyncBound: to ensure chain time approximates "real" time.

Types

type AtomicTxExecutor

type AtomicTxExecutor struct {
	// inputs, to be filled before visitor methods are called
	*Backend
	ParentID      ids.ID
	StateVersions state.Versions
	Tx            *txs.Tx

	// outputs of visitor execution
	OnAccept       state.Diff
	Inputs         set.Set[ids.ID]
	AtomicRequests map[ids.ID]*atomic.Requests
}

atomicTxExecutor is used to execute atomic transactions pre-AP5. After AP5 the execution was moved to be performed inside of the standardTxExecutor.

func (*AtomicTxExecutor) AddDelegatorTx

func (*AtomicTxExecutor) AddDelegatorTx(*txs.AddDelegatorTx) error

func (*AtomicTxExecutor) AddPermissionlessDelegatorTx

func (*AtomicTxExecutor) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDelegatorTx) error

func (*AtomicTxExecutor) AddPermissionlessValidatorTx

func (*AtomicTxExecutor) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error

func (*AtomicTxExecutor) AddSupernetValidatorTx

func (*AtomicTxExecutor) AddSupernetValidatorTx(*txs.AddSupernetValidatorTx) error

func (*AtomicTxExecutor) AddValidatorTx

func (*AtomicTxExecutor) AddValidatorTx(*txs.AddValidatorTx) error

func (*AtomicTxExecutor) AdvanceTimeTx

func (*AtomicTxExecutor) AdvanceTimeTx(*txs.AdvanceTimeTx) error

func (*AtomicTxExecutor) BaseTx

func (*AtomicTxExecutor) BaseTx(*txs.BaseTx) error

func (*AtomicTxExecutor) CreateChainTx

func (*AtomicTxExecutor) CreateChainTx(*txs.CreateChainTx) error

func (*AtomicTxExecutor) CreateSupernetTx

func (*AtomicTxExecutor) CreateSupernetTx(*txs.CreateSupernetTx) error

func (*AtomicTxExecutor) DonationTx added in v1.2.0

func (*AtomicTxExecutor) DonationTx(*txs.DonationTx) error

func (*AtomicTxExecutor) ExportTx

func (e *AtomicTxExecutor) ExportTx(tx *txs.ExportTx) error

func (*AtomicTxExecutor) ImportTx

func (e *AtomicTxExecutor) ImportTx(tx *txs.ImportTx) error

func (*AtomicTxExecutor) RemoveSupernetValidatorTx

func (*AtomicTxExecutor) RemoveSupernetValidatorTx(*txs.RemoveSupernetValidatorTx) error

func (*AtomicTxExecutor) RewardValidatorTx

func (*AtomicTxExecutor) RewardValidatorTx(*txs.RewardValidatorTx) error

func (*AtomicTxExecutor) TransferSupernetOwnershipTx

func (*AtomicTxExecutor) TransferSupernetOwnershipTx(*txs.TransferSupernetOwnershipTx) error

func (*AtomicTxExecutor) TransformSupernetTx

func (*AtomicTxExecutor) TransformSupernetTx(*txs.TransformSupernetTx) error

type Backend

type Backend struct {
	Config       *config.Config
	Ctx          *snow.Context
	Clk          *mockable.Clock
	Fx           fx.Fx
	FlowChecker  utxo.Verifier
	Uptimes      uptime.Calculator
	Rewards      reward.Calculator
	Bootstrapped *utils.Atomic[bool]
}

type ProposalTxExecutor

type ProposalTxExecutor struct {
	// inputs, to be filled before visitor methods are called
	*Backend
	Tx *txs.Tx
	// [OnCommitState] is the state used for validation.
	// [OnCommitState] is modified by this struct's methods to
	// reflect changes made to the state if the proposal is committed.
	//
	// Invariant: Both [OnCommitState] and [OnAbortState] represent the same
	//            state when provided to this struct.
	OnCommitState state.Diff
	// [OnAbortState] is modified by this struct's methods to
	// reflect changes made to the state if the proposal is aborted.
	OnAbortState state.Diff
}

func (*ProposalTxExecutor) AddDelegatorTx

func (e *ProposalTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error

func (*ProposalTxExecutor) AddPermissionlessDelegatorTx

func (*ProposalTxExecutor) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDelegatorTx) error

func (*ProposalTxExecutor) AddPermissionlessValidatorTx

func (*ProposalTxExecutor) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error

func (*ProposalTxExecutor) AddSupernetValidatorTx

func (e *ProposalTxExecutor) AddSupernetValidatorTx(tx *txs.AddSupernetValidatorTx) error

func (*ProposalTxExecutor) AddValidatorTx

func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error

func (*ProposalTxExecutor) AdvanceTimeTx

func (e *ProposalTxExecutor) AdvanceTimeTx(tx *txs.AdvanceTimeTx) error

func (*ProposalTxExecutor) BaseTx

func (*ProposalTxExecutor) BaseTx(*txs.BaseTx) error

func (*ProposalTxExecutor) CreateChainTx

func (*ProposalTxExecutor) CreateChainTx(*txs.CreateChainTx) error

func (*ProposalTxExecutor) CreateSupernetTx

func (*ProposalTxExecutor) CreateSupernetTx(*txs.CreateSupernetTx) error

func (*ProposalTxExecutor) DonationTx added in v1.2.0

func (*ProposalTxExecutor) DonationTx(*txs.DonationTx) error

func (*ProposalTxExecutor) ExportTx

func (*ProposalTxExecutor) ExportTx(*txs.ExportTx) error

func (*ProposalTxExecutor) ImportTx

func (*ProposalTxExecutor) ImportTx(*txs.ImportTx) error

func (*ProposalTxExecutor) RemoveSupernetValidatorTx

func (*ProposalTxExecutor) RemoveSupernetValidatorTx(*txs.RemoveSupernetValidatorTx) error

func (*ProposalTxExecutor) RewardValidatorTx

func (e *ProposalTxExecutor) RewardValidatorTx(tx *txs.RewardValidatorTx) error

func (*ProposalTxExecutor) TransferSupernetOwnershipTx

func (*ProposalTxExecutor) TransferSupernetOwnershipTx(*txs.TransferSupernetOwnershipTx) error

func (*ProposalTxExecutor) TransformSupernetTx

func (*ProposalTxExecutor) TransformSupernetTx(*txs.TransformSupernetTx) error

type StandardTxExecutor

type StandardTxExecutor struct {
	// inputs, to be filled before visitor methods are called
	*Backend
	State state.Diff // state is expected to be modified
	Tx    *txs.Tx

	// outputs of visitor execution
	OnAccept       func() // may be nil
	Inputs         set.Set[ids.ID]
	AtomicRequests map[ids.ID]*atomic.Requests // may be nil
}

func (*StandardTxExecutor) AddDelegatorTx

func (e *StandardTxExecutor) AddDelegatorTx(tx *txs.AddDelegatorTx) error

func (*StandardTxExecutor) AddPermissionlessDelegatorTx

func (e *StandardTxExecutor) AddPermissionlessDelegatorTx(tx *txs.AddPermissionlessDelegatorTx) error

func (*StandardTxExecutor) AddPermissionlessValidatorTx

func (e *StandardTxExecutor) AddPermissionlessValidatorTx(tx *txs.AddPermissionlessValidatorTx) error

func (*StandardTxExecutor) AddSupernetValidatorTx

func (e *StandardTxExecutor) AddSupernetValidatorTx(tx *txs.AddSupernetValidatorTx) error

func (*StandardTxExecutor) AddValidatorTx

func (e *StandardTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error

func (*StandardTxExecutor) AdvanceTimeTx

func (*StandardTxExecutor) AdvanceTimeTx(*txs.AdvanceTimeTx) error

func (*StandardTxExecutor) BaseTx

func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error

func (*StandardTxExecutor) CreateChainTx

func (e *StandardTxExecutor) CreateChainTx(tx *txs.CreateChainTx) error

func (*StandardTxExecutor) CreateSupernetTx

func (e *StandardTxExecutor) CreateSupernetTx(tx *txs.CreateSupernetTx) error

func (*StandardTxExecutor) DonationTx added in v1.2.0

func (e *StandardTxExecutor) DonationTx(tx *txs.DonationTx) error

func (*StandardTxExecutor) ExportTx

func (e *StandardTxExecutor) ExportTx(tx *txs.ExportTx) error

func (*StandardTxExecutor) ImportTx

func (e *StandardTxExecutor) ImportTx(tx *txs.ImportTx) error

func (*StandardTxExecutor) RemoveSupernetValidatorTx

func (e *StandardTxExecutor) RemoveSupernetValidatorTx(tx *txs.RemoveSupernetValidatorTx) error

Verifies a *txs.RemoveSupernetValidatorTx and, if it passes, executes it on [e.State]. For verification rules, see [verifyRemoveSupernetValidatorTx]. This transaction will result in [tx.NodeID] being removed as a validator of [tx.SupernetID]. Note: [tx.NodeID] may be either a current or pending validator.

func (*StandardTxExecutor) RewardValidatorTx

func (*StandardTxExecutor) RewardValidatorTx(*txs.RewardValidatorTx) error

func (*StandardTxExecutor) TransferSupernetOwnershipTx

func (e *StandardTxExecutor) TransferSupernetOwnershipTx(tx *txs.TransferSupernetOwnershipTx) error

Verifies a *txs.TransferSupernetOwnershipTx and, if it passes, executes it on [e.State]. For verification rules, see [verifyTransferSupernetOwnershipTx]. This transaction will result in the ownership of [tx.Supernet] being transferred to [tx.Owner].

func (*StandardTxExecutor) TransformSupernetTx

func (e *StandardTxExecutor) TransformSupernetTx(tx *txs.TransformSupernetTx) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL