blockstore

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	SkipListBase = uint64(2)
)

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

View Source
var File_block_txs_id_proto protoreflect.FileDescriptor
View Source
var File_location_proto protoreflect.FileDescriptor

Functions

func CalculateSkipListLinks(blockNum uint64) []uint64

func ComputeBlockBaseHash

func ComputeBlockBaseHash(block *types.Block) ([]byte, error)

ComputeBlockBaseHash returns block hash before all validation and state data was updated. Currently block header base hash is considered block hash, because it contains all crypto related information, like Tx Merkle tree root and hash of previous block before validation as well

func ComputeBlockHash

func ComputeBlockHash(block *types.Block) ([]byte, error)

ComputeBlockHash returns block hash. Currently block header hash is considered block hash, because it contains all crypto related information, like Merkle tree root(s) and Merkle list and skip list hashes.

Types

type BlockLocation

type BlockLocation struct {
	FileChunkNum uint64 `protobuf:"varint,1,opt,name=file_chunk_num,json=fileChunkNum,proto3" json:"file_chunk_num,omitempty"`
	Offset       int64  `protobuf:"varint,2,opt,name=offset,proto3" json:"offset,omitempty"`
	Length       int64  `protobuf:"varint,3,opt,name=length,proto3" json:"length,omitempty"`
	// contains filtered or unexported fields
}

func (*BlockLocation) Descriptor deprecated

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

Deprecated: Use BlockLocation.ProtoReflect.Descriptor instead.

func (*BlockLocation) GetFileChunkNum

func (x *BlockLocation) GetFileChunkNum() uint64

func (*BlockLocation) GetLength

func (x *BlockLocation) GetLength() int64

func (*BlockLocation) GetOffset

func (x *BlockLocation) GetOffset() int64

func (*BlockLocation) ProtoMessage

func (*BlockLocation) ProtoMessage()

func (*BlockLocation) ProtoReflect added in v0.2.6

func (x *BlockLocation) ProtoReflect() protoreflect.Message

func (*BlockLocation) Reset

func (x *BlockLocation) Reset()

func (*BlockLocation) String

func (x *BlockLocation) String() string

type BlockTxIDs

type BlockTxIDs struct {
	TxIds []string `protobuf:"bytes,1,rep,name=tx_ids,json=txIds,proto3" json:"tx_ids,omitempty"`
	// contains filtered or unexported fields
}

func (*BlockTxIDs) Descriptor deprecated

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

Deprecated: Use BlockTxIDs.ProtoReflect.Descriptor instead.

func (*BlockTxIDs) GetTxIds

func (x *BlockTxIDs) GetTxIds() []string

func (*BlockTxIDs) ProtoMessage

func (*BlockTxIDs) ProtoMessage()

func (*BlockTxIDs) ProtoReflect added in v0.2.6

func (x *BlockTxIDs) ProtoReflect() protoreflect.Message

func (*BlockTxIDs) Reset

func (x *BlockTxIDs) Reset()

func (*BlockTxIDs) String

func (x *BlockTxIDs) String() string

type Config

type Config struct {
	StoreDir string
	Logger   *logger.SugarLogger
}

Config holds the configuration of a block store

type Store

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

Store maintains a chain of blocks in an append-only filesystem

func Open

func Open(c *Config) (*Store, error)

Open opens the store to maintains a chain of blocks

func (s *Store) AddSkipListLinks(block *types.Block) error

AddSkipListLinks calculated and add skip list block number to the block

func (*Store) Close

func (s *Store) Close() error

Close closes the store

func (*Store) Commit

func (s *Store) Commit(block *types.Block) error

Commit commits the block to the block store

func (*Store) DoesTxIDExist

func (s *Store) DoesTxIDExist(txID string) (bool, error)

DoesTxIDExist returns true if any of the committed block has a transaction with the given txID. Otherwise, it returns false

func (*Store) Get

func (s *Store) Get(blockNumber uint64) (*types.Block, error)

Get returns the requested block

func (*Store) GetAugmentedHeader

func (s *Store) GetAugmentedHeader(blockNumber uint64) (*types.AugmentedBlockHeader, error)

GetAugmentedHeader returns block header with slice of block tx ids

func (*Store) GetBaseHeaderHash

func (s *Store) GetBaseHeaderHash(blockNumber uint64) ([]byte, error)

GetBaseHeaderHash returns block header base hash by block number

func (*Store) GetHash

func (s *Store) GetHash(blockNumber uint64) ([]byte, error)

GetHash returns block hash by block number

func (*Store) GetHeader

func (s *Store) GetHeader(blockNumber uint64) (*types.BlockHeader, error)

GetHeader returns block header by block number, operation should be faster that regular Get, because it requires only one db access, without file reads

func (*Store) GetHeaderByHash

func (s *Store) GetHeaderByHash(blockHash []byte) (*types.BlockHeader, error)

GetHeaderByHash returns block header by block hash, used for travel in Merkle list or Merkle skip list

func (*Store) GetTxInfo added in v0.2.5

func (s *Store) GetTxInfo(txID string) (*TxInfo, error)

GetTxInfo returns the TxInfo associated with a given txID

func (*Store) GetValidationInfo

func (s *Store) GetValidationInfo(txID string) (*types.ValidationInfo, error)

GetValidationInfo returns the validation info associated with a given txID

func (*Store) Height

func (s *Store) Height() (uint64, error)

Height returns the height of the block store, i.e., the last committed block number

type TxInfo added in v0.2.5

type TxInfo struct {
	BlockNumber uint64                `protobuf:"varint,1,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"`
	TxIndex     uint64                `protobuf:"varint,2,opt,name=tx_index,json=txIndex,proto3" json:"tx_index,omitempty"`
	Validation  *types.ValidationInfo `protobuf:"bytes,3,opt,name=validation,proto3" json:"validation,omitempty"`
	// contains filtered or unexported fields
}

func (*TxInfo) Descriptor deprecated added in v0.2.5

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

Deprecated: Use TxInfo.ProtoReflect.Descriptor instead.

func (*TxInfo) GetBlockNumber added in v0.2.5

func (x *TxInfo) GetBlockNumber() uint64

func (*TxInfo) GetTxIndex added in v0.2.5

func (x *TxInfo) GetTxIndex() uint64

func (*TxInfo) GetValidation added in v0.2.5

func (x *TxInfo) GetValidation() *types.ValidationInfo

func (*TxInfo) ProtoMessage added in v0.2.5

func (*TxInfo) ProtoMessage()

func (*TxInfo) ProtoReflect added in v0.2.6

func (x *TxInfo) ProtoReflect() protoreflect.Message

func (*TxInfo) Reset added in v0.2.5

func (x *TxInfo) Reset()

func (*TxInfo) String added in v0.2.5

func (x *TxInfo) String() string

Jump to

Keyboard shortcuts

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