tx

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 30 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tx builds, simulates and prices the reporter's unordered transactions and derives their nonce slots (spec §6.1).

Index

Constants

View Source
const (
	VoteSlots   = 128
	SingleSlots = 1024
)

Nonce scheme v1 slot counts. These are protocol values, not configuration.

Variables

View Source
var ErrSignBytesLimit = errors.New("sign bytes exceed the signer's limit")

ErrSignBytesLimit reports sign bytes longer than the signer's declared limit.

Functions

func EffectiveMaxGas

func EffectiveMaxGas(maxGas uint64, blockMaxGas int64) uint64

EffectiveMaxGas is the gas cap of a transaction: tx.max-gas, or the chain's block max gas when that is positive and lower, since no block includes a transaction declaring more (spec §6.4).

func FeeFor

func FeeFor(gasLimit uint64, prices sdk.DecCoins, fees sdk.Coins) sdk.Coins

FeeFor returns fees when set, otherwise ceil(gasLimit × price) for each of prices.

func SendCutoff

func SendCutoff(signerTimeout time.Duration) time.Duration

SendCutoff returns the least time a slot's timeout must lie ahead of the latest block time for its transaction to be signed: the cutoff base plus the signer timeout.

func SlotOf

func SlotOf(id sinkid.ID, k policy.Key) int

SlotOf returns the nonce slot of a message: 0 to 127 for a vote, 128 to 1151 for a veto or a refund.

func SlotTimeout

func SlotTimeout(w int64, slot int) time.Time

SlotTimeout returns T(w, s) = (w + 1)·W − (s + 1)·spacing, in UTC.

func WindowOf

func WindowOf(blockTime time.Time) int64

WindowOf returns the window that contains blockTime: ⌊t / W⌋ with t in Unix nanoseconds.

func WindowStart

func WindowStart(w int64) time.Time

WindowStart returns the first instant of window w, in UTC.

Types

type Broadcaster

type Broadcaster struct {
	// contains filtered or unexported fields
}

Broadcaster sends planned messages as batched unordered transactions under the nonce-slot rules of spec §6. One owner goroutine, Run's, holds the slot table and writes outcome events; workers do every request.

func New

func New(o Options, chain Chain, b *Builder, ev *events.Writer) *Broadcaster

New returns a broadcaster; Run starts it.

func (*Broadcaster) Flush

func (b *Broadcaster) Flush()

Flush reports that the pass feeding Queue has ended: the partial vote batches it filled go out now, except those a follow-up review is still filling. A refund-head review that failed is retried.

func (*Broadcaster) Queue

func (b *Broadcaster) Queue(p policy.Planned) bool

Queue offers a planned message. It reports false when the message was skipped, because its key is already queued or sent in its slot, or deferred to a later window. It is safe for concurrent use and never waits for signing.

func (*Broadcaster) Run

func (b *Broadcaster) Run(ctx context.Context) error

Run owns the slot table until ctx ends, then gives sent transactions up to ShutdownGrace to resolve.

func (*Broadcaster) SetReviewer

func (b *Broadcaster) SetReviewer(r Reviewer)

SetReviewer sets the scanner that runs follow-up reviews.

func (*Broadcaster) SimBytes

func (b *Broadcaster) SimBytes(msgs []sdk.Msg, timeout time.Time) ([]byte, error)

SimBytes returns the transaction the broadcaster simulates msgs with, under timeout.

func (*Broadcaster) TakeFailures

func (b *Broadcaster) TakeFailures() int

TakeFailures returns the failures resolved since the last call.

func (*Broadcaster) Wait

func (b *Broadcaster) Wait(ctx context.Context) int

Wait returns once nothing is queued, unresolved or deferred and no follow-up review runs or waits to start, or once WaitLimit passes without progress; it then reports what is left (spec §6.5). It also returns when ctx ends. It returns the failures resolved since the last TakeFailures.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder builds the reporter's unordered transactions: sequence 0, SIGN_MODE_DIRECT, no timeout height.

func NewBuilder

func NewBuilder(cfg client.TxConfig, chainID string, accountNumber uint64, s signer.Signer) *Builder

NewBuilder returns a builder for the account accountNumber that s signs for.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, msgs []sdk.Msg, gasLimit uint64, fee sdk.Coins, timeout time.Time) (txBytes, hash []byte, err error)

Build signs the transaction and returns its bytes and its hash, SHA-256 of the bytes. It refuses sign bytes longer than the signer's limit with ErrSignBytesLimit before asking the signer.

func (*Builder) SignBytesLen

func (b *Builder) SignBytesLen(msgs []sdk.Msg, gasLimit uint64, fee sdk.Coins, timeout time.Time) (int, error)

SignBytesLen returns the length of the direct sign doc that Build would sign for the same arguments.

func (*Builder) SimBytes

func (b *Builder) SimBytes(msgs []sdk.Msg, gasLimit uint64, fee sdk.Coins, timeout time.Time) ([]byte, error)

SimBytes returns the transaction to simulate msgs with. It has the gas-relevant shape of the signed transaction: the fee, which the ante handler deducts only when it is set, the gas limit, and a zero signature of full length in place of the real one. Simulation does not verify signatures.

type Chain

type Chain interface {
	Latest(ctx context.Context) (*akash.State, error)
	Simulate(ctx context.Context, txBytes []byte) (uint64, error)
	BroadcastSync(ctx context.Context, txBytes []byte) (akash.BroadcastResult, error)
	Tx(ctx context.Context, hash []byte) (*akash.TxResult, error)
	TxIndexedBelow(ctx context.Context, hash []byte, height int64) (*akash.TxResult, bool, error)
	TxIndexEnabled() bool
}

Chain is what the broadcaster reads and sends through: the methods of *akash.Client it uses.

type Dropped

type Dropped struct {
	Planned policy.Planned
	Err     error
}

Dropped is a message that simulation rejected, with the rejection.

type Options

type Options struct {
	// Reporter is the policy member whose key signs.
	Reporter    string
	MaxMsgs     int
	MaxInFlight int
	// GasPerMessage is the numeric gas setting; zero means gas = auto.
	GasPerMessage uint64
	GasAdjustment float64
	GasPrices     sdk.DecCoins
	Fees          sdk.Coins
	MaxGas        uint64
	// BlockMaxGas is the chain's consensus block max gas; when positive and below MaxGas, it is the gas cap.
	BlockMaxGas int64
	MaxFee      sdk.Coin
	// SignerTimeout is the remote signer's timeout, 0 for the keyring; it lengthens the send cutoff.
	SignerTimeout time.Duration
	// RefreshInterval paces snapshot refreshes, re-sends and retries; zero means one second.
	RefreshInterval time.Duration
	// WaitLimit is how long Wait waits without progress; zero means three minutes.
	WaitLimit time.Duration
	// ShutdownGrace is how long Run waits for sent transactions after its context ends; zero means 30 s.
	ShutdownGrace time.Duration
	// Clock drives timers only; chain time comes from snapshots. Nil means the system clock.
	Clock   clock.Clock
	Metrics *metrics.Metrics
	// contains filtered or unexported fields
}

Options configures a Broadcaster.

type PruneResult

type PruneResult struct {
	// Kept simulated successfully together, using GasUsed.
	Kept    []policy.Planned
	GasUsed uint64
	Dropped []Dropped
	// Deferred holds the messages still left after three failing rounds.
	Deferred []policy.Planned
	// Unavailable is a simulation error that is not the chain's answer, such as a transport failure. Pruning stopped
	// at it, and Retry holds the messages it had not decided yet.
	Unavailable error
	Retry       []policy.Planned
}

PruneResult splits a batch by simulation (spec §6.4).

func Prune

func Prune(sim func([]sdk.Msg) (uint64, error), batch []policy.Planned) PruneResult

Prune simulates batch and drops the message each failure names, for up to three failing rounds. A failure without a message index, or with one outside the batch, drops every remaining message. An error that is not the chain's answer stops pruning without dropping anything more.

type Reviewer

type Reviewer interface {
	ReviewRefundHead(ctx context.Context, minHeight int64) error
	Review(ctx context.Context, ids []sinkid.ID, minHeight int64) error
}

Reviewer runs the follow-up reviews of spec §6.6; *scan.Scanner satisfies it.

Jump to

Keyboard shortcuts

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