ldb

package
v0.0.0-...-43c3cf5 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

This file is only used to check data correctness for 1.1.0

Index

Constants

View Source
const (
	UnknownHeight = math.MaxUint64
)

Variables

View Source
var (
	ErrUpgradeHeight     = errors.New("upgrade error: height")
	ErrUpgradeBlockHash  = errors.New("upgrade error: block hash")
	ErrUpgradeFileNumber = errors.New("upgrade error: file number")
)
View Source
var (
	ErrWrongScriptHashLength  = errors.New("length of script hash error")
	ErrBindingIndexBroken     = errors.New("binding transaction index was broken")
	ErrIncorrectDbData        = errors.New("incorrect db data")
	ErrCheckStakingDuplicated = errors.New("duplicated staking")

	// errors for submit.go
	ErrPreBatchNotReady    = errors.New("previous batch is not ready")
	ErrUnrelatedBatch      = errors.New("unrelated batch to be submitted")
	ErrCommitHashNotEqual  = errors.New("commit hash is not equal to batch hash")
	ErrCommitBatchNotReady = errors.New("commit batch is not ready")

	// errors for binding transaction index
	ErrWrongBindingTxIndexLen         = errors.New("length of binding tx index is invalid")
	ErrWrongBindingTxIndexPrefix      = errors.New("prefix of binding tx index is invalid")
	ErrWrongBindingShIndexLen         = errors.New("length of binding sh index is invalid")
	ErrWrongBindingShIndexPrefix      = errors.New("prefix of binding sh index is invalid")
	ErrWrongBindingTxSpentIndexLen    = errors.New("length of binding tx spent index is invalid")
	ErrWrongBindingTxSpentIndexPrefix = errors.New("prefix of binding tx spent index is invalid")

	// for disk file
	ErrInvalidBlockFileMeta = errors.New("invalid blockfile meta")
	ErrIncorrectValueLength = errors.New("incorrect value length")
	ErrIncorrectValue       = errors.New("incorrect value")
)
View Source
var (
	PUBLICKEYLENGTH_MASS = 33
	PUBLICKEYLENGTH_CHIA = 48
)
View Source
var (
	ErrCheckStakingDeletion = errors.New("failed to delete staking")
)

Functions

This section is empty.

Types

type ChainDb

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

ChainDb holds internal state for databse.

func NewChainDb

func NewChainDb(dbpath string, stor storage.Storage) (*ChainDb, error)

func (*ChainDb) Batch

func (db *ChainDb) Batch(index int) *LBatch

func (*ChainDb) CheckBindingIndex

func (db *ChainDb) CheckBindingIndex(rebuild bool) error

func (*ChainDb) CheckScriptHashUsed

func (db *ChainDb) CheckScriptHashUsed(scriptHash []byte) (bool, error)

func (*ChainDb) CheckStakingTxIndex

func (db *ChainDb) CheckStakingTxIndex(rebuild bool) error

func (*ChainDb) CheckTxIndex_1_1_0

func (db *ChainDb) CheckTxIndex_1_1_0() error

func (*ChainDb) Close

func (db *ChainDb) Close() error

Close cleanly shuts down database, syncing all data.

func (*ChainDb) Commit

func (db *ChainDb) Commit(hash wire.Hash) error

func (*ChainDb) CountByPrefix

func (db *ChainDb) CountByPrefix(prefix string) (num, size int)

func (*ChainDb) CountByPrefixForNew

func (db *ChainDb) CountByPrefixForNew(prefix string) (num, size int)

func (*ChainDb) DeleteAddrIndex

func (db *ChainDb) DeleteAddrIndex(hash *wire.Hash, height uint64) error

func (*ChainDb) DeleteBlock

func (db *ChainDb) DeleteBlock(hash *wire.Hash) error

func (*ChainDb) ExistsFaultPk

func (db *ChainDb) ExistsFaultPk(sha *wire.Hash) (bool, error)

ExistsFaultPk - check whether a specific PubKey has been banned, returns true if banned

func (*ChainDb) ExistsPunishment

func (db *ChainDb) ExistsPunishment(pk interfaces.PublicKey) (bool, error)

func (*ChainDb) ExistsSha

func (db *ChainDb) ExistsSha(sha *wire.Hash) (bool, error)

ExistsSha looks up the given block hash returns true if it is present in the database.

func (*ChainDb) ExistsTxSha

func (db *ChainDb) ExistsTxSha(txsha *wire.Hash) (bool, error)

ExistsTxSha returns if the given tx sha exists in the database

func (*ChainDb) FetchAddrIndexTip

func (db *ChainDb) FetchAddrIndexTip() (*wire.Hash, uint64, error)

FetchAddrIndexTip returns the hash and block height of the most recent block whose transactions have been indexed by address. It will return ErrAddrIndexDoesNotExist along with a zero hash, and UnknownHeight if the addrIndex hasn't yet been built up.

func (*ChainDb) FetchAllFaultPks

func (db *ChainDb) FetchAllFaultPks() ([]*wire.FaultPubKey, []uint64, error)

func (*ChainDb) FetchAllPunishment

func (db *ChainDb) FetchAllPunishment() ([]*wire.FaultPubKey, error)

func (*ChainDb) FetchBlockBySha

func (db *ChainDb) FetchBlockBySha(sha *wire.Hash) (blk *massutil.Block, err error)

FetchBlockBySha - return a massutil Block

func (*ChainDb) FetchBlockHeaderBySha

func (db *ChainDb) FetchBlockHeaderBySha(sha *wire.Hash) (bh *wire.BlockHeader, err error)

FetchBlockHeaderBySha - return a Hash

func (*ChainDb) FetchBlockHeightBySha

func (db *ChainDb) FetchBlockHeightBySha(sha *wire.Hash) (uint64, error)

FetchBlockHeightBySha returns the block height for the given hash. This is part of the database.Db interface implementation.

func (*ChainDb) FetchBlockLocByHeight

func (db *ChainDb) FetchBlockLocByHeight(height uint64) (*database.BlockLoc, error)

func (*ChainDb) FetchBlockShaByHeight

func (db *ChainDb) FetchBlockShaByHeight(height uint64) (sha *wire.Hash, err error)

FetchBlockShaByHeight returns a block hash based on its height in the block chain.

func (*ChainDb) FetchExpiredStakingTxListByHeight

func (db *ChainDb) FetchExpiredStakingTxListByHeight(expiredHeight uint64) (database.StakingNodes, error)

func (*ChainDb) FetchFaultPkBySha

func (db *ChainDb) FetchFaultPkBySha(sha *wire.Hash) (fpk *wire.FaultPubKey, height uint64, err error)

FetchFaultPkBySha - return a banned pubKey along with corresponding testimony

func (*ChainDb) FetchFaultPkListByHeight

func (db *ChainDb) FetchFaultPkListByHeight(blkHeight uint64) ([]*wire.FaultPubKey, error)

FetchFaultPkListByHeight - return newly banned PubKey list on specific height

func (*ChainDb) FetchHeightRange

func (db *ChainDb) FetchHeightRange(startHeight, endHeight uint64) ([]wire.Hash, error)

FetchHeightRange looks up a range of blocks by the start and ending heights. Fetch is inclusive of the start height and exclusive of the ending height.

func (*ChainDb) FetchLastFullySpentTxBeforeHeight

func (db *ChainDb) FetchLastFullySpentTxBeforeHeight(txsha *wire.Hash,
	height uint64) (msgtx *wire.MsgTx, blkHeight uint64, blksha *wire.Hash, err error)

Returns database.ErrTxShaMissing if txsha not exist

func (*ChainDb) FetchMinedBlocks

func (db *ChainDb) FetchMinedBlocks(pubKey interfaces.PublicKey) ([]uint64, error)

func (*ChainDb) FetchOldBinding

func (db *ChainDb) FetchOldBinding(scriptHash []byte) ([]*database.BindingTxReply, error)

func (*ChainDb) FetchScriptHashRelatedTx

func (db *ChainDb) FetchScriptHashRelatedTx(
	scriptHashes [][]byte,
	startBlock, stopBlock uint64,
) (map[uint64][]*wire.TxLoc, error)

from start to stop-1

func (*ChainDb) FetchStakingRank

func (db *ChainDb) FetchStakingRank(height uint64, onlyOnList bool) ([]database.Rank, error)

FetchStakingRank returns staking rank at any height. This function may be slow.

func (*ChainDb) FetchStakingTxMap

func (db *ChainDb) FetchStakingTxMap() (database.StakingNodes, error)

func (*ChainDb) FetchTxByFileLoc

func (db *ChainDb) FetchTxByFileLoc(blkLoc *database.BlockLoc, txLoc *wire.TxLoc) (*wire.MsgTx, error)

func (*ChainDb) FetchTxByLoc

func (db *ChainDb) FetchTxByLoc(blkHeight uint64, txOff int, txLen int) (*wire.MsgTx, error)

func (*ChainDb) FetchTxBySha

func (db *ChainDb) FetchTxBySha(txsha *wire.Hash) ([]*database.TxReply, error)

FetchTxBySha returns some data for the given Tx Sha. Be careful, main chain may be revoked during invocation.

func (*ChainDb) FetchTxByShaList

func (db *ChainDb) FetchTxByShaList(txShaList []*wire.Hash) []*database.TxReply

FetchTxByShaList returns the most recent tx of the name fully spent or not

func (*ChainDb) FetchUnSpentTxByShaList

func (db *ChainDb) FetchUnSpentTxByShaList(txShaList []*wire.Hash) []*database.TxReply

FetchUnSpentTxByShaList given a array of Hash, look up the transactions and return them in a TxReply array.

func (*ChainDb) FetchUnexpiredStakingRank

func (db *ChainDb) FetchUnexpiredStakingRank(height uint64, onlyOnList bool) ([]database.Rank, error)

FetchUnexpiredStakingRank returns only currently unexpired staking rank at target height. This function is for mining and validating block.

func (*ChainDb) ForEach

func (db *ChainDb) ForEach(prefix string, callback func(k, v []byte) error) error

func (*ChainDb) Get

func (db *ChainDb) Get(key []byte) ([]byte, error)

func (*ChainDb) GetAllStaking

func (db *ChainDb) GetAllStaking() (database.StakingNodes, database.StakingNodes, error)

func (*ChainDb) GetBlkLocByHeight

func (db *ChainDb) GetBlkLocByHeight(height uint64) (sha *wire.Hash, fileNo uint32, offset int64, size int64, err error)

func (*ChainDb) GetUnspentTxData

func (db *ChainDb) GetUnspentTxData(txsha *wire.Hash) (uint64, int, int, error)

func (*ChainDb) InitByGenesisBlock

func (db *ChainDb) InitByGenesisBlock(block *massutil.Block) error

func (*ChainDb) InsertPunishment

func (db *ChainDb) InsertPunishment(fpk *wire.FaultPubKey) error

func (*ChainDb) NewestSha

func (db *ChainDb) NewestSha() (rSha *wire.Hash, rBlkHeight uint64, err error)

NewestSha returns the hash and block height of the most recent (end) block of the block chain. It will return the zero hash, UnknownHeight for the block height, and no error (nil) if there are not any blocks in the database yet.

func (*ChainDb) Rollback

func (db *ChainDb) Rollback()

func (*ChainDb) RollbackClose

func (db *ChainDb) RollbackClose() error

RollbackClose this is part of the database.Db interface and should discard recent changes to the db and the close the db. This currently just does a clean shutdown.

func (*ChainDb) SubmitAddrIndex

func (db *ChainDb) SubmitAddrIndex(hash *wire.Hash, height uint64, addrIndexData *database.AddrIndexData) error

func (*ChainDb) SubmitBlock

func (db *ChainDb) SubmitBlock(block *massutil.Block) error

func (*ChainDb) Sync

func (db *ChainDb) Sync() error

Sync verifies that the database is coherent on disk, and no outstanding transactions are in flight.

func (*ChainDb) TestExportDbEntries

func (db *ChainDb) TestExportDbEntries() map[string][]byte

For testing purpose

func (*ChainDb) Upgrade_1_1_0

func (db *ChainDb) Upgrade_1_1_0() error

type LBatch

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

LBatch represents batch for submitting block/addrIndex

func NewLBatch

func NewLBatch(batch storage.Batch) *LBatch

func (*LBatch) Batch

func (b *LBatch) Batch() storage.Batch

func (*LBatch) Done

func (b *LBatch) Done()

func (*LBatch) Reset

func (b *LBatch) Reset()

func (*LBatch) Set

func (b *LBatch) Set(block wire.Hash)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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