Documentation ¶
Index ¶
- Constants
- Variables
- func MustRandInt16() int16
- func MustRandInt32() int32
- func MustRandInt64() int64
- func MustRandUInt16() uint16
- func MustRandUint64() uint64
- func NewRandInt16() (int16, error)
- func NewRandInt32() (int32, error)
- func NewRandInt64() (int64, error)
- func NewRandUInt16() (uint16, error)
- func NewRandUint64() (uint64, error)
- func OriginalSrcFromCtx(ctx context.Context) string
- func WithOriginalSrc(parent context.Context, src string) context.Context
- type Config
- type InsecurePoolAddressesValidator
- type Matcher
- func (matcher *Matcher) AddParticipant(ctx context.Context, maxAmount uint64, sessionName string, ...) (*SessionParticipant, error)
- func (matcher *Matcher) FundSplit(ctx context.Context, sessionID ParticipantID, inputScriptSigs [][]byte, ...) ([]byte, []splitticket.SecretNumber, error)
- func (matcher *Matcher) FundTicket(ctx context.Context, sessionID ParticipantID, inputsScriptSig [][]byte, ...) ([][]byte, [][]byte, error)
- func (matcher *Matcher) Run(serverCtx context.Context) error
- func (matcher *Matcher) SetParticipantsOutputs(ctx context.Context, sessionID ParticipantID, ...) (*wire.MsgTx, *wire.MsgTx, []*ParticipantTicketOutput, uint32, error)
- func (matcher *Matcher) WatchWaitingList(ctx context.Context, watcher chan []WaitingQueue, sendCurrentQueues bool)
- type NetworkProvider
- type ParticipantID
- type ParticipantTicketOutput
- type PoolAddressValidationProvider
- type Session
- func (sess *Session) AllOutputsFilled() bool
- func (sess *Session) CreateTransactions() (*wire.MsgTx, *wire.MsgTx, error)
- func (sess *Session) CreateVoterTransactions() (*wire.MsgTx, *wire.MsgTx, *wire.MsgTx, error)
- func (sess *Session) FindVoterCoinIndex() (dcrutil.Amount, int)
- func (sess *Session) ParticipantAmounts() []dcrutil.Amount
- func (sess *Session) ParticipantTicketOutputs() []*ParticipantTicketOutput
- func (sess *Session) SaveSession(sessionDir string) error
- func (sess *Session) SecretNumberHashes() []splitticket.SecretNumberHash
- func (sess *Session) SecretNumbers() []splitticket.SecretNumber
- func (sess *Session) SplitTxIsFunded() bool
- func (sess *Session) SplitUtxoMap() (splitticket.UtxoMap, error)
- func (sess *Session) TicketIsFunded() bool
- func (sess *Session) VoteAddresses() []dcrutil.Address
- type SessionID
- type SessionParticipant
- type SessionStage
- type SignPoolSplitOutputProvider
- type VoteAddressValidationProvider
- type WaitingQueue
Constants ¶
const (
// MaximumExpiry accepted for split and ticket transactions
MaximumExpiry = 16
)
Variables ¶
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 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 MustRandUint64 ¶
func MustRandUint64() uint64
MustRandUint64 returns a new random uint64 or panics
func NewRandInt16 ¶
NewRandInt16 generates a new int16 or returns an error in case of entropy exhaustion
func NewRandInt32 ¶
NewRandInt32 generates a new random int32 number or an error in case of entropy exhaustion
func NewRandInt64 ¶ added in v0.6.0
NewRandInt64 returns a new int64 or an error
func NewRandUInt16 ¶
NewRandUInt16 generates a new uint16 or returns an error in case of entropy exhaustion
func NewRandUint64 ¶
NewRandUint64 returns a new uint64 or an error
func OriginalSrcFromCtx ¶ added in v0.6.0
OriginalSrcFromCtx extracts the original source from a context variable
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 ¶
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) 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 ¶
AllOutputsFilled returns true if all commitment and change outputs for all participants have been filled
func (*Session) CreateTransactions ¶
CreateTransactions creates the ticket and split tx transactions with all the currently available information
func (*Session) CreateVoterTransactions ¶ added in v0.4.6
CreateVoterTransactions creates the transactions (including the revocation) once the voter is known to the session.
func (*Session) FindVoterCoinIndex ¶ added in v0.5.1
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
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
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 ¶
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 ¶
TicketIsFunded returns true if all ticket inputs have been filled.
func (*Session) VoteAddresses ¶ added in v0.5.1
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
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
WaitingQueue returns information about participants waiting on a specific queue