filedao

package
v1.8.2-rc2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Apache-2.0 Imports: 35 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FileLegacyMaster    = "V1-master"
	FileLegacyAuxiliary = "V1-aux"
	FileV2              = "V2"
	FileAll             = "All"
)

constants

Variables

View Source
var (
	ErrFileNotExist     = errors.New("file does not exist")
	ErrFileCantAccess   = errors.New("cannot access file")
	ErrFileInvalid      = errors.New("file format is not valid")
	ErrNotSupported     = errors.New("feature not supported")
	ErrAlreadyExist     = errors.New("block already exist")
	ErrInvalidTipHeight = errors.New("invalid tip height")
	ErrDataCorruption   = errors.New("data is corrupted")
)

vars

Functions

func WriteHeaderV2

func WriteHeaderV2(kv db.KVStore, header *FileHeader) error

WriteHeaderV2 writes header to KVStore

func WriteTip

func WriteTip(kv db.KVStore, ns string, key []byte, tip *FileTip) error

WriteTip writes tip to KVStore

Types

type BaseFileDAO

type BaseFileDAO interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	Height() (uint64, error)
	GetBlockHash(uint64) (hash.Hash256, error)
	GetBlockHeight(hash.Hash256) (uint64, error)
	GetBlock(hash.Hash256) (*block.Block, error)
	GetBlockByHeight(uint64) (*block.Block, error)
	GetReceipts(uint64) ([]*action.Receipt, error)
	ContainsTransactionLog() bool
	TransactionLogs(uint64) (*iotextypes.TransactionLogs, error)
	PutBlock(context.Context, *block.Block) error
	DeleteTipBlock() error
}

BaseFileDAO represents the basic data access object

type FileDAO

type FileDAO interface {
	BaseFileDAO
	Header(hash.Hash256) (*block.Header, error)
	HeaderByHeight(uint64) (*block.Header, error)
	FooterByHeight(uint64) (*block.Footer, error)
}

FileDAO represents the data access object for managing block db file

func CreateFileDAO

func CreateFileDAO(legacy bool, cfg db.Config, deser *block.Deserializer) (FileDAO, error)

CreateFileDAO creates FileDAO according to master file

func NewFileDAO

func NewFileDAO(cfg db.Config, deser *block.Deserializer) (FileDAO, error)

NewFileDAO creates an instance of FileDAO

func NewFileDAOInMemForTest

func NewFileDAOInMemForTest() (FileDAO, error)

NewFileDAOInMemForTest creates an in-memory FileDAO for testing

type FileHeader

type FileHeader struct {
	Version        string
	Compressor     string
	BlockStoreSize uint64
	Start          uint64
}

FileHeader is header of chain db file

func DeserializeFileHeader

func DeserializeFileHeader(buf []byte) (*FileHeader, error)

DeserializeFileHeader deserializes byte-stream to FileHeader

func ReadHeaderLegacy

func ReadHeaderLegacy(kv *db.BoltDB) (*FileHeader, error)

ReadHeaderLegacy reads header from KVStore

func ReadHeaderV2

func ReadHeaderV2(kv db.KVStore) (*FileHeader, error)

ReadHeaderV2 reads header from KVStore

func (*FileHeader) Serialize

func (h *FileHeader) Serialize() ([]byte, error)

Serialize serializes FileHeader to byte-stream

type FileTip

type FileTip struct {
	Height uint64
	Hash   hash.Hash256
}

FileTip is tip info of chain

func DeserializeFileTip

func DeserializeFileTip(buf []byte) (*FileTip, error)

DeserializeFileTip deserializes byte-stream to FileTip

func ReadTip

func ReadTip(kv db.KVStore, ns string, key []byte) (*FileTip, error)

ReadTip reads tip from KVStore

func (*FileTip) Serialize

func (t *FileTip) Serialize() ([]byte, error)

Serialize serializes FileTip to byte-stream

type FileV2Manager

type FileV2Manager struct {
	Indices []*fileV2Index
}

FileV2Manager manages collection of v2 files

func (*FileV2Manager) AddFileDAO

func (fm *FileV2Manager) AddFileDAO(fd *fileDAOv2, start uint64) error

AddFileDAO add a new v2 file

func (*FileV2Manager) FileDAOByHeight

func (fm *FileV2Manager) FileDAOByHeight(height uint64) BaseFileDAO

FileDAOByHeight returns FileDAO for the given height

func (*FileV2Manager) GetBlock

func (fm *FileV2Manager) GetBlock(hash hash.Hash256) (*block.Block, error)

GetBlock returns block by hash

func (*FileV2Manager) GetBlockHeight

func (fm *FileV2Manager) GetBlockHeight(hash hash.Hash256) (uint64, error)

GetBlockHeight returns height by hash

func (*FileV2Manager) Start

func (fm *FileV2Manager) Start(ctx context.Context) error

Start starts the FileV2Manager

func (*FileV2Manager) Stop

func (fm *FileV2Manager) Stop(ctx context.Context) error

Stop stops the FileV2Manager

func (*FileV2Manager) TopFd

func (fm *FileV2Manager) TopFd() (BaseFileDAO, uint64)

TopFd returns the top (with maximum height) v2 file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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