Documentation ¶
Index ¶
- Constants
- func DbCreate(dbTx database.Tx) error
- func DbDeleteTicket(dbTx database.Tx, ticketBucket []byte, hash *chainhash.Hash) error
- func DbDropBlockUndoData(dbTx database.Tx, height uint32) error
- func DbDropNewTickets(dbTx database.Tx, height uint32) error
- func DbLoadAllTickets(dbTx database.Tx, ticketBucket []byte) (*tickettreap.Immutable, error)
- func DbPutBestState(dbTx database.Tx, bcs BestChainState) error
- func DbPutBlockUndoData(dbTx database.Tx, height uint32, utds []UndoTicketData) error
- func DbPutDatabaseInfo(dbTx database.Tx, dbi *DatabaseInfo) error
- func DbPutNewTickets(dbTx database.Tx, height uint32, ths TicketHashes) error
- func DbPutTicket(dbTx database.Tx, ticketBucket []byte, hash *chainhash.Hash, height uint32, ...) error
- func DbRemoveAllBuckets(dbTx database.Tx) error
- type BestChainState
- type DBError
- type DatabaseInfo
- type ErrorKind
- type TicketHashes
- type UndoTicketData
Constants ¶
const ( // ErrUndoDataShortRead indicates that the given undo serialized data // was took small. ErrUndoDataShortRead = ErrorKind("ErrUndoDataShortRead") // ErrUndoDataNoEntries indicates that the data for undoing ticket data // in a serialized entry was corrupt. ErrUndoDataCorrupt = ErrorKind("ErrUndoDataCorrupt") // ErrTicketHashesShortRead indicates that the given ticket hashes // serialized data was took small. ErrTicketHashesShortRead = ErrorKind("ErrTicketHashesShortRead") // ErrTicketHashesCorrupt indicates that the data for ticket hashes // in a serialized entry was corrupt. ErrTicketHashesCorrupt = ErrorKind("ErrTicketHashesCorrupt") // ErrUninitializedBucket indicates that a database bucket was not // initialized and therefore could not be written to or read from. ErrUninitializedBucket = ErrorKind("ErrUninitializedBucket") // ErrMissingKey indicates that a key was not found in a bucket. ErrMissingKey = ErrorKind("ErrMissingKey") // ErrChainStateShortRead indicates that the given chain state data // was too small. ErrChainStateShortRead = ErrorKind("ErrChainStateShortRead") // ErrDatabaseInfoShortRead indicates that the given database information // was too small. ErrDatabaseInfoShortRead = ErrorKind("ErrDatabaseInfoShortRead") // ErrLoadAllTickets indicates that there was an error loading the tickets // from the database, presumably at startup. ErrLoadAllTickets = ErrorKind("ErrLoadAllTickets") )
These constants are used to identify a specific DBError.
Variables ¶
This section is empty.
Functions ¶
func DbCreate ¶
func DbCreate(dbTx database.Tx) error
DbCreate initializes all the buckets required for the database and stores the current database version information.
func DbDeleteTicket ¶
DbDeleteTicket removes a ticket from one of the ticket database buckets. This differs from the bucket deletion method in that it will fail if the value itself is missing.
func DbDropBlockUndoData ¶
DbDropBlockUndoData drops block undo data from the database at a given height.
func DbDropNewTickets ¶
DbDropNewTickets drops new tickets for a mainchain block data at some height.
func DbLoadAllTickets ¶
func DbLoadAllTickets(dbTx database.Tx, ticketBucket []byte) (*tickettreap.Immutable, error)
DbLoadAllTickets loads all the live tickets from the database into a treap.
func DbPutBestState ¶
func DbPutBestState(dbTx database.Tx, bcs BestChainState) error
DbPutBestState uses an existing database transaction to update the best chain state with the given parameters.
func DbPutBlockUndoData ¶
func DbPutBlockUndoData(dbTx database.Tx, height uint32, utds []UndoTicketData) error
DbPutBlockUndoData inserts block undo data into the database for a given height.
func DbPutDatabaseInfo ¶
func DbPutDatabaseInfo(dbTx database.Tx, dbi *DatabaseInfo) error
DbPutDatabaseInfo uses an existing database transaction to store the database information.
func DbPutNewTickets ¶
func DbPutNewTickets(dbTx database.Tx, height uint32, ths TicketHashes) error
DbPutNewTickets inserts new tickets for a mainchain block data into the database.
func DbPutTicket ¶
func DbPutTicket(dbTx database.Tx, ticketBucket []byte, hash *chainhash.Hash, height uint32, missed, revoked, spent, expired bool) error
DbPutTicket inserts a ticket into one of the ticket database buckets.
func DbRemoveAllBuckets ¶
func DbRemoveAllBuckets(dbTx database.Tx) error
DbRemoveAllBuckets removes all buckets from the database.
Types ¶
type BestChainState ¶
type BestChainState struct { Hash chainhash.Hash Height uint32 Live uint32 Missed uint64 Revoked uint64 PerBlock uint16 NextWinners []chainhash.Hash }
BestChainState represents the data to be stored the database for the current best chain state.
func DbFetchBestState ¶
func DbFetchBestState(dbTx database.Tx) (BestChainState, error)
DbFetchBestState uses an existing database transaction to fetch the best chain state.
type DBError ¶
DBError identifies an error related to the stake database for tickets. It has full support for errors.Is and errors.As, so the caller can ascertain the specific reason for the error by checking the underlying error.
type DatabaseInfo ¶
DatabaseInfo is the structure for a database.
func DbFetchDatabaseInfo ¶
func DbFetchDatabaseInfo(dbTx database.Tx) (*DatabaseInfo, error)
DbFetchDatabaseInfo uses an existing database transaction to fetch the database versioning and creation information.
type ErrorKind ¶
type ErrorKind string
ErrorKind identifies a kind of error. It has full support for errors.Is and errors.As, so the caller can directly check against an error kind when determining the reason for an error.
type TicketHashes ¶
TicketHashes is a list of ticket hashes that will mature in TicketMaturity many blocks from the block in which they were included.
func DbFetchNewTickets ¶
func DbFetchNewTickets(dbTx database.Tx, height uint32) (TicketHashes, error)
DbFetchNewTickets fetches new tickets for a mainchain block from the database.
type UndoTicketData ¶
type UndoTicketData struct { TicketHash chainhash.Hash TicketHeight uint32 Missed bool Revoked bool Spent bool Expired bool }
UndoTicketData is the data for any ticket that has been spent, missed, or revoked at some new height. It is used to roll back the database in the event of reorganizations or determining if a side chain block is valid. The last 3 are encoded as a single byte of flags. The flags describe a particular state for the ticket:
- Missed is set, but revoked and spent are not (0000 0001). The ticket was selected in the lottery at this block height but missed, or the ticket became too old and was missed. The ticket is being moved to the missed ticket bucket from the live ticket bucket.
- Missed and revoked are set (0000 0011). The ticket was missed previously at a block before this one and was revoked, and as such is being moved to the revoked ticket bucket from the missed ticket bucket.
- Spent is set (0000 0100). The ticket has been spent and is removed from the live ticket bucket.
- No flags are set. The ticket was newly added to the live ticket bucket this block as a maturing ticket.
func DbFetchBlockUndoData ¶
func DbFetchBlockUndoData(dbTx database.Tx, height uint32) ([]UndoTicketData, error)
DbFetchBlockUndoData fetches block undo data from the database.