Documentation
¶
Overview ¶
Package tx builds, simulates and prices the reporter's unordered transactions and derives their nonce slots (spec §6.1).
Index ¶
- Constants
- Variables
- func EffectiveMaxGas(maxGas uint64, blockMaxGas int64) uint64
- func FeeFor(gasLimit uint64, prices sdk.DecCoins, fees sdk.Coins) sdk.Coins
- func SendCutoff(signerTimeout time.Duration) time.Duration
- func SlotOf(id sinkid.ID, k policy.Key) int
- func SlotTimeout(w int64, slot int) time.Time
- func WindowOf(blockTime time.Time) int64
- func WindowStart(w int64) time.Time
- type Broadcaster
- func (b *Broadcaster) Flush()
- func (b *Broadcaster) Queue(p policy.Planned) bool
- func (b *Broadcaster) Run(ctx context.Context) error
- func (b *Broadcaster) SetReviewer(r Reviewer)
- func (b *Broadcaster) SimBytes(msgs []sdk.Msg, timeout time.Time) ([]byte, error)
- func (b *Broadcaster) TakeFailures() int
- func (b *Broadcaster) Wait(ctx context.Context) int
- type Builder
- func (b *Builder) Build(ctx context.Context, msgs []sdk.Msg, gasLimit uint64, fee sdk.Coins, ...) (txBytes, hash []byte, err error)
- func (b *Builder) SignBytesLen(msgs []sdk.Msg, gasLimit uint64, fee sdk.Coins, timeout time.Time) (int, error)
- func (b *Builder) SimBytes(msgs []sdk.Msg, gasLimit uint64, fee sdk.Coins, timeout time.Time) ([]byte, error)
- type Chain
- type Dropped
- type Options
- type PruneResult
- type Reviewer
Constants ¶
const ( VoteSlots = 128 SingleSlots = 1024 )
Nonce scheme v1 slot counts. These are protocol values, not configuration.
Variables ¶
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 ¶
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 SendCutoff ¶
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 ¶
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 ¶
SlotTimeout returns T(w, s) = (w + 1)·W − (s + 1)·spacing, in UTC.
func WindowOf ¶
WindowOf returns the window that contains blockTime: ⌊t / W⌋ with t in Unix nanoseconds.
func WindowStart ¶
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 (*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 ¶
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 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.
Retry []policy.Planned
}
PruneResult splits a batch by simulation (spec §6.4).