Documentation ¶
Index ¶
- func AddBlocksToState(t *testing.T, blockState *BlockState, depth int) ([]*types.Header, []*types.Header)
- func AddBlocksToStateWithFixedBranches(t *testing.T, blockState *BlockState, depth int, branches map[int]int)
- func LoadBestBlockHash(db database.Database) (common.Hash, error)
- func LoadGenesisData(db database.Database) (*genesis.Data, error)
- func LoadLatestStorageHash(db database.Database) (common.Hash, error)
- func LoadTrie(db database.Database, t *trie.Trie, root common.Hash) error
- func StoreBestBlockHash(db database.Database, hash common.Hash) error
- func StoreGenesisData(db database.Database, gen *genesis.Data) error
- func StoreLatestStorageHash(db database.Database, t *trie.Trie) error
- func StoreTrie(db database.Database, t *trie.Trie) error
- type BlockDB
- type BlockState
- func (bs *BlockState) AddBlock(block *types.Block) error
- func (bs *BlockState) AddBlockWithArrivalTime(block *types.Block, arrivalTime uint64) error
- func (bs *BlockState) BestBlock() (*types.Block, error)
- func (bs *BlockState) BestBlockHash() common.Hash
- func (bs *BlockState) BestBlockHeader() (*types.Header, error)
- func (bs *BlockState) BestBlockNumber() (*big.Int, error)
- func (bs *BlockState) BlocktreeAsString() string
- func (bs *BlockState) CompareAndSetBlockData(bd *types.BlockData) error
- func (bs *BlockState) GenesisHash() common.Hash
- func (bs *BlockState) GetAllBlocksAtDepth(hash common.Hash) []common.Hash
- func (bs *BlockState) GetArrivalTime(hash common.Hash) (uint64, error)
- func (bs *BlockState) GetBabeHeader(epoch uint64, slot uint64) (*types.BabeHeader, error)
- func (bs *BlockState) GetBlockBody(hash common.Hash) (*types.Body, error)
- func (bs *BlockState) GetBlockByHash(hash common.Hash) (*types.Block, error)
- func (bs *BlockState) GetBlockByNumber(blockNumber *big.Int) (*types.Block, error)
- func (bs *BlockState) GetBlockHash(blockNumber *big.Int) (*common.Hash, error)
- func (bs *BlockState) GetFinalizedHead() (*types.Header, error)
- func (bs *BlockState) GetHeader(hash common.Hash) (*types.Header, error)
- func (bs *BlockState) GetJustification(hash common.Hash) ([]byte, error)
- func (bs *BlockState) GetMessageQueue(hash common.Hash) ([]byte, error)
- func (bs *BlockState) GetReceipt(hash common.Hash) ([]byte, error)
- func (bs *BlockState) GetSlotForBlock(hash common.Hash) (uint64, error)
- func (bs *BlockState) HasHeader(hash common.Hash) (bool, error)
- func (bs *BlockState) HighestBlockHash() common.Hash
- func (bs *BlockState) HighestBlockNumber() *big.Int
- func (bs *BlockState) HighestCommonAncestor(a, b common.Hash) (common.Hash, error)
- func (bs *BlockState) IsDescendantOf(parent, child common.Hash) (bool, error)
- func (bs *BlockState) Leaves() []common.Hash
- func (bs *BlockState) SetBabeHeader(epoch uint64, slot uint64, bh *types.BabeHeader) error
- func (bs *BlockState) SetBlockAddedChannel(rcvr chan<- *types.Block, done <-chan struct{})
- func (bs *BlockState) SetBlockBody(hash common.Hash, body *types.Body) error
- func (bs *BlockState) SetHeader(header *types.Header) error
- func (bs *BlockState) SetJustification(hash common.Hash, data []byte) error
- func (bs *BlockState) SetMessageQueue(hash common.Hash, data []byte) error
- func (bs *BlockState) SetReceipt(hash common.Hash, data []byte) error
- func (bs *BlockState) SubChain(start, end common.Hash) ([]common.Hash, error)
- type NetworkState
- func (ns *NetworkState) GetHealth() common.Health
- func (ns *NetworkState) GetNetworkState() common.NetworkState
- func (ns *NetworkState) GetPeers() []common.PeerInfo
- func (ns *NetworkState) SetHealth(health common.Health)
- func (ns *NetworkState) SetNetworkState(networkState common.NetworkState)
- func (ns *NetworkState) SetPeers(peers []common.PeerInfo)
- type Service
- type StorageDB
- type StorageState
- func (s *StorageState) ClearPrefix(prefix []byte)
- func (s *StorageState) ClearStorage(key []byte) error
- func (s *StorageState) Entries() map[string][]byte
- func (s *StorageState) EnumeratedTrieRoot(values [][]byte)
- func (s *StorageState) ExistsStorage(key []byte) (bool, error)
- func (s *StorageState) GetBalance(key [32]byte) (uint64, error)
- func (s *StorageState) GetStorage(key []byte) ([]byte, error)
- func (s *StorageState) GetStorageChild(keyToChild []byte) (*trie.Trie, error)
- func (s *StorageState) GetStorageFromChild(keyToChild, key []byte) ([]byte, error)
- func (s *StorageState) LoadCode() ([]byte, error)
- func (s *StorageState) LoadCodeHash() (common.Hash, error)
- func (s *StorageState) LoadFromDB(root common.Hash) error
- func (s *StorageState) SetBalance(key [32]byte, balance uint64) error
- func (s *StorageState) SetStorage(key []byte, value []byte) error
- func (s *StorageState) SetStorageChild(keyToChild []byte, child *trie.Trie) error
- func (s *StorageState) SetStorageIntoChild(keyToChild, key, value []byte) error
- func (s *StorageState) StorageRoot() (common.Hash, error)
- func (s *StorageState) StoreInDB() error
- type TransactionQueue
- func (q *TransactionQueue) Peek() *transaction.ValidTransaction
- func (q *TransactionQueue) Pending() []*transaction.ValidTransaction
- func (q *TransactionQueue) Pop() *transaction.ValidTransaction
- func (q *TransactionQueue) Push(vt *transaction.ValidTransaction) (common.Hash, error)
- func (q *TransactionQueue) RemoveExtrinsic(ext types.Extrinsic)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddBlocksToState ¶
func AddBlocksToState(t *testing.T, blockState *BlockState, depth int) ([]*types.Header, []*types.Header)
AddBlocksToState adds blocks to a BlockState up to depth, with random branches
func AddBlocksToStateWithFixedBranches ¶
func AddBlocksToStateWithFixedBranches(t *testing.T, blockState *BlockState, depth int, branches map[int]int)
AddBlocksToStateWithFixedBranches adds blocks to a BlockState up to depth, with fixed branches branches are provided with a map of depth -> # of branches
func LoadBestBlockHash ¶
LoadBestBlockHash loads the hash stored at BestBlockHashKey
func LoadGenesisData ¶
LoadGenesisData retrieves the genesis data stored at the known GenesisDataKey.
func LoadLatestStorageHash ¶
LoadLatestStorageHash retrieves the hash stored at LatestStorageHashKey from the DB
func StoreBestBlockHash ¶
StoreBestBlockHash stores the hash at the BestBlockHashKey
func StoreGenesisData ¶
StoreGenesisData stores the given genesis data at the known GenesisDataKey.
func StoreLatestStorageHash ¶
StoreLatestStorageHash stores the current root hash in the database at LatestStorageHashKey
Types ¶
type BlockDB ¶
type BlockDB struct {
// contains filtered or unexported fields
}
BlockDB stores block's in an underlying Database
func NewBlockDB ¶
NewBlockDB instantiates a badgerDB instance for storing relevant BlockData
type BlockState ¶
type BlockState struct {
// contains filtered or unexported fields
}
BlockState defines fields for manipulating the state of blocks, such as BlockTree, BlockDB and Header
func NewBlockState ¶
NewBlockState will create a new BlockState backed by the database located at basePath
func NewBlockStateFromGenesis ¶
NewBlockStateFromGenesis initializes a BlockState from a genesis header, saving it to the database located at basePath
func (*BlockState) AddBlock ¶
func (bs *BlockState) AddBlock(block *types.Block) error
AddBlock adds a block to the blocktree and the DB with arrival time as current unix time
func (*BlockState) AddBlockWithArrivalTime ¶
func (bs *BlockState) AddBlockWithArrivalTime(block *types.Block, arrivalTime uint64) error
AddBlockWithArrivalTime adds a block to the blocktree and the DB with the given arrival time
func (*BlockState) BestBlock ¶
func (bs *BlockState) BestBlock() (*types.Block, error)
BestBlock returns the current head of the chain
func (*BlockState) BestBlockHash ¶
func (bs *BlockState) BestBlockHash() common.Hash
BestBlockHash returns the hash of the head of the current chain
func (*BlockState) BestBlockHeader ¶
func (bs *BlockState) BestBlockHeader() (*types.Header, error)
BestBlockHeader returns the block header of the current head of the chain
func (*BlockState) BestBlockNumber ¶
func (bs *BlockState) BestBlockNumber() (*big.Int, error)
BestBlockNumber returns the block number of the current head of the chain
func (*BlockState) BlocktreeAsString ¶
func (bs *BlockState) BlocktreeAsString() string
BlocktreeAsString returns the blocktree as a string
func (*BlockState) CompareAndSetBlockData ¶
func (bs *BlockState) CompareAndSetBlockData(bd *types.BlockData) error
CompareAndSetBlockData will compare empty fields and set all elements in a block data to db
func (*BlockState) GenesisHash ¶
func (bs *BlockState) GenesisHash() common.Hash
GenesisHash returns the hash of the genesis block
func (*BlockState) GetAllBlocksAtDepth ¶
func (bs *BlockState) GetAllBlocksAtDepth(hash common.Hash) []common.Hash
GetAllBlocksAtDepth returns all hashes with the depth of the given hash plus one
func (*BlockState) GetArrivalTime ¶
func (bs *BlockState) GetArrivalTime(hash common.Hash) (uint64, error)
GetArrivalTime returns the arrival time of a block given its hash
func (*BlockState) GetBabeHeader ¶
func (bs *BlockState) GetBabeHeader(epoch uint64, slot uint64) (*types.BabeHeader, error)
GetBabeHeader retrieves a BabeHeader from the database
func (*BlockState) GetBlockBody ¶
GetBlockBody will return Body for a given hash
func (*BlockState) GetBlockByHash ¶
GetBlockByHash returns a block for a given hash
func (*BlockState) GetBlockByNumber ¶
GetBlockByNumber returns a block for a given blockNumber
func (*BlockState) GetBlockHash ¶
GetBlockHash returns block hash for a given blockNumber
func (*BlockState) GetFinalizedHead ¶
func (bs *BlockState) GetFinalizedHead() (*types.Header, error)
GetFinalizedHead returns the latest finalized block header TODO: relies on GRANDPA implementation. currently returns genesis header.
func (*BlockState) GetJustification ¶
func (bs *BlockState) GetJustification(hash common.Hash) ([]byte, error)
GetJustification retrieves a Justification from the database
func (*BlockState) GetMessageQueue ¶
func (bs *BlockState) GetMessageQueue(hash common.Hash) ([]byte, error)
GetMessageQueue retrieves a MessageQueue from the database
func (*BlockState) GetReceipt ¶
func (bs *BlockState) GetReceipt(hash common.Hash) ([]byte, error)
GetReceipt retrieves a Receipt from the database
func (*BlockState) GetSlotForBlock ¶
func (bs *BlockState) GetSlotForBlock(hash common.Hash) (uint64, error)
GetSlotForBlock returns the slot for a block
func (*BlockState) HasHeader ¶
func (bs *BlockState) HasHeader(hash common.Hash) (bool, error)
HasHeader returns if the db contains a header with the given hash
func (*BlockState) HighestBlockHash ¶
func (bs *BlockState) HighestBlockHash() common.Hash
HighestBlockHash returns the hash of the block with the highest number we have received This block may not necessarily be in the blocktree. TODO: can probably remove this once BlockResponses are implemented
func (*BlockState) HighestBlockNumber ¶
func (bs *BlockState) HighestBlockNumber() *big.Int
HighestBlockNumber returns the largest block number we have seen This block may not necessarily be in the blocktree. TODO: can probably remove this once BlockResponses are implemented
func (*BlockState) HighestCommonAncestor ¶
HighestCommonAncestor returns the block with the highest number that is an ancestor of both a and b
func (*BlockState) IsDescendantOf ¶
func (bs *BlockState) IsDescendantOf(parent, child common.Hash) (bool, error)
IsDescendantOf returns true if child is a descendant of parent, false otherwise. it returns an error if parent or child are not in the blocktree.
func (*BlockState) Leaves ¶
func (bs *BlockState) Leaves() []common.Hash
Leaves returns the leaves of the blocktree as an array
func (*BlockState) SetBabeHeader ¶
func (bs *BlockState) SetBabeHeader(epoch uint64, slot uint64, bh *types.BabeHeader) error
SetBabeHeader sets a BabeHeader in the database
func (*BlockState) SetBlockAddedChannel ¶
func (bs *BlockState) SetBlockAddedChannel(rcvr chan<- *types.Block, done <-chan struct{})
SetBlockAddedChannel to sets channel that blocks will be received on
func (*BlockState) SetBlockBody ¶
SetBlockBody will add a block body to the db
func (*BlockState) SetHeader ¶
func (bs *BlockState) SetHeader(header *types.Header) error
SetHeader will set the header into DB
func (*BlockState) SetJustification ¶
func (bs *BlockState) SetJustification(hash common.Hash, data []byte) error
SetJustification sets a Justification in the database
func (*BlockState) SetMessageQueue ¶
func (bs *BlockState) SetMessageQueue(hash common.Hash, data []byte) error
SetMessageQueue sets a MessageQueue in the database
func (*BlockState) SetReceipt ¶
func (bs *BlockState) SetReceipt(hash common.Hash, data []byte) error
SetReceipt sets a Receipt in the database
type NetworkState ¶
type NetworkState struct { Health common.Health NetworkState common.NetworkState Peers []common.PeerInfo }
NetworkState defines fields for manipulating the state of network
func (*NetworkState) GetHealth ¶
func (ns *NetworkState) GetHealth() common.Health
GetHealth retrieves network health from the database
func (*NetworkState) GetNetworkState ¶
func (ns *NetworkState) GetNetworkState() common.NetworkState
GetNetworkState retrieves network state from the database
func (*NetworkState) GetPeers ¶
func (ns *NetworkState) GetPeers() []common.PeerInfo
GetPeers retrieves network state from the database
func (*NetworkState) SetHealth ¶
func (ns *NetworkState) SetHealth(health common.Health)
SetHealth sets network health in the database
func (*NetworkState) SetNetworkState ¶
func (ns *NetworkState) SetNetworkState(networkState common.NetworkState)
SetNetworkState sets network state in the database
func (*NetworkState) SetPeers ¶
func (ns *NetworkState) SetPeers(peers []common.PeerInfo)
SetPeers sets network state in the database
type Service ¶
type Service struct { Storage *StorageState Block *BlockState Network *NetworkState TransactionQueue *TransactionQueue // contains filtered or unexported fields }
Service is the struct that holds storage, block and network states
func (*Service) Initialize ¶
Initialize initializes the genesis state of the DB using the given storage trie. The trie should be loaded with the genesis storage state. This only needs to be called during genesis initialization of the node; it doesn't need to be called during normal startup.
type StorageDB ¶
type StorageDB struct {
// contains filtered or unexported fields
}
StorageDB stores trie structure in an underlying database
func NewStorageDB ¶
NewStorageDB instantiates badgerDB instance for storing trie structure
type StorageState ¶
type StorageState struct {
// contains filtered or unexported fields
}
StorageState is the struct that holds the trie, db and lock
func NewStorageState ¶
NewStorageState creates a new StorageState backed by the given trie and database located at basePath.
func (*StorageState) ClearPrefix ¶
func (s *StorageState) ClearPrefix(prefix []byte)
ClearPrefix not implemented
func (*StorageState) ClearStorage ¶
func (s *StorageState) ClearStorage(key []byte) error
ClearStorage will delete a key/value from the trie for a given @key
func (*StorageState) Entries ¶
func (s *StorageState) Entries() map[string][]byte
Entries returns Entries from the trie
func (*StorageState) EnumeratedTrieRoot ¶
func (s *StorageState) EnumeratedTrieRoot(values [][]byte)
EnumeratedTrieRoot not implemented
func (*StorageState) ExistsStorage ¶
func (s *StorageState) ExistsStorage(key []byte) (bool, error)
ExistsStorage check if the key exists in the storage trie
func (*StorageState) GetBalance ¶
func (s *StorageState) GetBalance(key [32]byte) (uint64, error)
GetBalance gets the balance for an account with the given public key
func (*StorageState) GetStorage ¶
func (s *StorageState) GetStorage(key []byte) ([]byte, error)
GetStorage gets the object from the trie using key
func (*StorageState) GetStorageChild ¶
func (s *StorageState) GetStorageChild(keyToChild []byte) (*trie.Trie, error)
GetStorageChild return GetChild from the trie
func (*StorageState) GetStorageFromChild ¶
func (s *StorageState) GetStorageFromChild(keyToChild, key []byte) ([]byte, error)
GetStorageFromChild return GetFromChild from the trie
func (*StorageState) LoadCode ¶
func (s *StorageState) LoadCode() ([]byte, error)
LoadCode returns the runtime code (located at :code)
func (*StorageState) LoadCodeHash ¶
func (s *StorageState) LoadCodeHash() (common.Hash, error)
LoadCodeHash returns the hash of the runtime code (located at :code)
func (*StorageState) LoadFromDB ¶
func (s *StorageState) LoadFromDB(root common.Hash) error
LoadFromDB loads an encoded trie from the DB where the key is `root`
func (*StorageState) SetBalance ¶
func (s *StorageState) SetBalance(key [32]byte, balance uint64) error
SetBalance sets the balance for an account with the given public key
func (*StorageState) SetStorage ¶
func (s *StorageState) SetStorage(key []byte, value []byte) error
SetStorage set the storage value for a given key in the trie
func (*StorageState) SetStorageChild ¶
func (s *StorageState) SetStorageChild(keyToChild []byte, child *trie.Trie) error
SetStorageChild return PutChild from the trie
func (*StorageState) SetStorageIntoChild ¶
func (s *StorageState) SetStorageIntoChild(keyToChild, key, value []byte) error
SetStorageIntoChild return PutIntoChild from the trie
func (*StorageState) StorageRoot ¶
func (s *StorageState) StorageRoot() (common.Hash, error)
StorageRoot returns the trie hash
func (*StorageState) StoreInDB ¶
func (s *StorageState) StoreInDB() error
StoreInDB encodes the entire trie and writes it to the DB The key to the DB entry is the root hash of the trie
type TransactionQueue ¶
type TransactionQueue struct {
// contains filtered or unexported fields
}
TransactionQueue represents the queue of transactions
func NewTransactionQueue ¶
func NewTransactionQueue() *TransactionQueue
NewTransactionQueue returns a new TransactionQueue
func (*TransactionQueue) Peek ¶
func (q *TransactionQueue) Peek() *transaction.ValidTransaction
Peek returns the head of the queue without removing it
func (*TransactionQueue) Pending ¶
func (q *TransactionQueue) Pending() []*transaction.ValidTransaction
Pending returns the current transactions in the queue
func (*TransactionQueue) Pop ¶
func (q *TransactionQueue) Pop() *transaction.ValidTransaction
Pop removes and returns the head of the queue
func (*TransactionQueue) Push ¶
func (q *TransactionQueue) Push(vt *transaction.ValidTransaction) (common.Hash, error)
Push pushes a transaction to the queue, ordered by priority
func (*TransactionQueue) RemoveExtrinsic ¶
func (q *TransactionQueue) RemoveExtrinsic(ext types.Extrinsic)
RemoveExtrinsic removes an extrinsic from the queue