Documentation ¶
Index ¶
- Variables
- func NewDBStore(db DB, genesisState consensus.State, genesisBlock types.Block) (*DBStore, Checkpoint, error)
- type ApplyUpdate
- type Checkpoint
- type DB
- type DBBucket
- type DBStore
- func (db DBStore) AddCheckpoint(c Checkpoint) error
- func (db DBStore) ApplyDiff(s consensus.State, diff consensus.BlockDiff) (mayCommit bool, err error)
- func (db DBStore) BestIndex(height uint64) (index types.ChainIndex, err error)
- func (db DBStore) Checkpoint(id types.BlockID) (c Checkpoint, err error)
- func (db DBStore) RevertDiff(s consensus.State, diff consensus.BlockDiff) error
- func (db DBStore) WithConsensus(fn func(consensus.Store) error) error
- type DBTx
- type Manager
- func (m *Manager) AddBlocks(blocks []types.Block) error
- func (m *Manager) AddSubscriber(s Subscriber, tip types.ChainIndex) error
- func (m *Manager) Block(id types.BlockID) (types.Block, error)
- func (m *Manager) BlocksForHistory(blocks []types.Block, history []types.BlockID) ([]types.Block, error)
- func (m *Manager) History() ([32]types.BlockID, error)
- func (m *Manager) Tip() types.ChainIndex
- func (m *Manager) TipState() consensus.State
- type MemDB
- type RevertUpdate
- type Store
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFutureBlock is returned when a block's timestamp is too far in the future. ErrFutureBlock = errors.New("block's timestamp is too far in the future") )
Functions ¶
func NewDBStore ¶
func NewDBStore(db DB, genesisState consensus.State, genesisBlock types.Block) (*DBStore, Checkpoint, error)
NewDBStore creates a new DBStore using the provided database. The current checkpoint is also returned.
Types ¶
type ApplyUpdate ¶
type ApplyUpdate struct { Block types.Block State consensus.State // post-application Diff consensus.BlockDiff }
An ApplyUpdate reflects the changes to the blockchain resulting from the addition of a block.
type Checkpoint ¶
type Checkpoint struct { Block types.Block State consensus.State Diff *consensus.BlockDiff // nil if the block has not been validated }
A Checkpoint pairs a block with its resulting chain state.
func (*Checkpoint) DecodeFrom ¶
func (c *Checkpoint) DecodeFrom(d *types.Decoder)
DecodeFrom implements types.DecoderFrom.
func (Checkpoint) EncodeTo ¶
func (c Checkpoint) EncodeTo(e *types.Encoder)
EncodeTo implements types.EncoderTo.
type DBBucket ¶
type DBBucket interface { Get(key []byte) []byte Put(key, value []byte) error Delete(key []byte) error }
A DBBucket is a set of key-value pairs.
type DBStore ¶
type DBStore struct {
// contains filtered or unexported fields
}
DBStore implements Store using a key-value database.
func (DBStore) AddCheckpoint ¶
func (db DBStore) AddCheckpoint(c Checkpoint) error
AddCheckpoint implements Store.
func (DBStore) ApplyDiff ¶
func (db DBStore) ApplyDiff(s consensus.State, diff consensus.BlockDiff) (mayCommit bool, err error)
ApplyDiff implements Store.
func (DBStore) BestIndex ¶
func (db DBStore) BestIndex(height uint64) (index types.ChainIndex, err error)
BestIndex implements Store.
func (DBStore) Checkpoint ¶
func (db DBStore) Checkpoint(id types.BlockID) (c Checkpoint, err error)
Checkpoint implements Store.
func (DBStore) RevertDiff ¶
RevertDiff implements Store.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
A Manager tracks multiple blockchains and identifies the best valid chain.
func NewManager ¶
NewManager returns a Manager initialized with the provided Store and State.
func (*Manager) AddBlocks ¶
AddBlocks adds a sequence of blocks to a tracked chain. If the blocks are valid, the chain may become the new best chain, triggering a reorg.
func (*Manager) AddSubscriber ¶
func (m *Manager) AddSubscriber(s Subscriber, tip types.ChainIndex) error
AddSubscriber subscribes s to m, ensuring that it will receive updates when the best chain changes. If tip does not match the Manager's current tip, s is updated accordingly.
func (*Manager) BlocksForHistory ¶
func (m *Manager) BlocksForHistory(blocks []types.Block, history []types.BlockID) ([]types.Block, error)
BlocksForHistory fills the provided slice with consecutive blocks from the best chain, starting from the "attach point" -- the first ID in the history that is present in the best chain (or, if no match is found, genesis).
The returned slice may have fewer than len(blocks) elements if the end of the best chain is reached.
func (*Manager) History ¶
History returns a set of block IDs that span the best chain, beginning with the 10 most-recent blocks, and subsequently spaced exponentionally farther apart until reaching the genesis block.
func (*Manager) Tip ¶
func (m *Manager) Tip() types.ChainIndex
Tip returns the tip of the best known valid chain.
type MemDB ¶
type MemDB struct {
// contains filtered or unexported fields
}
MemDB implements DB with an in-memory map.
type RevertUpdate ¶
type RevertUpdate struct { Block types.Block State consensus.State // post-reversion, i.e. pre-application Diff consensus.BlockDiff }
A RevertUpdate reflects the changes to the blockchain resulting from the removal of a block.
type Store ¶
type Store interface { WithConsensus(func(consensus.Store) error) error AddCheckpoint(c Checkpoint) error Checkpoint(id types.BlockID) (Checkpoint, error) BestIndex(height uint64) (types.ChainIndex, error) ApplyDiff(s consensus.State, diff consensus.BlockDiff) (mayCommit bool, err error) RevertDiff(s consensus.State, diff consensus.BlockDiff) error }
A Store durably commits Manager-related data to storage.
type Subscriber ¶
type Subscriber interface { // Implementations MUST not commit updates to persistent storage unless mayCommit is set. ProcessChainApplyUpdate(cau *ApplyUpdate, mayCommit bool) error ProcessChainRevertUpdate(cru *RevertUpdate) error }
A Subscriber processes updates to the blockchain. Implementations must not modify or retain the provided update object.