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 ¶
- Variables
- func ConvertRunnerPrice(priceUSD, unit string, weiPerUSD *big.Rat) (*big.Int, string, error)
- func RemoteBatchSize(params TicketParams, fee, balance *big.Rat) (int, error)
- func ValidatePayerFunds(info PayerFunds) error
- type ChainSnapshot
- type DefaultSigVerifier
- type EthereumChain
- func (c EthereumChain) IsActiveAt(ctx context.Context, recipient ethcommon.Address, snapshot ChainSnapshot) (bool, error)
- func (c EthereumChain) PayerFunds(ctx context.Context, payer, recipient ethcommon.Address) (PayerFunds, error)
- func (c EthereumChain) Snapshot(ctx context.Context) (ChainSnapshot, error)
- type PayerChain
- type PayerFunds
- type PayerPolicy
- type PaymentChain
- type SigVerifier
- type SignedTicket
- type Ticket
- type TicketBatch
- type TicketExpirationParams
- type TicketParams
- type TicketPayerParams
- type TicketSigner
- type TicketStore
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoTickets = errors.New("no tickets needed") ErrRefreshRequired = errors.New("refresh session for remote signer") )
Functions ¶
func ConvertRunnerPrice ¶
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{}
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 ¶
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 ¶
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 ¶
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) 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 ¶
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 ¶
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 ¶
TicketPayerParams contains a ticket nonce and the payer's signature over its hash.
type TicketSigner ¶
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