ledgerstore

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: LGPL-3.0 Imports: 36 Imported by: 13

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/>.

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 (
	STATE_CACHE_SIZE = 100000
)

Variables

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

Functions

func SaveNotify

func SaveNotify(eventStore scommon.EventStore, txHash common.Uint256, notifies []*event.NotifyEventInfo, execSucc bool) 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 retuen 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) 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) 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) 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) 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) error

SaveHeaderIndexList persist header index list to store

func (*BlockStore) SaveTransaction

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

SaveTransaction persist transaction to store

func (*BlockStore) SaveVersion

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

SaveVersion persist version to store

type CacheCodeTable

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

func (*CacheCodeTable) GetCode

func (table *CacheCodeTable) GetCode(codeHash []byte) ([]byte, 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) SaveCurrentBlock

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

SaveCurrentBlock persist current block height and block hash to event store

func (*EventStore) SaveEventNotifyByBlock

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

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) (*LedgerStoreImp, error)

NewLedgerStore return LedgerStoreImp instance

func (*LedgerStoreImp) AddBlock

func (this *LedgerStoreImp) AddBlock(block *types.Block) 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) 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) GetBlockRootWithNewTxRoot

func (this *LedgerStoreImp) GetBlockRootWithNewTxRoot(txRoot common.Uint256) common.Uint256

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

type StateCache

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

func NewStateCache

func NewStateCache() (*StateCache, error)

func (*StateCache) AddState

func (this *StateCache) AddState(key []byte, state states.StateValue)

func (*StateCache) DeleteState

func (this *StateCache) DeleteState(key []byte)

func (*StateCache) GetState

func (this *StateCache) GetState(key []byte) states.StateValue

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 NewStateStore

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

NewStateStore return state store instance

func (*StateStore) AddMerkleTreeRoot

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

AddMerkleTreeRoot add a new tree root

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

func (self *StateStore) GetBlockRootWithNewTxRoot(txRoot 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) GetCurrentBlock

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

GetCurrentBlock return current block height and current hash in state store

func (*StateStore) GetMerkleProof

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

GetMerkleProof return merkle proof of block

func (*StateStore) GetMerkleTree

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

GetMerkleTree 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) GetVoteStates

func (self *StateStore) GetVoteStates() (map[common.Address]*states.VoteState, error)

GetVoteStates return vote states

func (*StateStore) HandleDeployTransaction

func (self *StateStore) HandleDeployTransaction(store store.LedgerStore, stateBatch *statestore.StateBatch,
	tx *types.Transaction, block *types.Block, eventStore scommon.EventStore) error

HandleDeployTransaction deal with smart contract deploy transaction

func (*StateStore) HandleInvokeTransaction

func (self *StateStore) HandleInvokeTransaction(store store.LedgerStore, stateBatch *statestore.StateBatch,
	tx *types.Transaction, block *types.Block, eventStore scommon.EventStore) error

HandleInvokeTransaction deal with smart contract invoke transaction

func (*StateStore) NewBatch

func (self *StateStore) NewBatch()

NewBatch start new commit batch

func (*StateStore) NewStateBatch

func (self *StateStore) NewStateBatch() *statestore.StateBatch

NewStateBatch return state commit bathe. Usually using in smart contract execution

func (*StateStore) SaveBookkeeperState

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

SaveBookkeeperState persist book keeper state to store

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