Documentation
¶
Overview ¶
Copyright 2020 ChainSafe Systems (ON) Corp. This file is part of gossamer.
The gossamer library 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 gossamer library 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 gossamer library. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Variables
- 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, r byte)
- 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 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) BestBlockStateRoot() (common.Hash, error)
- func (bs *BlockState) BlocktreeAsString() string
- func (bs *BlockState) CompareAndSetBlockData(bd *types.BlockData) error
- func (bs *BlockState) DeleteBlock(hash common.Hash) 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(num *big.Int) (*types.Block, error)
- func (bs *BlockState) GetBlockHash(blockNumber *big.Int) (*common.Hash, error)
- func (bs *BlockState) GetFinalizedHash(round, setID uint64) (common.Hash, error)
- func (bs *BlockState) GetFinalizedHeader(round, setID uint64) (*types.Header, error)
- func (bs *BlockState) GetHeader(hash common.Hash) (*types.Header, error)
- func (bs *BlockState) GetHeaderByNumber(num *big.Int) (*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) GetRound() (uint64, error)
- func (bs *BlockState) GetSlotForBlock(hash common.Hash) (uint64, error)
- func (bs *BlockState) HasArrivalTime(hash common.Hash) (bool, error)
- func (bs *BlockState) HasBlockBody(hash common.Hash) (bool, error)
- func (bs *BlockState) HasFinalizedBlock(round, setID uint64) (bool, error)
- func (bs *BlockState) HasHeader(hash common.Hash) (bool, error)
- func (bs *BlockState) HasJustification(hash common.Hash) (bool, error)
- func (bs *BlockState) HasMessageQueue(hash common.Hash) (bool, error)
- func (bs *BlockState) HasReceipt(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) RegisterFinalizedChannel(ch chan<- *types.Header) (byte, error)
- func (bs *BlockState) RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
- func (bs *BlockState) SetBabeHeader(epoch uint64, slot uint64, bh *types.BabeHeader) error
- func (bs *BlockState) SetBlockBody(hash common.Hash, body *types.Body) error
- func (bs *BlockState) SetFinalizedHash(hash common.Hash, round, setID uint64) 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) SetRound(round uint64) error
- func (bs *BlockState) SubChain(start, end common.Hash) ([]common.Hash, error)
- func (bs *BlockState) UnregisterFinalizedChannel(id byte)
- func (bs *BlockState) UnregisterImportedChannel(id byte)
- type EpochState
- func (s *EpochState) GetCurrentEpoch() (uint64, error)
- func (s *EpochState) GetEpochInfo(epoch uint64) (*types.EpochInfo, error)
- func (s *EpochState) GetStartSlotForEpoch(epoch uint64) (uint64, error)
- func (s *EpochState) HasEpochInfo(epoch uint64) (bool, error)
- func (s *EpochState) SetCurrentEpoch(epoch uint64) error
- func (s *EpochState) SetEpochInfo(epoch uint64, info *types.EpochInfo) error
- type KeyValue
- 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 StorageState
- func (s *StorageState) Entries(hash *common.Hash) (map[string][]byte, error)
- func (s *StorageState) EnumeratedTrieRoot(values [][]byte)
- func (s *StorageState) ExistsStorage(hash *common.Hash, key []byte) (bool, error)
- func (s *StorageState) GetBalance(hash *common.Hash, key [32]byte) (uint64, error)
- func (s *StorageState) GetStorage(hash *common.Hash, key []byte) ([]byte, error)
- func (s *StorageState) GetStorageByBlockHash(bhash common.Hash, key []byte) ([]byte, error)
- func (s *StorageState) GetStorageChild(hash *common.Hash, keyToChild []byte) (*trie.Trie, error)
- func (s *StorageState) GetStorageFromChild(hash *common.Hash, keyToChild, key []byte) ([]byte, error)
- func (s *StorageState) LoadCode(hash *common.Hash) ([]byte, error)
- func (s *StorageState) LoadCodeHash(hash *common.Hash) (common.Hash, error)
- func (s *StorageState) LoadFromDB(root common.Hash) (*trie.Trie, error)
- func (s *StorageState) RegisterStorageChangeChannel(ch chan<- *KeyValue) (byte, error)
- func (s *StorageState) StorageRoot() (common.Hash, error)
- func (s *StorageState) StoreInDB(root common.Hash) error
- func (s *StorageState) StoreTrie(root common.Hash, ts *TrieState) error
- func (s *StorageState) TrieState(hash *common.Hash) (*TrieState, error)
- func (s *StorageState) UnregisterStorageChangeChannel(id byte)
- type TransactionState
- func (s *TransactionState) AddToPool(vt *transaction.ValidTransaction) common.Hash
- func (s *TransactionState) Peek() *transaction.ValidTransaction
- func (s *TransactionState) Pending() []*transaction.ValidTransaction
- func (s *TransactionState) PendingInPool() []*transaction.ValidTransaction
- func (s *TransactionState) Pop() *transaction.ValidTransaction
- func (s *TransactionState) Push(vt *transaction.ValidTransaction) (common.Hash, error)
- func (s *TransactionState) RemoveExtrinsic(ext types.Extrinsic)
- func (s *TransactionState) RemoveExtrinsicFromPool(ext types.Extrinsic)
- type TrieState
- func (s *TrieState) ClearChildStorage(keyToChild, key []byte) error
- func (s *TrieState) Commit() error
- func (s *TrieState) Delete(key []byte) error
- func (s *TrieState) DeleteChildStorage(key []byte) error
- func (s *TrieState) Entries() map[string][]byte
- func (s *TrieState) Free() error
- func (s *TrieState) Get(key []byte) ([]byte, error)
- func (s *TrieState) GetBalance(key [32]byte) (uint64, error)
- func (s *TrieState) GetChild(keyToChild []byte) (*trie.Trie, error)
- func (s *TrieState) GetChildStorage(keyToChild, key []byte) ([]byte, error)
- func (s *TrieState) Has(key []byte) (bool, error)
- func (s *TrieState) MustRoot() common.Hash
- func (s *TrieState) NextKey(key []byte) []byte
- func (s *TrieState) Root() (common.Hash, error)
- func (s *TrieState) Set(key []byte, value []byte) error
- func (s *TrieState) SetBalance(key [32]byte, balance uint64) error
- func (s *TrieState) SetChild(keyToChild []byte, child *trie.Trie) error
- func (s *TrieState) SetChildStorage(keyToChild, key, value []byte) error
- func (s *TrieState) WriteTrieToDB() error
Constants ¶
This section is empty.
Variables ¶
var ErrTrieDoesNotExist = errors.New("trie with given root does not exist")
ErrTrieDoesNotExist is returned when attempting to interact with a trie that is not stored in the StorageState
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, r byte)
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 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) BestBlockStateRoot ¶ added in v0.2.0
func (bs *BlockState) BestBlockStateRoot() (common.Hash, error)
BestBlockStateRoot returns the state root 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) DeleteBlock ¶ added in v0.2.0
func (bs *BlockState) DeleteBlock(hash common.Hash) error
DeleteBlock deletes all instances of the block and its related data in the database
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) GetFinalizedHash ¶ added in v0.2.0
func (bs *BlockState) GetFinalizedHash(round, setID uint64) (common.Hash, error)
GetFinalizedHash gets the latest finalized block header
func (*BlockState) GetFinalizedHeader ¶ added in v0.2.0
func (bs *BlockState) GetFinalizedHeader(round, setID uint64) (*types.Header, error)
GetFinalizedHeader returns the latest finalized block header
func (*BlockState) GetHeaderByNumber ¶ added in v0.2.0
GetHeaderByNumber returns a block header given a number
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) GetRound ¶ added in v0.2.0
func (bs *BlockState) GetRound() (uint64, error)
GetRound gets the latest finalized GRANDPA round from the db
func (*BlockState) GetSlotForBlock ¶
func (bs *BlockState) GetSlotForBlock(hash common.Hash) (uint64, error)
GetSlotForBlock returns the slot for a block
func (*BlockState) HasArrivalTime ¶ added in v0.2.0
func (bs *BlockState) HasArrivalTime(hash common.Hash) (bool, error)
HasArrivalTime returns true if the db contains the block's arrival time
func (*BlockState) HasBlockBody ¶ added in v0.2.0
func (bs *BlockState) HasBlockBody(hash common.Hash) (bool, error)
HasBlockBody returns true if the db contains the block body
func (*BlockState) HasFinalizedBlock ¶ added in v0.2.0
func (bs *BlockState) HasFinalizedBlock(round, setID uint64) (bool, error)
HasFinalizedBlock returns true if there is a finalized block for a given round and setID, false otherwise
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) HasJustification ¶ added in v0.2.0
func (bs *BlockState) HasJustification(hash common.Hash) (bool, error)
HasJustification returns if the db contains a Justification at the given hash
func (*BlockState) HasMessageQueue ¶ added in v0.2.0
func (bs *BlockState) HasMessageQueue(hash common.Hash) (bool, error)
HasMessageQueue returns if the db contains a MessageQueue at the given hash
func (*BlockState) HasReceipt ¶ added in v0.2.0
func (bs *BlockState) HasReceipt(hash common.Hash) (bool, error)
HasReceipt returns if the db contains a receipt at 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) RegisterFinalizedChannel ¶ added in v0.2.0
func (bs *BlockState) RegisterFinalizedChannel(ch chan<- *types.Header) (byte, error)
RegisterFinalizedChannel registers a channel for block notification upon block finalization. It returns the channel ID (used for unregistering the channel)
func (*BlockState) RegisterImportedChannel ¶ added in v0.2.0
func (bs *BlockState) RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
RegisterImportedChannel registers a channel for block notification upon block import. It returns the channel ID (used for unregistering the channel)
func (*BlockState) SetBabeHeader ¶
func (bs *BlockState) SetBabeHeader(epoch uint64, slot uint64, bh *types.BabeHeader) error
SetBabeHeader sets a BabeHeader in the database
func (*BlockState) SetBlockBody ¶
SetBlockBody will add a block body to the db
func (*BlockState) SetFinalizedHash ¶ added in v0.2.0
func (bs *BlockState) SetFinalizedHash(hash common.Hash, round, setID uint64) error
SetFinalizedHash sets the latest finalized block header
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
func (*BlockState) SetRound ¶ added in v0.2.0
func (bs *BlockState) SetRound(round uint64) error
SetRound sets the latest finalized GRANDPA round in the db TODO: this needs to use both setID and round
func (*BlockState) SubChain ¶
SubChain returns the sub-blockchain between the starting hash and the ending hash using the block tree
func (*BlockState) UnregisterFinalizedChannel ¶ added in v0.2.0
func (bs *BlockState) UnregisterFinalizedChannel(id byte)
UnregisterFinalizedChannel removes the block finalization notification channel with the given ID. A channel must be unregistered before closing it.
func (*BlockState) UnregisterImportedChannel ¶ added in v0.2.0
func (bs *BlockState) UnregisterImportedChannel(id byte)
UnregisterImportedChannel removes the block import notification channel with the given ID. A channel must be unregistered before closing it.
type EpochState ¶ added in v0.2.0
type EpochState struct {
// contains filtered or unexported fields
}
EpochState tracks information related to each epoch
func NewEpochState ¶ added in v0.2.0
func NewEpochState(db chaindb.Database) *EpochState
NewEpochState returns a new EpochState
func NewEpochStateFromGenesis ¶ added in v0.2.0
NewEpochStateFromGenesis returns a new EpochState given information for the first epoch, fetched from the runtime
func (*EpochState) GetCurrentEpoch ¶ added in v0.2.0
func (s *EpochState) GetCurrentEpoch() (uint64, error)
GetCurrentEpoch returns the current epoch
func (*EpochState) GetEpochInfo ¶ added in v0.2.0
func (s *EpochState) GetEpochInfo(epoch uint64) (*types.EpochInfo, error)
GetEpochInfo returns the epoch info for a given epoch
func (*EpochState) GetStartSlotForEpoch ¶ added in v0.2.0
func (s *EpochState) GetStartSlotForEpoch(epoch uint64) (uint64, error)
GetStartSlotForEpoch returns the first slot in the given epoch. If 0 is passed as the epoch, it returns the start slot for the current epoch.
func (*EpochState) HasEpochInfo ¶ added in v0.2.0
func (s *EpochState) HasEpochInfo(epoch uint64) (bool, error)
HasEpochInfo returns whether epoch info exists for a given epoch
func (*EpochState) SetCurrentEpoch ¶ added in v0.2.0
func (s *EpochState) SetCurrentEpoch(epoch uint64) error
SetCurrentEpoch sets the current epoch
func (*EpochState) SetEpochInfo ¶ added in v0.2.0
func (s *EpochState) SetEpochInfo(epoch uint64, info *types.EpochInfo) error
SetEpochInfo sets the epoch info for a given epoch
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
Transaction *TransactionState
Epoch *EpochState
// contains filtered or unexported fields
}
Service is the struct that holds storage, block and network states
func NewService ¶
NewService create a new instance of Service
func (*Service) Initialize ¶
func (s *Service) Initialize(data *genesis.Data, header *types.Header, t *trie.Trie, epochInfo *types.EpochInfo) error
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 StorageState ¶
type StorageState struct {
// contains filtered or unexported fields
}
StorageState is the struct that holds the trie, db and lock
func NewStorageState ¶
func NewStorageState(db chaindb.Database, blockState *BlockState, t *trie.Trie) (*StorageState, error)
NewStorageState creates a new StorageState backed by the given trie and database located at basePath.
func (*StorageState) EnumeratedTrieRoot ¶
func (s *StorageState) EnumeratedTrieRoot(values [][]byte)
EnumeratedTrieRoot not implemented
func (*StorageState) ExistsStorage ¶
ExistsStorage check if the key exists in the storage trie with the given storage hash If no hash is provided, the current chain head is used
func (*StorageState) GetBalance ¶
GetBalance gets the balance for an account with the given public key
func (*StorageState) GetStorage ¶
GetStorage gets the object from the trie using the given key and storage hash If no hash is provided, the current chain head is used
func (*StorageState) GetStorageByBlockHash ¶ added in v0.2.0
GetStorageByBlockHash returns the value at the given key at the given block hash
func (*StorageState) GetStorageChild ¶
GetStorageChild return GetChild from the trie
func (*StorageState) GetStorageFromChild ¶
func (s *StorageState) GetStorageFromChild(hash *common.Hash, keyToChild, key []byte) ([]byte, error)
GetStorageFromChild return GetFromChild from the trie
func (*StorageState) LoadCode ¶
func (s *StorageState) LoadCode(hash *common.Hash) ([]byte, error)
LoadCode returns the runtime code (located at :code)
func (*StorageState) LoadCodeHash ¶
LoadCodeHash returns the hash of the runtime code (located at :code)
func (*StorageState) LoadFromDB ¶
LoadFromDB loads an encoded trie from the DB where the key is `root`
func (*StorageState) RegisterStorageChangeChannel ¶ added in v0.2.0
func (s *StorageState) RegisterStorageChangeChannel(ch chan<- *KeyValue) (byte, error)
RegisterStorageChangeChannel function to register storage change channels
func (*StorageState) StorageRoot ¶
func (s *StorageState) StorageRoot() (common.Hash, error)
StorageRoot returns the root hash of the current storage trie
func (*StorageState) StoreInDB ¶
func (s *StorageState) StoreInDB(root common.Hash) 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
func (*StorageState) StoreTrie ¶ added in v0.2.0
func (s *StorageState) StoreTrie(root common.Hash, ts *TrieState) error
StoreTrie stores the given trie in the StorageState and writes it to the database
func (*StorageState) TrieState ¶ added in v0.2.0
func (s *StorageState) TrieState(hash *common.Hash) (*TrieState, error)
TrieState returns the TrieState for a given state root. If no state root is provided, it returns the TrieState for the current chain head.
func (*StorageState) UnregisterStorageChangeChannel ¶ added in v0.2.0
func (s *StorageState) UnregisterStorageChangeChannel(id byte)
UnregisterStorageChangeChannel removes the storage change notification channel with the given ID. A channel must be unregistered before closing it.
type TransactionState ¶ added in v0.2.0
type TransactionState struct {
// contains filtered or unexported fields
}
TransactionState represents the queue of transactions
func NewTransactionState ¶ added in v0.2.0
func NewTransactionState() *TransactionState
NewTransactionState returns a new TransactionState
func (*TransactionState) AddToPool ¶ added in v0.2.0
func (s *TransactionState) AddToPool(vt *transaction.ValidTransaction) common.Hash
AddToPool adds a transaction to the pool
func (*TransactionState) Peek ¶ added in v0.2.0
func (s *TransactionState) Peek() *transaction.ValidTransaction
Peek returns the head of the queue without removing it
func (*TransactionState) Pending ¶ added in v0.2.0
func (s *TransactionState) Pending() []*transaction.ValidTransaction
Pending returns the current transactions in the queue and pool
func (*TransactionState) PendingInPool ¶ added in v0.2.0
func (s *TransactionState) PendingInPool() []*transaction.ValidTransaction
PendingInPool returns the current transactions in the pool
func (*TransactionState) Pop ¶ added in v0.2.0
func (s *TransactionState) Pop() *transaction.ValidTransaction
Pop removes and returns the head of the queue
func (*TransactionState) Push ¶ added in v0.2.0
func (s *TransactionState) Push(vt *transaction.ValidTransaction) (common.Hash, error)
Push pushes a transaction to the queue, ordered by priority
func (*TransactionState) RemoveExtrinsic ¶ added in v0.2.0
func (s *TransactionState) RemoveExtrinsic(ext types.Extrinsic)
RemoveExtrinsic removes an extrinsic from the queue and pool
func (*TransactionState) RemoveExtrinsicFromPool ¶ added in v0.2.0
func (s *TransactionState) RemoveExtrinsicFromPool(ext types.Extrinsic)
RemoveExtrinsicFromPool removes an extrinsic from the pool
type TrieState ¶ added in v0.2.0
type TrieState struct {
// contains filtered or unexported fields
}
TrieState is a wrapper around a transient trie that is used during the course of executing some runtime call. If the execution of the call is successful, the trie will be saved in the StorageState.
func NewTrieState ¶ added in v0.2.0
NewTrieState returns a new TrieState with the given trie
func (*TrieState) ClearChildStorage ¶ added in v0.2.0
ClearChildStorage removes the child storage entry from the trie
func (*TrieState) Commit ¶ added in v0.2.0
nolint Commit ensures that the TrieState's trie and database match The database is the source of truth due to the runtime interpreter's undefined behaviour regarding the trie
func (*TrieState) DeleteChildStorage ¶ added in v0.2.0
DeleteChildStorage deletes child storage from the trie
func (*TrieState) Free ¶ added in v0.2.0
Free should be called once this trie state is no longer needed
func (*TrieState) GetBalance ¶ added in v0.2.0
GetBalance returns the balance for a given public key
func (*TrieState) GetChildStorage ¶ added in v0.2.0
GetChildStorage returns a value from a child trie
func (*TrieState) MustRoot ¶ added in v0.2.0
MustRoot returns the trie's root hash. It panics if it fails to compute the root.
func (*TrieState) NextKey ¶ added in v0.2.0
NextKey returns the next key in the trie in lexigraphical order. If it does not exist, it returns nil.
func (*TrieState) SetBalance ¶ added in v0.2.0
SetBalance sets the balance for a given public key
func (*TrieState) SetChildStorage ¶ added in v0.2.0
SetChildStorage sets a key-value pair in a child trie
func (*TrieState) WriteTrieToDB ¶ added in v0.2.0
WriteTrieToDB writes the trie to the database