stake

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2016 License: ISC Imports: 20 Imported by: 0

Documentation

Overview

Package stake contains code for all of dcrd's stake transaction chain handling and other portions related to the Proof-of-Stake (PoS) system.

At the heart of the PoS system are tickets, votes and revocations. These 3 pieces work together to determine if previous blocks are valid and their txs should be confirmed.

Important Parts included in stake package:

- Processing SSTx (tickets), SSGen (votes), SSRtx (revocations) - TicketDB - Stake Reward calculation - Stake transaction identification (IsSStx, IsSSGen, IsSSRtx)

Index

Constants

View Source
const (
	// ErrSStxTooManyInputs indicates that a given SStx contains too many
	// inputs.
	ErrSStxTooManyInputs = iota

	// ErrSStxTooManyOutputs indicates that a given SStx contains too many
	// outputs.
	ErrSStxTooManyOutputs

	// ErrSStxNoOutputs indicates that a given SStx has no outputs.
	ErrSStxNoOutputs

	// ErrSStxInvalidInput indicates that an invalid output has been used as
	// an input for a SStx; only non-SStx tagged outputs may be used to
	// purchase stake tickets.
	// TODO: Add this into validate
	// Ensure that all inputs are not tagged SStx outputs of some sort,
	// along with checks to make sure they exist and are available.
	ErrSStxInvalidInputs

	// ErrSStxInvalidOutput indicates that the output for an SStx tx is
	// invalid; in particular, either the output was not tagged SStx or the
	// OP_RETURNs were missing or contained invalid addresses.
	ErrSStxInvalidOutputs

	// ErrSStxInOutProportions indicates the the number of inputs in an SStx
	// was not equal to the number of output minus one.
	ErrSStxInOutProportions

	// ErrSStxBadCommitAmount indicates that a ticket tried to commit 0 or
	// a negative value as the commitment amount.
	ErrSStxBadCommitAmount

	// ErrSStxBadChangeAmts indicates that the change amount for some SStx
	// was invalid, for instance spending more than its inputs.
	ErrSStxBadChangeAmts

	// ErrSStxVerifyCalcAmts indicates that passed calculated amounts failed
	// to conform to the amounts found in the ticket.
	ErrSStxVerifyCalcAmts

	// ErrSSGenWrongNumInputs indicates that a given SSGen tx contains an
	// invalid number of inputs.
	ErrSSGenWrongNumInputs

	// ErrSSGenTooManyOutputs indicates that a given SSGen tx contains too
	// many outputs.
	ErrSSGenTooManyOutputs

	// ErrSSGenNoOutputs indicates that a given SSGen has no outputs.
	ErrSSGenNoOutputs

	// ErrSSGenWrongIndex indicates that a given SSGen sstx input was not
	// using the correct index.
	ErrSSGenWrongIndex

	// ErrSSGenWrongTxTree indicates that a given SSGen tx input was not found in
	// the stake tx tree.
	ErrSSGenWrongTxTree

	// ErrSSGenNoStakebase indicates that the SSGen tx did not contain a
	// valid StakeBase in the zeroeth position of inputs.
	ErrSSGenNoStakebase

	// ErrSSGenNoReference indicates that there is no reference OP_RETURN
	// included as the first output.
	ErrSSGenNoReference

	// ErrSSGenNoReference indicates that the OP_RETURN included as the
	// first output was corrupted in some way.
	ErrSSGenBadReference

	// ErrSSGenNoVotePush indicates that there is no vote bits OP_RETURN
	// included as the second output.
	ErrSSGenNoVotePush

	// ErrSSGenBadVotePush indicates that the OP_RETURN included as the
	// second output was corrupted in some way.
	ErrSSGenBadVotePush

	// ErrSSGenBadGenOuts indicates that the something was wrong with the
	// stake generation outputs that were present after the first two
	// OP_RETURN pushes in an SSGen tx.
	ErrSSGenBadGenOuts

	// ErrSSRtxWrongNumInputs indicates that a given SSRtx contains an
	// invalid number of inputs.
	ErrSSRtxWrongNumInputs

	// ErrSSRtxTooManyOutputs indicates that a given SSRtx contains too many
	// outputs.
	ErrSSRtxTooManyOutputs

	// ErrSSRtxNoOutputs indicates that a given SSRtx has no outputs.
	ErrSSRtxNoOutputs

	// ErrSSRtxWrongTxTree indicates that a given SSRtx input was not found in
	// the stake tx tree.
	ErrSSRtxWrongTxTree

	// ErrSSRtxBadGenOuts indicates that there was a non-SSRtx tagged output
	// present in an SSRtx.
	ErrSSRtxBadOuts

	// ErrVerSStxAmts indicates there was an error verifying the calculated
	// SStx out amounts and the actual SStx out amounts.
	ErrVerSStxAmts

	// ErrVerifyInput indicates that there was an error in verification
	// function input.
	ErrVerifyInput

	// ErrVerifyOutType indicates that there was a non-equivalence in the
	// output type.
	ErrVerifyOutType

	// ErrVerifyTooMuchFees indicates that a transaction's output gave
	// too much in fees after taking into accounts the limits imposed
	// by the SStx output's version field.
	ErrVerifyTooMuchFees

	// ErrVerifySpendTooMuch indicates that a transaction's output spent more
	// than it was allowed to spend based on the calculated subsidy or return
	// for a vote or revocation.
	ErrVerifySpendTooMuch

	// ErrVerifyOutputAmt indicates that for a vote/revocation spend output,
	// the rule was given that it must exactly match the calculated maximum,
	// however the amount in the output did not (e.g. it gave fees).
	ErrVerifyOutputAmt

	// ErrVerifyOutPkhs indicates that the recipient of the P2PKH or P2SH
	// script was different from that indicated in the SStx input.
	ErrVerifyOutPkhs
)

These constants are used to identify a specific RuleError.

View Source
const (
	TxTypeRegular = iota
	TxTypeSStx
	TxTypeSSGen
	TxTypeSSRtx
)

Possible TxTypes

View Source
const (
	// MaxInputsPerSStx is the maximum number of inputs allowed in an SStx.
	MaxInputsPerSStx = 64

	// MaxOutputsPerSStx is the maximum number of outputs allowed in an SStx;
	// you need +1 for the tagged SStx output.
	MaxOutputsPerSStx = MaxInputsPerSStx*2 + 1

	// NumInputsPerSSGen is the exact number of inputs for an SSGen
	// (stakebase) tx. Inputs are a tagged SStx output and a stakebase (null)
	// input.
	NumInputsPerSSGen = 2 // SStx and stakebase

	// MaxOutputsPerSSGen is the maximum number of outputs in an SSGen tx,
	// which are all outputs to the addresses specified in the OP_RETURNs of
	// the original SStx referenced as input plus reference and vote
	// OP_RETURN outputs in the zeroeth and first position.
	MaxOutputsPerSSGen = MaxInputsPerSStx + 2

	// NumInputsPerSSRtx is the exact number of inputs for an SSRtx (stake
	// revocation tx); the only input should be the SStx output.
	NumInputsPerSSRtx = 1

	// MaxOutputsPerSSRtx is the maximum number of outputs in an SSRtx, which
	// are all outputs to the addresses specified in the OP_RETURNs of the
	// original SStx referenced as input plus a reference to the block header
	// hash of the block in which voting was missed.
	MaxOutputsPerSSRtx = MaxInputsPerSStx

	// SStxPKHMinOutSize is the minimum size of of an OP_RETURN commitment output
	// for an SStx tx.
	// 20 bytes P2SH/P2PKH + 8 byte amount + 4 byte fee range limits
	SStxPKHMinOutSize = 32

	// SStxPKHMaxOutSize is the maximum size of of an OP_RETURN commitment output
	// for an SStx tx.
	SStxPKHMaxOutSize = 77

	// SSGenBlockReferenceOutSize is the size of a block reference OP_RETURN
	// output for an SSGen tx.
	SSGenBlockReferenceOutSize = 38

	// SSGenVoteBitsOutputMinSize is the minimum size for a VoteBits push
	// in an SSGen.
	SSGenVoteBitsOutputMinSize = 4

	// SSGenVoteBitsOutputMaxSize is the maximum size for a VoteBits push
	// in an SSGen.
	SSGenVoteBitsOutputMaxSize = 77

	// MaxSingleBytePushLength is the largest maximum push for an
	// SStx commitment or VoteBits push.
	MaxSingleBytePushLength = 75

	// SStxVoteReturnFractionMask extracts the return fraction from a
	// commitment output version.
	// If after applying this mask &0x003f is given, the entire amount of
	// the output is allowed to be spent as fees if the flag to allow fees
	// is set.
	SStxVoteReturnFractionMask = 0x003f

	// SStxRevReturnFractionMask extracts the return fraction from a
	// commitment output version.
	// If after applying this mask &0x3f00 is given, the entire amount of
	// the output is allowed to be spent as fees if the flag to allow fees
	// is set.
	SStxRevReturnFractionMask = 0x3f00

	// SStxVoteFractionFlag is a bitflag mask specifying whether or not to
	// apply a fractional limit to the amount used for fees in a vote.
	// 00000000 00000000 = No fees allowed
	// 00000000 01000000 = Apply fees rule
	SStxVoteFractionFlag = 0x0040

	// SStxRevFractionFlag is a bitflag mask specifying whether or not to
	// apply a fractional limit to the amount used for fees in a vote.
	// 00000000 00000000 = No fees allowed
	// 01000000 00000000 = Apply fees rule
	SStxRevFractionFlag = 0x4000
)
View Source
const BucketsSize = math.MaxUint8 + 1

BucketsSize is the number of pre-sort buckets for the in memory database of live tickets. This allows an approximately 1.5x-2.5x increase in sorting speed and easier/more efficient handling of new block insertion and evaluation of reorgs. TODO Storing the size of the buckets somewhere would make evaluation of blocks being added to HEAD extremely fast and should eventually be implemented. For example, when finding the tickets to use you can cycle through a struct for each bucket where the struct stores the number of tickets in the bucket, so you can easily find the index of the ticket you need without creating a giant slice and sorting it. Optimizations for reorganize are possible.

Variables

This section is empty.

Functions

func AddrFromSStxPkScrCommitment added in v0.0.8

func AddrFromSStxPkScrCommitment(pkScript []byte,
	params *chaincfg.Params) (dcrutil.Address, error)

AddrFromSStxPkScrCommitment extracts a P2SH or P2PKH address from a ticket commitment pkScript.

func AmountFromSStxPkScrCommitment added in v0.1.0

func AmountFromSStxPkScrCommitment(pkScript []byte) (dcrutil.Amount, error)

AmountFromSStxPkScrCommitment extracts a commitment amount from a ticket commitment pkScript.

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func FindTicketIdxs

func FindTicketIdxs(size int64, n int, prng *Hash256PRNG) ([]int, error)

FindTicketIdxs finds n many unique index numbers for a list length size.

func GetSSGenBlockVotedOn

func GetSSGenBlockVotedOn(tx *dcrutil.Tx) (chainhash.Hash, uint32, error)

GetSSGenBlockVotedOn takes an SSGen tx and returns the block voted on in the first OP_RETURN by hash and height.

func GetSSGenStakeOutputInfo

func GetSSGenStakeOutputInfo(tx *dcrutil.Tx, params *chaincfg.Params) ([]bool,
	[][]byte, []int64, error)

GetSSGenStakeOutputInfo takes an SSGen tx as input and scans through its outputs, returning the amount of the output and the PKH or SH that it was sent to.

func GetSSGenVoteBits

func GetSSGenVoteBits(tx *dcrutil.Tx) uint16

GetSSGenVoteBits takes an SSGen tx as input and scans through its outputs, returning the VoteBits of the index 1 output.

func GetSSRtxStakeOutputInfo

func GetSSRtxStakeOutputInfo(tx *dcrutil.Tx, params *chaincfg.Params) ([]bool,
	[][]byte, []int64, error)

GetSSRtxStakeOutputInfo takes an SSRtx tx as input and scans through its outputs, returning the amount of the output and the pkh that it was sent to.

func GetSStxNullOutputAmounts

func GetSStxNullOutputAmounts(amounts []int64,
	changeAmounts []int64,
	amountTicket int64) (int64, []int64, error)

GetSStxNullOutputAmounts takes an array of input amounts, change amounts, and a ticket purchase amount, calculates the adjusted proportion from the purchase amount, stores it in an array, then returns the array. That is, for any given SStx, this function calculates the proportional outputs that any single user should receive. Returns: (1) Fees (2) Output Amounts (3) Error

func GetSStxStakeOutputInfo

func GetSStxStakeOutputInfo(tx *dcrutil.Tx) ([]bool, [][]byte, []int64, []int64,
	[][]bool, [][]uint16)

GetSStxStakeOutputInfo takes an SStx as input and scans through its outputs, returning the pubkeyhashs and amounts for any NullDataTy's (future commitments to stake generation rewards).

func GetStakeRewards

func GetStakeRewards(amounts []int64,
	amountTicket int64,
	subsidy int64) []int64

GetStakeRewards takes a list of SStx adjusted output amounts, the amount used to purchase that ticket, and the reward for an SSGen tx and subsequently generates what the outputs should be in the SSGen tx. If used for calculating the outputs for an SSRtx, pass 0 for subsidy.

func IsSSGen

func IsSSGen(tx *dcrutil.Tx) (bool, error)

IsSSGen returns whether or not a transaction is an SSGen tx. It does some simple validation steps to make sure the number of inputs, number of outputs, and the input/output scripts are valid.

This does NOT check to see if the subsidy is valid or whether or not the value of input[0] + subsidy = value of the outputs.

SSGen transactions are specified as below. Inputs: Stakebase null input [index 0] SStx-tagged output [index 1]

Outputs: OP_RETURN push of 40 bytes containing: [index 0]

i. 32-byte block header of block being voted on.
ii. 8-byte int of this block's height.

OP_RETURN push of 2 bytes containing votebits [index 1] SSGen-tagged output to address from SStx-tagged output's tx index output 1

[index 2]

SSGen-tagged output to address from SStx-tagged output's tx index output 2

[index 3]

... SSGen-tagged output to address from SStx-tagged output's tx index output

MaxInputsPerSStx [index MaxOutputsPerSSgen - 1]

The errors in this function can be ignored if you want to use it in to identify SSGen from a list of stake tx.

func IsSSRtx

func IsSSRtx(tx *dcrutil.Tx) (bool, error)

IsSSRtx returns whether or not a transaction is an SSRtx. It does some simple validation steps to make sure the number of inputs, number of outputs, and the input/output scripts are valid.

SSRtx transactions are specified as below. Inputs: SStx-tagged output [index 0]

Outputs: SSGen-tagged output to address from SStx-tagged output's tx index output 1

[index 0]

SSGen-tagged output to address from SStx-tagged output's tx index output 2

[index 1]

... SSGen-tagged output to address from SStx-tagged output's tx index output

MaxInputsPerSStx [index MaxOutputsPerSSRtx - 1]

The errors in this function can be ignored if you want to use it in to identify SSRtx from a list of stake tx.

func IsSStx

func IsSStx(tx *dcrutil.Tx) (bool, error)

IsSStx returns whether or not a transaction is an SStx. It does some simple validation steps to make sure the number of inputs, number of outputs, and the input/output scripts are valid.

SStx transactions are specified as below. Inputs: untagged output 1 [index 0] untagged output 2 [index 1] ... untagged output MaxInputsPerSStx [index MaxInputsPerSStx-1]

Outputs: OP_SSTX tagged output [index 0] OP_RETURN push of input 1's address for reward receiving [index 1] OP_SSTXCHANGE tagged output for input 1 [index 2] OP_RETURN push of input 2's address for reward receiving [index 3] OP_SSTXCHANGE tagged output for input 2 [index 4] ... OP_RETURN push of input MaxInputsPerSStx's address for reward receiving

[index (MaxInputsPerSStx*2)-2]

OP_SSTXCHANGE tagged output [index (MaxInputsPerSStx*2)-1]

The output OP_RETURN pushes should be of size 20 bytes (standard address).

The errors in this function can be ignored if you want to use it in to identify SStx from a list of stake tx.

func IsStakeBase

func IsStakeBase(tx *dcrutil.Tx) bool

IsStakeBase returns whether or not a tx could be considered as having a topically valid stake base present.

func SetLogWriter

func SetLogWriter(w io.Writer, level string) error

SetLogWriter uses a specified io.Writer to output package logging info. This allows a caller to direct package logging output without needing a dependency on seelog. If the caller is also using btclog, UseLogger should be used instead.

func SetTxTree

func SetTxTree(tx *dcrutil.Tx)

SetTxTree analyzes the embedded MsgTx and sets the transaction tree accordingly.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

func VerifySStxAmounts

func VerifySStxAmounts(sstxAmts []int64, sstxCalcAmts []int64) error

VerifySStxAmounts compares a list of calculated amounts for ticket commitments to the list of commitment amounts from the actual SStx.

func VerifyStakingPkhsAndAmounts

func VerifyStakingPkhsAndAmounts(
	sstxTypes []bool,
	sstxPkhs [][]byte,
	ssSpendAmts []int64,
	ssSpendTypes []bool,
	ssSpendPkhs [][]byte,
	ssSpendCalcAmts []int64,
	isVote bool,
	spendRules [][]bool,
	spendLimits [][]uint16) error

VerifyStakingPkhsAndAmounts takes the following:

  1. sstxTypes: A list of types for what the output should be (P2PK or P2SH).
  2. sstxPkhs: A list of payee PKHs from NullDataTy outputs of an input SStx.
  3. ssSpendAmts: What the payouts in an SSGen/SSRtx tx actually were.
  4. ssSpendTypes: A list of types for what the outputs actually were.
  5. ssSpendPkhs: A list of payee PKHs from OP_SSGEN tagged outputs of the SSGen or SSRtx.
  6. ssSpendCalcAmts: A list of payee amounts that was calculated based on the input SStx. These are the maximum possible amounts that can be transacted from this output.
  7. isVote: Whether this is a vote (true) or revocation (false).
  8. spendRules: Spending rules for each output in terms of fees allowable as extracted from the origin output Version.
  9. spendLimits: Spending limits for each output in terms of fees allowable as extracted from the origin output Version.

and determines if the two pairs of slices are congruent or not.

Types

type ErrorCode

type ErrorCode int

ErrorCode identifies a kind of error.

func (ErrorCode) String

func (e ErrorCode) String() string

String returns the ErrorCode as a human-readable name.

type Hash256PRNG

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

Hash256PRNG is a determinstic pseudorandom number generator that uses a 256-bit secure hashing function to generate random uint32s starting from an initial seed.

func NewHash256PRNG

func NewHash256PRNG(seed []byte) *Hash256PRNG

NewHash256PRNG creates a pointer to a newly created hash256PRNG.

func (*Hash256PRNG) Hash256Rand

func (hp *Hash256PRNG) Hash256Rand() uint32

Hash256Rand returns a uint32 random number using the pseudorandom number generator and updates the state.

func (*Hash256PRNG) StateHash

func (hp *Hash256PRNG) StateHash() chainhash.Hash

StateHash returns a hash referencing the current state the deterministic PRNG.

type RuleError added in v0.0.4

type RuleError struct {
	ErrorCode   ErrorCode // Describes the kind of error
	Description string    // Human readable description of the issue
}

RuleError identifies a rule violation. It is used to indicate that processing of a block or transaction failed due to one of the many validation rules. The caller can use type assertions to determine if a failure was specifically due to a rule violation and access the ErrorCode field to ascertain the specific reason for the rule violation.

func (RuleError) Error added in v0.0.4

func (e RuleError) Error() string

Error satisfies the error interface and prints human-readable errors.

func (RuleError) GetCode added in v0.0.4

func (e RuleError) GetCode() ErrorCode

GetCode satisfies the error interface and prints human-readable errors.

type SStxMemMap

type SStxMemMap map[chainhash.Hash]*TicketData

SStxMemMap is a memory map of SStx keyed to the txHash.

type TicketDB

type TicketDB struct {
	StakeEnabledHeight int64
	// contains filtered or unexported fields
}

TicketDB is the ticket in-memory database.

func (*TicketDB) CheckLiveTicket

func (tmdb *TicketDB) CheckLiveTicket(txHash chainhash.Hash) (bool, error)

CheckLiveTicket checks for the existence of a live ticket in ticketMap.

This function is safe for concurrent access.

func (*TicketDB) CheckMissedTicket

func (tmdb *TicketDB) CheckMissedTicket(txHash chainhash.Hash) bool

CheckMissedTicket checks for the existence of a missed ticket in the missed ticket map. Assumes missedTicketMap is initialized.

This function is safe for concurrent access.

func (*TicketDB) CheckRevokedTicket

func (tmdb *TicketDB) CheckRevokedTicket(txHash chainhash.Hash) bool

CheckRevokedTicket checks for the existence of a revoked ticket in the revoked ticket map. Assumes missedTicketMap is initialized.

This function is safe for concurrent access.

func (*TicketDB) Close

func (tmdb *TicketDB) Close()

Close deletes a TicketDB and its contents. Intended to be called only when store() has first been called. Decred: In the daemon this is never called because it causes some problems with storage. As everything is a native Go structure in the first place, we don't really need this as far as I can tell, but I'll leave this in here in case a usage is found.

This function is safe for concurrent access.

func (*TicketDB) DumpAllLiveTicketHashes added in v0.0.8

func (tmdb *TicketDB) DumpAllLiveTicketHashes() ([]*chainhash.Hash, error)

DumpAllLiveTicketHashes duplicates the contents of a ticket bucket from the databases's ticketMap and returns them to the user.

This function is safe for concurrent access.

func (*TicketDB) DumpLiveTickets

func (tmdb *TicketDB) DumpLiveTickets(bucket uint8) (SStxMemMap, error)

DumpLiveTickets duplicates the contents of a ticket bucket from the databases's ticketMap and returns them to the user.

This function is safe for concurrent access.

func (*TicketDB) DumpMapsPointer

func (tmdb *TicketDB) DumpMapsPointer() TicketMaps

DumpMapsPointer is a testing function that returns a pointer to the internally held maps. Used for testing.

This function is safe for concurrent access.

func (*TicketDB) DumpMissedTickets

func (tmdb *TicketDB) DumpMissedTickets() (SStxMemMap, error)

DumpMissedTickets duplicates the contents of a ticket bucket from the databases's missedTicketMap and returns them to the user.

This function is safe for concurrent access.

func (*TicketDB) DumpRevokedTickets

func (tmdb *TicketDB) DumpRevokedTickets() (SStxMemMap, error)

DumpRevokedTickets duplicates the contents of a ticket bucket from the databases's missedTicketMap and returns them to the user.

This function is safe for concurrent access.

func (*TicketDB) DumpSpentTickets

func (tmdb *TicketDB) DumpSpentTickets(height int64) (SStxMemMap, error)

DumpSpentTickets duplicates the contents of a ticket bucket from the databases's spentTicketMap and returns them to the user.

This function is safe for concurrent access.

func (*TicketDB) GetLiveTicketBucketData

func (tmdb *TicketDB) GetLiveTicketBucketData() map[int]int

GetLiveTicketBucketData creates a map of [int]int indicating the number of tickets in each bucket. Used for an RPC call.

func (*TicketDB) GetLiveTicketsForAddress

func (tmdb *TicketDB) GetLiveTicketsForAddress(
	address dcrutil.Address) ([]chainhash.Hash, error)

GetLiveTicketsForAddress gets all currently active tickets for a given address.

func (*TicketDB) GetLiveTicketsInBucketData

func (tmdb *TicketDB) GetLiveTicketsInBucketData(
	bucket uint8) (map[chainhash.Hash]dcrutil.Address, error)

GetLiveTicketsInBucketData creates a map indicating the ticket hash and the owner's address for each bucket. Used for an RPC call.

func (*TicketDB) GetMissedTicket

func (tmdb *TicketDB) GetMissedTicket(hash chainhash.Hash) *TicketData

GetMissedTicket locates a missed ticket in the missed ticket database, duplicates the ticket data, and returns it.

This function is safe for concurrent access.

func (*TicketDB) GetRevokedTicket

func (tmdb *TicketDB) GetRevokedTicket(hash chainhash.Hash) *TicketData

GetRevokedTicket locates a revoked ticket in the revoked ticket database, duplicates the ticket data, and returns it.

This function is safe for concurrent access.

func (*TicketDB) GetTicketHashesForMissed

func (tmdb *TicketDB) GetTicketHashesForMissed() []chainhash.Hash

GetTicketHashesForMissed gets all the currently missed tickets, copies their hashes, and returns them. TODO: Is a pointer to a pointer for a slice really necessary?

This function is safe for concurrent access.

func (*TicketDB) GetTopBlock

func (tmdb *TicketDB) GetTopBlock() int64

GetTopBlock returns the top (current) block from a TicketDB.

This function is safe for concurrent access.

func (*TicketDB) Initialize

func (tmdb *TicketDB) Initialize(np *chaincfg.Params, db database.Db)

Initialize allocates buckets for each ticket number in ticketMap and buckets for each height up to the declared height from 0. This should be called only when no suitable files exist to load the TicketDB from or when rescanTicketDB() is called. WARNING: Height should be 0 for all non-debug uses.

This function is safe for concurrent access.

func (*TicketDB) InsertBlock

func (tmdb *TicketDB) InsertBlock(block *dcrutil.Block) (SStxMemMap,
	SStxMemMap, SStxMemMap, error)

InsertBlock is the main work horse for inserting blocks in the TicketDB. Warning: I think this and the remove block functions pass pointers back to TicketDB data. If you call this function and use the SStxMemMaps it returns you need to make sure you don't modify their contents externally. In the future consider passing by value if this causes a consensus failure somehow.

This function is safe for concurrent access.

func (*TicketDB) LoadTicketDBs

func (tmdb *TicketDB) LoadTicketDBs(tmsPath, tmsLoc string, np *chaincfg.Params,
	db database.Db) error

LoadTicketDBs fetches the stored TicketDB and UsedTicketDB from the disk and stores them. Call this after the blockchain has been loaded into the daemon. TODO: Make a function that checks to see if the files exist before attempting to load them? Or do that elsewhere.

This function is safe for concurrent access.

func (*TicketDB) RemoveBlockToHeight

func (tmdb *TicketDB) RemoveBlockToHeight(height int64) (map[int64]SStxMemMap,
	map[int64]SStxMemMap, map[int64]SStxMemMap, error)

RemoveBlockToHeight is the exported version of removeBlockToHeight.

This function is safe for concurrent access.

func (*TicketDB) RescanTicketDB

func (tmdb *TicketDB) RescanTicketDB() error

RescanTicketDB rescans and regenerates both ticket memory maps starting from the genesis block and extending to the current block. This uses a lot of memory because it doesn't kill the old buckets.

This function is safe for concurrent access.

func (*TicketDB) Store

func (tmdb *TicketDB) Store(tmsPath string, tmsLoc string) error

Store serializes and stores a TicketDB. Only intended to be called when shut down has been initiated and daemon network activity has ceased. TODO: Serialize in a way that is cross-platform instead of gob encoding.

This function is safe for concurrent access.

type TicketData

type TicketData struct {
	SStxHash    chainhash.Hash
	Prefix      uint8 // Ticket hash prefix for pre-sort
	SpendHash   chainhash.Hash
	BlockHeight int64 // Block for where the original sstx was located
	Missed      bool  // Whether or not the ticket was spent
	Expired     bool  // Whether or not the ticket expired
}

TicketData contains contextual information about tickets as indicated below. TODO Replace Missed/Expired bool with single byte bitflags.

func NewTicketData

func NewTicketData(sstxHash chainhash.Hash,
	prefix uint8,
	spendHash chainhash.Hash,
	blockHeight int64,
	missed bool,
	expired bool) *TicketData

NewTicketData returns the a filled in new TicketData structure.

func (*TicketData) GobDecode

func (td *TicketData) GobDecode(buf []byte) error

GobDecode deserializes the TicketData struct into a gob for use in retrieval from storage.

func (*TicketData) GobEncode

func (td *TicketData) GobEncode() ([]byte, error)

GobEncode serializes the TicketData struct into a gob for use in storage.

This function is safe for concurrent access.

type TicketDataSlice

type TicketDataSlice []*TicketData

TicketDataSlice is a sortable data structure of pointers to TicketData.

func NewTicketDataSlice

func NewTicketDataSlice(size int) TicketDataSlice

NewTicketDataSlice creates and returns TicketData of the requested size.

func NewTicketDataSliceEmpty

func NewTicketDataSliceEmpty() TicketDataSlice

NewTicketDataSliceEmpty creates and returns a new, empty slice of TIcketData.

func (TicketDataSlice) Len

func (tds TicketDataSlice) Len() int

Len returns the length of the slice.

func (TicketDataSlice) Less

func (tds TicketDataSlice) Less(i, j int) bool

Less determines which of two *TicketData values is smaller; used for sort.

func (TicketDataSlice) Swap

func (tds TicketDataSlice) Swap(i, j int)

Swap swaps two *TicketData values.

type TicketMaps

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

TicketMaps is a struct of maps that encompass the four major buckets of the ticket in-memory database.

func (*TicketMaps) GobDecode

func (tm *TicketMaps) GobDecode(buf []byte) error

GobDecode deserializes the TicketMaps struct into a gob for use in retrieval from storage.

func (*TicketMaps) GobEncode

func (tm *TicketMaps) GobEncode() ([]byte, error)

GobEncode serializes the TicketMaps struct into a gob for use in storage.

type TxType

type TxType int

TxType indicates the type of tx (regular or stake type).

func DetermineTxType

func DetermineTxType(tx *dcrutil.Tx) TxType

DetermineTxType determines the type of stake transaction a transaction is; if none, it returns that it is an assumed regular tx.

Directories

Path Synopsis
internal
tickettreap
Package tickettreap implements a treap data structure that is used to hold live tickets ordered by their key along with some associated data using a combination of binary search tree and heap semantics.
Package tickettreap implements a treap data structure that is used to hold live tickets ordered by their key along with some associated data using a combination of binary search tree and heap semantics.

Jump to

Keyboard shortcuts

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