state

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0, BSD-2-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const BlockHashSize = 20
View Source
const (
	OriginStateCommitmentHex = "c4f09061cd63ea506f89b7cbb3c6e0984f124158"
)

Variables

This section is empty.

Functions

func EqualCommitments added in v0.3.0

func EqualCommitments(c1, c2 trie.Serializable) bool

func ForEachBlockIndex added in v0.3.0

func ForEachBlockIndex(store kvstore.KVStore, fun func(blockIndex uint32) bool) error

ForEachBlockIndex iterates over all indices of block saved in the DB Order non-deterministic

func GetMerkleProof added in v0.3.0

func GetMerkleProof(key []byte, tr trie.NodeStore) *trie_blake2b.Proof

func LoadBlockBytes added in v0.2.0

func LoadBlockBytes(store kvstore.KVStore, stateIndex uint32) ([]byte, error)

LoadBlockBytes loads block bytes of the specified block index from DB

func NewOptimisticStateReader added in v0.2.0

func NewOptimisticStateReader(db kvstore.KVStore, glb coreutil.ChainStateSync) *optimisticStateReaderImpl

NewOptimisticStateReader creates new optimistic read-only access to the database. It contains own read baseline

func NewStateUpdate

func NewStateUpdate(timestamp ...time.Time) *stateUpdateImpl

NewStateUpdate creates a state update with timestamp mutation, if provided

func NewTrie added in v0.3.0

func NewTrie(db kvstore.KVStore) *trie.Trie

func NewTrieReader added in v0.3.0

func NewTrieReader(trieKV, valueKV trie.KVReader) *trie.TrieReader

func NewVirtualState

func NewVirtualState(db kvstore.KVStore) *virtualStateAccess

NewVirtualState creates VirtualStateAccess interface with the partition of KVStore

func OriginStateCommitment added in v0.3.0

func OriginStateCommitment() trie.VCommitment

func RootCommitment added in v0.3.0

func RootCommitment(tr trie.NodeStore) trie.VCommitment

func VCommitmentFromBytes added in v0.3.0

func VCommitmentFromBytes(data []byte) (trie.VCommitment, error)

func ValidateMerkleProof added in v0.3.0

func ValidateMerkleProof(proof *trie_blake2b.Proof, root trie.VCommitment, value ...[]byte) error

Types

type Block added in v0.1.0

type Block interface {
	BlockIndex() uint32
	ApprovingOutputID() *iotago.UTXOInput
	SetApprovingOutputID(*iotago.UTXOInput)
	Timestamp() time.Time
	PreviousL1Commitment() *L1Commitment
	EssenceBytes() []byte // except state transaction id
	Bytes() []byte
}

Block is a wrapped update

func BlockFromBytes added in v0.2.0

func BlockFromBytes(data []byte) (Block, error)

func LoadBlock added in v0.1.0

func LoadBlock(store kvstore.KVStore, stateIndex uint32) (Block, error)

LoadBlock loads block from DB and decodes it

type BlockHash added in v0.3.0

type BlockHash [BlockHashSize]byte

func BlockHashFromData added in v0.3.0

func BlockHashFromData(data []byte) (ret BlockHash)

func OriginBlockHash added in v0.3.0

func OriginBlockHash() (ret BlockHash)

func (BlockHash) String added in v0.3.0

func (bh BlockHash) String() string

type L1Commitment added in v0.3.0

type L1Commitment struct {
	// root commitment to the state
	StateCommitment trie.VCommitment
	// hash of the essence of the last block
	BlockHash BlockHash
}

L1Commitment represents parsed data stored as a metadata in the anchor output

var L1CommitmentNil *L1Commitment

func L1CommitmentFromAliasOutput added in v0.3.0

func L1CommitmentFromAliasOutput(output *iotago.AliasOutput) (*L1Commitment, error)

func L1CommitmentFromAnchorOutput added in v0.3.0

func L1CommitmentFromAnchorOutput(o *iotago.AliasOutput) (L1Commitment, error)

func L1CommitmentFromBytes added in v0.3.0

func L1CommitmentFromBytes(data []byte) (L1Commitment, error)

func NewL1Commitment added in v0.3.0

func NewL1Commitment(c trie.VCommitment, blockHash BlockHash) *L1Commitment

func OriginL1Commitment added in v0.3.0

func OriginL1Commitment() *L1Commitment

func RandL1Commitment added in v0.3.0

func RandL1Commitment() *L1Commitment

RandL1Commitment for testing only

func (*L1Commitment) Bytes added in v0.3.0

func (s *L1Commitment) Bytes() []byte

func (*L1Commitment) Read added in v0.3.0

func (s *L1Commitment) Read(r io.Reader) error

func (*L1Commitment) String added in v0.3.0

func (s *L1Commitment) String() string

func (*L1Commitment) Write added in v0.3.0

func (s *L1Commitment) Write(w io.Writer) error

type OnBlockSaveClosure added in v0.3.0

type OnBlockSaveClosure func(stateCommitment trie.VCommitment, block Block)

func SaveRawBlockClosure added in v0.3.0

func SaveRawBlockClosure(dir string, log *logger.Logger) OnBlockSaveClosure

SaveRawBlockClosure return closure which saves block in specified directory

type OptimisticStateReader added in v0.2.0

type OptimisticStateReader interface {
	ChainID() (*isc.ChainID, error)
	BlockIndex() (uint32, error)
	Timestamp() (time.Time, error)
	KVStoreReader() kv.KVStoreReader
	SetBaseline()
	TrieNodeStore() trie.NodeStore
}

type Update added in v0.3.0

type Update interface {
	Mutations() *buffered.Mutations
	Clone() Update
	Bytes() []byte
	String() string
}

Update is a set of mutations

func NewStateUpdateWithBlockLogValues added in v0.3.0

func NewStateUpdateWithBlockLogValues(blockIndex uint32, timestamp time.Time, prevL1Commitment *L1Commitment) Update

type VirtualStateAccess added in v0.2.0

type VirtualStateAccess interface {
	ChainID() *isc.ChainID
	BlockIndex() uint32
	Timestamp() time.Time
	TrieNodeStore() trie.NodeStore
	PreviousL1Commitment() *L1Commitment
	Commit()
	ReconcileTrie() []kv.Key
	KVStoreReader() kv.KVStoreReader
	OptimisticStateReader(glb coreutil.ChainStateSync) OptimisticStateReader
	ApplyStateUpdate(Update)
	ApplyBlock(Block) error
	ProofGeneric(key []byte) *trie.ProofGeneric
	ExtractBlock() (Block, error)
	Save(blocks ...Block) error
	KVStore() *buffered.BufferedKVStoreAccess
	Copy() VirtualStateAccess
	DangerouslyConvertToString() string
	WithOnBlockSave(fun OnBlockSaveClosure)
}

VirtualStateAccess is a virtualized access interface to the chain's database It consists of state reader and the buffer to collect mutations to key values

func CreateOriginState added in v0.2.0

func CreateOriginState(store kvstore.KVStore, chainID *isc.ChainID) (VirtualStateAccess, error)

CreateOriginState creates and saves origin state in DB

func LoadSolidState

func LoadSolidState(store kvstore.KVStore, chainID *isc.ChainID) (VirtualStateAccess, bool, error)

LoadSolidState establishes VirtualStateAccess interface with the solid state in DB. Checks root commitment to chainID

func WrapMustOptimisticVirtualStateAccess added in v0.2.0

func WrapMustOptimisticVirtualStateAccess(state VirtualStateAccess, baseline coreutil.StateBaseline) VirtualStateAccess

WrapMustOptimisticVirtualStateAccess wraps virtual state with state baseline in on object Does not copy buffers

Jump to

Keyboard shortcuts

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