Documentation ¶
Index ¶
- Constants
- Variables
- func ClearPreResetHeight(blockStorageDir string, ledgerIDs []string) error
- func DeleteBlockStoreIndex(blockStorageDir string) error
- func LoadPreResetHeight(blockStorageDir string, ledgerIDs []string) (map[string]uint64, error)
- func ResetBlockStore(blockStorageDir string) error
- func Rollback(blockStorageDir, ledgerID string, targetBlockNum uint64, ...) error
- func ValidateRollbackParams(blockStorageDir, ledgerID string, targetBlockNum uint64) error
- type BlockStore
- func (store *BlockStore) AddBlock(block *common.Block) error
- func (store *BlockStore) ExportTxIds(dir string, newHashFunc snapshot.NewHashFunc) (map[string][]byte, error)
- func (store *BlockStore) GetBlockchainInfo() (*common.BlockchainInfo, error)
- func (store *BlockStore) RetrieveBlockByHash(blockHash []byte) (*common.Block, error)
- func (store *BlockStore) RetrieveBlockByNumber(blockNum uint64) (*common.Block, error)
- func (store *BlockStore) RetrieveBlockByTxID(txID string) (*common.Block, error)
- func (store *BlockStore) RetrieveBlocks(startNum uint64) (ledger.ResultsIterator, error)
- func (store *BlockStore) RetrieveTxByBlockNumTranNum(blockNum uint64, tranNum uint64) (*common.Envelope, error)
- func (store *BlockStore) RetrieveTxByID(txID string) (*common.Envelope, error)
- func (store *BlockStore) RetrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error)
- func (store *BlockStore) Shutdown()
- type BlockStoreProvider
- func (p *BlockStoreProvider) BootstrapFromSnapshottedTxIDs(snapshotDir string, snapshotInfo *SnapshotInfo) (*BlockStore, error)
- func (p *BlockStoreProvider) Close()
- func (p *BlockStoreProvider) Exists(ledgerid string) (bool, error)
- func (p *BlockStoreProvider) List() ([]string, error)
- func (p *BlockStoreProvider) Open(ledgerid string) (*BlockStore, error)
- func (p *BlockStoreProvider) Remove(ledgerid string) error
- type BootstrappingSnapshotInfo
- func (*BootstrappingSnapshotInfo) Descriptor() ([]byte, []int)
- func (m *BootstrappingSnapshotInfo) GetLastBlockHash() []byte
- func (m *BootstrappingSnapshotInfo) GetLastBlockNum() uint64
- func (m *BootstrappingSnapshotInfo) GetPreviousBlockHash() []byte
- func (*BootstrappingSnapshotInfo) ProtoMessage()
- func (m *BootstrappingSnapshotInfo) Reset()
- func (m *BootstrappingSnapshotInfo) String() string
- func (m *BootstrappingSnapshotInfo) XXX_DiscardUnknown()
- func (m *BootstrappingSnapshotInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *BootstrappingSnapshotInfo) XXX_Merge(src proto.Message)
- func (m *BootstrappingSnapshotInfo) XXX_Size() int
- func (m *BootstrappingSnapshotInfo) XXX_Unmarshal(b []byte) error
- type Conf
- type IndexConfig
- type IndexableAttr
- type SnapshotInfo
- type TxIDIndexValue
- func (*TxIDIndexValue) Descriptor() ([]byte, []int)
- func (m *TxIDIndexValue) GetBlkLocation() []byte
- func (m *TxIDIndexValue) GetTxLocation() []byte
- func (m *TxIDIndexValue) GetTxValidationCode() int32
- func (*TxIDIndexValue) ProtoMessage()
- func (m *TxIDIndexValue) Reset()
- func (m *TxIDIndexValue) String() string
- func (m *TxIDIndexValue) XXX_DiscardUnknown()
- func (m *TxIDIndexValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *TxIDIndexValue) XXX_Merge(src proto.Message)
- func (m *TxIDIndexValue) XXX_Size() int
- func (m *TxIDIndexValue) XXX_Unmarshal(b []byte) error
Constants ¶
const ( IndexableAttrBlockNum = IndexableAttr("BlockNum") IndexableAttrBlockHash = IndexableAttr("BlockHash") IndexableAttrTxID = IndexableAttr("TxID") IndexableAttrBlockNumTranNum = IndexableAttr("BlockNumTranNum") )
constants for indexable attributes
const ( // ChainsDir is the name of the directory containing the channel ledgers. ChainsDir = "chains" // IndexDir is the name of the directory containing all block indexes across ledgers. IndexDir = "index" )
Variables ¶
var ( // ErrNotFoundInIndex is used to indicate missing entry in the index ErrNotFoundInIndex = ledger.NotFoundInIndexErr("") // ErrAttrNotIndexed is used to indicate that an attribute is not indexed ErrAttrNotIndexed = errors.New("attribute not indexed") )
var ErrUnexpectedEndOfBlockfile = errors.New("unexpected end of blockfile")
ErrUnexpectedEndOfBlockfile error used to indicate an unexpected end of a file segment this can happen mainly if a crash occurs during appending a block and partial block contents get written towards the end of the file
Functions ¶
func ClearPreResetHeight ¶ added in v1.5.6
ClearPreResetHeight deletes the files that contain the last recorded reset heights for the specified ledgers
func DeleteBlockStoreIndex ¶ added in v1.5.6
DeleteBlockStoreIndex deletes block store index file
func LoadPreResetHeight ¶ added in v1.5.6
LoadPreResetHeight searches the preResetHeight files for the specified ledgers and returns a map of channelname to the last recorded block height during one of the reset operations.
func ResetBlockStore ¶ added in v1.5.6
ResetBlockStore drops the block storage index and truncates the blocks files for all channels/ledgers to genesis blocks
func Rollback ¶ added in v1.5.6
func Rollback(blockStorageDir, ledgerID string, targetBlockNum uint64, indexConfig *IndexConfig) error
Rollback reverts changes made to the block store beyond a given block number.
func ValidateRollbackParams ¶ added in v1.5.6
ValidateRollbackParams performs necessary validation on the input given for the rollback operation.
Types ¶
type BlockStore ¶
type BlockStore struct {
// contains filtered or unexported fields
}
BlockStore - filesystem based implementation for `BlockStore`
func (*BlockStore) AddBlock ¶
func (store *BlockStore) AddBlock(block *common.Block) error
AddBlock adds a new block
func (*BlockStore) ExportTxIds ¶ added in v1.5.6
func (store *BlockStore) ExportTxIds(dir string, newHashFunc snapshot.NewHashFunc) (map[string][]byte, error)
ExportTxIds creates two files in the specified dir and returns a map that contains the mapping between the names of the files and their hashes. Technically, the TxIDs appear in the sort order of radix-sort/shortlex. However, since practically all the TxIDs are of same length, so the sort order would be the lexical sort order
func (*BlockStore) GetBlockchainInfo ¶
func (store *BlockStore) GetBlockchainInfo() (*common.BlockchainInfo, error)
GetBlockchainInfo returns the current info about blockchain
func (*BlockStore) RetrieveBlockByHash ¶
func (store *BlockStore) RetrieveBlockByHash(blockHash []byte) (*common.Block, error)
RetrieveBlockByHash returns the block for given block-hash
func (*BlockStore) RetrieveBlockByNumber ¶
func (store *BlockStore) RetrieveBlockByNumber(blockNum uint64) (*common.Block, error)
RetrieveBlockByNumber returns the block at a given blockchain height
func (*BlockStore) RetrieveBlockByTxID ¶
func (store *BlockStore) RetrieveBlockByTxID(txID string) (*common.Block, error)
RetrieveBlockByTxID returns the block for the specified txID
func (*BlockStore) RetrieveBlocks ¶
func (store *BlockStore) RetrieveBlocks(startNum uint64) (ledger.ResultsIterator, error)
RetrieveBlocks returns an iterator that can be used for iterating over a range of blocks
func (*BlockStore) RetrieveTxByBlockNumTranNum ¶
func (store *BlockStore) RetrieveTxByBlockNumTranNum(blockNum uint64, tranNum uint64) (*common.Envelope, error)
RetrieveTxByBlockNumTranNum returns a transaction for the given <blockNum, tranNum>
func (*BlockStore) RetrieveTxByID ¶
func (store *BlockStore) RetrieveTxByID(txID string) (*common.Envelope, error)
RetrieveTxByID returns a transaction for given transaction id
func (*BlockStore) RetrieveTxValidationCodeByTxID ¶
func (store *BlockStore) RetrieveTxValidationCodeByTxID(txID string) (peer.TxValidationCode, error)
RetrieveTxValidationCodeByTxID returns the validation code for the specified txID
func (*BlockStore) Shutdown ¶
func (store *BlockStore) Shutdown()
Shutdown shuts down the block store
type BlockStoreProvider ¶
type BlockStoreProvider struct {
// contains filtered or unexported fields
}
BlockStoreProvider provides handle to block storage - this is not thread-safe
func NewProvider ¶ added in v1.5.6
func NewProvider(conf *Conf, indexConfig *IndexConfig, metricsProvider metrics.Provider) (*BlockStoreProvider, error)
NewProvider constructs a filesystem based block store provider
func (*BlockStoreProvider) BootstrapFromSnapshottedTxIDs ¶ added in v1.5.6
func (p *BlockStoreProvider) BootstrapFromSnapshottedTxIDs( snapshotDir string, snapshotInfo *SnapshotInfo) (*BlockStore, error)
BootstrapFromSnapshottedTxIDs initializes blockstore from a previously generated snapshot Any failure during bootstrapping the blockstore may leave the partial loaded data on disk. The consumer, such as peer is expected to keep track of failures and cleanup the data explicitly.
func (*BlockStoreProvider) Close ¶
func (p *BlockStoreProvider) Close()
Close closes the BlockStoreProvider
func (*BlockStoreProvider) Exists ¶
func (p *BlockStoreProvider) Exists(ledgerid string) (bool, error)
Exists tells whether the BlockStore with given id exists
func (*BlockStoreProvider) List ¶
func (p *BlockStoreProvider) List() ([]string, error)
List lists the ids of the existing ledgers
func (*BlockStoreProvider) Open ¶ added in v1.5.6
func (p *BlockStoreProvider) Open(ledgerid string) (*BlockStore, error)
Open opens a block store for given ledgerid. If a blockstore is not existing, this method creates one This method should be invoked only once for a particular ledgerid
func (*BlockStoreProvider) Remove ¶ added in v1.5.6
func (p *BlockStoreProvider) Remove(ledgerid string) error
Remove block index and blocks for the given ledgerid (channelID). It is not an error if the channel does not exist. This function is not error safe. If this function returns an error or a crash takes place, it is highly likely that the data for this ledger is left in an inconsistent state. Opening the ledger again or reusing the previously opened ledger can show unknown behavior.
type BootstrappingSnapshotInfo ¶ added in v1.5.6
type BootstrappingSnapshotInfo struct { LastBlockNum uint64 `protobuf:"varint,1,opt,name=lastBlockNum,proto3" json:"lastBlockNum,omitempty"` LastBlockHash []byte `protobuf:"bytes,2,opt,name=lastBlockHash,proto3" json:"lastBlockHash,omitempty"` PreviousBlockHash []byte `protobuf:"bytes,3,opt,name=previousBlockHash,proto3" json:"previousBlockHash,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*BootstrappingSnapshotInfo) Descriptor ¶ added in v1.5.6
func (*BootstrappingSnapshotInfo) Descriptor() ([]byte, []int)
func (*BootstrappingSnapshotInfo) GetLastBlockHash ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) GetLastBlockHash() []byte
func (*BootstrappingSnapshotInfo) GetLastBlockNum ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) GetLastBlockNum() uint64
func (*BootstrappingSnapshotInfo) GetPreviousBlockHash ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) GetPreviousBlockHash() []byte
func (*BootstrappingSnapshotInfo) ProtoMessage ¶ added in v1.5.6
func (*BootstrappingSnapshotInfo) ProtoMessage()
func (*BootstrappingSnapshotInfo) Reset ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) Reset()
func (*BootstrappingSnapshotInfo) String ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) String() string
func (*BootstrappingSnapshotInfo) XXX_DiscardUnknown ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) XXX_DiscardUnknown()
func (*BootstrappingSnapshotInfo) XXX_Marshal ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*BootstrappingSnapshotInfo) XXX_Merge ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) XXX_Merge(src proto.Message)
func (*BootstrappingSnapshotInfo) XXX_Size ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) XXX_Size() int
func (*BootstrappingSnapshotInfo) XXX_Unmarshal ¶ added in v1.5.6
func (m *BootstrappingSnapshotInfo) XXX_Unmarshal(b []byte) error
type Conf ¶ added in v1.5.6
type Conf struct {
// contains filtered or unexported fields
}
Conf encapsulates all the configurations for `BlockStore`
type IndexConfig ¶
type IndexConfig struct {
AttrsToIndex []IndexableAttr
}
IndexConfig - a configuration that includes a list of attributes that should be indexed
func (*IndexConfig) Contains ¶ added in v1.5.6
func (c *IndexConfig) Contains(indexableAttr IndexableAttr) bool
Contains returns true iff the supplied parameter is present in the IndexConfig.AttrsToIndex
type SnapshotInfo ¶ added in v1.5.6
type SnapshotInfo struct { LedgerID string LastBlockNum uint64 LastBlockHash []byte PreviousBlockHash []byte }
SnapshotInfo captures some of the details about the snapshot
type TxIDIndexValue ¶ added in v1.5.6
type TxIDIndexValue struct { BlkLocation []byte `protobuf:"bytes,1,opt,name=blk_location,json=blkLocation,proto3" json:"blk_location,omitempty"` TxLocation []byte `protobuf:"bytes,2,opt,name=tx_location,json=txLocation,proto3" json:"tx_location,omitempty"` TxValidationCode int32 `protobuf:"varint,3,opt,name=tx_validation_code,json=txValidationCode,proto3" json:"tx_validation_code,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*TxIDIndexValue) Descriptor ¶ added in v1.5.6
func (*TxIDIndexValue) Descriptor() ([]byte, []int)
func (*TxIDIndexValue) GetBlkLocation ¶ added in v1.5.6
func (m *TxIDIndexValue) GetBlkLocation() []byte
func (*TxIDIndexValue) GetTxLocation ¶ added in v1.5.6
func (m *TxIDIndexValue) GetTxLocation() []byte
func (*TxIDIndexValue) GetTxValidationCode ¶ added in v1.5.6
func (m *TxIDIndexValue) GetTxValidationCode() int32
func (*TxIDIndexValue) ProtoMessage ¶ added in v1.5.6
func (*TxIDIndexValue) ProtoMessage()
func (*TxIDIndexValue) Reset ¶ added in v1.5.6
func (m *TxIDIndexValue) Reset()
func (*TxIDIndexValue) String ¶ added in v1.5.6
func (m *TxIDIndexValue) String() string
func (*TxIDIndexValue) XXX_DiscardUnknown ¶ added in v1.5.6
func (m *TxIDIndexValue) XXX_DiscardUnknown()
func (*TxIDIndexValue) XXX_Marshal ¶ added in v1.5.6
func (m *TxIDIndexValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*TxIDIndexValue) XXX_Merge ¶ added in v1.5.6
func (m *TxIDIndexValue) XXX_Merge(src proto.Message)
func (*TxIDIndexValue) XXX_Size ¶ added in v1.5.6
func (m *TxIDIndexValue) XXX_Size() int
func (*TxIDIndexValue) XXX_Unmarshal ¶ added in v1.5.6
func (m *TxIDIndexValue) XXX_Unmarshal(b []byte) error