state

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: LGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfigNotFound   = errors.New("config data not found")
	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 (
	ErrNoNextAuthorityChange = errors.New("no next authority change")
)
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 added in v0.3.0

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

NewInMemoryDB creates a new in-memory database

Types

type BaseState added in v0.7.0

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

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

func NewBaseState added in v0.7.0

func NewBaseState(db chaindb.Database) *BaseState

NewBaseState returns a new BaseState

func (*BaseState) Del added in v0.7.0

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

Del deletes key from database

func (*BaseState) Get added in v0.7.0

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

Get retrieves value by key from database

func (*BaseState) LoadCodeSubstitutedBlockHash added in v0.7.0

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

LoadCodeSubstitutedBlockHash loads the hash stored at CodeSubstitutedBlock key

func (*BaseState) LoadGenesisData added in v0.7.0

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

LoadGenesisData retrieves the genesis data stored at the known GenesisDataKey.

func (*BaseState) LoadNodeGlobalName added in v0.7.0

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

LoadNodeGlobalName loads the latest stored node global name

func (*BaseState) Put added in v0.7.0

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

Put stores key/value pair in database

func (*BaseState) StoreCodeSubstitutedBlockHash added in v0.7.0

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

StoreCodeSubstitutedBlockHash stores the hash at the CodeSubstitutedBlock key

func (*BaseState) StoreGenesisData added in v0.7.0

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

StoreGenesisData stores the given genesis data at the known GenesisDataKey.

func (*BaseState) StoreNodeGlobalName added in v0.7.0

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 added in v0.3.2

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 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) FreeFinalisedNotifierChannel added in v0.7.0

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

FreeFinalisedNotifierChannel to free finalised notifier channel

func (*BlockState) FreeImportedBlockNotifierChannel added in v0.7.0

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 added in v0.7.0

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) GetBlockHashesBySlot added in v0.7.0

func (bs *BlockState) GetBlockHashesBySlot(slotNum uint64) ([]common.Hash, error)

GetBlockHashesBySlot gets all block hashes that were produced in the given slot.

func (*BlockState) GetBlockStateRoot added in v0.7.0

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 added in v0.7.0

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

GetFinalisedHash gets the finalised block header by round and setID

func (*BlockState) GetFinalisedHeader added in v0.7.0

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

GetFinalisedHeader returns the finalised block header by round and setID

func (*BlockState) GetFinalisedNotifierChannel added in v0.7.0

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

GetFinalisedNotifierChannel function to retrieve a finalised block notifier channel

func (*BlockState) GetHashByNumber added in v0.4.0

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 added in v0.2.0

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 added in v0.7.0

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

GetHighestFinalisedHash returns the highest finalised block hash

func (*BlockState) GetHighestFinalisedHeader added in v0.7.0

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

GetHighestFinalisedHeader returns the highest finalised block header

func (*BlockState) GetHighestRoundAndSetID added in v0.7.0

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

GetHighestRoundAndSetID gets the highest round and setID that have been finalised

func (*BlockState) GetImportedBlockNotifierChannel added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

func (bs *BlockState) GetRuntime(blockHash common.Hash) (instance runtime.Instance, err error)

GetRuntime gets the runtime instance pointer for the block hash given.

func (*BlockState) GetSlotForBlock

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

GetSlotForBlock returns the slot for a block

func (*BlockState) HandleRuntimeChanges added in v0.7.0

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

HandleRuntimeChanges handles the update in runtime.

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) HasFinalisedBlock added in v0.7.0

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 added in v0.7.0

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 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) 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) LowestCommonAncestor added in v0.7.0

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

LowestCommonAncestor returns the lowest common ancestor between two blocks in the tree.

func (*BlockState) NumberIsFinalised added in v0.7.0

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

NumberIsFinalised checks if a block number is finalised or not

func (*BlockState) RegisterRuntimeUpdatedChannel added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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

UnregisterRuntimeUpdatedChannel function to unregister runtime updated channel

type Config added in v0.7.0

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

Config is the default configuration used by state service.

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, blockState *BlockState) (*EpochState, error)

NewEpochState returns a new EpochState

func NewEpochStateFromGenesis added in v0.2.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.3.0

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

GetConfigData returns the newest config data for a given epoch persisted in database otherwise tries to get the data from the in-memory map using the header. If we don't find any config data for the current epoch we lookup in the previous epochs, as the spec says: - The supplied configuration data are intended to be used from the next epoch onwards. If the header params is nil then it will search only in the database.

func (*EpochState) GetCurrentEpoch added in v0.2.0

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

GetCurrentEpoch returns the current epoch

func (*EpochState) GetEpochData added in v0.3.0

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 added in v0.3.0

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 added in v0.7.0

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

GetEpochFromTime returns the epoch for a given time

func (*EpochState) GetEpochLength added in v0.7.0

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

GetEpochLength returns the length of an epoch in slots

func (*EpochState) GetLatestConfigData added in v0.7.0

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

GetLatestConfigData returns the most recently set ConfigData

func (*EpochState) GetLatestEpochData added in v0.3.0

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

GetLatestEpochData returns the EpochData for the current epoch

func (*EpochState) GetSlotDuration added in v0.7.0

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

GetSlotDuration returns the duration of a slot

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) SetConfigData added in v0.3.0

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

SetConfigData sets the BABE config data 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) SetEpochData added in v0.3.0

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

SetEpochData sets the epoch data for a given epoch

func (*EpochState) SetFirstSlot added in v0.3.0

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

SetFirstSlot sets the first slot number of the network

func (*EpochState) SkipVerify added in v0.3.2

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 added in v0.7.0

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 added in v0.7.0

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

StoreBABENextEpochData stores the types.NextEpochData under epoch and hash keys

type GrandpaState added in v0.7.0

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

GrandpaState tracks information related to grandpa

func NewGrandpaState added in v0.7.0

func NewGrandpaState(db chaindb.Database, bs *BlockState) *GrandpaState

NewGrandpaState returns a new GrandpaState

func NewGrandpaStateFromGenesis added in v0.7.0

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

NewGrandpaStateFromGenesis returns a new GrandpaState given the grandpa genesis authorities

func (*GrandpaState) ApplyForcedChanges added in v0.7.0

func (s *GrandpaState) ApplyForcedChanges(importedBlockHeader *types.Header) error

ApplyForcedChanges will check for if there is a scheduled forced change relative to the imported block and then apply it otherwise nothing happens

func (*GrandpaState) ApplyScheduledChanges added in v0.7.0

func (s *GrandpaState) ApplyScheduledChanges(finalizedHeader *types.Header) error

ApplyScheduledChanges will check the schedules changes in order to find a root equal or behind the finalized number and will apply its authority set changes

func (*GrandpaState) GetAuthorities added in v0.7.0

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

GetAuthorities returns the authorities for the given setID

func (*GrandpaState) GetCurrentSetID added in v0.7.0

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

GetCurrentSetID retrieves the current set ID

func (*GrandpaState) GetLatestRound added in v0.7.0

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

GetLatestRound gets the latest finalised GRANDPA roundfrom the db

func (*GrandpaState) GetNextPause added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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

GetSetIDByBlockNumber returns the set ID for a given block number

func (*GrandpaState) GetSetIDChange added in v0.7.0

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

GetSetIDChange returns the block number where the set ID was updated

func (*GrandpaState) HandleGRANDPADigest added in v0.7.0

func (s *GrandpaState) HandleGRANDPADigest(header *types.Header, digest scale.VaryingDataType) error

HandleGRANDPADigest receives a decoded GRANDPA digest and calls the right function to handles the digest

func (*GrandpaState) IncrementSetID added in v0.7.0

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

IncrementSetID increments the set ID

func (*GrandpaState) NextGrandpaAuthorityChange added in v0.7.0

func (s *GrandpaState) NextGrandpaAuthorityChange(bestBlockHash common.Hash, bestBlockNumber uint) (
	blockNumber uint, err error)

NextGrandpaAuthorityChange returns the block number of the next upcoming grandpa authorities change. It returns 0 if no change is scheduled.

func (*GrandpaState) SetLatestRound added in v0.7.0

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

SetLatestRound sets the latest finalised GRANDPA round in the db

func (*GrandpaState) SetNextChange added in v0.7.0

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 added in v0.7.0

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

SetNextPause sets the next grandpa pause at the given block number

func (*GrandpaState) SetNextResume added in v0.7.0

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

SetNextResume sets the next grandpa resume at the given block number

func (*GrandpaState) SetPrecommits added in v0.7.0

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 added in v0.7.0

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 added in v0.2.0

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

KeyValue struct to hold key value pairs

func (KeyValue) String added in v0.7.0

func (kv KeyValue) String() string

type MockObserver added in v0.7.0

type MockObserver struct {
	mock.Mock
}

MockObserver is an autogenerated mock type for the Observer type

func NewMockObserver added in v0.7.0

func NewMockObserver(t mockConstructorTestingTNewMockObserver) *MockObserver

NewMockObserver creates a new instance of MockObserver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockObserver) GetFilter added in v0.7.0

func (_m *MockObserver) GetFilter() map[string][]byte

GetFilter provides a mock function with given fields:

func (*MockObserver) GetID added in v0.7.0

func (_m *MockObserver) GetID() uint

GetID provides a mock function with given fields:

func (*MockObserver) Update added in v0.7.0

func (_m *MockObserver) Update(result *SubscriptionResult)

Update provides a mock function with given fields: result

type Observer added in v0.7.0

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

Observer interface defines functions needed for observers, Observer Design Pattern

type OfflinePruner added in v0.7.0

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 added in v0.7.0

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

NewOfflinePruner creates an instance of OfflinePruner.

func (*OfflinePruner) Prune added in v0.7.0

func (p *OfflinePruner) Prune() error

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

func (*OfflinePruner) SetBloomFilter added in v0.7.0

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 added in v0.7.0

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 added in v0.3.2

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 added in v0.7.0

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 added in v0.3.1

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 added in v0.7.0

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() (err 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 added in v0.7.0

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

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

func (*StorageState) GetKeysWithPrefix added in v0.3.0

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 added in v0.3.0

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 added in v0.2.0

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 added in v0.7.0

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 added in v0.2.0

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 added in v0.2.0

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 added in v0.7.0

func (s *StorageState) UnregisterStorageObserver(o Observer)

UnregisterStorageObserver removes observer from notification list

type SubscriptionResult added in v0.3.0

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

SubscriptionResult holds results of storage changes

func (SubscriptionResult) String added in v0.7.0

func (s SubscriptionResult) String() string

String serialises the subscription result changes to human readable strings.

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(telemetry telemetry.Client) *TransactionState

NewTransactionState returns a new TransactionState

func (*TransactionState) AddToPool added in v0.2.0

AddToPool adds a transaction to the pool

func (*TransactionState) Exists added in v0.7.0

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 added in v0.7.0

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

FreeStatusNotifierChannel deletes given status notifier channel from our map.

func (*TransactionState) GetStatusNotifierChannel added in v0.7.0

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

GetStatusNotifierChannel creates and returns a status notifier channel.

func (*TransactionState) Peek added in v0.2.0

Peek returns the head of the queue without removing it

func (*TransactionState) Pending added in v0.2.0

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

Pop removes and returns the head of the queue

func (*TransactionState) PopWithTimer added in v0.7.0

func (s *TransactionState) PopWithTimer(timerCh <-chan time.Time) (transaction *transaction.ValidTransaction)

PopWithTimer returns the next valid transaction from the queue. When the timer expires, it returns `nil`.

func (*TransactionState) Push added in v0.2.0

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 Tries added in v0.7.0

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

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

func NewTries added in v0.7.0

func NewTries() (tries *Tries)

NewTries creates a new thread safe map of root hash to trie.

func (*Tries) SetEmptyTrie added in v0.7.0

func (t *Tries) SetEmptyTrie()

SetEmptyTrie sets the empty trie in the tries. Note the empty trie is the same for the v0 and the v1 state trie versions.

func (*Tries) SetTrie added in v0.7.0

func (t *Tries) SetTrie(trie *trie.Trie)

SetTrie sets the trie at its root hash in the tries map.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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