stake

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2017 License: ISC Imports: 19 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

	// ErrDatabaseCorrupt indicates a database inconsistency.
	ErrDatabaseCorrupt

	// ErrMissingDatabaseTx indicates that a node disconnection failed to
	// pass a database transaction when attempted to remove a very old
	// node.
	ErrMissingDatabaseTx

	// ErrMemoryCorruption indicates that memory has somehow become corrupt,
	// for example invalid block header serialization from an in memory
	// struct.
	ErrMemoryCorruption

	// ErrFindTicketIdxs indicates a failure to find the selected ticket
	// indexes from the block header.
	ErrFindTicketIdxs

	// ErrMissingTicket indicates that a ticket was missing in one of the
	// ticket treaps when it was attempted to be fetched.
	ErrMissingTicket

	// ErrDuplicateTicket indicates that a duplicate ticket was attempted
	// to be inserted into a ticket treap or the database.
	ErrDuplicateTicket

	// ErrUnknownTicketSpent indicates that an unknown ticket was spent by
	// the block.
	ErrUnknownTicketSpent
)

These constants are used to identify a specific RuleError.

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

	// SSGenVoteBitsExtendedMaxSize is the maximum size for a VoteBitsExtended
	// push in an SSGen.
	//
	// The final vote transaction includes a single data push for all vote
	// bits concatenated.  The non-extended vote bits occupy the first 2
	// bytes, thus the max number of extended vote bits is the maximum
	// allow length for a single byte data push minus the 2 bytes required
	// by the non-extended vote bits.
	SSGenVoteBitsExtendedMaxSize = MaxSingleBytePushLength - 2

	// 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

	// VoteConsensusVersionAbsent is the value of the consensus version
	// for a short read of the voteBits.
	VoteConsensusVersionAbsent = 0
)

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 CalculateRewards added in v0.5.0

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

CalculateRewards 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 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 is the exported version of findTicketIdxs used for testing.

func IsSSGen

func IsSSGen(tx *wire.MsgTx) (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 *wire.MsgTx) (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 *wire.MsgTx) (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 *wire.MsgTx) bool

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

func SSGenBlockVotedOn added in v0.5.0

func SSGenBlockVotedOn(tx *wire.MsgTx) (chainhash.Hash, uint32, error)

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

This function is only safe to be called on a transaction that has passed IsSSGen.

func SSGenVersion added in v0.6.0

func SSGenVersion(tx *wire.MsgTx) uint32

SSGenVersion takes an SSGen tx as input and returns the network consensus version from the VoteBits output. If there is a short read, the network consensus version is considered 0 or "unset".

This function is only safe to be called on a transaction that has passed IsSSGen.

func SSGenVoteBits added in v0.5.0

func SSGenVoteBits(tx *wire.MsgTx) uint16

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

This function is only safe to be called on a transaction that has passed IsSSGen.

func SStxNullOutputAmounts added in v0.5.0

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

SStxNullOutputAmounts 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 SStxStakeOutputInfo added in v0.5.0

func SStxStakeOutputInfo(outs []*MinimalOutput) ([]bool, [][]byte, []int64,
	[]int64, [][]bool, [][]uint16)

SStxStakeOutputInfo 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 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 TxSSGenStakeOutputInfo added in v0.5.0

func TxSSGenStakeOutputInfo(tx *wire.MsgTx, params *chaincfg.Params) ([]bool,
	[][]byte, []int64, error)

TxSSGenStakeOutputInfo 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 TxSSRtxStakeOutputInfo added in v0.5.0

func TxSSRtxStakeOutputInfo(tx *wire.MsgTx, params *chaincfg.Params) ([]bool,
	[][]byte, []int64, error)

TxSSRtxStakeOutputInfo 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 TxSStxStakeOutputInfo added in v0.5.0

func TxSStxStakeOutputInfo(tx *wire.MsgTx) ([]bool, [][]byte, []int64, []int64,
	[][]bool, [][]uint16)

TxSStxStakeOutputInfo 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 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.

func WriteConnectedBestNode added in v0.5.0

func WriteConnectedBestNode(dbTx database.Tx, node *Node, hash chainhash.Hash) error

WriteConnectedBestNode writes the newly connected best node to the database under an atomic database transaction, performing all the necessary writes to the database buckets for live, missed, and revoked tickets.

func WriteDisconnectedBestNode added in v0.5.0

func WriteDisconnectedBestNode(dbTx database.Tx, node *Node, hash chainhash.Hash, childUndoData UndoTicketDataSlice) error

WriteDisconnectedBestNode writes the newly connected best node to the database under an atomic database transaction, performing all the necessary writes to reverse the contents of the database buckets for live, missed, and revoked tickets. It does so by using the parent's block undo data to restore the original state in the database. It also drops new ticket and reversion data for any nodes that have a height higher than this one after.

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 MinimalOutput added in v0.5.0

type MinimalOutput struct {
	PkScript []byte
	Value    int64
	Version  uint16
}

MinimalOutput is a struct encoding a minimally sized output for use in parsing stake related information.

func ConvertToMinimalOutputs added in v0.5.0

func ConvertToMinimalOutputs(tx *wire.MsgTx) []*MinimalOutput

ConvertToMinimalOutputs converts a transaction to its minimal outputs derivative.

type Node added in v0.5.0

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

Node is in-memory stake data for a node. It contains a list of database updates to be written in the case that the block is inserted in the main chain database. Because of its use of immutable treap data structures, it allows for a fast, efficient in-memory representation of the ticket database for each node. It handles connection of and disconnection of new blocks simply.

Like the immutable treap structures, stake nodes themselves are considered to be immutable. The connection or disconnection of past or future nodes returns a pointer to a new stake node, which must be saved and used appropriately.

func InitDatabaseState added in v0.5.0

func InitDatabaseState(dbTx database.Tx, params *chaincfg.Params) (*Node, error)

InitDatabaseState initializes the chain with the best state being the genesis block.

func LoadBestNode added in v0.5.0

func LoadBestNode(dbTx database.Tx, height uint32, blockHash chainhash.Hash, header wire.BlockHeader, params *chaincfg.Params) (*Node, error)

LoadBestNode is used when the blockchain is initialized, to get the initial stake node from the database bucket. The blockchain must pass the height and the blockHash to confirm that the ticket database is on the same location in the blockchain as the blockchain itself. This function also checks to ensure that the database has not failed the upgrade process and reports the current version. Upgrades are also handled by this function, when they become applicable.

func (*Node) ConnectNode added in v0.5.0

func (sn *Node) ConnectNode(header wire.BlockHeader, ticketsSpentInBlock, revokedTickets, newTickets []chainhash.Hash) (*Node, error)

ConnectNode connects a stake node to the node and returns a pointer to the stake node of the child.

func (*Node) DisconnectNode added in v0.5.0

func (sn *Node) DisconnectNode(parentHeader wire.BlockHeader, parentUtds UndoTicketDataSlice, parentTickets []chainhash.Hash, dbTx database.Tx) (*Node, error)

DisconnectNode disconnects a stake node from the node and returns a pointer to the stake node of the parent.

func (*Node) ExistsExpiredTicket added in v0.5.0

func (sn *Node) ExistsExpiredTicket(ticket chainhash.Hash) bool

ExistsExpiredTicket returns whether or not a ticket was ever expired from the perspective of this stake node.

func (*Node) ExistsLiveTicket added in v0.5.0

func (sn *Node) ExistsLiveTicket(ticket chainhash.Hash) bool

ExistsLiveTicket returns whether or not a ticket exists in the live ticket treap for this stake node.

func (*Node) ExistsMissedTicket added in v0.5.0

func (sn *Node) ExistsMissedTicket(ticket chainhash.Hash) bool

ExistsMissedTicket returns whether or not a ticket exists in the missed ticket treap for this stake node.

func (*Node) ExistsRevokedTicket added in v0.5.0

func (sn *Node) ExistsRevokedTicket(ticket chainhash.Hash) bool

ExistsRevokedTicket returns whether or not a ticket exists in the revoked ticket treap for this stake node.

func (*Node) FinalState added in v0.5.0

func (sn *Node) FinalState() [6]byte

FinalState returns the final state lottery checksum of the node.

func (*Node) Height added in v0.5.0

func (sn *Node) Height() uint32

Height returns the height of the node.

func (*Node) LiveTickets added in v0.5.0

func (sn *Node) LiveTickets() []chainhash.Hash

LiveTickets returns the list of live tickets for this stake node.

func (*Node) MissedByBlock added in v0.5.0

func (sn *Node) MissedByBlock() []chainhash.Hash

MissedByBlock returns the tickets that were missed in this block.

func (*Node) MissedTickets added in v0.5.0

func (sn *Node) MissedTickets() []chainhash.Hash

MissedTickets returns the list of missed tickets for this stake node.

func (*Node) NewTickets added in v0.5.0

func (sn *Node) NewTickets() []chainhash.Hash

NewTickets returns the stored UndoTicketDataSlice used to remove this node and restore it to the parent state.

func (*Node) PoolSize added in v0.5.0

func (sn *Node) PoolSize() int

PoolSize returns the size of the live ticket pool.

func (*Node) RevokedTickets added in v0.5.0

func (sn *Node) RevokedTickets() []*chainhash.Hash

RevokedTickets returns the list of revoked tickets for this stake node.

func (*Node) SpentByBlock added in v0.5.0

func (sn *Node) SpentByBlock() []chainhash.Hash

SpentByBlock returns the tickets that were spent in this block.

func (*Node) UndoData added in v0.5.0

func (sn *Node) UndoData() UndoTicketDataSlice

UndoData returns the stored UndoTicketDataSlice used to remove this node and restore it to the parent state.

func (*Node) Winners added in v0.5.0

func (sn *Node) Winners() []chainhash.Hash

Winners returns the current list of winners for this stake node, which can vote on this node.

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 TxType

type TxType int

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

const (
	TxTypeRegular TxType = iota
	TxTypeSStx
	TxTypeSSGen
	TxTypeSSRtx
)

Possible TxTypes. Statically declare these so that they might be used in consensus code.

func DetermineTxType

func DetermineTxType(tx *wire.MsgTx) TxType

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

type UndoTicketDataSlice added in v0.5.0

type UndoTicketDataSlice []ticketdb.UndoTicketData

UndoTicketDataSlice is a pass through for ticketdb's UndoTicketData, which is stored in memory in the node.

type VoteBits added in v0.6.0

type VoteBits struct {
	Bits         uint16
	ExtendedBits []byte
}

VoteBits is a field representing the mandatory 2-byte field of voteBits along with the optional 73-byte extended field for votes.

Directories

Path Synopsis
internal
dbnamespace
Package dbnamespace contains constants that define the database namespaces for the purpose of the blockchain, so that external callers may easily access this data.
Package dbnamespace contains constants that define the database namespaces for the purpose of the blockchain, so that external callers may easily access this data.
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