matcher

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2019 License: ISC Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaximumExpiry accepted for split and ticket transactions
	MaximumExpiry = 16
)

Variables

View Source
var (
	// EmptySStxChangeAddr is a pre-calculated pkscript for use in SStx change
	// outputs that pays to a zeroed address. This is usually used in change
	// addresses that have zero value.
	EmptySStxChangeAddr = []byte{
		0xbd, 0x76, 0xa9, 0x14, 0x0, 0x0, 0x0, 0x0, 0x0,
		0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
		0x0, 0x0, 0x0, 0x0, 0x0, 0x88, 0xac}

	// ErrSessionExpired is the error triggered when the session has expired the
	// maximum allowed elapsed time.
	ErrSessionExpired = errors.New("session expired")
)

Functions

func MustRandInt16

func MustRandInt16() int16

MustRandInt16 generates a new int16 or panics.

func MustRandInt32

func MustRandInt32() int32

MustRandInt32 generates a new int32 number or panics.

func MustRandInt64 added in v0.6.0

func MustRandInt64() int64

MustRandInt64 returns a new random int64 or panics

func MustRandUInt16

func MustRandUInt16() uint16

MustRandUInt16 generates a new uint16 or panics.

func MustRandUint64

func MustRandUint64() uint64

MustRandUint64 returns a new random uint64 or panics

func NewRandInt16

func NewRandInt16() (int16, error)

NewRandInt16 generates a new int16 or returns an error in case of entropy exhaustion

func NewRandInt32

func NewRandInt32() (int32, error)

NewRandInt32 generates a new random int32 number or an error in case of entropy exhaustion

func NewRandInt64 added in v0.6.0

func NewRandInt64() (int64, error)

NewRandInt64 returns a new int64 or an error

func NewRandUInt16

func NewRandUInt16() (uint16, error)

NewRandUInt16 generates a new uint16 or returns an error in case of entropy exhaustion

func NewRandUint64

func NewRandUint64() (uint64, error)

NewRandUint64 returns a new uint64 or an error

func OriginalSrcFromCtx added in v0.6.0

func OriginalSrcFromCtx(ctx context.Context) string

OriginalSrcFromCtx extracts the original source from a context variable

func WithOriginalSrc added in v0.6.0

func WithOriginalSrc(parent context.Context, src string) context.Context

WithOriginalSrc returns a new context usable within the matcher package that indicates the original source for a given matcher operation

Types

type Config

type Config struct {
	MinAmount                 uint64
	NetworkProvider           NetworkProvider
	SignPoolSplitOutProvider  SignPoolSplitOutputProvider
	VoteAddrValidator         VoteAddressValidationProvider
	PoolAddrValidator         PoolAddressValidationProvider
	Log                       slog.Logger
	SessionLog                slog.Logger
	ChainParams               *chaincfg.Params
	PoolFee                   float64
	MaxSessionDuration        time.Duration
	StakeDiffChangeStopWindow int32
	PublishTransactions       bool
	SessionDataDir            string

	// SuccessfulSesssionNtfn is a function run after a successful session is
	// completed. This is run as a goroutine.
	SuccessfulSesssionNtfn func(ticketHash chainhash.Hash)
}

Config stores the parameters for the matcher engine

type InsecurePoolAddressesValidator added in v0.5.0

type InsecurePoolAddressesValidator struct{}

InsecurePoolAddressesValidator is a validator for vote/pool addresses that always accepts the addresses, so it is insecure for production use.

func (InsecurePoolAddressesValidator) ValidatePoolSubsidyAddress added in v0.5.0

func (v InsecurePoolAddressesValidator) ValidatePoolSubsidyAddress(poolAddr dcrutil.Address) error

ValidatePoolSubsidyAddress fulfills the PoolAddressValidationProvider

func (InsecurePoolAddressesValidator) ValidateVoteAddress added in v0.5.0

func (v InsecurePoolAddressesValidator) ValidateVoteAddress(voteAddr dcrutil.Address) error

ValidateVoteAddress fulfills the VoteAddressValidationProvider interface

type Matcher

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

Matcher is the main engine for matching operations

func NewMatcher

func NewMatcher(cfg *Config) *Matcher

NewMatcher creates an instance of a new split ticket matcher. Call matcher.run() on a goroutine to start processing.

func (*Matcher) AddParticipant

func (matcher *Matcher) AddParticipant(ctx context.Context, maxAmount uint64,
	sessionName string, voteAddress, poolAddress dcrutil.Address) (*SessionParticipant, error)

AddParticipant is the public API for a matcher to add a new participant to a split ticket queue.

func (*Matcher) FundSplit

func (matcher *Matcher) FundSplit(ctx context.Context, sessionID ParticipantID,
	inputScriptSigs [][]byte, secretNb splitticket.SecretNumber, sessionToken []byte) ([]byte,
	[]splitticket.SecretNumber, error)

FundSplit is the public matcher API for participants to fund their respective split ticket inputs.

func (*Matcher) FundTicket

func (matcher *Matcher) FundTicket(ctx context.Context, sessionID ParticipantID,
	inputsScriptSig [][]byte, revocationScriptSig []byte, sessionToken []byte) ([][]byte, [][]byte, error)

FundTicket is the matcher public API to participants in a session to fund the ticket transaction.

func (*Matcher) Run

func (matcher *Matcher) Run(serverCtx context.Context) error

Run listens for all matcher messages and runs the matching engine.

func (*Matcher) SetParticipantsOutputs

func (matcher *Matcher) SetParticipantsOutputs(ctx context.Context,
	sessionID ParticipantID, commitAddress, splitTxAddress dcrutil.Address,
	splitTxChange *wire.TxOut, splitTxOutPoints []*wire.OutPoint,
	secretNbHash splitticket.SecretNumberHash, sessionToken []byte) (*wire.MsgTx,
	*wire.MsgTx, []*ParticipantTicketOutput, uint32, error)

SetParticipantsOutputs validates and sets the outputs of the given participant for the provided outputs, waits for all participants to provide their own outputs, then generates the ticket tx and returns the index of the input that should receive this participants funds

func (*Matcher) WatchWaitingList

func (matcher *Matcher) WatchWaitingList(ctx context.Context,
	watcher chan []WaitingQueue, sendCurrentQueues bool)

WatchWaitingList is the public matcher API for listeners of queue changes.

type NetworkProvider added in v0.4.6

type NetworkProvider interface {
	CurrentTicketPrice() uint64
	CurrentBlockHeight() uint32
	CurrentBlockHash() chainhash.Hash
	ConnectedToDecredNetwork() bool
	PublishTransactions([]*wire.MsgTx) error
	GetUtxos(outpoints []*wire.OutPoint) (splitticket.UtxoMap, error)
}

NetworkProvider is the interface for operations that the matcher service needs from the decred network. These operations might be provided by a connection to a full node or to an external api (such as dcrdata).

type ParticipantID

type ParticipantID uint32

ParticipantID is the unique ID of a participant of a session

func (ParticipantID) String

func (id ParticipantID) String() string

type ParticipantTicketOutput added in v0.4.6

type ParticipantTicketOutput struct {
	SecretHash   *splitticket.SecretNumberHash
	VotePkScript []byte
	PoolPkScript []byte
	Amount       dcrutil.Amount
}

ParticipantTicketOutput returns information about a particular participant's tickets.

type PoolAddressValidationProvider added in v0.5.0

type PoolAddressValidationProvider interface {
	ValidatePoolSubsidyAddress(poolAddr dcrutil.Address) error
}

PoolAddressValidationProvider is the interface for operations the matcher needs to validate if a given pool fee/pool subsidy address is valid. Implementation should return nil if the address is valid or an error otherwise.

type Session

type Session struct {
	ID              SessionID
	Participants    []*SessionParticipant
	TicketPrice     dcrutil.Amount
	MainchainHash   chainhash.Hash
	MainchainHeight uint32
	VoterIndex      int
	SelectedCoin    dcrutil.Amount
	PoolFee         dcrutil.Amount
	TicketFee       dcrutil.Amount
	ChainParams     *chaincfg.Params
	SplitTxPoolOut  *wire.TxOut
	TicketPoolIn    *wire.TxIn
	StartTime       time.Time
	Done            bool
	Canceled        bool
	TicketExpiry    uint32
	CurrentStage    SessionStage
	// contains filtered or unexported fields
}

Session is a particular ticket being built

func (*Session) AllOutputsFilled

func (sess *Session) AllOutputsFilled() bool

AllOutputsFilled returns true if all commitment and change outputs for all participants have been filled

func (*Session) CreateTransactions

func (sess *Session) CreateTransactions() (*wire.MsgTx, *wire.MsgTx, error)

CreateTransactions creates the ticket and split tx transactions with all the currently available information

func (*Session) CreateVoterTransactions added in v0.4.6

func (sess *Session) CreateVoterTransactions() (*wire.MsgTx, *wire.MsgTx, *wire.MsgTx, error)

CreateVoterTransactions creates the transactions (including the revocation) once the voter is known to the session.

func (*Session) FindVoterCoinIndex added in v0.5.1

func (sess *Session) FindVoterCoinIndex() (dcrutil.Amount, int)

FindVoterCoinIndex returns the coin and index of the voter for the current session. Assumes all secret numbers are known.

func (*Session) ParticipantAmounts added in v0.4.6

func (sess *Session) ParticipantAmounts() []dcrutil.Amount

ParticipantAmounts returns an array with the commitment amounts for each individual participant

func (*Session) ParticipantTicketOutputs added in v0.4.6

func (sess *Session) ParticipantTicketOutputs() []*ParticipantTicketOutput

ParticipantTicketOutputs returns an array with information on the outputs of of the ticket built for each voting participant. Only safe to be called after all participants have sent their outputs.

func (*Session) SaveSession added in v0.4.7

func (sess *Session) SaveSession(sessionDir string) error

SaveSession saves the session data as a text file in the given directory. The name of the file will be the ticket hash.

func (*Session) SecretNumberHashes added in v0.4.6

func (sess *Session) SecretNumberHashes() []splitticket.SecretNumberHash

SecretNumberHashes returns an array with the individual secret number hashes for all participants

func (*Session) SecretNumbers added in v0.4.6

func (sess *Session) SecretNumbers() []splitticket.SecretNumber

SecretNumbers returns a slice with the secret number of all participants

func (*Session) SplitTxIsFunded

func (sess *Session) SplitTxIsFunded() bool

SplitTxIsFunded returns true if the split tx is funded

func (*Session) SplitUtxoMap added in v0.4.6

func (sess *Session) SplitUtxoMap() (splitticket.UtxoMap, error)

SplitUtxoMap returns the full utxo map for the split transaction's inputs for every participant. Returns an error if the same utxo is used more than once across all participants.

func (*Session) TicketIsFunded

func (sess *Session) TicketIsFunded() bool

TicketIsFunded returns true if all ticket inputs have been filled.

func (*Session) VoteAddresses added in v0.5.1

func (sess *Session) VoteAddresses() []dcrutil.Address

VoteAddresses returns a slice with every participant's vote addresses in order.

type SessionID

type SessionID uint16

SessionID stores the unique id for an in-progress ticket buying session

func (SessionID) String

func (id SessionID) String() string

type SessionParticipant

type SessionParticipant struct {
	ID                ParticipantID
	CommitAmount      dcrutil.Amount
	Fee               dcrutil.Amount
	PoolFee           dcrutil.Amount
	VoteAddress       dcrutil.Address
	PoolAddress       dcrutil.Address
	CommitmentAddress dcrutil.Address
	SplitTxAddress    dcrutil.Address
	SecretHash        splitticket.SecretNumberHash
	SecretNb          splitticket.SecretNumber
	SessionToken      []byte
	CurrentStage      SessionStage

	Session *Session
	Index   int
	// contains filtered or unexported fields
}

SessionParticipant is a participant of a split in a given session

type SessionStage added in v0.7.0

type SessionStage int

SessionStage is the stage of a given session

const (
	StageUnknown SessionStage = iota
	StageWaitingOutputs
	StageWaitingTicketFunds
	StageWaitingSplitFunds
	StageDone
)

The below constants are for the possible stages a session can be in.

func (SessionStage) String added in v0.7.0

func (ss SessionStage) String() string

String returns the string representation of the session stage

type SignPoolSplitOutputProvider

type SignPoolSplitOutputProvider interface {
	PoolFeeAddress() dcrutil.Address
	SignPoolSplitOutput(split, ticket *wire.MsgTx) ([]byte, error)
}

SignPoolSplitOutputProvider is the interface for the poerations the matcher needs for generating and signing the pool fee address input of tickets.

type VoteAddressValidationProvider added in v0.5.0

type VoteAddressValidationProvider interface {
	ValidateVoteAddress(voteAddr dcrutil.Address) error
}

VoteAddressValidationProvider is the interface for operations the matcher needs to validate if a given vote address is valid. Implementations should return nil if the address is valid or an error otherwise.

type WaitingQueue added in v0.4.6

type WaitingQueue struct {
	Name    string
	Amounts []dcrutil.Amount
}

WaitingQueue returns information about participants waiting on a specific queue

Jump to

Keyboard shortcuts

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