redemption

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 34 Imported by: 1 module, 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.

README

Redemption source history

The shared queue preserves Node's ticket and transaction records. Its upstream source is pinned to go-livepeer afaaa36e743d39e6f460e7993d516d52b3a81341.

The scoped source history is retained as an additional parent using the pattern from Node PR #40. It preserves original authors, committers, dates, and messages, with Original-Commit and Source-Scope trailers. The filtered ancestry contains 37 effective changes; its tip is ff9c88a9354ec0b0333b1e685ba4389c43b16415.

Upstream source Treatment
pm/queue.go, pm/queue_test.go Queue history retained; adapted to bounded durable scheduling
pm/sendermonitor.go History scoped to redeemWinningTicket; reused redemption and face-value/cost policy
pm/sendermonitor_test.go Winning-ticket redemption tests retained, excluding max-float mutation tests
server/redeemer.go History scoped to both QueueTicket methods and ticket conversion; HTTP adaptation attributed in source
server/redeemer_test.go QueueTicket and conversion test history retained
net/redeemer.proto and generated gRPC bindings Excluded; Node uses HTTP
Max-float calculation, subscriptions, and client balance cache Excluded
doc/redeemer.md Operating guide rewritten for Node

Earlier source attributions in Node remain valid. In particular, the existing queue/recovery port cites 0ff08af1, ticket types cite bd645a09, and SQLite operations cite 404d24a9. Retaining the new scoped ancestry does not replace those notices. The original MIT notice is in LICENSE.

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

View Source
const MaxTicketBody = 16 << 10

Variables

View Source
var DefaultLimits = Limits{Pending: 100000, PerRecipient: 10000}
View Source
var ErrCapacity = errors.New("winning-ticket queue capacity exhausted")
View Source
var ErrConflict = errors.New("ticket scheduling metadata conflicts with stored ticket")
View Source
var ErrExposedRandomness = errors.New("ticket randomness is already exposed")
View Source
var MigrationFiles embed.FS

Functions

func Command

func Command(component, defaultDB string) *cobra.Command

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 OpenDatabase(ctx context.Context, path string, create bool) (*sql.DB, error)

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

func RedeemerURL(u *url.URL) (*url.URL, error)

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 Binding

type Binding struct {
	ChainID           string
	Controller        common.Address
	Role, Destination string
}

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 Limits

type Limits struct{ Pending, PerRecipient int }

type NonceReader

type NonceReader interface {
	FinalizedNonce(context.Context, common.Address) (uint64, error)
}

type ReceiptReader

type ReceiptReader interface {
	FinalizedReceipt(context.Context, common.Hash) (*types.Receipt, error)
}

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) Binding

func (s *RedeemerDB) Binding(ctx context.Context) (Binding, error)

func (*RedeemerDB) CapacityAvailable

func (s *RedeemerDB) CapacityAvailable(ctx context.Context, recipient common.Address) (bool, error)

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 RedemptionOptions struct {
	Timeout         time.Duration
	MaxReplacements int
}

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 Rejection

type Rejection struct{ Status int }

func (*Rejection) Error

func (e *Rejection) Error() string

type SubmittedRedemption

type SubmittedRedemption struct {
	Signature []byte
	Hash      ethcommon.Hash
}

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 TicketResponse struct {
	Hash common.Hash `json:"ticket_hash"`
}

type Worker

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

func NewWorker

func NewWorker(s *RedeemerDB, c eth.PaymentChain, d Destination) (*Worker, error)

func (*Worker) Process

func (w *Worker) Process(ctx context.Context) []error

Process performs a bounded, rotating pass. Inclusion recovery belongs to the daemon lifetime; a slow payer cannot monopolize the next pass's starting point.

Jump to

Keyboard shortcuts

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