ldb

package
v0.0.0-...-163fc3c Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

 LSN  (log sequence number)

	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")
)

Functions

This section is empty.

Types

type ChainDb

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

ChainDb holds internal state for database.

func NewChainDb

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

func (*ChainDb) Batch

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

func (*ChainDb) CheckScriptHashUsed

func (db *ChainDb) CheckScriptHashUsed(scriptHash []byte) (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(blockSha wire.Hash) error

func (*ChainDb) DeleteAddrIndex

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

func (*ChainDb) DeleteBlock

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

func (*ChainDb) ExistsBlockSha

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

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

func (*ChainDb) ExistsFaultPubKey

func (db *ChainDb) ExistsFaultPubKey(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 *pocec.PublicKey) (bool, error)

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) ExportDbEntries

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

For testing purpose

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) FetchAllFaultPubKeys

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

func (*ChainDb) FetchAllPunishment

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

func (*ChainDb) FetchBlockBySha

func (db *ChainDb) FetchBlockBySha(sha *wire.Hash) (block *chainutil.Block, err error)

FetchBlockBySha - return a 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(blockSha *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)

FetchBlockLocByHeight

func (*ChainDb) FetchBlockShaByHeight

func (db *ChainDb) FetchBlockShaByHeight(height uint64) (rawBlockSha *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) FetchFaultPubKeyBySha

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

FetchFaultPkBySha - return a banned pubKey along with corresponding testimony

func (*ChainDb) FetchFaultPubKeyListByHeight

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

FetchFaultPkListByHeight - return newly banned PubKey list on specific height

func (*ChainDb) FetchGovernConfigData

func (db *ChainDb) FetchGovernConfigData(id uint16, height uint64, includeShadow bool) ([]*database.GovernConfigData, error)

FetchGovernConfigData fetch all config

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, blockHeight uint64, blockSha *wire.Hash, err error)

Returns database.ErrTxShaMissing if txsha not exist

func (*ChainDb) FetchMinedBlocks

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

func (*ChainDb) FetchScriptHashRelatedBindingTx

func (db *ChainDb) FetchScriptHashRelatedBindingTx(scriptHash []byte, chainParams *config.Params) ([]*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) FetchStakingAwardedRecordByTime

func (db *ChainDb) FetchStakingAwardedRecordByTime(queryTime uint64) ([]database.StakingAwardedRecord, error)

FetchStakingAwardedRecordByTime +-----------+-----------+--------------+ +-----------+ | prefix(3) | day(8) | TxId(32) | ->| timestamp | +-----------+-----------+--------------+ +-----------+

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) FetchStakingStakingRewardInfo

func (db *ChainDb) FetchStakingStakingRewardInfo(height uint64) (*database.StakingRewardInfo, error)

func (*ChainDb) FetchStakingTxMap

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

func (*ChainDb) FetchTxByFileLoc

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

func (*ChainDb) FetchTxByLoc

func (db *ChainDb) FetchTxByLoc(blockHeight 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) FetchUnSpentStaking

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

func (*ChainDb) FetchUnSpentStakingPoolTxOutByHeight

func (db *ChainDb) FetchUnSpentStakingPoolTxOutByHeight(startHeight uint64, endHeight uint64) ([]*database.TxOutReply, error)

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) GetPubkeyBLHeightRecord

func (db *ChainDb) GetPubkeyBLHeightRecord(publicKey *pocec.PublicKey) ([]*database.BLHeight, error)

func (*ChainDb) GetUnspentTxData

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

func (*ChainDb) IndexPubKeyBLHeight

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

transition code that will be removed soon

func (*ChainDb) InitByGenesisBlock

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

func (*ChainDb) InsertGovernConfig

func (db *ChainDb) InsertGovernConfig(id uint16, height, activeHeight uint64, shadow bool, txSha *wire.Hash, data []byte) error

func (*ChainDb) InsertPunishment

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

func (*ChainDb) IsTxOutSpent

func (db *ChainDb) IsTxOutSpent(txSha *wire.Hash, index int) (bool, error)

IsTxOutSpent index --> 32 bits +------------------------------------------------------ | index | spent flag offset ( 8 bits ) | +-----------------------------------------------------+

txSpent
index(offset) --> spent

+-----------------------------------------------------+ | 1 | 0 | | +-----------------------------------------------------+

func (*ChainDb) NewestSha

func (db *ChainDb) NewestSha() (rawBlockSha *wire.Hash, rawBlockHeight 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 *chainutil.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) 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