Documentation
¶
Overview ¶
QueueTicket admission and ticket conversion adapt Nico Vergauwen's and Yondon Fu's go-livepeer/server/redeemer.go at afaaa36e743d39e6f460e7993d516d52b3a81341. HTTP transport, deployment binding and validation are implemented for Node.
Winning-ticket store operations follow livepeer/go-livepeer/common/db.go, by Elad Mallel and Nico Vergauwen (404d24a9455cd0997af1be6d18faa998702cce69). The redemption recovery schema and transaction state are implemented here.
Recovery adapters for the go-livepeer port at 0ff08af1bb4cb268f428d619cc968b5eaee0d093. These bridge node's durable store and finalized settlement to the upstream nonce/send/wait/replace lifecycle.
Queue scheduling and the face-value/cost guard adapt go-livepeer pm/queue.go and pm/sendermonitor.go at afaaa36e743d39e6f460e7993d516d52b3a81341. Original authors: Nico Vergauwen, Yondon Fu and Rafał Leszko. MIT: LICENSE.
Index ¶
- Constants
- Variables
- func Command(component, defaultDB string) *cobra.Command
- func Handler(s *RedeemerDB) http.Handler
- func HandlerWithAuthorization(s *RedeemerDB, ...) http.Handler
- func OpenDatabase(ctx context.Context, path string, create bool) (*sql.DB, error)
- func ReconcileSubmitted(ctx context.Context, store *RedeemerDB, chain ReceiptReader) []error
- func RedeemerURL(u *url.URL) (*url.URL, error)
- func RetryRedemption(ctx context.Context, store *RedeemerDB, contracts *eth.Contracts, ...) error
- func StandalonePolicy(chain eth.PaymentChain, id *big.Int) func(context.Context, *types.Transaction) error
- func ValidateTicket(t *pm.SignedTicket) error
- type Binding
- type ChainDestination
- type Destination
- type HTTPDestination
- type Limits
- type NonceReader
- type ReceiptReader
- type RedeemerDB
- func (s *RedeemerDB) Admit(ctx context.Context, t *pm.SignedTicket) error
- func (s *RedeemerDB) Bind(ctx context.Context, b Binding, limits Limits, chain NonceReader) error
- func (s *RedeemerDB) Binding(ctx context.Context) (Binding, error)
- func (s *RedeemerDB) CapacityAvailable(ctx context.Context, recipient common.Address) (bool, error)
- func (s *RedeemerDB) CheckStorage(ctx context.Context) error
- func (s *RedeemerDB) Close() error
- func (s *RedeemerDB) CollectMetrics(emit observability.Emit)
- func (s *RedeemerDB) Configure(logger *slog.Logger, metrics *observability.Metrics, ...)
- func (s *RedeemerDB) RecordPrepared(ctx context.Context, ticket *pm.SignedTicket, prepared eth.SignedTransaction) error
- func (s *RedeemerDB) Redemptions() ([]RedemptionStatus, error)
- func (s *RedeemerDB) SavedNonceFloor(ctx context.Context, address ethcommon.Address) (uint64, error)
- func (s *RedeemerDB) SelectEarliestWinningTicket(payer ethcommon.Address, minCreationRound int64) (*pm.SignedTicket, error)
- func (s *RedeemerDB) StoreWinningTicket(t *pm.SignedTicket) error
- func (s *RedeemerDB) StoreWinningTickets(ctx context.Context, payer ethcommon.Address, randHash ethcommon.Hash, ...) error
- func (s *RedeemerDB) SubmittedRedemptions() ([]SubmittedRedemption, error)
- func (s *RedeemerDB) WinningTicketCount(payer ethcommon.Address) (int, error)
- type RedemptionOptions
- type RedemptionStatus
- type Rejection
- type SubmittedRedemption
- type TicketJSON
- type TicketRequest
- type TicketResponse
- type Worker
Constants ¶
const MaxTicketBody = 16 << 10
Variables ¶
var DefaultLimits = Limits{Pending: 100000, PerRecipient: 10000}
var ErrCapacity = errors.New("winning-ticket queue capacity exhausted")
var ErrConflict = errors.New("ticket scheduling metadata conflicts with stored ticket")
var ErrExposedRandomness = errors.New("ticket randomness is already exposed")
var MigrationFiles embed.FS
Functions ¶
func Handler ¶
func Handler(s *RedeemerDB) http.Handler
func HandlerWithAuthorization ¶
func HandlerWithAuthorization(s *RedeemerDB, authorize func(http.ResponseWriter, *http.Request, *TicketJSON) bool) http.Handler
HandlerWithAuthorization calls authorize before validating or storing a ticket. The ticket is nil if decoding fails. authorize must write any failure response.
func OpenDatabase ¶
func ReconcileSubmitted ¶
func ReconcileSubmitted(ctx context.Context, store *RedeemerDB, chain ReceiptReader) []error
ReconcileSubmitted checks every retained identity, including old retry groups. A finalized success wins over sibling failures; failed attempts alone cannot release liability while another signed identity might still redeem the ticket.
func RedeemerURL ¶
RedeemerURL is normalized before both binding and dispatch. Redirects must never forward ticket randomness to a destination selected by the server.
func RetryRedemption ¶
func RetryRedemption(ctx context.Context, store *RedeemerDB, contracts *eth.Contracts, hash ethcommon.Hash) error
RetryRedemption preserves the existing explicit identical-byte retry command. Historical identities are inspectable, but cannot replace a newer active job.
func StandalonePolicy ¶
func StandalonePolicy(chain eth.PaymentChain, id *big.Int) func(context.Context, *types.Transaction) error
StandalonePolicy checks the actual sender, including retained transactions from a previous key. All rebroadcast paths use Contracts.Broadcast.
func ValidateTicket ¶
func ValidateTicket(t *pm.SignedTicket) error
Types ¶
type ChainDestination ¶
type ChainDestination struct {
// contains filtered or unexported fields
}
func NewChainDestination ¶
func NewChainDestination(ctx context.Context, s *RedeemerDB, c eth.PaymentChain, k *eth.Key, id *big.Int, options RedemptionOptions) (*ChainDestination, error)
func (*ChainDestination) Submit ¶
func (d *ChainDestination) Submit(ctx context.Context, t *pm.SignedTicket) error
type Destination ¶
type Destination interface {
Submit(context.Context, *pm.SignedTicket) error
}
Destination acknowledges submission/handoff, never financial settlement.
type HTTPDestination ¶
type HTTPDestination struct {
// contains filtered or unexported fields
}
func NewHTTPDestination ¶
func NewHTTPDestination(u *url.URL, policy destination.Policy, b Binding, headers ...http.Header) (*HTTPDestination, error)
func (*HTTPDestination) Close ¶
func (d *HTTPDestination) Close()
func (*HTTPDestination) Submit ¶
func (d *HTTPDestination) Submit(ctx context.Context, t *pm.SignedTicket) error
type NonceReader ¶
type ReceiptReader ¶
type RedeemerDB ¶
type RedeemerDB struct {
// contains filtered or unexported fields
}
RedeemerDB owns the shared durable winning-ticket queue, redemption lifecycle, and chain activity observations.
func NewStore ¶
func NewStore(db *sql.DB) (*RedeemerDB, error)
NewStore takes ownership of db and initializes the shared migration catalog.
func OpenRedeemerDB ¶
func OpenRedeemerDB(path string) (*RedeemerDB, error)
func (*RedeemerDB) Admit ¶
func (s *RedeemerDB) Admit(ctx context.Context, t *pm.SignedTicket) error
Admit is the untrusted HTTP boundary. Validation also precedes deduplication: another signature for the same hash can have a different winning outcome.
func (*RedeemerDB) Bind ¶
func (s *RedeemerDB) Bind(ctx context.Context, b Binding, limits Limits, chain NonceReader) error
Bind prevents retained tickets from being reinterpreted on another deployment. An unbound Node database is adopted only by the orchestrator and only after checking every retained signed transaction's chain identity.
func (*RedeemerDB) CapacityAvailable ¶
CapacityAvailable reports admission backpressure without evicting retained work.
func (*RedeemerDB) CheckStorage ¶
func (s *RedeemerDB) CheckStorage(ctx context.Context) error
A rolled-back empty write validates the payment table and SQLite's ability to enter a write transaction, without changing payment or redemption state.
func (*RedeemerDB) Close ¶
func (s *RedeemerDB) Close() error
func (*RedeemerDB) CollectMetrics ¶
func (s *RedeemerDB) CollectMetrics(emit observability.Emit)
collectMetrics uses a read transaction so tickets and replacement identities describe one durable snapshot. The caller never probes the chain.
func (*RedeemerDB) Configure ¶
func (s *RedeemerDB) Configure(logger *slog.Logger, metrics *observability.Metrics, snapshot func() (eth.ChainSnapshot, bool))
Configure installs observation hooks before starting workers.
func (*RedeemerDB) RecordPrepared ¶
func (s *RedeemerDB) RecordPrepared(ctx context.Context, ticket *pm.SignedTicket, prepared eth.SignedTransaction) error
func (*RedeemerDB) Redemptions ¶
func (s *RedeemerDB) Redemptions() ([]RedemptionStatus, error)
func (*RedeemerDB) SavedNonceFloor ¶
func (s *RedeemerDB) SavedNonceFloor(ctx context.Context, address ethcommon.Address) (uint64, error)
SavedNonceFloor restores only acknowledged sends, following upstream backend's Update-after-send rule. A rejected/prepared identity must not create a gap.
func (*RedeemerDB) SelectEarliestWinningTicket ¶
func (s *RedeemerDB) SelectEarliestWinningTicket(payer ethcommon.Address, minCreationRound int64) (*pm.SignedTicket, error)
func (*RedeemerDB) StoreWinningTicket ¶
func (s *RedeemerDB) StoreWinningTicket(t *pm.SignedTicket) error
func (*RedeemerDB) StoreWinningTickets ¶
func (s *RedeemerDB) StoreWinningTickets(ctx context.Context, payer ethcommon.Address, randHash ethcommon.Hash, collateral *big.Int, tickets []*pm.SignedTicket, snapshot pm.ChainSnapshot) error
StoreWinningTickets commits a validated receipt batch before the payment engine publishes replay guards or credit. Check exposure and liability in the same transaction so redemption and concurrent receipts cannot race these gates.
func (*RedeemerDB) SubmittedRedemptions ¶
func (s *RedeemerDB) SubmittedRedemptions() ([]SubmittedRedemption, error)
func (*RedeemerDB) WinningTicketCount ¶
func (s *RedeemerDB) WinningTicketCount(payer ethcommon.Address) (int, error)
type RedemptionOptions ¶
type RedemptionStatus ¶
type RedemptionStatus struct {
Hash string `json:"hash,omitempty"`
Phase string `json:"phase"`
Error string `json:"error,omitempty"`
}
RedemptionStatus excludes recipient randomness, signatures and signed bytes.
type SubmittedRedemption ¶
type TicketJSON ¶
type TicketJSON struct {
Payer common.Address `json:"payer_address"`
Recipient common.Address `json:"recipient"`
FaceValue string `json:"face_value"`
WinProb string `json:"win_prob"`
Nonce uint32 `json:"ticket_nonce"`
RandHash common.Hash `json:"recipient_rand_hash"`
CreationRound string `json:"creation_round"`
RoundHash common.Hash `json:"creation_round_block_hash"`
Expiration string `json:"params_expiration_block"`
Signature hexutil.Bytes `json:"sig"`
Randomness string `json:"recipient_rand"`
}
func (TicketJSON) SignedTicket ¶
func (j TicketJSON) SignedTicket() (*pm.SignedTicket, error)
type TicketRequest ¶
type TicketRequest struct {
ChainID string `json:"chain_id"`
Controller common.Address `json:"controller"`
Ticket TicketJSON `json:"ticket"`
}
type TicketResponse ¶
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
func NewWorker ¶
func NewWorker(s *RedeemerDB, c eth.PaymentChain, d Destination) (*Worker, error)