nonce

package
v1.10.21-0...-67c1a71 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvironmentInstanceSolanaMainnet = "mainnet"
	EnvironmentInstanceSolanaDevnet  = "devnet"
	EnvironmentInstanceSolanaTestnet = "testnet"
)

Variables

View Source
var (
	ErrStaleVersion  = errors.New("nonce version is stale")
	ErrNonceNotFound = errors.New("no nonce could be found")
)

Functions

This section is empty.

Types

type Environment

type Environment uint8
const (
	EnvironmentUnknown Environment = iota
	EnvironmentSolana              // Environment instance is the cluster name (ie. mainnet, devnet, testnet, etc)
	EnvironmentCvm                 // Environment instance is the VM public key
)

func (Environment) String

func (e Environment) String() string

type Purpose

type Purpose uint8

Split nonce pool across different use cases. This has an added benefit of:.

  • Avoiding different use cases from starving each other and ending up in a deadlocked state. Concretely, it would be really bad if clients could starve internal processes from creating transactions that would allow us to progress and submit existing transactions.
const (
	PurposeUnknown Purpose = iota
	PurposeClientTransaction
	PurposeInternalServerProcess
	PurposeOnDemandTransaction
)

func (Purpose) String

func (p Purpose) String() string

type Record

type Record struct {
	Id uint64

	Address   string
	Authority string
	Blockhash string

	Environment         Environment
	EnvironmentInstance string

	Purpose Purpose
	State   State

	Signature string

	ClaimNodeID    *string
	ClaimExpiresAt *time.Time

	Version uint64
}

func (*Record) CanReserveWithSignature

func (r *Record) CanReserveWithSignature() bool

func (*Record) Clone

func (r *Record) Clone() Record

func (*Record) CopyTo

func (r *Record) CopyTo(dst *Record)

func (*Record) GetPublicKey

func (r *Record) GetPublicKey() (ed25519.PublicKey, error)

func (*Record) IsAvailableToClaim

func (r *Record) IsAvailableToClaim() bool

func (*Record) Validate

func (r *Record) Validate() error

type State

type State uint8
const (
	StateUnknown   State = iota
	StateReleased        // The nonce is almost ready but we don't know its blockhash yet.
	StateAvailable       // The nonce is available to be used by a fulfillment for a virtual instruction or transaction.
	StateReserved        // The nonce is reserved by a fulfillment for a virtual instruction or transaction.
	StateInvalid         // The nonce account is invalid (e.g. insufficient funds, etc).
	StateClaimed         // The nonce is claimed by a process for future use (identified by a node ID)
)

func (State) String

func (s State) String() string

type Store

type Store interface {
	// Count returns the total count of nonce accounts within an environment instance
	Count(ctx context.Context, env Environment, instance string) (uint64, error)

	// CountByState returns the total count of nonce accounts in the provided state within
	// an environment instance
	CountByState(ctx context.Context, env Environment, instance string, state State) (uint64, error)

	// CountByStateAndPurpose returns the total count of nonce accounts in the provided
	// state and use case within an environment instance
	CountByStateAndPurpose(ctx context.Context, env Environment, instance string, state State, purpose Purpose) (uint64, error)

	// Save creates or updates nonce metadata in the store.
	Save(ctx context.Context, record *Record) error

	// Get finds the nonce record for a given address.
	//
	// Returns ErrNotFound if no record is found.
	Get(ctx context.Context, address string) (*Record, error)

	// GetAllByState returns nonce records in the store for a given confirmation state
	// within an environment intance.
	//
	// Returns ErrNotFound if no records are found.
	GetAllByState(ctx context.Context, env Environment, instance string, state State, cursor query.Cursor, limit uint64, direction query.Ordering) ([]*Record, error)

	// BatchClaimAvailableByPurpose batch claims up to the specified limit.
	//
	// The returned nonces will be marked as claimed by the current node, with
	// the specified expiry date.
	//
	// Note: Implementations need not randomize the results/selection.
	// The transactional nature of the call means that any contention exists
	// on the tx level (which always occurs), and not around fighting over
	// individual nonces.
	BatchClaimAvailableByPurpose(ctx context.Context, env Environment, instance string, purpose Purpose, limit int, nodeID string, minExpireAt, maxExpireAt time.Time) ([]*Record, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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