ledger

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: GPL-3.0 Imports: 17 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

This section is empty.

Types

type Account

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

func (*Account) AddState added in v1.0.1

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

AddState Add account state

func (*Account) Code

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

Code return the contract code

func (*Account) CodeHash

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

func (*Account) GetBalance

func (o *Account) GetBalance() uint64

GetBalance Get the balance from the account

func (*Account) GetNonce

func (o *Account) GetNonce() uint64

GetNonce Get the nonce from user account

func (*Account) GetState

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

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

func (*Account) Query

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

Query Query the value using key

func (*Account) SetBalance

func (o *Account) SetBalance(balance uint64)

SetBalance Set the balance to the account

func (*Account) SetCodeAndHash

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

SetCodeAndHash Set the contract code and hash

func (*Account) SetNonce

func (o *Account) SetNonce(nonce uint64)

SetNonce Set the nonce which indicates the contract number

func (*Account) SetState

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

SetState Set account state

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]*Account
	Journal        *BlockJournal
	InterchainMeta *pb.InterchainMeta
	TxHashList     []*types.Hash
}

type BlockJournal

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

type BlockchainLedger

type BlockchainLedger interface {
	// PutBlock put block into store
	PutBlock(height uint64, block *pb.Block) error

	// GetBlock get block with height
	GetBlock(height uint64) (*pb.Block, error)

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

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

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

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

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

	// GetInterchainMeta get interchain meta data
	GetInterchainMeta(height uint64) (*pb.InterchainMeta, error)

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

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

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

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

BlockchainLedger handles block, transaction and receipt data.

type ChainLedger

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

func New

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

New create a new ledger instance

func (*ChainLedger) AccountCache added in v1.0.1

func (l *ChainLedger) AccountCache() *AccountCache

func (*ChainLedger) AddEvent

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

AddEvent add ledger event

func (*ChainLedger) AddState added in v1.0.1

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

AddState add account state value using account Address and key

func (*ChainLedger) Clear

func (l *ChainLedger) Clear()

func (*ChainLedger) Close

func (l *ChainLedger) Close()

Close close the ledger instance

func (*ChainLedger) Commit

func (l *ChainLedger) Commit(height uint64, accounts map[string]*Account, blockJournal *BlockJournal) error

Commit commit the state

func (*ChainLedger) Events

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

Events return ledger events

func (*ChainLedger) FlushDirtyDataAndComputeJournal

func (l *ChainLedger) FlushDirtyDataAndComputeJournal() (map[string]*Account, *BlockJournal)

FlushDirtyDataAndComputeJournal gets dirty accounts and computes block journal

func (*ChainLedger) GetAccount

func (l *ChainLedger) GetAccount(address *types.Address) *Account

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

func (*ChainLedger) GetBalance

func (l *ChainLedger) GetBalance(addr *types.Address) uint64

GetBalanec get account balance using account Address

func (*ChainLedger) GetBlock

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

GetBlock get block with height

func (*ChainLedger) GetBlockByHash

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

GetBlockByHash get the block using block hash

func (*ChainLedger) GetBlockSign

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

GetBlockSign get the signature of block

func (*ChainLedger) GetChainMeta

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

GetChainMeta get chain meta data

func (*ChainLedger) GetCode

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

GetCode get contract code

func (*ChainLedger) GetInterchainMeta

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

func (*ChainLedger) GetNonce

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

GetNonce get account nonce

func (*ChainLedger) GetOrCreateAccount

func (l *ChainLedger) GetOrCreateAccount(addr *types.Address) *Account

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

func (*ChainLedger) GetReceipt

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

GetReceipt get the transaction receipt

func (*ChainLedger) GetState

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

GetState get account state value using account Address and key

func (*ChainLedger) GetTransaction

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

GetTransaction get the transaction using transaction hash

func (*ChainLedger) GetTransactionCount added in v1.0.1

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

func (*ChainLedger) GetTransactionMeta

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

GetTransactionMeta get the transaction meta data

func (*ChainLedger) PersistBlockData

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

PersistBlockData persists block data

func (*ChainLedger) PersistExecutionResult

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

PersistExecutionResult persist the execution result

func (*ChainLedger) PutBlock

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

PutBlock put block into store

func (*ChainLedger) QueryByPrefix

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

QueryByPrefix query value using key

func (*ChainLedger) RemoveJournalsBeforeBlock

func (l *ChainLedger) RemoveJournalsBeforeBlock(height uint64) error

RemoveJournalsBeforeBlock removes ledger journals whose block number < height

func (*ChainLedger) Rollback

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

Rollback rollback ledger to history version

func (*ChainLedger) SetBalance

func (l *ChainLedger) SetBalance(addr *types.Address, value uint64)

SetBalance set account balance

func (*ChainLedger) SetCode

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

SetCode set contract code

func (*ChainLedger) SetNonce

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

SetNonce set account nonce

func (*ChainLedger) SetState

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

SetState set account state value using account Address and key

func (*ChainLedger) UpdateChainMeta

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

UpdateChainMeta update the chain meta data

func (*ChainLedger) Version

func (l *ChainLedger) Version() uint64

Version returns the current version

type Ledger

type Ledger interface {
	BlockchainLedger
	StateAccessor

	AccountCache() *AccountCache

	// PersistBlockData
	PersistBlockData(blockData *BlockData)

	// AddEvent
	AddEvent(*pb.Event)

	// Events
	Events(txHash string) []*pb.Event

	// Rollback
	Rollback(height uint64) error

	// RemoveJournalsBeforeBlock
	RemoveJournalsBeforeBlock(height uint64) error

	// Close release resource
	Close()
}

type StateAccessor

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

	// GetAccount
	GetAccount(*types.Address) *Account

	// GetBalance
	GetBalance(*types.Address) uint64

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

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

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

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

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

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

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

	// GetNonce
	GetNonce(*types.Address) uint64

	// QueryByPrefix
	QueryByPrefix(address *types.Address, prefix string) (bool, [][]byte)

	// Commit commits the state data
	Commit(height uint64, accounts map[string]*Account, blockJournal *BlockJournal) error

	// FlushDirtyDataAndComputeJournal flushes the dirty data and computes block journal
	FlushDirtyDataAndComputeJournal() (map[string]*Account, *BlockJournal)

	// Version
	Version() uint64

	// Clear
	Clear()
}

StateAccessor manipulates the state data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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