Documentation
¶
Index ¶
- type BlockStore
- func (bs *BlockStore) Base() int64
- func (bs *BlockStore) Close() error
- func (bs *BlockStore) CoreChainLockedHeight() uint32
- func (bs *BlockStore) DeleteBlock(height int64) (uint64, error)
- func (bs *BlockStore) Height() int64
- func (bs *BlockStore) LoadBaseMeta() *types.BlockMeta
- func (bs *BlockStore) LoadBlock(height int64) *types.Block
- func (bs *BlockStore) LoadBlockByHash(hash []byte) *types.Block
- func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit
- func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta
- func (bs *BlockStore) LoadBlockMetaByHash(hash []byte) *types.BlockMeta
- func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part
- func (bs *BlockStore) LoadSeenCommit() *types.Commit
- func (bs *BlockStore) LoadSeenCommitAt(height int64) *types.Commit
- func (bs *BlockStore) PruneBlocks(height int64) (uint64, error)
- func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
- func (bs *BlockStore) SaveSeenCommit(seenCommit *types.Commit) error
- func (bs *BlockStore) SaveSignedHeader(sh *types.SignedHeader, blockID types.BlockID) error
- func (bs *BlockStore) Size() int64
- func (bs *BlockStore) UnsafeNoFsync() bool
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockStore ¶
type BlockStore struct {
// contains filtered or unexported fields
}
BlockStore is a simple low level store for blocks.
There are three types of information stored:
- BlockMeta: Meta information about each block
- Block part: Parts of each block, aggregated w/ PartSet
- Commit: The commit part of each block, for gossiping precommit votes
Currently the precommit signatures are duplicated in the Block parts as well as the Commit. In the future this may change, perhaps by moving the Commit data outside the Block. (TODO)
The store can be assumed to contain all contiguous blocks between base and height (inclusive).
// NOTE: BlockStore methods will panic if they encounter errors // deserializing loaded data, indicating probable corruption on disk.
func NewBlockStore ¶
func NewBlockStore(db dbm.DB, opts ...Option) *BlockStore
NewBlockStore returns a new BlockStore with the given DB, initialized to the last height that was committed to the DB.
func (*BlockStore) Base ¶
func (bs *BlockStore) Base() int64
Base returns the first known contiguous block height, or 0 for empty block stores.
func (*BlockStore) Close ¶
func (bs *BlockStore) Close() error
func (*BlockStore) CoreChainLockedHeight ¶
func (bs *BlockStore) CoreChainLockedHeight() uint32
func (*BlockStore) DeleteBlock ¶ added in v1.5.0
func (bs *BlockStore) DeleteBlock(height int64) (uint64, error)
DeleteBlock removes the block at the given height, including its parts and commit. It returns the number of blocks removed, which is always 1 in this case.
func (*BlockStore) Height ¶
func (bs *BlockStore) Height() int64
Height returns the last known contiguous block height, or 0 for empty block stores.
func (*BlockStore) LoadBaseMeta ¶
func (bs *BlockStore) LoadBaseMeta() *types.BlockMeta
LoadBase atomically loads the base block meta, or returns nil if no base is found.
func (*BlockStore) LoadBlock ¶
func (bs *BlockStore) LoadBlock(height int64) *types.Block
LoadBlock returns the block with the given height. If no block is found for that height, it returns nil.
func (*BlockStore) LoadBlockByHash ¶
func (bs *BlockStore) LoadBlockByHash(hash []byte) *types.Block
LoadBlockByHash returns the block with the given hash. If no block is found for that hash, it returns nil. Panics if it fails to parse height associated with the given hash.
func (*BlockStore) LoadBlockCommit ¶
func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit
LoadBlockCommit returns the Commit for the given height. This commit consists of the +2/3 and other Precommit-votes for block at `height`, and it comes from the block.LastCommit for `height+1`. If no commit is found for the given height, it returns nil.
func (*BlockStore) LoadBlockMeta ¶
func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta
LoadBlockMeta returns the BlockMeta for the given height. If no block is found for the given height, it returns nil.
func (*BlockStore) LoadBlockMetaByHash ¶
func (bs *BlockStore) LoadBlockMetaByHash(hash []byte) *types.BlockMeta
LoadBlockMetaByHash returns the blockmeta who's header corresponds to the given hash. If none is found, returns nil.
func (*BlockStore) LoadBlockPart ¶
func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part
LoadBlockPart returns the Part at the given index from the block at the given height. If no part is found for the given height and index, it returns nil.
func (*BlockStore) LoadSeenCommit ¶
func (bs *BlockStore) LoadSeenCommit() *types.Commit
LoadSeenCommit returns the last locally seen Commit before being cannonicalized. This is useful when we've seen a commit, but there has not yet been a new block at `height + 1` that includes this commit in its block.LastCommit.
func (*BlockStore) LoadSeenCommitAt ¶
func (bs *BlockStore) LoadSeenCommitAt(height int64) *types.Commit
func (*BlockStore) PruneBlocks ¶
func (bs *BlockStore) PruneBlocks(height int64) (uint64, error)
PruneBlocks removes block up to (but not including) a height. It returns the number of blocks pruned.
func (*BlockStore) SaveBlock ¶
func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
SaveBlock persists the given block, blockParts, and seenCommit to the underlying db. blockParts: Must be parts of the block seenCommit: The +2/3 precommits that were seen which committed at height.
If all the nodes restart after committing a block, we need this to reload the precommits to catch-up nodes to the most recent height. Otherwise they'd stall at H-1.
func (*BlockStore) SaveSeenCommit ¶
func (bs *BlockStore) SaveSeenCommit(seenCommit *types.Commit) error
SaveSeenCommit saves a seen commit, used by e.g. the state sync reactor when bootstrapping node.
func (*BlockStore) SaveSignedHeader ¶
func (bs *BlockStore) SaveSignedHeader(sh *types.SignedHeader, blockID types.BlockID) error
func (*BlockStore) Size ¶
func (bs *BlockStore) Size() int64
Size returns the number of blocks in the block store.
func (*BlockStore) UnsafeNoFsync ¶ added in v1.8.0
func (bs *BlockStore) UnsafeNoFsync() bool
UnsafeNoFsync reports whether this store's writes skip the fsync. It exists so callers that wire the store from config can assert what they built.
type Option ¶ added in v1.8.0
type Option func(*BlockStore)
Option configures a BlockStore at construction.
func WithUnsafeNoFsync ¶ added in v1.8.0
func WithUnsafeNoFsync() Option
WithUnsafeNoFsync makes every write to the block store return before it has reached the disk. It exists for benchmarking: on macOS Go's File.Sync issues F_FULLFSYNC, which costs several milliseconds per call and swamps everything else in a block sync profile, while on Linux the same call is a plain fsync costing a fraction of that. Dropping it takes durability out of the measurement.
Never use it on a node whose data matters: a power loss can leave the block store behind the application, which the replayer rejects with ErrAppBlockHeightTooHigh.