ledger

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const MinJournalHeight = 10

Variables

View Source
var (
	ErrorRollbackToHigherNumber  = errors.New("rollback to higher blockchain height")
	ErrorRollbackTooMuch         = errors.New("rollback too much block")
	ErrorRemoveJournalOutOfRange = errors.New("remove journal out of range")
)
View Source
var (
	ErrNotFound = errors.New("not found in DB")
)

Functions

func CreateBloom

func CreateBloom(receipts EvmReceipts) *types.Bloom

func InnerAccountChanged

func InnerAccountChanged(account0 *InnerAccount, account1 *InnerAccount) bool

func NewChanger

func NewChanger() *stateChanger

func NewEvmLogs

func NewEvmLogs() *evmLogs

Types

type AccessList

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

func NewAccessList

func NewAccessList() *AccessList

func (*AccessList) AddAddress

func (al *AccessList) AddAddress(address types.Address) bool

func (*AccessList) AddSlot

func (al *AccessList) AddSlot(address types.Address, slot types.Hash) (bool, bool)

func (*AccessList) Contains

func (al *AccessList) Contains(addr types.Address, slot types.Hash) (bool, bool)

func (*AccessList) ContainsAddress

func (al *AccessList) ContainsAddress(addr types.Address) bool

func (*AccessList) Copy

func (al *AccessList) Copy() *AccessList

func (*AccessList) DeleteAddress

func (al *AccessList) DeleteAddress(address types.Address)

func (*AccessList) DeleteSlot

func (al *AccessList) DeleteSlot(address types.Address, slot types.Hash)

type AccessTuple

type AccessTuple struct {
	Address     types.Address `json:"address"        gencodec:"required"`
	StorageKeys []types.Hash  `json:"storageKeys"    gencodec:"required"`
}

type AccessTupleList

type AccessTupleList []AccessTuple

func (AccessTupleList) StorageKeys

func (al AccessTupleList) StorageKeys() int

type AccountCache

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

func NewAccountCache

func NewAccountCache(cacheSize int, disable bool) (*AccountCache, error)

func (*AccountCache) SetEnableExpensiveMetric

func (ac *AccountCache) SetEnableExpensiveMetric(enable bool)

type BlockData

type BlockData struct {
	Block      *types.Block
	Receipts   []*types.Receipt
	TxHashList []*types.Hash
}

type BlockJournal

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

type ChainLedger

type ChainLedger interface {
	// GetBlock get block with height
	GetBlock(height uint64) (*types.Block, error)

	// GetBlockSign get the signature of block
	GetBlockSign(height uint64) ([]byte, error)

	// GetBlockByHash get the block using block hash
	GetBlockByHash(hash *types.Hash) (*types.Block, error)

	// GetTransaction get the transaction using transaction hash
	GetTransaction(hash *types.Hash) (*types.Transaction, error)

	// GetTransactionMeta get the transaction meta data
	GetTransactionMeta(hash *types.Hash) (*types.TransactionMeta, error)

	// GetReceipt get the transaction receipt
	GetReceipt(hash *types.Hash) (*types.Receipt, error)

	// PersistExecutionResult persist the execution result
	PersistExecutionResult(block *types.Block, receipts []*types.Receipt) error

	// GetChainMeta get chain meta data
	GetChainMeta() *types.ChainMeta

	// UpdateChainMeta update the chain meta data
	UpdateChainMeta(*types.ChainMeta)

	// LoadChainMeta get chain meta data
	LoadChainMeta() (*types.ChainMeta, error)

	// GetTransactionCount get the transaction count in a block
	GetTransactionCount(height uint64) (uint64, error)

	RollbackBlockChain(height uint64) error

	GetBlockHash(height uint64) *types.Hash

	Close()

	CloseBlockfile()
}

ChainLedgerImpl handles block, transaction and receipt data.

type ChainLedgerImpl

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

func NewChainLedger

func NewChainLedger(rep *repo.Repo, storageDir string) (*ChainLedgerImpl, error)

func (*ChainLedgerImpl) Close

func (l *ChainLedgerImpl) Close()

func (*ChainLedgerImpl) CloseBlockfile

func (l *ChainLedgerImpl) CloseBlockfile()

func (*ChainLedgerImpl) GetBlock

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

GetBlock get block with height

func (*ChainLedgerImpl) GetBlockByHash

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

GetBlockByHash get the block using block hash

func (*ChainLedgerImpl) GetBlockHash

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

func (*ChainLedgerImpl) GetBlockSign

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

GetBlockSign get the signature of block

func (*ChainLedgerImpl) GetChainMeta

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

GetChainMeta get chain meta data

func (*ChainLedgerImpl) GetReceipt

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

GetReceipt get the transaction receipt

func (*ChainLedgerImpl) GetTransaction

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

GetTransaction get the transaction using transaction hash

func (*ChainLedgerImpl) GetTransactionCount

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

func (*ChainLedgerImpl) GetTransactionMeta

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

GetTransactionMeta get the transaction meta data

func (*ChainLedgerImpl) LoadChainMeta

func (l *ChainLedgerImpl) LoadChainMeta() (*types.ChainMeta, error)

LoadChainMeta load chain meta data

func (*ChainLedgerImpl) PersistExecutionResult

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

PersistExecutionResult persist the execution result

func (*ChainLedgerImpl) RollbackBlockChain

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

func (*ChainLedgerImpl) UpdateChainMeta

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

UpdateChainMeta update the chain meta data

type EvmReceipts

type EvmReceipts []*types.Receipt

type IAccount

type IAccount interface {
	fmt.Stringer

	GetAddress() *types.Address

	GetState(key []byte) (bool, []byte)

	GetCommittedState(key []byte) []byte

	SetState(key []byte, value []byte)

	SetCodeAndHash(code []byte)

	Code() []byte

	CodeHash() []byte

	SetNonce(nonce uint64)

	GetNonce() uint64

	GetBalance() *big.Int

	SetBalance(balance *big.Int)

	SubBalance(amount *big.Int)

	AddBalance(amount *big.Int)

	Finalise()

	IsEmpty() bool

	Suicided() bool

	SetSuicided(bool)

	SetEnableExpensiveMetric(bool)
}

type InnerAccount

type InnerAccount struct {
	Nonce       uint64      `json:"nonce"`
	Balance     *big.Int    `json:"balance"`
	CodeHash    []byte      `json:"code_hash"`
	StorageRoot common.Hash `json:"storage_root"`
}

func CopyOrNewIfEmpty

func CopyOrNewIfEmpty(o *InnerAccount) *InnerAccount

func (*InnerAccount) Marshal

func (o *InnerAccount) Marshal() ([]byte, error)

Marshal Marshal the account into byte

func (*InnerAccount) String

func (o *InnerAccount) String() string

func (*InnerAccount) Unmarshal

func (o *InnerAccount) Unmarshal(data []byte) error

Unmarshal Unmarshal the account byte into structure

type Ledger

type Ledger struct {
	ChainLedger ChainLedger
	StateLedger StateLedger
}

func NewLedger

func NewLedger(rep *repo.Repo) (*Ledger, error)

func NewLedgerWithStores

func NewLedgerWithStores(repo *repo.Repo, blockchainStore storage.Storage, ldb storage.Storage, bf *blockfile.BlockFile) (*Ledger, error)

func (*Ledger) Close

func (l *Ledger) Close()

func (*Ledger) NewView

func (l *Ledger) NewView() *Ledger

NewView load the latest state ledger and chain ledger by default

func (*Ledger) NewViewWithoutCache

func (l *Ledger) NewViewWithoutCache() *Ledger

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

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

func NewAccount

func NewAccount(blockHeight uint64, ldb storage.Storage, accountCache *AccountCache, addr *types.Address, changer *stateChanger) *SimpleAccount

func NewMockAccount

func NewMockAccount(blockHeight uint64, addr *types.Address) *SimpleAccount

func (*SimpleAccount) AddBalance

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

func (*SimpleAccount) Code

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

Code return the contract code

func (*SimpleAccount) CodeHash

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

func (*SimpleAccount) Finalise

func (o *SimpleAccount) Finalise()

Finalise moves all dirty states into the pending states.

func (*SimpleAccount) GetAddress

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

func (*SimpleAccount) GetBalance

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

GetBalance Get the balance from the account

func (*SimpleAccount) GetCommittedState

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

func (*SimpleAccount) GetNonce

func (o *SimpleAccount) GetNonce() uint64

GetNonce Get the nonce from user account

func (*SimpleAccount) GetState

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

func (o *SimpleAccount) IsEmpty() bool

func (*SimpleAccount) SetBalance

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

SetBalance Set the balance to the account

func (*SimpleAccount) SetCodeAndHash

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

SetCodeAndHash Set the contract code and hash

func (*SimpleAccount) SetEnableExpensiveMetric

func (o *SimpleAccount) SetEnableExpensiveMetric(enable bool)

func (*SimpleAccount) SetNonce

func (o *SimpleAccount) SetNonce(nonce uint64)

SetNonce Set the nonce which indicates the contract number

func (*SimpleAccount) SetState

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

SetState Set account state

func (*SimpleAccount) SetSuicided

func (o *SimpleAccount) SetSuicided(suicided bool)

func (*SimpleAccount) String

func (o *SimpleAccount) String() string

func (*SimpleAccount) SubBalance

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

func (*SimpleAccount) Suicided

func (o *SimpleAccount) Suicided() bool

type StateAccessor

type StateAccessor interface {
	// GetOrCreateAccount
	GetOrCreateAccount(*types.Address) IAccount

	// GetAccount
	GetAccount(*types.Address) IAccount

	// GetBalance
	GetBalance(*types.Address) *big.Int

	// SetBalance
	SetBalance(*types.Address, *big.Int)

	// GetState
	GetState(*types.Address, []byte) (bool, []byte)

	// SetState
	SetState(*types.Address, []byte, []byte)

	// SetCode
	SetCode(*types.Address, []byte)

	// GetCode
	GetCode(*types.Address) []byte

	// SetNonce
	SetNonce(*types.Address, uint64)

	// GetNonce
	GetNonce(*types.Address) uint64

	// Commit commits the state data
	Commit() (*types.Hash, error)

	// Set tx context for state db
	SetTxContext(thash *types.Hash, txIndex int)

	// Clear
	Clear()
}

StateAccessor manipulates the state data

type StateLedger

type StateLedger interface {
	StateAccessor

	vm.StateDB

	AddLog(log *types.EvmLog)

	GetLogs(types.Hash, uint64, *types.Hash) []*types.EvmLog

	RollbackState(height uint64, lastStateRoot *types.Hash) error

	PrepareBlock(*types.Hash, *types.Hash, uint64)

	ClearChangerAndRefund()

	// Close release resource
	Close()

	Finalise()

	Version() uint64

	NewView(block *types.Block) StateLedger

	NewViewWithoutCache(block *types.Block) StateLedger
}

func NewStateLedger

func NewStateLedger(rep *repo.Repo, storageDir string) (StateLedger, error)

NewStateLedger create a new ledger instance

type StateLedgerImpl

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

func (*StateLedgerImpl) AddAddressToAccessList

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

func (*StateLedgerImpl) AddAddressToEVMAccessList

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

func (*StateLedgerImpl) AddBalance

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

func (*StateLedgerImpl) AddEVMBalance

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

func (*StateLedgerImpl) AddEVMLog

func (l *StateLedgerImpl) AddEVMLog(log *ethertypes.Log)

func (*StateLedgerImpl) AddEVMPreimage

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

func (*StateLedgerImpl) AddEVMRefund

func (l *StateLedgerImpl) AddEVMRefund(gas uint64)

func (*StateLedgerImpl) AddLog

func (l *StateLedgerImpl) AddLog(log *types.EvmLog)

func (*StateLedgerImpl) AddPreimage

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

func (*StateLedgerImpl) AddRefund

func (l *StateLedgerImpl) AddRefund(gas uint64)

func (*StateLedgerImpl) AddSlotToAccessList

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

func (*StateLedgerImpl) AddSlotToEVMAccessList

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

func (*StateLedgerImpl) AddressInAccessList

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

func (*StateLedgerImpl) AddressInEVMAccessList

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

func (*StateLedgerImpl) Clear

func (l *StateLedgerImpl) Clear()

func (*StateLedgerImpl) ClearChangerAndRefund

func (l *StateLedgerImpl) ClearChangerAndRefund()

func (*StateLedgerImpl) Close

func (l *StateLedgerImpl) Close()

Close close the ledger instance

func (*StateLedgerImpl) Commit

func (l *StateLedgerImpl) Commit() (*types.Hash, error)

Commit the state, and get account trie root hash

func (*StateLedgerImpl) CreateEVMAccount

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

func (*StateLedgerImpl) Empty

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

func (*StateLedgerImpl) EmptyEVM

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

func (*StateLedgerImpl) Exist

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

func (*StateLedgerImpl) ExistEVM

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

func (*StateLedgerImpl) Finalise

func (l *StateLedgerImpl) Finalise()

func (*StateLedgerImpl) GetAccount

func (l *StateLedgerImpl) GetAccount(address *types.Address) IAccount

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

func (*StateLedgerImpl) GetBalance

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

GetBalance get account balance using account Address

func (*StateLedgerImpl) GetCode

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

GetCode get contract code

func (*StateLedgerImpl) GetCodeHash

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

func (*StateLedgerImpl) GetCodeSize

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

func (*StateLedgerImpl) GetCommittedState

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

func (*StateLedgerImpl) GetEVMBalance

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

func (*StateLedgerImpl) GetEVMCode

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

func (*StateLedgerImpl) GetEVMCodeHash

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

func (*StateLedgerImpl) GetEVMCodeSize

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

func (*StateLedgerImpl) GetEVMCommittedState

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

func (*StateLedgerImpl) GetEVMNonce

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

func (*StateLedgerImpl) GetEVMRefund

func (l *StateLedgerImpl) GetEVMRefund() uint64

func (*StateLedgerImpl) GetEVMState

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

func (*StateLedgerImpl) GetEVMTransientState

func (l *StateLedgerImpl) GetEVMTransientState(addr common.Address, key common.Hash) common.Hash

func (*StateLedgerImpl) GetLogs

func (l *StateLedgerImpl) GetLogs(hash types.Hash, height uint64, blockHash *types.Hash) []*types.EvmLog

func (*StateLedgerImpl) GetNonce

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

GetNonce get account nonce

func (*StateLedgerImpl) GetOrCreateAccount

func (l *StateLedgerImpl) GetOrCreateAccount(addr *types.Address) IAccount

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

func (*StateLedgerImpl) GetRefund

func (l *StateLedgerImpl) GetRefund() uint64

func (*StateLedgerImpl) GetState

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

GetState get account state value using account Address and key

func (*StateLedgerImpl) HasSuicide

func (l *StateLedgerImpl) HasSuicide(addr *types.Address) bool

func (*StateLedgerImpl) HasSuicideEVM

func (l *StateLedgerImpl) HasSuicideEVM(addr common.Address) bool

func (*StateLedgerImpl) Logs

func (l *StateLedgerImpl) Logs() []*types.EvmLog

func (*StateLedgerImpl) NewView

func (l *StateLedgerImpl) NewView(block *types.Block) StateLedger

NewView get a view

func (*StateLedgerImpl) NewViewWithoutCache

func (l *StateLedgerImpl) NewViewWithoutCache(block *types.Block) StateLedger

NewView get a view

func (*StateLedgerImpl) PrepareAccessList

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

func (*StateLedgerImpl) PrepareBlock

func (l *StateLedgerImpl) PrepareBlock(lastStateRoot *types.Hash, hash *types.Hash, currentExecutingHeight uint64)

func (*StateLedgerImpl) PrepareEVM

func (l *StateLedgerImpl) PrepareEVM(rules params.Rules, sender, coinbase common.Address, dst *common.Address, precompiles []common.Address, list ethertypes.AccessList)

func (*StateLedgerImpl) PrepareEVMAccessList

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

func (*StateLedgerImpl) RevertToSnapshot

func (l *StateLedgerImpl) RevertToSnapshot(revid int)

func (*StateLedgerImpl) RollbackState

func (l *StateLedgerImpl) RollbackState(height uint64, stateRoot *types.Hash) error

RollbackState does not delete the state data that has been persisted in KV. This manner will not affect the correctness of ledger, todo but maybe need to optimize to free allocated space in KV.

func (*StateLedgerImpl) SetBalance

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

SetBalance set account balance

func (*StateLedgerImpl) SetCode

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

SetCode set contract code

func (*StateLedgerImpl) SetEVMCode

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

func (*StateLedgerImpl) SetEVMNonce

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

func (*StateLedgerImpl) SetEVMState

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

func (*StateLedgerImpl) SetEVMTransientState

func (l *StateLedgerImpl) SetEVMTransientState(addr common.Address, key, value common.Hash)

func (*StateLedgerImpl) SetNonce

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

SetNonce set account nonce

func (*StateLedgerImpl) SetState

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

SetState set account state value using account Address and key

func (*StateLedgerImpl) SetTxContext

func (l *StateLedgerImpl) SetTxContext(thash *types.Hash, ti int)

func (*StateLedgerImpl) SlotInAccessList

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

func (*StateLedgerImpl) SlotInEVMAceessList

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

func (*StateLedgerImpl) Snapshot

func (l *StateLedgerImpl) Snapshot() int

func (*StateLedgerImpl) StateDB

func (l *StateLedgerImpl) StateDB() vm.StateDB

func (*StateLedgerImpl) SubBalance

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

func (*StateLedgerImpl) SubEVMBalance

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

func (*StateLedgerImpl) SubEVMRefund

func (l *StateLedgerImpl) SubEVMRefund(gas uint64)

func (*StateLedgerImpl) SubRefund

func (l *StateLedgerImpl) SubRefund(gas uint64)

func (*StateLedgerImpl) Suicide

func (l *StateLedgerImpl) Suicide(addr *types.Address) bool

func (*StateLedgerImpl) SuicideEVM

func (l *StateLedgerImpl) SuicideEVM(addr common.Address) bool

func (*StateLedgerImpl) Version

func (l *StateLedgerImpl) 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