ledger

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorRollbackToHigherNumber  = fmt.Errorf("rollback to higher blockchain height")
	ErrorRollbackWithoutJournal  = fmt.Errorf("rollback to blockchain height without journal")
	ErrorRollbackTooMuch         = fmt.Errorf("rollback too much block")
	ErrorRemoveJournalOutOfRange = fmt.Errorf("remove journal out of range")
)
View Source
var (
	PersistBlockDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
		Namespace: "bitxhub",
		Subsystem: "ledger",
		Name:      "persist_block_duration_second",
		Help:      "The total latency of block persist",
		Buckets:   prometheus.ExponentialBuckets(0.001, 2, 10),
	})
)

Functions

func CreateBloom added in v1.8.0

func CreateBloom(receipts EvmReceipts) *types.Bloom

func NewBxhTxFromEth added in v1.12.0

func NewBxhTxFromEth(tx *types2.EthTransaction) *pb.BxhTransaction

func NewEvmLogs added in v1.8.0

func NewEvmLogs() *evmLogs

func NewMessageFromBxh added in v1.10.0

func NewMessageFromBxh(tx *pb.BxhTransaction) etherTypes.Message

func NewSimpleLedger added in v1.9.0

func NewSimpleLedger(repo *repo.Repo, ldb storage.Storage, accountCache *AccountCache, logger logrus.FieldLogger) (ledger.StateLedger, error)

New create a new ledger instance

func OpenStateDB added in v1.9.0

func OpenStateDB(file string, typ string) (stateStorage, error)

Types

type AccountCache

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

func NewAccountCache

func NewAccountCache() (*AccountCache, error)

type BlockData

type BlockData struct {
	Block          *pb.Block
	Receipts       []*pb.Receipt
	Accounts       map[string]ledger.IAccount
	InterchainMeta *pb.InterchainMeta
	TxHashList     []*types.Hash
}

type BlockJournal

type BlockJournal struct {
	Journals    []*blockJournalEntry
	ChangedHash *types.Hash
}

type ChainLedgerImpl added in v1.9.0

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

func NewChainLedgerImpl added in v1.9.0

func NewChainLedgerImpl(blockchainStore storage.Storage, bf *blockfile.BlockFile, repo *repo.Repo, logger logrus.FieldLogger) (*ChainLedgerImpl, error)

func (*ChainLedgerImpl) Close added in v1.9.0

func (l *ChainLedgerImpl) Close()

func (*ChainLedgerImpl) GetBlock added in v1.9.0

func (l *ChainLedgerImpl) GetBlock(height uint64) (*pb.Block, error)

GetBlock get block with height

func (*ChainLedgerImpl) GetBlockByHash added in v1.9.0

func (l *ChainLedgerImpl) GetBlockByHash(hash *types.Hash) (*pb.Block, error)

GetBlockByHash get the block using block hash

func (*ChainLedgerImpl) GetBlockHash added in v1.9.0

func (l *ChainLedgerImpl) GetBlockHash(height uint64) *types.Hash

func (*ChainLedgerImpl) GetBlockSign added in v1.9.0

func (l *ChainLedgerImpl) GetBlockSign(height uint64) ([]byte, error)

GetBlockSign get the signature of block

func (*ChainLedgerImpl) GetChainMeta added in v1.9.0

func (l *ChainLedgerImpl) GetChainMeta() *pb.ChainMeta

GetChainMeta get chain meta data

func (*ChainLedgerImpl) GetInterchainMeta added in v1.9.0

func (l *ChainLedgerImpl) GetInterchainMeta(height uint64) (*pb.InterchainMeta, error)

func (*ChainLedgerImpl) GetReceipt added in v1.9.0

func (l *ChainLedgerImpl) GetReceipt(hash *types.Hash) (*pb.Receipt, error)

GetReceipt get the transaction receipt

func (*ChainLedgerImpl) GetTransaction added in v1.9.0

func (l *ChainLedgerImpl) GetTransaction(hash *types.Hash) (pb.Transaction, error)

GetTransaction get the transaction using transaction hash

func (*ChainLedgerImpl) GetTransactionCount added in v1.9.0

func (l *ChainLedgerImpl) GetTransactionCount(height uint64) (uint64, error)

func (*ChainLedgerImpl) GetTransactionMeta added in v1.9.0

func (l *ChainLedgerImpl) GetTransactionMeta(hash *types.Hash) (*pb.TransactionMeta, error)

GetTransactionMeta get the transaction meta data

func (*ChainLedgerImpl) LoadChainMeta added in v1.9.0

func (l *ChainLedgerImpl) LoadChainMeta() *pb.ChainMeta

LoadChainMeta load chain meta data

func (*ChainLedgerImpl) PersistExecutionResult added in v1.9.0

func (l *ChainLedgerImpl) PersistExecutionResult(block *pb.Block, receipts []*pb.Receipt, interchainMeta *pb.InterchainMeta) error

PersistExecutionResult persist the execution result

func (*ChainLedgerImpl) PutBlock added in v1.9.0

func (l *ChainLedgerImpl) PutBlock(height uint64, block *pb.Block) error

PutBlock put block into store

func (*ChainLedgerImpl) RollbackBlockChain added in v1.9.0

func (l *ChainLedgerImpl) RollbackBlockChain(height uint64) error

func (*ChainLedgerImpl) UpdateChainMeta added in v1.9.0

func (l *ChainLedgerImpl) UpdateChainMeta(meta *pb.ChainMeta)

UpdateChainMeta update the chain meta data

type EvmReceipts added in v1.8.0

type EvmReceipts []*pb.Receipt

type Ledger

type Ledger struct {
	ledger.ChainLedger
	ledger.StateLedger
}

func New

func New(repo *repo.Repo, blockchainStore storage.Storage, ldb stateStorage, bf *blockfile.BlockFile, accountCache *AccountCache, logger logrus.FieldLogger) (*Ledger, error)

func (*Ledger) Close

func (l *Ledger) Close()

func (*Ledger) PersistBlockData

func (l *Ledger) PersistBlockData(blockData *BlockData)

PersistBlockData persists block data

func (*Ledger) Rollback

func (l *Ledger) Rollback(height uint64) error

Rollback rollback ledger to history version

type SimpleAccount added in v1.9.0

type SimpleAccount struct {
	Addr *types.Address
	// contains filtered or unexported fields
}

func (*SimpleAccount) AddBalance added in v1.9.0

func (o *SimpleAccount) AddBalance(amount *big.Int)

func (*SimpleAccount) AddState added in v1.9.0

func (o *SimpleAccount) AddState(key []byte, value []byte)

AddState Add account state

func (*SimpleAccount) Code added in v1.9.0

func (o *SimpleAccount) Code() []byte

Code return the contract code

func (*SimpleAccount) CodeHash added in v1.9.0

func (o *SimpleAccount) CodeHash() []byte

func (*SimpleAccount) GetAddress added in v1.9.0

func (o *SimpleAccount) GetAddress() *types.Address

func (*SimpleAccount) GetBalance added in v1.9.0

func (o *SimpleAccount) GetBalance() *big.Int

GetBalance Get the balance from the account

func (*SimpleAccount) GetCommittedState added in v1.9.0

func (o *SimpleAccount) GetCommittedState(key []byte) []byte

func (*SimpleAccount) GetNonce added in v1.9.0

func (o *SimpleAccount) GetNonce() uint64

GetNonce Get the nonce from user account

func (*SimpleAccount) GetState added in v1.9.0

func (o *SimpleAccount) GetState(key []byte) (bool, []byte)

GetState Get state from local cache, if not found, then get it from DB

func (*SimpleAccount) IsEmpty added in v1.9.0

func (o *SimpleAccount) IsEmpty() bool

func (*SimpleAccount) Query added in v1.9.0

func (o *SimpleAccount) Query(prefix string) (bool, [][]byte)

Query Query the value using key

func (*SimpleAccount) SetBalance added in v1.9.0

func (o *SimpleAccount) SetBalance(balance *big.Int)

SetBalance Set the balance to the account

func (*SimpleAccount) SetCodeAndHash added in v1.9.0

func (o *SimpleAccount) SetCodeAndHash(code []byte)

SetCodeAndHash Set the contract code and hash

func (*SimpleAccount) SetNonce added in v1.9.0

func (o *SimpleAccount) SetNonce(nonce uint64)

SetNonce Set the nonce which indicates the contract number

func (*SimpleAccount) SetState added in v1.9.0

func (o *SimpleAccount) SetState(key []byte, value []byte)

SetState Set account state

func (*SimpleAccount) SetSuicided added in v1.9.0

func (o *SimpleAccount) SetSuicided(suicided bool)

func (*SimpleAccount) SubBalance added in v1.9.0

func (o *SimpleAccount) SubBalance(amount *big.Int)

func (*SimpleAccount) Suicided added in v1.9.0

func (o *SimpleAccount) Suicided() bool

type SimpleLedger added in v1.9.0

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

func (*SimpleLedger) AccountCache added in v1.9.0

func (l *SimpleLedger) AccountCache() *AccountCache

func (*SimpleLedger) AddAddressToAccessList added in v1.9.0

func (l *SimpleLedger) AddAddressToAccessList(addr types.Address)

func (*SimpleLedger) AddAddressToEVMAccessList added in v1.9.0

func (l *SimpleLedger) AddAddressToEVMAccessList(addr common.Address)

func (*SimpleLedger) AddBalance added in v1.9.0

func (l *SimpleLedger) AddBalance(addr *types.Address, value *big.Int)

func (*SimpleLedger) AddEVMBalance added in v1.9.0

func (l *SimpleLedger) AddEVMBalance(addr common.Address, amount *big.Int)

func (*SimpleLedger) AddEVMLog added in v1.9.0

func (l *SimpleLedger) AddEVMLog(log *etherTypes.Log)

func (*SimpleLedger) AddEVMPreimage added in v1.9.0

func (l *SimpleLedger) AddEVMPreimage(hash common.Hash, data []byte)

func (*SimpleLedger) AddEVMRefund added in v1.9.0

func (l *SimpleLedger) AddEVMRefund(gas uint64)

func (*SimpleLedger) AddEvent added in v1.9.0

func (l *SimpleLedger) AddEvent(event *pb.Event)

AddEvent add ledger event

func (*SimpleLedger) AddLog added in v1.9.0

func (l *SimpleLedger) AddLog(log *pb.EvmLog)

func (*SimpleLedger) AddPreimage added in v1.9.0

func (l *SimpleLedger) AddPreimage(hash types.Hash, preimage []byte)

func (*SimpleLedger) AddRefund added in v1.9.0

func (l *SimpleLedger) AddRefund(gas uint64)

func (*SimpleLedger) AddSlotToAccessList added in v1.9.0

func (l *SimpleLedger) AddSlotToAccessList(addr types.Address, slot types.Hash)

func (*SimpleLedger) AddSlotToEVMAccessList added in v1.9.0

func (l *SimpleLedger) AddSlotToEVMAccessList(addr common.Address, slot common.Hash)

func (*SimpleLedger) AddState added in v1.9.0

func (l *SimpleLedger) AddState(addr *types.Address, key []byte, v []byte)

AddState add account state value using account Address and key

func (*SimpleLedger) AddressInAccessList added in v1.9.0

func (l *SimpleLedger) AddressInAccessList(addr types.Address) bool

func (*SimpleLedger) AddressInEVMAccessList added in v1.9.0

func (l *SimpleLedger) AddressInEVMAccessList(addr common.Address) bool

func (*SimpleLedger) Clear added in v1.9.0

func (l *SimpleLedger) Clear()

func (*SimpleLedger) ClearChangerAndRefund added in v1.9.0

func (l *SimpleLedger) ClearChangerAndRefund()

func (*SimpleLedger) Close added in v1.9.0

func (l *SimpleLedger) Close()

Close close the ledger instance

func (*SimpleLedger) Commit added in v1.9.0

func (l *SimpleLedger) Commit(height uint64, accounts map[string]ledger.IAccount, stateRoot *types.Hash) error

Commit commit the state

func (*SimpleLedger) Copy added in v1.10.0

func (l *SimpleLedger) Copy() ledger.StateLedger

func (*SimpleLedger) CreateEVMAccount added in v1.9.0

func (l *SimpleLedger) CreateEVMAccount(addr common.Address)

func (*SimpleLedger) Empty added in v1.9.0

func (l *SimpleLedger) Empty(addr *types.Address) bool

func (*SimpleLedger) EmptyEVM added in v1.9.0

func (l *SimpleLedger) EmptyEVM(addr common.Address) bool

func (*SimpleLedger) Events added in v1.9.0

func (l *SimpleLedger) Events(txHash string) []*pb.Event

Events return ledger events

func (*SimpleLedger) Exist added in v1.9.0

func (l *SimpleLedger) Exist(addr *types.Address) bool

func (*SimpleLedger) ExistEVM added in v1.9.0

func (l *SimpleLedger) ExistEVM(addr common.Address) bool

func (*SimpleLedger) Finalise added in v1.9.0

func (l *SimpleLedger) Finalise(b bool)

func (*SimpleLedger) FlushDirtyData added in v1.10.0

func (l *SimpleLedger) FlushDirtyData() (map[string]ledger.IAccount, *types.Hash)

FlushDirtyData gets dirty accounts and computes block journal

func (*SimpleLedger) GetAccount added in v1.9.0

func (l *SimpleLedger) GetAccount(address *types.Address) ledger.IAccount

GetAccount get account info using account Address, if not found, create a new account

func (*SimpleLedger) GetBalance added in v1.9.0

func (l *SimpleLedger) GetBalance(addr *types.Address) *big.Int

GetBalanec get account balance using account Address

func (*SimpleLedger) GetCode added in v1.9.0

func (l *SimpleLedger) GetCode(addr *types.Address) []byte

GetCode get contract code

func (*SimpleLedger) GetCodeHash added in v1.9.0

func (l *SimpleLedger) GetCodeHash(addr *types.Address) *types.Hash

func (*SimpleLedger) GetCodeSize added in v1.9.0

func (l *SimpleLedger) GetCodeSize(addr *types.Address) int

func (*SimpleLedger) GetCommittedState added in v1.9.0

func (l *SimpleLedger) GetCommittedState(addr *types.Address, key []byte) []byte

func (*SimpleLedger) GetEVMBalance added in v1.9.0

func (l *SimpleLedger) GetEVMBalance(addr common.Address) *big.Int

func (*SimpleLedger) GetEVMCode added in v1.9.0

func (l *SimpleLedger) GetEVMCode(addr common.Address) []byte

func (*SimpleLedger) GetEVMCodeHash added in v1.9.0

func (l *SimpleLedger) GetEVMCodeHash(addr common.Address) common.Hash

func (*SimpleLedger) GetEVMCodeSize added in v1.9.0

func (l *SimpleLedger) GetEVMCodeSize(addr common.Address) int

func (*SimpleLedger) GetEVMCommittedState added in v1.9.0

func (l *SimpleLedger) GetEVMCommittedState(addr common.Address, hash common.Hash) common.Hash

func (*SimpleLedger) GetEVMNonce added in v1.9.0

func (l *SimpleLedger) GetEVMNonce(addr common.Address) uint64

func (*SimpleLedger) GetEVMRefund added in v1.9.0

func (l *SimpleLedger) GetEVMRefund() uint64

func (*SimpleLedger) GetEVMState added in v1.9.0

func (l *SimpleLedger) GetEVMState(addr common.Address, hash common.Hash) common.Hash

func (*SimpleLedger) GetLogs added in v1.9.0

func (l *SimpleLedger) GetLogs(hash types.Hash) []*pb.EvmLog

func (*SimpleLedger) GetNonce added in v1.9.0

func (l *SimpleLedger) GetNonce(addr *types.Address) uint64

GetNonce get account nonce

func (*SimpleLedger) GetOrCreateAccount added in v1.9.0

func (l *SimpleLedger) GetOrCreateAccount(addr *types.Address) ledger.IAccount

GetOrCreateAccount get the account, if not exist, create a new account

func (*SimpleLedger) GetRefund added in v1.9.0

func (l *SimpleLedger) GetRefund() uint64

func (*SimpleLedger) GetState added in v1.9.0

func (l *SimpleLedger) GetState(addr *types.Address, key []byte) (bool, []byte)

GetState get account state value using account Address and key

func (*SimpleLedger) HasSuiside added in v1.9.0

func (l *SimpleLedger) HasSuiside(addr *types.Address) bool

func (*SimpleLedger) HasSuisideEVM added in v1.9.0

func (l *SimpleLedger) HasSuisideEVM(addr common.Address) bool

func (*SimpleLedger) Logs added in v1.9.0

func (l *SimpleLedger) Logs() []*pb.EvmLog

func (*SimpleLedger) PrepareAccessList added in v1.9.0

func (l *SimpleLedger) PrepareAccessList(sender types.Address, dst *types.Address, precompiles []types.Address, list ledger.AccessTupleList)

func (*SimpleLedger) PrepareBlock added in v1.9.0

func (l *SimpleLedger) PrepareBlock(hash *types.Hash, height uint64)

func (*SimpleLedger) PrepareEVM added in v1.9.0

func (l *SimpleLedger) PrepareEVM(hash common.Hash, index int)

func (*SimpleLedger) PrepareEVMAccessList added in v1.9.0

func (l *SimpleLedger) PrepareEVMAccessList(sender common.Address, dest *common.Address, preEVMcompiles []common.Address, txEVMAccesses etherTypes.AccessList)

func (*SimpleLedger) QueryByPrefix added in v1.9.0

func (l *SimpleLedger) QueryByPrefix(addr *types.Address, prefix string) (bool, [][]byte)

QueryByPrefix query value using key

func (*SimpleLedger) RevertToSnapshot added in v1.9.0

func (l *SimpleLedger) RevertToSnapshot(revid int)

func (*SimpleLedger) RollbackState added in v1.9.0

func (l *SimpleLedger) RollbackState(height uint64) error

func (*SimpleLedger) SetBalance added in v1.9.0

func (l *SimpleLedger) SetBalance(addr *types.Address, value *big.Int)

SetBalance set account balance

func (*SimpleLedger) SetCode added in v1.9.0

func (l *SimpleLedger) SetCode(addr *types.Address, code []byte)

SetCode set contract code

func (*SimpleLedger) SetEVMCode added in v1.9.0

func (l *SimpleLedger) SetEVMCode(addr common.Address, code []byte)

func (*SimpleLedger) SetEVMNonce added in v1.9.0

func (l *SimpleLedger) SetEVMNonce(addr common.Address, nonce uint64)

func (*SimpleLedger) SetEVMState added in v1.9.0

func (l *SimpleLedger) SetEVMState(addr common.Address, key, value common.Hash)

func (*SimpleLedger) SetNonce added in v1.9.0

func (l *SimpleLedger) SetNonce(addr *types.Address, nonce uint64)

SetNonce set account nonce

func (*SimpleLedger) SetState added in v1.9.0

func (l *SimpleLedger) SetState(addr *types.Address, key []byte, v []byte)

SetState set account state value using account Address and key

func (*SimpleLedger) SlotInAccessList added in v1.9.0

func (l *SimpleLedger) SlotInAccessList(addr types.Address, slot types.Hash) (bool, bool)

func (*SimpleLedger) SlotInEVMAceessList added in v1.9.0

func (l *SimpleLedger) SlotInEVMAceessList(addr common.Address, slot common.Hash) (bool, bool)

func (*SimpleLedger) Snapshot added in v1.9.0

func (l *SimpleLedger) Snapshot() int

func (*SimpleLedger) StateDB added in v1.9.0

func (l *SimpleLedger) StateDB() ledger2.StateDB

func (*SimpleLedger) SubBalance added in v1.9.0

func (l *SimpleLedger) SubBalance(addr *types.Address, value *big.Int)

func (*SimpleLedger) SubEVMBalance added in v1.9.0

func (l *SimpleLedger) SubEVMBalance(addr common.Address, amount *big.Int)

func (*SimpleLedger) SubEVMRefund added in v1.9.0

func (l *SimpleLedger) SubEVMRefund(gas uint64)

func (*SimpleLedger) SubRefund added in v1.9.0

func (l *SimpleLedger) SubRefund(gas uint64)

func (*SimpleLedger) Suiside added in v1.9.0

func (l *SimpleLedger) Suiside(addr *types.Address) bool

func (*SimpleLedger) SuisideEVM added in v1.9.0

func (l *SimpleLedger) SuisideEVM(addr common.Address) bool

func (*SimpleLedger) Version added in v1.9.0

func (l *SimpleLedger) Version() uint64

Version returns the current version

Directories

Path Synopsis
Package mock_ledger is a generated GoMock package.
Package mock_ledger is a generated GoMock package.

Jump to

Keyboard shortcuts

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