ticketdb

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: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrUndoDataShortRead indicates that the given undo serialized data
	// was took small.
	ErrUndoDataShortRead = iota

	// ErrUndoDataNoEntries indicates that the data for undoing ticket data
	// in a serialized entry was corrupt.
	ErrUndoDataCorrupt

	// ErrTicketHashesShortRead indicates that the given ticket hashes
	// serialized data was took small.
	ErrTicketHashesShortRead

	// ErrTicketHashesCorrupt indicates that the data for ticket hashes
	// in a serialized entry was corrupt.
	ErrTicketHashesCorrupt

	// ErrUninitializedBucket indicates that a database bucket was not
	// initialized and therefore could not be written to or read from.
	ErrUninitializedBucket

	// ErrMissingKey indicates that a key was not found in a bucket.
	ErrMissingKey

	// ErrChainStateShortRead indicates that the given chain state data
	// was too small.
	ErrChainStateShortRead

	// ErrDatabaseInfoShortRead indicates that the given database information
	// was too small.
	ErrDatabaseInfoShortRead

	// ErrLoadAllTickets indicates that there was an error loading the tickets
	// from the database, presumably at startup.
	ErrLoadAllTickets
)

These constants are used to identify a specific RuleError.

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

func DbDeleteTicket(dbTx database.Tx, ticketBucket []byte, hash *chainhash.Hash) error

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

func DbDropBlockUndoData(dbTx database.Tx, height uint32) error

DbDropBlockUndoData drops block undo data from the database at a given height.

func DbDropNewTickets

func DbDropNewTickets(dbTx database.Tx, height uint32) error

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.

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

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

DBError identifies a an error in the stake database for tickets. 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 (DBError) Error

func (e DBError) Error() string

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

func (DBError) GetCode

func (e DBError) GetCode() ErrorCode

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

type DatabaseInfo

type DatabaseInfo struct {
	Version        uint32
	Date           time.Time
	UpgradeStarted bool
}

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

type TicketHashes []chainhash.Hash

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:

  1. 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.
  2. 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.
  3. Spent is set (0000 0100). The ticket has been spent and is removed from the live ticket bucket.
  4. 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.

Jump to

Keyboard shortcuts

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