blkstorage

package
v0.0.0-...-9b7ba46 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IndexableAttrBlockNum        = IndexableAttr("BlockNum")
	IndexableAttrBlockHash       = IndexableAttr("BlockHash")
	IndexableAttrTxID            = IndexableAttr("TxID")
	IndexableAttrBlockNumTranNum = IndexableAttr("BlockNumTranNum")
)

constants for indexable attributes

View Source
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

View Source
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

func ClearPreResetHeight(blockStorageDir string, ledgerIDs []string) error

ClearPreResetHeight deletes the files that contain the last recorded reset heights for the specified ledgers

func DeleteBlockStoreIndex

func DeleteBlockStoreIndex(blockStorageDir string) error

DeleteBlockStoreIndex deletes block store index file

func GetLedgersBootstrappedFromSnapshot

func GetLedgersBootstrappedFromSnapshot(blockStorageDir string) ([]string, error)

func IsBootstrappedFromSnapshot

func IsBootstrappedFromSnapshot(blockStorageDir, ledgerID string) (bool, error)

func LoadPreResetHeight

func LoadPreResetHeight(blockStorageDir string, ledgerIDs []string) (map[string]uint64, error)

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

func ResetBlockStore(blockStorageDir string) error

ResetBlockStore drops the block storage index and truncates the blocks files for all channels/ledgers to genesis blocks

func Rollback

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

func ValidateRollbackParams(blockStorageDir, ledgerID string, targetBlockNum uint64) error

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

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, uint64, error)

RetrieveTxValidationCodeByTxID returns validation code and blocknumber for the specified txID

func (*BlockStore) Shutdown

func (store *BlockStore) Shutdown()

Shutdown shuts down the block store

func (*BlockStore) TxIDExists

func (store *BlockStore) TxIDExists(txID string) (bool, error)

TxIDExists returns true if a transaction with the txID is ever committed

type BlockStoreProvider

type BlockStoreProvider struct {
	// contains filtered or unexported fields
}

BlockStoreProvider provides handle to block storage - this is not thread-safe

func NewProvider

func NewProvider(conf *Conf, indexConfig *IndexConfig, metricsProvider metrics.Provider) (*BlockStoreProvider, error)

NewProvider constructs a filesystem based block store provider

func (*BlockStoreProvider) Close

func (p *BlockStoreProvider) Close()

Close closes the BlockStoreProvider

func (*BlockStoreProvider) Drop

func (p *BlockStoreProvider) Drop(ledgerid string) error

Drop drops blockstore data (block index and blocks directory) 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.

func (*BlockStoreProvider) Exists

func (p *BlockStoreProvider) Exists(ledgerid string) (bool, error)

Exists tells whether the BlockStore with given id exists

func (*BlockStoreProvider) ImportFromSnapshot

func (p *BlockStoreProvider) ImportFromSnapshot(
	ledgerID string,
	snapshotDir string,
	snapshotInfo *SnapshotInfo,
) error

ImportFromSnapshot 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) List

func (p *BlockStoreProvider) List() ([]string, error)

List lists the ids of the existing ledgers

func (*BlockStoreProvider) Open

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

type BootstrappingSnapshotInfo

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

func (*BootstrappingSnapshotInfo) Descriptor() ([]byte, []int)

func (*BootstrappingSnapshotInfo) GetLastBlockHash

func (m *BootstrappingSnapshotInfo) GetLastBlockHash() []byte

func (*BootstrappingSnapshotInfo) GetLastBlockNum

func (m *BootstrappingSnapshotInfo) GetLastBlockNum() uint64

func (*BootstrappingSnapshotInfo) GetPreviousBlockHash

func (m *BootstrappingSnapshotInfo) GetPreviousBlockHash() []byte

func (*BootstrappingSnapshotInfo) ProtoMessage

func (*BootstrappingSnapshotInfo) ProtoMessage()

func (*BootstrappingSnapshotInfo) Reset

func (m *BootstrappingSnapshotInfo) Reset()

func (*BootstrappingSnapshotInfo) String

func (m *BootstrappingSnapshotInfo) String() string

func (*BootstrappingSnapshotInfo) XXX_DiscardUnknown

func (m *BootstrappingSnapshotInfo) XXX_DiscardUnknown()

func (*BootstrappingSnapshotInfo) XXX_Marshal

func (m *BootstrappingSnapshotInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BootstrappingSnapshotInfo) XXX_Merge

func (m *BootstrappingSnapshotInfo) XXX_Merge(src proto.Message)

func (*BootstrappingSnapshotInfo) XXX_Size

func (m *BootstrappingSnapshotInfo) XXX_Size() int

func (*BootstrappingSnapshotInfo) XXX_Unmarshal

func (m *BootstrappingSnapshotInfo) XXX_Unmarshal(b []byte) error

type Conf

type Conf struct {
	// contains filtered or unexported fields
}

Conf encapsulates all the configurations for `BlockStore`

func NewConf

func NewConf(blockStorageDir string, maxBlockfileSize int) *Conf

NewConf constructs new `Conf`. blockStorageDir is the top level folder under which `BlockStore` manages its data

type IndexConfig

type IndexConfig struct {
	AttrsToIndex []IndexableAttr
}

IndexConfig - a configuration that includes a list of attributes that should be indexed

func (*IndexConfig) Contains

func (c *IndexConfig) Contains(indexableAttr IndexableAttr) bool

Contains returns true iff the supplied parameter is present in the IndexConfig.AttrsToIndex

type IndexableAttr

type IndexableAttr string

IndexableAttr represents an indexable attribute

type SnapshotInfo

type SnapshotInfo struct {
	LastBlockNum      uint64
	LastBlockHash     []byte
	PreviousBlockHash []byte
}

SnapshotInfo captures some of the details about the snapshot

type TxIDIndexValue

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

func (*TxIDIndexValue) Descriptor() ([]byte, []int)

func (*TxIDIndexValue) GetBlkLocation

func (m *TxIDIndexValue) GetBlkLocation() []byte

func (*TxIDIndexValue) GetTxLocation

func (m *TxIDIndexValue) GetTxLocation() []byte

func (*TxIDIndexValue) GetTxValidationCode

func (m *TxIDIndexValue) GetTxValidationCode() int32

func (*TxIDIndexValue) ProtoMessage

func (*TxIDIndexValue) ProtoMessage()

func (*TxIDIndexValue) Reset

func (m *TxIDIndexValue) Reset()

func (*TxIDIndexValue) String

func (m *TxIDIndexValue) String() string

func (*TxIDIndexValue) XXX_DiscardUnknown

func (m *TxIDIndexValue) XXX_DiscardUnknown()

func (*TxIDIndexValue) XXX_Marshal

func (m *TxIDIndexValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TxIDIndexValue) XXX_Merge

func (m *TxIDIndexValue) XXX_Merge(src proto.Message)

func (*TxIDIndexValue) XXX_Size

func (m *TxIDIndexValue) XXX_Size() int

func (*TxIDIndexValue) XXX_Unmarshal

func (m *TxIDIndexValue) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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