package blockstore
import "go.dedis.ch/dela/core/ordering/cosipbft/blockstore"
Package blockstore defines the different storage the ordering service is using.
The block store defines the primitives to store a block and read one from the disk. It also provide an API to read a chain from the genesis block to the latest block. It is important to notice that a block is stored alongside the link that has been created during the consensus.
The tree cache stores the latest state of the tree, which is modified after each new block.
The genesis store allows to set a definitive genesis block and persist it so that it can be reloaded later on.
Documentation Last Review: 13.10.2020
Index ¶
- Variables
- type BlockStore
- type GenesisStore
- type InDisk
- func NewDiskStore(db kv.DB, fac types.LinkFactory) *InDisk
- func (s *InDisk) Get(id types.Digest) (types.BlockLink, error)
- func (s *InDisk) GetByIndex(index uint64) (link types.BlockLink, err error)
- func (s *InDisk) GetChain() (types.Chain, error)
- func (s *InDisk) Last() (types.BlockLink, error)
- func (s *InDisk) Len() uint64
- func (s *InDisk) Load() error
- func (s *InDisk) Store(link types.BlockLink) error
- func (s *InDisk) Watch(ctx context.Context) <-chan types.BlockLink
- func (s *InDisk) WithTx(txn store.Transaction) BlockStore
- type InMemory
- func NewInMemory() *InMemory
- func (s *InMemory) Get(id types.Digest) (types.BlockLink, error)
- func (s *InMemory) GetByIndex(index uint64) (types.BlockLink, error)
- func (s *InMemory) GetChain() (types.Chain, error)
- func (s *InMemory) Last() (types.BlockLink, error)
- func (s *InMemory) Len() uint64
- func (s *InMemory) Store(link types.BlockLink) error
- func (s *InMemory) Watch(ctx context.Context) <-chan types.BlockLink
- func (s *InMemory) WithTx(txn store.Transaction) BlockStore
- type PersistentGenesisCache
- func NewGenesisDiskStore(db kv.DB, fac serde.Factory) PersistentGenesisCache
- func (s PersistentGenesisCache) Exists() bool
- func (s PersistentGenesisCache) Get() (types.Genesis, error)
- func (s PersistentGenesisCache) Load() error
- func (s PersistentGenesisCache) Set(genesis types.Genesis) error
- type TreeCache
Variables ¶
ErrNoBlock is the error message returned when the block is unknown.
Types ¶
type BlockStore ¶
type BlockStore interface { // Len must return the length of the store. Len() uint64 // Store must store the block link only if it matches the latest link, // otherwise it must return an error. Store(types.BlockLink) error // Get must return the block link associated to the digest, or an error. Get(id types.Digest) (types.BlockLink, error) // GetByIndex return the block link associated to the index, or an error. GetByIndex(index uint64) (types.BlockLink, error) // GetChain returns a chain of the blocks. It can be used to prove the // integrity of the last block from the genesis. GetChain() (types.Chain, error) // Last must return the latest block link in the store. Last() (types.BlockLink, error) // Watch returns a channel that is filled with new block links. The is // closed as soon as the context is done. Watch(context.Context) <-chan types.BlockLink // WithTx returns a block store that is using the transaction to perform // operations on the database. WithTx(store.Transaction) BlockStore }
BlockStore is the interface to store and get blocks.
type GenesisStore ¶
type GenesisStore interface { // Get must return the genesis block if it is set, otherwise an error. Get() (types.Genesis, error) // Set must set the genesis block. Set(types.Genesis) error // Exists returns true if the genesis is already set. Exists() bool }
GenesisStore is the interface to store and get the genesis block. It is left to the implementation to persist it.
func NewGenesisStore ¶
func NewGenesisStore() GenesisStore
NewGenesisStore returns a new empty genesis store.
type InDisk ¶
type InDisk struct {
// contains filtered or unexported fields
}
InDisk is a persistent storage implementation for the blocks.
- implements blockstore.BlockStore
func NewDiskStore ¶
func NewDiskStore(db kv.DB, fac types.LinkFactory) *InDisk
NewDiskStore creates a new persistent storage.
func (*InDisk) Get ¶
Get implements blockstore.BlockStore. It loads the block with the given identifier if it exists, otherwise it returns an error.
func (*InDisk) GetByIndex ¶
GetByIndex implements blockstore.BlockStore. It returns the block associated to the index if it exists, otherwise it returns an error.
func (*InDisk) GetChain ¶
GetChain implements blockstore.Blockstore. It returns a chain to the latest block.
func (*InDisk) Last ¶
Last implements blockstore.BlockStore. It returns the last block stored in the database.
func (*InDisk) Len ¶
Len implements blockstore.BlockStore. It returns the number of blocks stored in the database.
func (*InDisk) Load ¶
Load reads the database to rebuild the cache.
func (*InDisk) Store ¶
Store implements blockstore.BlockStore. It stores the link in the database if it matches the latest link.
func (*InDisk) Watch ¶
Watch implements blockstore.BlockStore. It returns a channel populated with new blocks stored.
func (*InDisk) WithTx ¶
func (s *InDisk) WithTx(txn store.Transaction) BlockStore
WithTx implements blockstore.BlockStore. It returns a store that will use the transaction for the operations on the database.
type InMemory ¶
InMemory is a block store that only stores the block in-memory which means they won't persist.
- implements blockstore.BlockStore
func NewInMemory ¶
func NewInMemory() *InMemory
NewInMemory returns a new empty in-memory block store.
func (*InMemory) Get ¶
Get implements blockstore.BlockStore. It returns the block link associated to the digest if it exists, otherwise it returns an error.
func (*InMemory) GetByIndex ¶
GetByIndex implements blockstore.BlockStore. It returns the block associated to the index if it exists.
func (*InMemory) GetChain ¶
GetChain implements blockstore.BlockStore. It returns the chain to the latest block.
func (*InMemory) Last ¶
Last implements blockstore.BlockStore. It returns the latest block of the store.
func (*InMemory) Len ¶
Len implements blockstore.BlockStore. It returns the length of the store.
func (*InMemory) Store ¶
Store implements blockstore.BlockStore. It stores the block only if the link matches the latest block.
func (*InMemory) Watch ¶
Watch implements blockstore.BlockStore. It returns a channel populated with new blocks.
func (*InMemory) WithTx ¶
func (s *InMemory) WithTx(txn store.Transaction) BlockStore
WithTx implements blockstore.BlockStore. It returns a new store that will apply the list of blocks at the end of the transaction.
type PersistentGenesisCache ¶
type PersistentGenesisCache struct {
// contains filtered or unexported fields
}
PersistentGenesisCache is a store to set a genesis block on disk. It also provides a function to load the block from the disk that will then stay in memory.
- implements blockstore.GenesisStore
func NewGenesisDiskStore ¶
func NewGenesisDiskStore(db kv.DB, fac serde.Factory) PersistentGenesisCache
NewGenesisDiskStore creates a new store that will load or set the genesis block using the given database.
func (PersistentGenesisCache) Exists ¶
func (s PersistentGenesisCache) Exists() bool
Exists implements blockstore.GenesisStore. It returns true if the genesis block is set.
func (PersistentGenesisCache) Get ¶
Get implements blockstore.GenesisStore. It returns the genesis block if it is set, otherwise it returns an error.
func (PersistentGenesisCache) Load ¶
func (s PersistentGenesisCache) Load() error
Load tries to read the genesis block in the database, and set it to memory only if it exists. It returns an error if the database cannot be read, or the value is malformed.
func (PersistentGenesisCache) Set ¶
func (s PersistentGenesisCache) Set(genesis types.Genesis) error
Set implements blockstore.GenesisStore. It writes the genesis block in disk, and then in memory for fast access.
type TreeCache ¶
type TreeCache interface { // Get returns the current value of the cache. Get() hashtree.Tree // GetWithLock implements blockstore.TreeCache. It returns the current value // of the cache alongside a function to unlock the cache. It allows one to // delay a set while fetching associated data. The function returned must be // called. GetWithLock() (tree hashtree.Tree, unlock func()) // Set sets a new tree in the cache. Set(hashtree.Tree) // SetWithLock implements blockstore.TreeCache. It sets the tree while // holding the lock and returns a function to unlock it. It allows one to // prevent an access until associated data is updated. The function returned // must be called. SetWithLock(hashtree.Tree) (unlock func()) }
TreeCache is a cache to store a tree that needs to be accessed in different places.
func NewTreeCache ¶
NewTreeCache creates a new cache with the given tree as the first value.
Source Files ¶
blockstore.go disk.go genesis.go mem.go tree.go
- Version
- v0.1.0 (latest)
- Published
- Apr 10, 2024
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 1 month ago –
Tools for package owners.