pm

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 9 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.

Documentation

Overview

Adapted from livepeer/go-livepeer/pm/sigverifier.go and crypto/verify.go, originally by Yondon Fu and Elad Mallel; Michael Ira Krufky moved VerifySig to crypto. The 27/28 recovery convention follows Yondon Fu's upstream commit 3b52399fc7b9177460864207a68eb9f3d2f4ee57.

Ticket types and encodings are adapted from livepeer/go-livepeer/pm/ticket.go at bd645a09266833fb859053445d9ac85846330756, by Yondon Fu, Elad Mallel, and Nico Vergauwen. The original source commits are retained in Git history.

Retained store interfaces from livepeer/go-livepeer/pm/ticketstore.go, by Yondon Fu, Nico Vergauwen, and Rafał Leszko. Source history is retained.

Ticket validation is adapted from livepeer/go-livepeer/pm/validator.go, originally by Yondon Fu. The original source commits are retained in Git history.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTickets        = errors.New("no tickets needed")
	ErrRefreshRequired  = errors.New("refresh session for remote signer")
	ErrPayerUnavailable = errors.New("payer funds unavailable")
)

Functions

func ConvertRunnerPrice

func ConvertRunnerPrice(priceUSD, unit string, weiPerUSD *big.Rat) (*big.Int, string, error)

ConvertRunnerPrice converts a runner's USD quote to whole wei per second or per fixed job. The exchange rate is supplied explicitly by the operator. Rounding upward avoids advertising a zero-wei charge for a positive quote. Unit conversion follows Josh Allmann's go-livepeer/ai/runner/live_runner.go: 5c8d3df277e38b403be5d3ca06cf27bf88ced224 and 2183b6755be5989d3041a5c1c9bf981997c51f91.

func RemoteBatchSize

func RemoteBatchSize(params TicketParams, fee, balance *big.Rat) (int, error)

RemoteBatchSize retains the legacy minimum-credit floor of one ticket EV. The fee is still debited from the balance after the tickets are created. Adapted from Yondon Fu's go-livepeer/server/segment_rpc.go newBalanceUpdate (5e31f8db3c1d06b40a344927c1cddfc33585c7f7) and core/accounting.go StageUpdate (85bdacc93774bf0a61887623802f79e0cfd1f85e).

func ValidatePayerFunds

func ValidatePayerFunds(info PayerFunds) error

Types

type ChainSnapshot

type ChainSnapshot = eth.ChainSnapshot

type DefaultSigVerifier

type DefaultSigVerifier struct{}

func (DefaultSigVerifier) Verify

func (DefaultSigVerifier) Verify(addr ethcommon.Address, msg, sig []byte) bool

type EthereumChain

type EthereumChain struct{ Client eth.PaymentChain }

EthereumChain adapts retained Ethereum contract reads to the payment engine's interface. Contract ABI and RPC logic remain in eth.

func (EthereumChain) IsActiveAt

func (c EthereumChain) IsActiveAt(ctx context.Context, recipient ethcommon.Address, snapshot ChainSnapshot) (bool, error)

func (EthereumChain) PayerFunds

func (c EthereumChain) PayerFunds(ctx context.Context, payer, recipient ethcommon.Address) (PayerFunds, error)

func (EthereumChain) Snapshot

func (c EthereumChain) Snapshot(ctx context.Context) (ChainSnapshot, error)

type PayerChain

type PayerChain interface {
	PayerFunds(context.Context, ethcommon.Address, ethcommon.Address) (PayerFunds, error)
}

PayerChain contains the payer collateral observation used by both payment sides.

type PayerFunds

type PayerFunds = eth.SenderInfo

type PayerPolicy

type PayerPolicy struct {
	MaxTicketEV, MaxBatchEV *big.Rat
	DepositMultiplier       int64
}

PayerPolicy limits actual ticket exposure, independently of the work price. Adapted from go-livepeer/pm/sender.go's validation by Yondon Fu and Nico Vergauwen, including Rafał Leszko's batch EV limit (366c2d68b39143f7b805c1aa98a0da069104134e).

func DefaultPayerPolicy

func DefaultPayerPolicy() PayerPolicy

func (PayerPolicy) Check

func (p PayerPolicy) Check(params TicketParams, count int, funds PayerFunds) error

func (PayerPolicy) Validate

func (p PayerPolicy) Validate() error

type PaymentChain

type PaymentChain interface {
	Snapshot(context.Context) (ChainSnapshot, error)
	IsActiveAt(context.Context, ethcommon.Address, ChainSnapshot) (bool, error)
	PayerChain
}

PaymentChain contains only the Ethereum reads needed by payment receipt.

type SigVerifier

type SigVerifier interface {
	Verify(addr ethcommon.Address, msg, sig []byte) bool
}

SigVerifier verifies Ethereum signed-message signatures for ticket payers.

type SignedTicket

type SignedTicket struct {
	// Ticket contains ticket fields that are directly
	// accessible on SignedTicket since it is embedded
	*Ticket

	// Sig is the payer's signature over the ticket
	Sig []byte

	// RecipientRand is the recipient's random value that should be
	// the preimage for the ticket's recipientRandHash
	RecipientRand *big.Int
}

SignedTicket is a wrapper around a Ticket with the payer's signature over the ticket and the recipient recipientRand

type Ticket

type Ticket struct {
	// Recipient is the ETH address of recipient
	Recipient ethcommon.Address

	// PayerAddress identifies the account that signs the ticket and funds its payment.
	PayerAddress ethcommon.Address

	// FaceValue represents the pay out to
	// the recipient if the ticket wins
	FaceValue *big.Int

	// WinProb represents how likely a ticket will win
	WinProb *big.Int

	// TicketNonce is the monotonically increasing counter that makes
	// each ticket unique given a particular recipientRand value
	TicketNonce uint32

	// RecipientRandHash is the 32 byte keccak-256 hash commitment to a random number
	// provided by the recipient. In order for the recipient to redeem
	// a winning ticket, it must reveal the preimage to this hash
	RecipientRandHash ethcommon.Hash

	// CreationRound is the round during which the ticket is created
	CreationRound int64

	// CreationRoundBlockHash is the block hash associated with CreationRound
	CreationRoundBlockHash ethcommon.Hash

	// ParamsExpirationBlock is the block number at which the ticket parameters used
	// to create the ticket will no longer be valid
	ParamsExpirationBlock *big.Int
}

Ticket is lottery ticket payment in a probabilistic micropayment protocol The expected value of the ticket constitutes the payment and can be calculated using the ticket's face value and winning probability

func NewTicket

func NewTicket(params *TicketParams, expirationParams *TicketExpirationParams, payer ethcommon.Address, ticketNonce uint32) *Ticket

NewTicket creates a Ticket instance

func (*Ticket) AuxData

func (t *Ticket) AuxData() []byte

AuxData returns the ticket's CreationRound and CreationRoundBlockHash encoded into a byte array: [0:31] = CreationRound (left padded with zero bytes) [32..63] = CreationRoundBlockHash See: https://github.com/livepeer/protocol/blob/pm/contracts/pm/mixins/MixinTicketProcessor.sol#L94

func (*Ticket) EV

func (t *Ticket) EV() *big.Rat

EV returns the expected value of a ticket

func (*Ticket) Hash

func (t *Ticket) Hash() ethcommon.Hash

Hash returns the keccak-256 hash of the ticket's fields as tightly packed arguments as described in the Solidity documentation See: https://solidity.readthedocs.io/en/v0.4.25/units-and-global-variables.html#mathematical-and-cryptographic-functions

func (*Ticket) WinProbRat

func (t *Ticket) WinProbRat() *big.Rat

WinProbRat returns the ticket WinProb as a percentage represented as a big.Rat

type TicketBatch

type TicketBatch struct {
	*TicketParams
	*TicketExpirationParams

	PayerAddress ethcommon.Address

	PayerParams []*TicketPayerParams
}

TicketBatch is a group of tickets that share the same TicketParams, TicketExpirationParams and PayerAddress Each ticket in a batch is identified by a unique TicketPayerParams

func DraftRemoteBatch

func DraftRemoteBatch(params TicketParams, payer ethcommon.Address, firstNonce uint32, fee, balance *big.Rat) (*TicketBatch, *big.Rat, error)

DraftRemoteBatch constructs unsigned tickets for the billable fee and carries forward unused expected value. The caller must keep params unchanged until signing. Ticket construction follows Yondon Fu's go-livepeer/pm/sender.go CreateTicketBatch (a5ffbb1d31fba67077d5564c1b5161ba900e0be6), used by Josh Allmann's remote signer in server/remote_signer.go (f117b4423f8614c7475f0bb0c5071433c7037b87).

func (*TicketBatch) Tickets

func (b *TicketBatch) Tickets() []*Ticket

Tickets returns the tickets in the batch

type TicketExpirationParams

type TicketExpirationParams struct {
	CreationRound int64

	CreationRoundBlockHash ethcommon.Hash
}

TicketExpirationParams indicates when/how a ticket expires

func (*TicketExpirationParams) AuxData

func (e *TicketExpirationParams) AuxData() []byte

type TicketParams

type TicketParams struct {
	Recipient ethcommon.Address

	FaceValue *big.Int

	WinProb *big.Int

	RecipientRandHash ethcommon.Hash

	Seed *big.Int

	ExpirationBlock *big.Int

	ExpirationParams *TicketExpirationParams
}

TicketParams represents the parameters defined by a receiver that a payer must adhere to when sending tickets to receiver.

func (*TicketParams) WinProbRat

func (p *TicketParams) WinProbRat() *big.Rat

WinProbRat returns the ticket WinProb as a percentage represented as a big.Rat

type TicketPayerParams

type TicketPayerParams struct {
	TicketNonce uint32

	Sig []byte
}

TicketPayerParams contains a ticket nonce and the payer's signature over its hash.

type TicketSigner

type TicketSigner interface {
	Address() ethcommon.Address
	SignMessage([]byte) ([]byte, error)
}

type TicketStore

type TicketStore interface {
	// SelectEarliestWinningTicket selects the earliest stored winning ticket for a 'payer'
	// which is not yet redeemed
	SelectEarliestWinningTicket(payer ethcommon.Address, minCreationRound int64) (*SignedTicket, error)

	// RemoveWinningTicket removes a ticket
	RemoveWinningTicket(ticket *SignedTicket) error

	// StoreWinningTicket stores a signed ticket
	StoreWinningTicket(ticket *SignedTicket) error

	// WinningTicketCount returns the amount of non-redeemed winning tickets for a payer in the TicketStore
	WinningTicketCount(payer ethcommon.Address, minCreationRound int64) (int, error)
}

TicketStore is an interface which describes an object capable of persisting tickets

type Validator

type Validator interface {
	// ValidateTicket checks if a ticket is valid
	ValidateTicket(recipient ethcommon.Address, ticket *Ticket, sig []byte, recipientRand *big.Int) error

	// IsWinningTicket checks if a ticket won
	// Note: This method does not check if a ticket is valid which is done using ValidateTicket
	IsWinningTicket(ticket *Ticket, sig []byte, recipientRand *big.Int) bool
}

Validator is an interface which describes an object capable of validating tickets

func NewValidator

func NewValidator(sigVerifier SigVerifier) Validator

NewValidator returns an instance of a validator

Directories

Path Synopsis
Package wire preserves the retained fields and field numbers of the legacy unversioned remote-signer Protobuf envelopes.
Package wire preserves the retained fields and field numbers of the legacy unversioned remote-signer Protobuf envelopes.

Jump to

Keyboard shortcuts

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