state

package
v0.0.0-...-c69f244 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: LGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEpochNotInMemory = errors.New("epoch not found in memory map")
)
View Source
var ErrKeySize = errors.New("cannot have nil keystore")

ErrKeySize is returned when key size does not fit

View Source
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 uint,
	withBranches bool) ([]*types.Header, []*types.Header)

AddBlocksToState adds `depth` number of blocks to the BlockState, optionally with random branches

func AddBlocksToStateWithFixedBranches

func AddBlocksToStateWithFixedBranches(t *testing.T, blockState *BlockState, depth uint, branches map[uint]int)

AddBlocksToStateWithFixedBranches adds blocks to a BlockState up to depth, with fixed branches branches are provided with a map of depth -> # of branches

func NewInMemoryDB

func NewInMemoryDB(t *testing.T) chaindb.Database

NewInMemoryDB creates a new in-memory database

Types

type BaseState

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

BaseState is a wrapper for the chaindb.Database, without any prefixes

func NewBaseState

func NewBaseState(db chaindb.Database) *BaseState

NewBaseState returns a new BaseState

func (*BaseState) Del

func (s *BaseState) Del(key []byte) error

Del deletes key from database

func (*BaseState) Get

func (s *BaseState) Get(key []byte) ([]byte, error)

Get retrieves value by key from database

func (*BaseState) LoadCodeSubstitutedBlockHash

func (s *BaseState) LoadCodeSubstitutedBlockHash() common.Hash

LoadCodeSubstitutedBlockHash loads the hash stored at CodeSubstitutedBlock key

func (*BaseState) LoadGenesisData

func (s *BaseState) LoadGenesisData() (*genesis.Data, error)

LoadGenesisData retrieves the genesis data stored at the known GenesisDataKey.

func (*BaseState) LoadNodeGlobalName

func (s *BaseState) LoadNodeGlobalName() (string, error)

LoadNodeGlobalName loads the latest stored node global name

func (*BaseState) Put

func (s *BaseState) Put(key, value []byte) error

Put stores key/value pair in database

func (*BaseState) StoreCodeSubstitutedBlockHash

func (s *BaseState) StoreCodeSubstitutedBlockHash(hash common.Hash) error

StoreCodeSubstitutedBlockHash stores the hash at the CodeSubstitutedBlock key

func (*BaseState) StoreGenesisData

func (s *BaseState) StoreGenesisData(gen *genesis.Data) error

StoreGenesisData stores the given genesis data at the known GenesisDataKey.

func (*BaseState) StoreNodeGlobalName

func (s *BaseState) StoreNodeGlobalName(nodeName string) error

StoreNodeGlobalName stores the current node name to avoid create new ones after each initialization

type BlockState

type BlockState struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

BlockState contains the historical block data of the blockchain, including block headers and bodies. It wraps the blocktree (which contains unfinalised blocks) and the database (which contains finalised blocks).

func NewBlockState

func NewBlockState(db chaindb.Database, trs *Tries, telemetry telemetry.Client) (*BlockState, error)

NewBlockState will create a new BlockState backed by the database located at basePath

func NewBlockStateFromGenesis

func NewBlockStateFromGenesis(db chaindb.Database, trs *Tries, header *types.Header,
	telemetryMailer telemetry.Client) (*BlockState, error)

NewBlockStateFromGenesis initialises 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) AddBlockToBlockTree

func (bs *BlockState) AddBlockToBlockTree(block *types.Block) error

AddBlockToBlockTree adds the given block to the blocktree. It does not write it to the database. TODO: remove this func and usage from sync (after sync refactor?)

func (*BlockState) AddBlockWithArrivalTime

func (bs *BlockState) AddBlockWithArrivalTime(block *types.Block, arrivalTime time.Time) 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() (blockNumber uint, err error)

BestBlockNumber returns the block number of the current head of the chain

func (*BlockState) BestBlockStateRoot

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) FreeFinalisedNotifierChannel

func (bs *BlockState) FreeFinalisedNotifierChannel(ch chan *types.FinalisationInfo)

FreeFinalisedNotifierChannel to free finalised notifier channel

func (*BlockState) FreeImportedBlockNotifierChannel

func (bs *BlockState) FreeImportedBlockNotifierChannel(ch chan *types.Block)

FreeImportedBlockNotifierChannel to free imported block notifier channel

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) GetAllBlocksAtNumber

func (bs *BlockState) GetAllBlocksAtNumber(num uint) ([]common.Hash, error)

GetAllBlocksAtNumber returns all unfinalised blocks with the given number

func (*BlockState) GetArrivalTime

func (bs *BlockState) GetArrivalTime(hash common.Hash) (time.Time, error)

GetArrivalTime returns the arrival time in nanoseconds since the Unix epoch of a block given its hash

func (*BlockState) GetBlockBody

func (bs *BlockState) GetBlockBody(hash common.Hash) (body *types.Body, err error)

GetBlockBody will return Body for a given hash

func (*BlockState) GetBlockByHash

func (bs *BlockState) GetBlockByHash(hash common.Hash) (*types.Block, error)

GetBlockByHash returns a block for a given hash

func (*BlockState) GetBlockByNumber

func (bs *BlockState) GetBlockByNumber(num uint) (*types.Block, error)

GetBlockByNumber returns the block on our best chain with the given number

func (*BlockState) GetBlockStateRoot

func (bs *BlockState) GetBlockStateRoot(bhash common.Hash) (
	hash common.Hash, err error)

GetBlockStateRoot returns the state root of the given block hash

func (*BlockState) GetFinalisedHash

func (bs *BlockState) GetFinalisedHash(round, setID uint64) (common.Hash, error)

GetFinalisedHash gets the finalised block header by round and setID

func (*BlockState) GetFinalisedHeader

func (bs *BlockState) GetFinalisedHeader(round, setID uint64) (*types.Header, error)

GetFinalisedHeader returns the finalised block header by round and setID

func (*BlockState) GetFinalisedNotifierChannel

func (bs *BlockState) GetFinalisedNotifierChannel() chan *types.FinalisationInfo

GetFinalisedNotifierChannel function to retrieve a finalised block notifier channel

func (*BlockState) GetHashByNumber

func (bs *BlockState) GetHashByNumber(num uint) (common.Hash, error)

GetHashByNumber returns the block hash on our best chain with the given number

func (*BlockState) GetHeader

func (bs *BlockState) GetHeader(hash common.Hash) (header *types.Header, err error)

GetHeader returns a BlockHeader for a given hash

func (*BlockState) GetHeaderByNumber

func (bs *BlockState) GetHeaderByNumber(num uint) (*types.Header, error)

GetHeaderByNumber returns the block header on our best chain with the given number

func (*BlockState) GetHighestFinalisedHash

func (bs *BlockState) GetHighestFinalisedHash() (common.Hash, error)

GetHighestFinalisedHash returns the highest finalised block hash

func (*BlockState) GetHighestFinalisedHeader

func (bs *BlockState) GetHighestFinalisedHeader() (*types.Header, error)

GetHighestFinalisedHeader returns the highest finalised block header

func (*BlockState) GetHighestRoundAndSetID

func (bs *BlockState) GetHighestRoundAndSetID() (uint64, uint64, error)

GetHighestRoundAndSetID gets the highest round and setID that have been finalised

func (*BlockState) GetImportedBlockNotifierChannel

func (bs *BlockState) GetImportedBlockNotifierChannel() chan *types.Block

GetImportedBlockNotifierChannel function to retrieve a imported block notifier channel

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) GetNonFinalisedBlocks

func (bs *BlockState) GetNonFinalisedBlocks() []common.Hash

GetNonFinalisedBlocks get all the blocks in the blocktree

func (*BlockState) GetReceipt

func (bs *BlockState) GetReceipt(hash common.Hash) ([]byte, error)

GetReceipt retrieves a Receipt from the database

func (*BlockState) GetRuntime

func (bs *BlockState) GetRuntime(hash *common.Hash) (runtime.Instance, error)

GetRuntime gets the runtime for the corresponding block hash.

func (*BlockState) GetSlotForBlock

func (bs *BlockState) GetSlotForBlock(hash common.Hash) (uint64, error)

GetSlotForBlock returns the slot for a block

func (*BlockState) HandleRuntimeChanges

func (bs *BlockState) HandleRuntimeChanges(newState *rtstorage.TrieState,
	rt runtime.Instance, bHash common.Hash) error

HandleRuntimeChanges handles the update in runtime.

func (*BlockState) HasBlockBody

func (bs *BlockState) HasBlockBody(hash common.Hash) (bool, error)

HasBlockBody returns true if the db contains the block body

func (*BlockState) HasFinalisedBlock

func (bs *BlockState) HasFinalisedBlock(round, setID uint64) (bool, error)

HasFinalisedBlock returns true if there is a finalised block for a given round and setID, false otherwise

func (*BlockState) HasHeader

func (bs *BlockState) HasHeader(hash common.Hash) (bool, error)

HasHeader returns true if the hash is part of the unfinalised blocks in-memory or persisted in the database.

func (*BlockState) HasHeaderInDatabase

func (bs *BlockState) HasHeaderInDatabase(hash common.Hash) (bool, error)

HasHeaderInDatabase returns true if the database contains a header with the given hash

func (*BlockState) HasJustification

func (bs *BlockState) HasJustification(hash common.Hash) (bool, error)

HasJustification returns if the db contains a Justification at the given hash

func (*BlockState) HasMessageQueue

func (bs *BlockState) HasMessageQueue(hash common.Hash) (bool, error)

HasMessageQueue returns if the db contains a MessageQueue at the given hash

func (*BlockState) HasReceipt

func (bs *BlockState) HasReceipt(hash common.Hash) (bool, error)

HasReceipt returns if the db contains a receipt at the given hash

func (*BlockState) HighestCommonAncestor

func (bs *BlockState) HighestCommonAncestor(a, b common.Hash) (common.Hash, error)

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) NumberIsFinalised

func (bs *BlockState) NumberIsFinalised(num uint) (bool, error)

NumberIsFinalised checks if a block number is finalised or not

func (*BlockState) RegisterRuntimeUpdatedChannel

func (bs *BlockState) RegisterRuntimeUpdatedChannel(ch chan<- runtime.Version) (uint32, error)

RegisterRuntimeUpdatedChannel function to register chan that is notified when runtime version changes

func (*BlockState) SetBlockBody

func (bs *BlockState) SetBlockBody(hash common.Hash, body *types.Body) error

SetBlockBody will add a block body to the db

func (*BlockState) SetFinalisedHash

func (bs *BlockState) SetFinalisedHash(hash common.Hash, round, setID uint64) error

SetFinalisedHash sets the latest finalised block hash

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) StoreRuntime

func (bs *BlockState) StoreRuntime(hash common.Hash, rt runtime.Instance)

StoreRuntime stores the runtime for corresponding block hash.

func (*BlockState) SubChain

func (bs *BlockState) SubChain(start, end common.Hash) ([]common.Hash, error)

SubChain returns the sub-blockchain between the starting hash and the ending hash using the block tree

func (*BlockState) UnregisterRuntimeUpdatedChannel

func (bs *BlockState) UnregisterRuntimeUpdatedChannel(id uint32) bool

UnregisterRuntimeUpdatedChannel function to unregister runtime updated channel

type Config

type Config struct {
	Path      string
	LogLevel  log.Level
	PrunerCfg pruner.Config
	Telemetry telemetry.Client
}

Config is the default configuration used by state service.

type EpochState

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

EpochState tracks information related to each epoch

func NewEpochState

func NewEpochState(db chaindb.Database, blockState *BlockState) (*EpochState, error)

NewEpochState returns a new EpochState

func NewEpochStateFromGenesis

func NewEpochStateFromGenesis(db chaindb.Database, blockState *BlockState,
	genesisConfig *types.BabeConfiguration) (*EpochState, error)

NewEpochStateFromGenesis returns a new EpochState given information for the first epoch, fetched from the runtime

func (*EpochState) FinalizeBABENextConfigData

func (s *EpochState) FinalizeBABENextConfigData(finalizedHeader *types.Header) error

FinalizeBABENextConfigData stores the right types.NextConfigData by getting the set of hashes from the received epoch and for each hash check if the header is in the database then it's been finalized and thus we can also set the corresponding NextConfigData in the database

func (*EpochState) FinalizeBABENextEpochData

func (s *EpochState) FinalizeBABENextEpochData(finalizedHeader *types.Header) error

FinalizeBABENextEpochData stores the right types.NextEpochData by getting the set of hashes from the received epoch and for each hash check if the header is in the database then it's been finalized and thus we can also set the corresponding EpochData in the database

func (*EpochState) GetConfigData

func (s *EpochState) GetConfigData(epoch uint64, header *types.Header) (*types.ConfigData, error)

GetConfigData returns the config data for a given epoch persisted in database otherwise tries to get the data from the in-memory map using the header. If the header params is nil then it will search only in the database

func (*EpochState) GetCurrentEpoch

func (s *EpochState) GetCurrentEpoch() (uint64, error)

GetCurrentEpoch returns the current epoch

func (*EpochState) GetEpochData

func (s *EpochState) GetEpochData(epoch uint64, header *types.Header) (*types.EpochData, error)

GetEpochData returns the epoch data for a given epoch persisted in database otherwise will try to get the data from the in-memory map using the header if the header params is nil then it will search only in database

func (*EpochState) GetEpochForBlock

func (s *EpochState) GetEpochForBlock(header *types.Header) (uint64, error)

GetEpochForBlock checks the pre-runtime digest to determine what epoch the block was formed in.

func (*EpochState) GetEpochFromTime

func (s *EpochState) GetEpochFromTime(t time.Time) (uint64, error)

GetEpochFromTime returns the epoch for a given time

func (*EpochState) GetEpochLength

func (s *EpochState) GetEpochLength() (uint64, error)

GetEpochLength returns the length of an epoch in slots

func (*EpochState) GetLatestConfigData

func (s *EpochState) GetLatestConfigData() (*types.ConfigData, error)

GetLatestConfigData returns the most recently set ConfigData

func (*EpochState) GetLatestEpochData

func (s *EpochState) GetLatestEpochData() (*types.EpochData, error)

GetLatestEpochData returns the EpochData for the current epoch

func (*EpochState) GetSlotDuration

func (s *EpochState) GetSlotDuration() (time.Duration, error)

GetSlotDuration returns the duration of a slot

func (*EpochState) GetStartSlotForEpoch

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) HasConfigData

func (s *EpochState) HasConfigData(epoch uint64) (bool, error)

HasConfigData returns whether config data exists for a given epoch

func (*EpochState) HasEpochData

func (s *EpochState) HasEpochData(epoch uint64) (bool, error)

HasEpochData returns whether epoch data exists for a given epoch

func (*EpochState) SetConfigData

func (s *EpochState) SetConfigData(epoch uint64, info *types.ConfigData) error

SetConfigData sets the BABE config data for a given epoch

func (*EpochState) SetCurrentEpoch

func (s *EpochState) SetCurrentEpoch(epoch uint64) error

SetCurrentEpoch sets the current epoch

func (*EpochState) SetEpochData

func (s *EpochState) SetEpochData(epoch uint64, info *types.EpochData) error

SetEpochData sets the epoch data for a given epoch

func (*EpochState) SetFirstSlot

func (s *EpochState) SetFirstSlot(slot uint64) error

SetFirstSlot sets the first slot number of the network

func (*EpochState) SkipVerify

func (s *EpochState) SkipVerify(header *types.Header) (bool, error)

SkipVerify returns whether verification for the given header should be skipped or not. Only used in the case of imported state.

func (*EpochState) StoreBABENextConfigData

func (s *EpochState) StoreBABENextConfigData(epoch uint64, hash common.Hash, nextConfigData types.NextConfigData)

StoreBABENextConfigData stores the types.NextConfigData under epoch and hash keys

func (*EpochState) StoreBABENextEpochData

func (s *EpochState) StoreBABENextEpochData(epoch uint64, hash common.Hash, nextEpochData types.NextEpochData)

StoreBABENextEpochData stores the types.NextEpochData under epoch and hash keys

type GrandpaState

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

GrandpaState tracks information related to grandpa

func NewGrandpaState

func NewGrandpaState(db chaindb.Database) (*GrandpaState, error)

NewGrandpaState returns a new GrandpaState

func NewGrandpaStateFromGenesis

func NewGrandpaStateFromGenesis(db chaindb.Database, genesisAuthorities []types.GrandpaVoter) (*GrandpaState, error)

NewGrandpaStateFromGenesis returns a new GrandpaState given the grandpa genesis authorities

func (*GrandpaState) GetAuthorities

func (s *GrandpaState) GetAuthorities(setID uint64) ([]types.GrandpaVoter, error)

GetAuthorities returns the authorities for the given setID

func (*GrandpaState) GetCurrentSetID

func (s *GrandpaState) GetCurrentSetID() (uint64, error)

GetCurrentSetID retrieves the current set ID

func (*GrandpaState) GetLatestRound

func (s *GrandpaState) GetLatestRound() (uint64, error)

GetLatestRound gets the latest finalised GRANDPA roundfrom the db

func (*GrandpaState) GetNextPause

func (s *GrandpaState) GetNextPause() (blockNumber uint, err error)

GetNextPause returns the block number of the next grandpa pause. If the key is not found in the database, the error chaindb.ErrKeyNotFound is returned.

func (*GrandpaState) GetNextResume

func (s *GrandpaState) GetNextResume() (blockNumber uint, err error)

GetNextResume returns the block number of the next grandpa resume. If the key is not found in the database, the error chaindb.ErrKeyNotFound is returned.

func (*GrandpaState) GetPrecommits

func (s *GrandpaState) GetPrecommits(round, setID uint64) ([]types.GrandpaSignedVote, error)

GetPrecommits retrieves the precommits for a specific round and set ID from the database

func (*GrandpaState) GetPrevotes

func (s *GrandpaState) GetPrevotes(round, setID uint64) ([]types.GrandpaSignedVote, error)

GetPrevotes retrieves the prevotes for a specific round and set ID from the database

func (*GrandpaState) GetSetIDByBlockNumber

func (s *GrandpaState) GetSetIDByBlockNumber(blockNumber uint) (uint64, error)

GetSetIDByBlockNumber returns the set ID for a given block number

func (*GrandpaState) GetSetIDChange

func (s *GrandpaState) GetSetIDChange(setID uint64) (blockNumber uint, err error)

GetSetIDChange returns the block number where the set ID was updated

func (*GrandpaState) IncrementSetID

func (s *GrandpaState) IncrementSetID() (newSetID uint64, err error)

IncrementSetID increments the set ID

func (*GrandpaState) SetLatestRound

func (s *GrandpaState) SetLatestRound(round uint64) error

SetLatestRound sets the latest finalised GRANDPA round in the db

func (*GrandpaState) SetNextChange

func (s *GrandpaState) SetNextChange(authorities []types.GrandpaVoter, number uint) error

SetNextChange sets the next authority change at the given block number. NOTE: This block number will be the last block in the current set and not part of the next set.

func (*GrandpaState) SetNextPause

func (s *GrandpaState) SetNextPause(number uint) error

SetNextPause sets the next grandpa pause at the given block number

func (*GrandpaState) SetNextResume

func (s *GrandpaState) SetNextResume(number uint) error

SetNextResume sets the next grandpa resume at the given block number

func (*GrandpaState) SetPrecommits

func (s *GrandpaState) SetPrecommits(round, setID uint64, pcs []types.GrandpaSignedVote) error

SetPrecommits sets the precommits for a specific round and set ID in the database

func (*GrandpaState) SetPrevotes

func (s *GrandpaState) SetPrevotes(round, setID uint64, pvs []types.GrandpaSignedVote) error

SetPrevotes sets the prevotes for a specific round and set ID in the database

type KeyValue

type KeyValue struct {
	Key   []byte
	Value []byte
}

KeyValue struct to hold key value pairs

func (KeyValue) String

func (kv KeyValue) String() string

type Observer

type Observer interface {
	Update(result *SubscriptionResult)
	GetID() uint
	GetFilter() map[string][]byte
}

Observer interface defines functions needed for observers, Observer Design Pattern

type OfflinePruner

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

OfflinePruner is a tool to prune the stale state with the help of bloom filter, The workflow of Pruner is very simple: - iterate the storage state, reconstruct the relevant state tries - iterate the database, stream all the targeted keys to new DB

func NewOfflinePruner

func NewOfflinePruner(inputDBPath, prunedDBPath string, bloomSize uint64,
	retainBlockNum int64) (*OfflinePruner, error)

NewOfflinePruner creates an instance of OfflinePruner.

func (*OfflinePruner) Prune

func (p *OfflinePruner) Prune() error

Prune starts streaming the data from input db to the pruned db.

func (*OfflinePruner) SetBloomFilter

func (p *OfflinePruner) SetBloomFilter() (err error)

SetBloomFilter loads keys with storage prefix of last `retainBlockNum` blocks into the bloom filter

type Service

type Service struct {
	Base        *BaseState
	Storage     *StorageState
	Block       *BlockState
	Transaction *TransactionState
	Epoch       *EpochState
	Grandpa     *GrandpaState

	PrunerCfg pruner.Config
	Telemetry telemetry.Client

	// Below are for testing only.
	BabeThresholdNumerator   uint64
	BabeThresholdDenominator uint64
	// contains filtered or unexported fields
}

Service is the struct that holds storage, block and network states

func NewService

func NewService(config Config) *Service

NewService create a new instance of Service

func (*Service) CreateGenesisRuntime

func (s *Service) CreateGenesisRuntime(t *trie.Trie, gen *genesis.Genesis) (runtime.Instance, error)

CreateGenesisRuntime creates runtime instance form genesis

func (*Service) DB

func (s *Service) DB() chaindb.Database

DB returns the Service's database

func (*Service) Import

func (s *Service) Import(header *types.Header, t *trie.Trie, firstSlot uint64) error

Import imports the given state corresponding to the given header and sets the head of the chain to it. Additionally, it uses the first slot to correctly set the epoch number of the block.

func (*Service) Initialise

func (s *Service) Initialise(gen *genesis.Genesis, header *types.Header, t *trie.Trie) error

Initialise initialises 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 initialisation of the node; it is not called during normal startup.

func (*Service) Rewind

func (s *Service) Rewind(toBlock uint) error

Rewind rewinds the chain to the given block number. If the given number of blocks is greater than the chain height, it will rewind to genesis.

func (*Service) SetupBase

func (s *Service) SetupBase() error

SetupBase intitializes state.Base property with the instance of a chain.NewBadger database

func (*Service) Start

func (s *Service) Start() error

Start initialises the Storage database and the Block database.

func (*Service) Stop

func (s *Service) Stop() error

Stop closes each state database

func (*Service) UseMemDB

func (s *Service) UseMemDB()

UseMemDB tells the service to use an in-memory key-value store instead of a persistent database. This should be called after NewService, and before Initialise. This should only be used for testing.

type StorageState

type StorageState struct {
	sync.RWMutex
	// 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,
	tries *Tries, onlinePruner pruner.Config) (*StorageState, error)

NewStorageState creates a new StorageState backed by the given block state and database located at basePath.

func (*StorageState) Entries

func (s *StorageState) Entries(root *common.Hash) (map[string][]byte, error)

Entries returns Entries from the trie with the given state root

func (*StorageState) ExistsStorage

func (s *StorageState) ExistsStorage(root *common.Hash, key []byte) (bool, error)

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) GenerateTrieProof

func (s *StorageState) GenerateTrieProof(stateRoot common.Hash, keys [][]byte) ([][]byte, error)

GenerateTrieProof returns the proofs related to the keys on the state root trie

func (*StorageState) GetKeysWithPrefix

func (s *StorageState) GetKeysWithPrefix(root *common.Hash, prefix []byte) ([][]byte, error)

GetKeysWithPrefix returns all that match the given prefix for the given hash (or best block state root if hash is nil) in lexicographic order

func (*StorageState) GetStateRootFromBlock

func (s *StorageState) GetStateRootFromBlock(bhash *common.Hash) (*common.Hash, error)

GetStateRootFromBlock returns the state root hash of a given block hash

func (*StorageState) GetStorage

func (s *StorageState) GetStorage(root *common.Hash, key []byte) ([]byte, error)

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

func (s *StorageState) GetStorageByBlockHash(bhash *common.Hash, key []byte) ([]byte, error)

GetStorageByBlockHash returns the value at the given key at the given block hash

func (*StorageState) GetStorageChild

func (s *StorageState) GetStorageChild(root *common.Hash, keyToChild []byte) (*trie.Trie, error)

GetStorageChild returns a child trie, if it exists

func (*StorageState) GetStorageFromChild

func (s *StorageState) GetStorageFromChild(root *common.Hash, keyToChild, key []byte) ([]byte, error)

GetStorageFromChild get a value from a child trie

func (*StorageState) LoadCode

func (s *StorageState) LoadCode(hash *common.Hash) ([]byte, error)

LoadCode returns the runtime code (located at :code)

func (*StorageState) LoadCodeHash

func (s *StorageState) LoadCodeHash(hash *common.Hash) (common.Hash, error)

LoadCodeHash returns the hash of the runtime code (located at :code)

func (*StorageState) LoadFromDB

func (s *StorageState) LoadFromDB(root common.Hash) (*trie.Trie, error)

LoadFromDB loads an encoded trie from the DB where the key is `root`

func (*StorageState) RegisterStorageObserver

func (s *StorageState) RegisterStorageObserver(o Observer)

RegisterStorageObserver to add abserver to notification list

func (*StorageState) StorageRoot

func (s *StorageState) StorageRoot() (common.Hash, error)

StorageRoot returns the root hash of the current storage trie

func (*StorageState) StoreTrie

func (s *StorageState) StoreTrie(ts *rtstorage.TrieState, header *types.Header) error

StoreTrie stores the given trie in the StorageState and writes it to the database

func (*StorageState) TrieState

func (s *StorageState) TrieState(root *common.Hash) (*rtstorage.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) UnregisterStorageObserver

func (s *StorageState) UnregisterStorageObserver(o Observer)

UnregisterStorageObserver removes observer from notification list

type SubscriptionResult

type SubscriptionResult struct {
	Hash    common.Hash
	Changes []KeyValue
}

SubscriptionResult holds results of storage changes

func (SubscriptionResult) String

func (s SubscriptionResult) String() string

String serialises the subscription result changes to human readable strings.

type TransactionState

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

TransactionState represents the queue of transactions

func NewTransactionState

func NewTransactionState(telemetry telemetry.Client) *TransactionState

NewTransactionState returns a new TransactionState

func (*TransactionState) AddToPool

AddToPool adds a transaction to the pool

func (*TransactionState) Exists

func (s *TransactionState) Exists(ext types.Extrinsic) bool

Exists returns true if an extrinsic is already in the pool or queue, false otherwise

func (*TransactionState) FreeStatusNotifierChannel

func (s *TransactionState) FreeStatusNotifierChannel(ch chan transaction.Status)

FreeStatusNotifierChannel deletes given status notifier channel from our map.

func (*TransactionState) GetStatusNotifierChannel

func (s *TransactionState) GetStatusNotifierChannel(ext types.Extrinsic) chan transaction.Status

GetStatusNotifierChannel creates and returns a status notifier channel.

func (*TransactionState) Peek

Peek returns the head of the queue without removing it

func (*TransactionState) Pending

Pending returns the current transactions in the queue and pool

func (*TransactionState) PendingInPool

func (s *TransactionState) PendingInPool() []*transaction.ValidTransaction

PendingInPool returns the current transactions in the pool

func (*TransactionState) Pop

Pop removes and returns the head of the queue

func (*TransactionState) Push

Push pushes a transaction to the queue, ordered by priority

func (*TransactionState) RemoveExtrinsic

func (s *TransactionState) RemoveExtrinsic(ext types.Extrinsic)

RemoveExtrinsic removes an extrinsic from the queue and pool

func (*TransactionState) RemoveExtrinsicFromPool

func (s *TransactionState) RemoveExtrinsicFromPool(ext types.Extrinsic)

RemoveExtrinsicFromPool removes an extrinsic from the pool

type Tries

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

Tries is a thread safe map of root hash to trie.

func NewTries

func NewTries(t *trie.Trie) (trs *Tries, err error)

NewTries creates a new thread safe map of root hash to trie using the trie given as a first trie.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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