ledgerstore

package
v0.0.0-...-ef73a9a Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: LGPL-3.0 Imports: 49 Imported by: 0

Documentation

Overview

  • Copyright (C) 2018 The ontology Authors

  • This file is part of The ontology library. *

  • The ontology is free software: you can redistribute it and/or modify

  • it under the terms of the GNU Lesser General Public License as published by

  • the Free Software Foundation, either version 3 of the License, or

  • (at your option) any later version. *

  • The ontology is distributed in the hope that it will be useful,

  • but WITHOUT ANY WARRANTY; without even the implied warranty of

  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

  • GNU Lesser General Public License for more details. *

  • You should have received a copy of the GNU Lesser General Public License

  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

  • Copyright (C) 2018 The ontology Authors

  • This file is part of The ontology library. *

  • The ontology is free software: you can redistribute it and/or modify

  • it under the terms of the GNU Lesser General Public License as published by

  • the Free Software Foundation, either version 3 of the License, or

  • (at your option) any later version. *

  • The ontology is distributed in the hope that it will be useful,

  • but WITHOUT ANY WARRANTY; without even the implied warranty of

  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

  • GNU Lesser General Public License for more details. *

  • You should have received a copy of the GNU Lesser General Public License

  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

Storage of ledger

Index

Constants

View Source
const (
	BLOCK_CAHE_SIZE        = 10    //Block cache size
	TRANSACTION_CACHE_SIZE = 10000 //Transaction cache size
)
View Source
const (
	SYSTEM_VERSION          = byte(1)      //Version of ledger store
	HEADER_INDEX_BATCH_SIZE = uint32(2000) //Bath size of saving header index

)
View Source
const (
	DBDirCrossChain = "crosschain"
)

Variables

View Source
var (
	//Storage save path.
	DBDirEvent          = "ledgerevent"
	DBDirBlock          = "block"
	DBDirState          = "states"
	MerkleTreeStorePath = "merkle_tree.db"
	StateTreeDb         = "state_avl"
)
View Source
var (
	BOOKKEEPER = []byte("Bookkeeper") //Bookkeeper store key
)

Functions

func SaveNotify

func SaveNotify(eventStore scommon.EventStore, txHash common.Uint256, notify *event.ExecuteNotify) error

Types

type BlockCache

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

BlockCache with block cache and transaction hash

func NewBlockCache

func NewBlockCache() (*BlockCache, error)

NewBlockCache return BlockCache instance

func (*BlockCache) AddBlock

func (this *BlockCache) AddBlock(block *types.Block)

AddBlock to cache

func (*BlockCache) AddTransaction

func (this *BlockCache) AddTransaction(tx *types.Transaction, height uint32)

AddTransaction add transaction to block cache

func (*BlockCache) ContainBlock

func (this *BlockCache) ContainBlock(blockHash common.Uint256) bool

ContainBlock return whether block is in cache

func (*BlockCache) ContainTransaction

func (this *BlockCache) ContainTransaction(txHash common.Uint256) bool

ContainTransaction return whether transaction is in cache

func (*BlockCache) GetBlock

func (this *BlockCache) GetBlock(blockHash common.Uint256) *types.Block

GetBlock return block by block hash from cache

func (*BlockCache) GetTransaction

func (this *BlockCache) GetTransaction(txHash common.Uint256) (*types.Transaction, uint32)

GetTransaction return transaction by transaction hash from cache

type BlockStore

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

Block store save the data of block & transaction

func NewBlockStore

func NewBlockStore(dbDir string, enableCache bool) (*BlockStore, error)

NewBlockStore return the block store instance

func (*BlockStore) ClearAll

func (this *BlockStore) ClearAll() error

ClearAll clear all the data of block store

func (*BlockStore) Close

func (this *BlockStore) Close() error

Close block store

func (*BlockStore) CommitTo

func (this *BlockStore) CommitTo() error

CommitTo commit the batch to store

func (*BlockStore) ContainBlock

func (this *BlockStore) ContainBlock(blockHash common.Uint256) (bool, error)

ContainBlock return the block specified by block hash save in store

func (*BlockStore) ContainTransaction

func (this *BlockStore) ContainTransaction(txHash common.Uint256) (bool, error)

IsContainTransaction return whether the transaction is in store

func (*BlockStore) GetBlock

func (this *BlockStore) GetBlock(blockHash common.Uint256) (*types.Block, error)

GetBlock return block by block hash

func (*BlockStore) GetBlockHash

func (this *BlockStore) GetBlockHash(height uint32) (common.Uint256, error)

GetBlockHash return block hash by block height

func (*BlockStore) GetBlockPrunedHeight

func (this *BlockStore) GetBlockPrunedHeight() (uint32, error)

func (*BlockStore) GetCurrentBlock

func (this *BlockStore) GetCurrentBlock() (common.Uint256, uint32, error)

GetCurrentBlock return the current block hash and current block height

func (*BlockStore) GetHeader

func (this *BlockStore) GetHeader(blockHash common.Uint256) (*types.Header, error)

GetHeader return the header specified by block hash

func (*BlockStore) GetHeaderIndexList

func (this *BlockStore) GetHeaderIndexList() (map[uint32]common.Uint256, error)

GetHeaderIndexList return the head index store in header index list

func (*BlockStore) GetRawHeader

func (this *BlockStore) GetRawHeader(blockHash common.Uint256) (*types.RawHeader, error)

func (*BlockStore) GetSysFeeAmount

func (this *BlockStore) GetSysFeeAmount(blockHash common.Uint256) (common.Fixed64, error)

GetSysFeeAmount return the sys fee for block by block hash

func (*BlockStore) GetTransaction

func (this *BlockStore) GetTransaction(txHash common.Uint256) (*types.Transaction, uint32, error)

GetTransaction return transaction by transaction hash

func (*BlockStore) GetVersion

func (this *BlockStore) GetVersion() (byte, error)

GetVersion return the version of store

func (*BlockStore) NewBatch

func (this *BlockStore) NewBatch()

NewBatch start a commit batch

func (*BlockStore) PruneBlock

func (this *BlockStore) PruneBlock(hash common.Uint256) []common.Uint256

func (*BlockStore) SaveBlock

func (this *BlockStore) SaveBlock(block *types.Block) error

SaveBlock persist block to store

func (*BlockStore) SaveBlockHash

func (this *BlockStore) SaveBlockHash(height uint32, blockHash common.Uint256)

SaveBlockHash persist block height and block hash to store

func (*BlockStore) SaveBlockPrunedHeight

func (this *BlockStore) SaveBlockPrunedHeight(height uint32)

func (*BlockStore) SaveCurrentBlock

func (this *BlockStore) SaveCurrentBlock(height uint32, blockHash common.Uint256) error

SaveCurrentBlock persist the current block height and current block hash to store

func (*BlockStore) SaveHeader

func (this *BlockStore) SaveHeader(block *types.Block, sysFee common.Fixed64) error

SaveHeader persist block header to store

func (*BlockStore) SaveHeaderIndexList

func (this *BlockStore) SaveHeaderIndexList(startIndex uint32, indexList []common.Uint256)

SaveHeaderIndexList persist header index list to store

func (*BlockStore) SaveTransaction

func (this *BlockStore) SaveTransaction(tx *types.Transaction, height uint32)

SaveTransaction persist transaction to store

func (*BlockStore) SaveVersion

func (this *BlockStore) SaveVersion(ver byte) error

SaveVersion persist version to store

type CrossChainStore

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

Block store save the data of block & transaction

func NewCrossChainStore

func NewCrossChainStore(dataDir string) (*CrossChainStore, error)

NewCrossChainStore return cross chain store instance

func (*CrossChainStore) GetCrossChainMsg

func (this *CrossChainStore) GetCrossChainMsg(height uint32) (*types.CrossChainMsg, error)

func (*CrossChainStore) SaveMsgToCrossChainStore

func (this *CrossChainStore) SaveMsgToCrossChainStore(crossChainMsg *types.CrossChainMsg) error

type EventStore

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

Saving event notifies gen by smart contract execution

func NewEventStore

func NewEventStore(dbDir string) (*EventStore, error)

NewEventStore return event store instance

func (*EventStore) ClearAll

func (this *EventStore) ClearAll() error

ClearAll all data in event store

func (*EventStore) Close

func (this *EventStore) Close() error

Close event store

func (*EventStore) CommitTo

func (this *EventStore) CommitTo() error

CommitTo event store batch to store

func (*EventStore) GetCurrentBlock

func (this *EventStore) GetCurrentBlock() (common.Uint256, uint32, error)

GetCurrentBlock return current block hash, and block height

func (*EventStore) GetEventNotifyByBlock

func (this *EventStore) GetEventNotifyByBlock(height uint32) ([]*event.ExecuteNotify, error)

GetEventNotifyByBlock return all event notify of transaction in block

func (*EventStore) GetEventNotifyByTx

func (this *EventStore) GetEventNotifyByTx(txHash common.Uint256) (*event.ExecuteNotify, error)

GetEventNotifyByTx return event notify by trasanction hash

func (*EventStore) NewBatch

func (this *EventStore) NewBatch()

NewBatch start event commit batch

func (*EventStore) PruneBlock

func (this *EventStore) PruneBlock(height uint32, hashes []common.Uint256)

func (*EventStore) SaveCurrentBlock

func (this *EventStore) SaveCurrentBlock(height uint32, blockHash common.Uint256)

SaveCurrentBlock persist current block height and block hash to event store

func (*EventStore) SaveEventNotifyByBlock

func (this *EventStore) SaveEventNotifyByBlock(height uint32, txHashs []common.Uint256)

SaveEventNotifyByBlock persist transaction hash which have event notify to store

func (*EventStore) SaveEventNotifyByTx

func (this *EventStore) SaveEventNotifyByTx(txHash common.Uint256, notify *event.ExecuteNotify) error

SaveEventNotifyByTx persist event notify by transaction hash

type LedgerStoreImp

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

LedgerStoreImp is main store struct fo ledger

func NewLedgerStore

func NewLedgerStore(dataDir string, stateHashHeight uint32) (*LedgerStoreImp, error)

NewLedgerStore return LedgerStoreImp instance

func (*LedgerStoreImp) AddBlock

func (this *LedgerStoreImp) AddBlock(block *types.Block, ccMsg *types.CrossChainMsg, stateMerkleRoot common.Uint256) error

AddBlock add the block to store. When the block is not the next block, it will be cache. until the missing block arrived

func (*LedgerStoreImp) AddHeader

func (this *LedgerStoreImp) AddHeader(header *types.Header) error

AddHeader add header to cache, and add the mapping of block height to block hash. Using in block sync

func (*LedgerStoreImp) AddHeaders

func (this *LedgerStoreImp) AddHeaders(headers []*types.Header) error

AddHeaders bath add header.

func (*LedgerStoreImp) Close

func (this *LedgerStoreImp) Close() error

Close ledger store.

func (*LedgerStoreImp) EnableBlockPrune

func (this *LedgerStoreImp) EnableBlockPrune(numBeforeCurr uint32)

func (*LedgerStoreImp) ExecuteBlock

func (this *LedgerStoreImp) ExecuteBlock(block *types.Block) (result store.ExecuteResult, err error)

func (*LedgerStoreImp) GetBlockByHash

func (this *LedgerStoreImp) GetBlockByHash(blockHash common.Uint256) (*types.Block, error)

GetBlockByHash return block by block hash. Wrap function of BlockStore.GetBlockByHash

func (*LedgerStoreImp) GetBlockByHeight

func (this *LedgerStoreImp) GetBlockByHeight(height uint32) (*types.Block, error)

GetBlockByHeight return block by height.

func (*LedgerStoreImp) GetBlockHash

func (this *LedgerStoreImp) GetBlockHash(height uint32) common.Uint256

GetBlockHash return the block hash by block height

func (*LedgerStoreImp) GetBlockRootWithNewTxRoots

func (this *LedgerStoreImp) GetBlockRootWithNewTxRoots(startHeight uint32, txRoots []common.Uint256) common.Uint256

GetBlockRootWithNewTxRoots return the block root(merkle root of blocks) after add a new tx root of block

func (*LedgerStoreImp) GetBookkeeperState

func (this *LedgerStoreImp) GetBookkeeperState() (*states.BookkeeperState, error)

GetBookkeeperState return the bookkeeper state. Wrap function of StateStore.GetBookkeeperState

func (*LedgerStoreImp) GetContractState

func (this *LedgerStoreImp) GetContractState(contractHash common.Address) (*payload.DeployCode, error)

GetContractState return contract by contract address. Wrap function of StateStore.GetContractState

func (*LedgerStoreImp) GetCrossChainMsg

func (this *LedgerStoreImp) GetCrossChainMsg(height uint32) (*types.CrossChainMsg, error)

func (*LedgerStoreImp) GetCrossStatesProof

func (this *LedgerStoreImp) GetCrossStatesProof(height uint32, key []byte) ([]byte, error)

func (*LedgerStoreImp) GetCrossStatesRoot

func (this *LedgerStoreImp) GetCrossStatesRoot(height uint32) (common.Uint256, error)

func (*LedgerStoreImp) GetCurrentBlock

func (this *LedgerStoreImp) GetCurrentBlock() (uint32, common.Uint256)

GetCurrentBlock return the current block height, and block hash. Current block means the latest block in store.

func (*LedgerStoreImp) GetCurrentBlockHash

func (this *LedgerStoreImp) GetCurrentBlockHash() common.Uint256

GetCurrentBlockHash return the current block hash

func (*LedgerStoreImp) GetCurrentBlockHeight

func (this *LedgerStoreImp) GetCurrentBlockHeight() uint32

GetCurrentBlockHeight return the current block height

func (*LedgerStoreImp) GetCurrentHeaderHash

func (this *LedgerStoreImp) GetCurrentHeaderHash() common.Uint256

GetCurrentHeaderHash return the current header hash. The current header means the latest header.

func (*LedgerStoreImp) GetCurrentHeaderHeight

func (this *LedgerStoreImp) GetCurrentHeaderHeight() uint32

GetCurrentHeaderHeight return the current header height. In block sync states, Header height is usually higher than block height that is has already committed to storage

func (*LedgerStoreImp) GetEventNotifyByBlock

func (this *LedgerStoreImp) GetEventNotifyByBlock(height uint32) ([]*event.ExecuteNotify, error)

GetEventNotifyByBlock return the transaction hash which have event notice after execution of smart contract. Wrap function of EventStore.GetEventNotifyByBlock

func (*LedgerStoreImp) GetEventNotifyByTx

func (this *LedgerStoreImp) GetEventNotifyByTx(tx common.Uint256) (*event.ExecuteNotify, error)

GetEventNotifyByTx return the events notify gen by executing of smart contract. Wrap function of EventStore.GetEventNotifyByTx

func (*LedgerStoreImp) GetGlobalStateRoot

func (this *LedgerStoreImp) GetGlobalStateRoot(height uint32) (common.Uint256, error)

func (*LedgerStoreImp) GetHeaderByHash

func (this *LedgerStoreImp) GetHeaderByHash(blockHash common.Uint256) (*types.Header, error)

GetHeaderByHash return the block header by block hash

func (*LedgerStoreImp) GetHeaderByHeight

func (this *LedgerStoreImp) GetHeaderByHeight(height uint32) (*types.Header, error)

GetHeaderByHash return the block header by block height

func (*LedgerStoreImp) GetMerkleProof

func (this *LedgerStoreImp) GetMerkleProof(proofHeight, rootHeight uint32) ([]common.Uint256, error)

GetMerkleProof return the block merkle proof. Wrap function of StateStore.GetMerkleProof

func (*LedgerStoreImp) GetRawHeaderByHash

func (this *LedgerStoreImp) GetRawHeaderByHash(blockHash common.Uint256) (*types.RawHeader, error)

func (*LedgerStoreImp) GetStateMerkleRoot

func (this *LedgerStoreImp) GetStateMerkleRoot(height uint32) (common.Uint256, error)

func (*LedgerStoreImp) GetStorageItem

func (this *LedgerStoreImp) GetStorageItem(key *states.StorageKey) (*states.StorageItem, error)

GetStorageItem return the storage value of the key in smart contract. Wrap function of StateStore.GetStorageState

func (*LedgerStoreImp) GetStoreProof

func (this *LedgerStoreImp) GetStoreProof(key []byte) ([]byte, []byte, uint32, error)

func (*LedgerStoreImp) GetSysFeeAmount

func (this *LedgerStoreImp) GetSysFeeAmount(blockHash common.Uint256) (common.Fixed64, error)

GetSysFeeAmount return the sys fee for block by block hash. Wrap function of BlockStore.GetSysFeeAmount

func (*LedgerStoreImp) GetTransaction

func (this *LedgerStoreImp) GetTransaction(txHash common.Uint256) (*types.Transaction, uint32, error)

GetTransaction return transaction by transaction hash. Wrap function of BlockStore.GetTransaction

func (*LedgerStoreImp) InitLedgerStoreWithGenesisBlock

func (this *LedgerStoreImp) InitLedgerStoreWithGenesisBlock(genesisBlock *types.Block, defaultBookkeeper []keypair.PublicKey) error

InitLedgerStoreWithGenesisBlock init the ledger store with genesis block. It's the first operation after NewLedgerStore.

func (*LedgerStoreImp) IsContainBlock

func (this *LedgerStoreImp) IsContainBlock(blockHash common.Uint256) (bool, error)

IsContainBlock return whether the block is in store

func (*LedgerStoreImp) IsContainTransaction

func (this *LedgerStoreImp) IsContainTransaction(txHash common.Uint256) (bool, error)

IsContainTransaction return whether the transaction is in store. Wrap function of BlockStore.ContainTransaction

func (*LedgerStoreImp) PreExecuteContract

func (this *LedgerStoreImp) PreExecuteContract(tx *types.Transaction) (*sstate.PreExecResult, error)

PreExecuteContract return the result of smart contract execution without commit to store

func (*LedgerStoreImp) PreExecuteContractBatch

func (this *LedgerStoreImp) PreExecuteContractBatch(txes []*types.Transaction, atomic bool) ([]*sstate.PreExecResult, uint32, error)

PreExecuteContract return the result of smart contract execution without commit to store

func (*LedgerStoreImp) PreExecuteContractWithParam

func (this *LedgerStoreImp) PreExecuteContractWithParam(tx *types.Transaction, preParam PrexecuteParam) (*sstate.PreExecResult, error)

PreExecuteContract return the result of smart contract execution without commit to store

func (*LedgerStoreImp) SubmitBlock

func (this *LedgerStoreImp) SubmitBlock(block *types.Block, ccMsg *types.CrossChainMsg, result store.ExecuteResult) error

type PrexecuteParam

type PrexecuteParam struct {
	JitMode    bool
	WasmFactor uint64
	MinGas     bool
}

type StateStore

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

StateStore saving the data of ledger states. Like balance of account, and the execution result of smart contract

func NewMemStateStore

func NewMemStateStore(stateHashHeight uint32) *StateStore

for test

func NewStateStore

func NewStateStore(dbDir, merklePath string, stateHashCheckHeight uint32) (*StateStore, error)

NewStateStore return state store instance

func (*StateStore) AddBlockMerkleTreeRoot

func (self *StateStore) AddBlockMerkleTreeRoot(txRoot common.Uint256) error

AddBlockMerkleTreeRoot add a new tree root

func (*StateStore) AddGlobalStateRoot

func (self *StateStore) AddGlobalStateRoot(height uint32, stateRoot common.Uint256) error

AddBlockMerkleTreeRoot add a new tree root

func (*StateStore) AddStateMerkleTreeRoot

func (self *StateStore) AddStateMerkleTreeRoot(blockHeight uint32, writeSetHash common.Uint256) error

func (*StateStore) BatchDeleteRawKey

func (self *StateStore) BatchDeleteRawKey(key []byte)

func (*StateStore) BatchPutRawKeyVal

func (self *StateStore) BatchPutRawKeyVal(key, val []byte)

func (*StateStore) CheckStorage

func (self *StateStore) CheckStorage() error

func (*StateStore) ClearAll

func (self *StateStore) ClearAll() error

ClearAll clear all data in state store

func (*StateStore) Close

func (self *StateStore) Close() error

Close state store

func (*StateStore) CommitTo

func (self *StateStore) CommitTo() error

CommitTo commit state batch to state store

func (*StateStore) GetBlockMerkleTree

func (self *StateStore) GetBlockMerkleTree() (uint32, []common.Uint256, error)

GetBlockMerkleTree return merkle tree size an tree node

func (*StateStore) GetBlockRootWithNewTxRoots

func (self *StateStore) GetBlockRootWithNewTxRoots(txRoots []common.Uint256) common.Uint256

func (*StateStore) GetBookkeeperState

func (self *StateStore) GetBookkeeperState() (*states.BookkeeperState, error)

GetBookkeeperState return current book keeper states

func (*StateStore) GetContractState

func (self *StateStore) GetContractState(contractHash common.Address) (*payload.DeployCode, error)

GetContractState return contract by contract address

func (*StateStore) GetCrossStates

func (self *StateStore) GetCrossStates(height uint32) ([]common.Uint256, error)

func (*StateStore) GetCrossStatesRoot

func (self *StateStore) GetCrossStatesRoot(height uint32) (common.Uint256, error)

func (*StateStore) GetCurrentBlock

func (self *StateStore) GetCurrentBlock() (common.Uint256, uint32, error)

GetCurrentBlock return current block height and current hash in state store

func (*StateStore) GetGlobalStateRoot

func (self *StateStore) GetGlobalStateRoot(height uint32) (result common.Uint256, err error)

func (*StateStore) GetMerkleProof

func (self *StateStore) GetMerkleProof(proofHeight, rootHeight uint32) ([]common.Uint256, error)

GetMerkleProof return merkle proof of block

func (*StateStore) GetStateMerkleRoot

func (self *StateStore) GetStateMerkleRoot(height uint32) (result common.Uint256, err error)

func (*StateStore) GetStateMerkleRootWithNewHash

func (self *StateStore) GetStateMerkleRootWithNewHash(writeSetHash common.Uint256) common.Uint256

func (*StateStore) GetStateMerkleTree

func (self *StateStore) GetStateMerkleTree() (uint32, []common.Uint256, error)

GetStateMerkleTree return merkle tree size an tree node

func (*StateStore) GetStorageState

func (self *StateStore) GetStorageState(key *states.StorageKey) (*states.StorageItem, error)

GetStorageItem return the storage value of the key in smart contract.

func (*StateStore) HandleDeployTransaction

func (self *StateStore) HandleDeployTransaction(store store.LedgerStore, overlay *overlaydb.OverlayDB, gasTable map[string]uint64, cache *storage.CacheDB,
	tx *types.Transaction, block *types.Block, notify *event.ExecuteNotify) error

HandleDeployTransaction deal with smart contract deploy transaction

func (*StateStore) HandleInvokeTransaction

func (self *StateStore) HandleInvokeTransaction(store store.LedgerStore, overlay *overlaydb.OverlayDB, gasTable map[string]uint64, cache *storage.CacheDB,
	tx *types.Transaction, block *types.Block, notify *event.ExecuteNotify) ([]common.Uint256, error)

HandleInvokeTransaction deal with smart contract invoke transaction

func (*StateStore) NewBatch

func (self *StateStore) NewBatch()

NewBatch start new commit batch

func (*StateStore) NewOverlayDB

func (self *StateStore) NewOverlayDB() *overlaydb.OverlayDB

func (*StateStore) SaveBookkeeperState

func (self *StateStore) SaveBookkeeperState(bookkeeperState *states.BookkeeperState) error

SaveBookkeeperState persist book keeper state to store

func (*StateStore) SaveCrossStates

func (self *StateStore) SaveCrossStates(height uint32, crossStates []common.Uint256) error

func (*StateStore) SaveCurrentBlock

func (self *StateStore) SaveCurrentBlock(height uint32, blockHash common.Uint256) error

SaveCurrentBlock persist current block to state store

type TransactionCacheaValue

type TransactionCacheaValue struct {
	Tx     *types.Transaction
	Height uint32
}

Value of transaction cache

Jump to

Keyboard shortcuts

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