Documentation ¶
Overview ¶
Package trie implements Merkle Patricia Tries.
Visualisation of Merkle Patricia Tries.
Index ¶
- Constants
- Variables
- func AddrHashFromCodeKey(codeKey []byte) []byte
- func CalcRoot(logPrefix string, tx kv.Tx) (libcommon.Hash, error)
- func CastTrieNodeValue(hashes, rootHash []byte) []libcommon.Hash
- func CodeHexFromHex(hex []byte) []byte
- func CodeKeyFromAddrHash(addrHash []byte) []byte
- func EncodeAsValue(data []byte) ([]byte, error)
- func FullKeys(t *Trie) []string
- func FullNode1()
- func FullNode2()
- func FullNode3()
- func FullNode4()
- func GenStructStep(retain func(prefix []byte) bool, curr, succ []byte, e structInfoReceiver, ...) ([]uint16, []uint16, []uint16, error)
- func GenStructStepEx(retain func(prefix []byte) bool, curr, succ []byte, e structInfoReceiver, ...) ([]uint16, []uint16, []uint16, error)
- func GenStructStepOld(retain func(prefix []byte) bool, curr, succ []byte, e structInfoReceiver, ...) ([]uint16, error)
- func Hash1()
- func Hash2()
- func Hash3()
- func Hash4()
- func Hash5()
- func Hash6()
- func Hash7()
- func HashWithModifications(t *Trie, aKeys common.Hashes, aValues []*accounts.Account, aCodes [][]byte, ...) (libcommon.Hash, error)
- func IsPointingToCode(key []byte) bool
- func KeyToQuad(key []byte) []byte
- func MarshalTrieNode(hasState, hasTree, hasHash uint16, hashes, rootHash []byte, buf []byte) []byte
- func MarshalTrieNodeTyped(hasState, hasTree, hasHash uint16, h []libcommon.Hash, buf []byte) []byte
- func NewShortNode(key []byte, value node) *shortNode
- func ShortNode1()
- func ShortNode2()
- func StarkStats(witness *Witness, w io.Writer, trace bool) error
- func StorageKey(addressHash []byte, incarnation uint64, prefix []byte) []byte
- func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, trace bool) (libcommon.Hash, error)
- func UnmarshalTrieNode(v []byte) (hasState, hasTree, hasHash uint16, hashes, rootHash []byte)
- func UnmarshalTrieNodeTyped(v []byte) (hasState, hasTree, hasHash uint16, hashes []libcommon.Hash, ...)
- func Visual(t *Trie, w io.Writer, opts *VisualOpts)
- type AccTrieCursor
- type BlockWitnessStats
- func (s *BlockWitnessStats) BlockWitnessSize() uint64
- func (s *BlockWitnessStats) CodesSize() uint64
- func (s *BlockWitnessStats) HashesSize() uint64
- func (s *BlockWitnessStats) LeafKeysSize() uint64
- func (s *BlockWitnessStats) LeafValuesSize() uint64
- func (s *BlockWitnessStats) StructureSize() uint64
- type ByteArrayWriter
- type FlatDBTrieLoader
- type GenStructStepAccountData
- type GenStructStepData
- type GenStructStepHashData
- type GenStructStepLeafData
- type HashBuilder
- type HashCollector
- type HashCollector2
- type HashNodeFunc
- type HexStdOutWriter
- type Iterator
- type Keybytes
- type LoadFunc
- type LoadRequestForCode
- type MerklePathLimiter
- type MissingNodeError
- type OperatorBranch
- type OperatorCode
- type OperatorEmptyRoot
- type OperatorExtension
- type OperatorHash
- type OperatorKindCode
- type OperatorLeafAccount
- type OperatorLeafValue
- type OperatorMarshaller
- func (w *OperatorMarshaller) GetStats() *BlockWitnessStats
- func (w *OperatorMarshaller) WithColumn(column StatsColumn) *OperatorMarshaller
- func (w *OperatorMarshaller) Write(p []byte) (int, error)
- func (w *OperatorMarshaller) WriteByteArrayValue(value []byte) error
- func (w *OperatorMarshaller) WriteByteValue(value byte) error
- func (w *OperatorMarshaller) WriteCode(value []byte) error
- func (w *OperatorMarshaller) WriteHash(hash libcommon.Hash) error
- func (w *OperatorMarshaller) WriteKey(keyNibbles []byte) error
- func (w *OperatorMarshaller) WriteOpCode(opcode OperatorKindCode) error
- func (w *OperatorMarshaller) WriteUint64Value(value uint64) error
- type OperatorUnmarshaller
- func (l *OperatorUnmarshaller) ReadByte() (byte, error)
- func (l *OperatorUnmarshaller) ReadByteArray() ([]byte, error)
- func (l *OperatorUnmarshaller) ReadHash() (libcommon.Hash, error)
- func (l *OperatorUnmarshaller) ReadKey() ([]byte, error)
- func (l *OperatorUnmarshaller) ReadUInt64() (uint64, error)
- func (l *OperatorUnmarshaller) ReadUint32() (uint32, error)
- type ProofRetainer
- type RetainDecider
- type RetainDeciderWithMarker
- type RetainList
- func (rl *RetainList) AddCodeTouch(codeHash libcommon.Hash)
- func (rl *RetainList) AddHex(hex []byte)
- func (rl *RetainList) AddKey(key []byte) []byte
- func (rl *RetainList) AddKeyWithMarker(key []byte, marker bool) []byte
- func (rl *RetainList) IsCodeTouched(codeHash libcommon.Hash) bool
- func (rl *RetainList) Len() int
- func (rl *RetainList) Less(i, j int) bool
- func (rl *RetainList) Retain(prefix []byte) bool
- func (rl *RetainList) RetainWithMarker(prefix []byte) (bool, []byte)
- func (rl *RetainList) Rewind()
- func (rl *RetainList) String() string
- func (rl *RetainList) Swap(i, j int)
- type RootHashAggregator
- type StarkStatsBuilder
- type StateCursor
- type StatsColumn
- type StorageHashCollector
- type StorageHashCollector2
- type StorageTrieCursor
- type Stream
- type StreamItem
- type StreamIterator
- type StreamMergeIterator
- type SubTrieLoader
- type SubTries
- type Trie
- func (t *Trie) DeepHash(keyPrefix []byte) (bool, libcommon.Hash)
- func (t *Trie) Delete(key []byte)
- func (t *Trie) DeleteSubtree(keyPrefix []byte)
- func (t *Trie) EvictNode(hex []byte)
- func (t *Trie) ExtractWitness(trace bool, rl RetainDecider) (*Witness, error)
- func (t *Trie) ExtractWitnessForPrefix(prefix []byte, trace bool, rl RetainDecider) (*Witness, error)
- func (t *Trie) FindSubTriesToLoad(rl RetainDecider) (prefixes [][]byte, fixedbits []int, hooks [][]byte)
- func (t *Trie) Fold(keys [][]byte)
- func (t *Trie) Get(key []byte) (value []byte, gotValue bool)
- func (t *Trie) GetAccount(key []byte) (value *accounts.Account, gotValue bool)
- func (t *Trie) GetAccountCode(key []byte) (value []byte, gotValue bool)
- func (t *Trie) GetAccountCodeSize(key []byte) (value int, gotValue bool)
- func (t *Trie) Hash() libcommon.Hash
- func (t *Trie) HashOfHexKey(hexKey []byte) (libcommon.Hash, error)
- func (t *Trie) HookSubTries(subTries SubTries, hooks [][]byte) error
- func (t *Trie) NeedLoadCode(addrHash libcommon.Hash, codeHash libcommon.Hash, bytecode bool) (bool, *LoadRequestForCode)
- func (t *Trie) NewLoadRequestForCode(addrHash libcommon.Hash, codeHash libcommon.Hash, bytecode bool) *LoadRequestForCode
- func (t *Trie) NumberOfAccounts() int
- func (t *Trie) Print(w io.Writer)
- func (t *Trie) PrintDiff(t2 *Trie, w io.Writer)
- func (t *Trie) PrintTrie()
- func (t *Trie) Prove(key []byte, fromLevel int, storage bool) ([][]byte, error)
- func (t *Trie) Reset()
- func (t *Trie) Root() []byte
- func (t *Trie) TrieSize() int
- func (t *Trie) Update(key, value []byte)
- func (t *Trie) UpdateAccount(key []byte, acc *accounts.Account)
- func (t *Trie) UpdateAccountCode(key []byte, code codeNode) error
- func (t *Trie) UpdateAccountCodeSize(key []byte, codeSize int) error
- type VisualOpts
- type Witness
- type WitnessBuilder
- type WitnessHeader
- type WitnessOperator
- type WitnessStorage
Constants ¶
const ( AccountFieldNonceOnly uint32 = 0x01 AccountFieldBalanceOnly uint32 = 0x02 AccountFieldStorageOnly uint32 = 0x04 AccountFieldCodeOnly uint32 = 0x08 AccountFieldSSizeOnly uint32 = 0x10 AccountFieldSetNotAccount uint32 = 0x00 )
Various values of the account field set
const ( ColumnStructure = StatsColumn("structure") ColumnHashes = StatsColumn("hashes") ColumnCodes = StatsColumn("codes") ColumnLeafKeys = StatsColumn("leaf_keys") ColumnLeafValues = StatsColumn("leaf_values") ColumnTotal = StatsColumn("total_witness_size") )
const WitnessVersion = uint8(1)
WitnessVersion represents the current version of the block witness in case of incompatible changes it should be updated and the code to migrate the old witness format should be present
Variables ¶
var EmptyCodeHash = crypto.Keccak256Hash(nil)
var ( // EmptyRoot is the known root hash of an empty trie. // DESCRIBED: docs/programmers_guide/guide.md#root EmptyRoot = libcommon.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") )
Functions ¶
func AddrHashFromCodeKey ¶
func CalcRoot ¶
CalcRoot is a combination of `ResolveStateTrie` and `UpdateStateTrie` DESCRIBED: docs/programmers_guide/guide.md#organising-ethereum-state-into-a-merkle-tree
func CastTrieNodeValue ¶
func CodeHexFromHex ¶
func CodeKeyFromAddrHash ¶
func EncodeAsValue ¶
func FullKeys ¶
FullKeys construct the list of full keys (i.e. keys that can be accessed without resolution via DB) that are present in the given trie
func GenStructStep ¶
func GenStructStepEx ¶
func GenStructStepEx( retain func(prefix []byte) bool, curr, succ []byte, e structInfoReceiver, h HashCollector2, data GenStructStepData, groups []uint16, hasTree []uint16, hasHash []uint16, trace bool, retainProof func(prefix []byte) *proofElement, cutoff bool, ) ([]uint16, []uint16, []uint16, error)
GenStructStepEx is extended to support optional generation of an Account Proof during trie_root.go CalcTrieRoot(). The wrapper below calls it with nil/false defaults so that other callers do not need to be modified.
func GenStructStepOld ¶
func GenStructStepOld( retain func(prefix []byte) bool, curr, succ []byte, e structInfoReceiver, h HashCollector, data GenStructStepData, groups []uint16, trace bool, ) ([]uint16, error)
func HashWithModifications ¶
func HashWithModifications( t *Trie, aKeys common.Hashes, aValues []*accounts.Account, aCodes [][]byte, sKeys common.StorageKeys, sValues [][]byte, storagePrefixLen int, newStream *Stream, hb *HashBuilder, trace bool, ) (libcommon.Hash, error)
HashWithModifications computes the hash of the would-be modified trie, but without any modifications
func IsPointingToCode ¶
func KeyToQuad ¶
KeyToQuad converts a key in KEY encoding to QUAD encoding (similar to HEX encoding, but uses digits 0..3 instead of digits 0..15)
func MarshalTrieNode ¶
func MarshalTrieNodeTyped ¶
func NewShortNode ¶
func NewShortNode(key []byte, value node) *shortNode
func ShortNode1 ¶
func ShortNode1()
func ShortNode2 ¶
func ShortNode2()
func StarkStats ¶
StarkStats collects Keccak256 stats from the witness and write them into the file
func StreamHash ¶
func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, trace bool) (libcommon.Hash, error)
StreamHash computes the hash of a stream, as if it was a trie
func UnmarshalTrieNode ¶
func UnmarshalTrieNodeTyped ¶
Types ¶
type AccTrieCursor ¶
type AccTrieCursor struct { SkipState bool // contains filtered or unexported fields }
AccTrieCursor - holds logic related to iteration over AccTrie bucket has 2 basic operations: _preOrderTraversalStep and _preOrderTraversalStepNoInDepth
func AccTrie ¶
func AccTrie(canUse func([]byte) (bool, []byte), hc HashCollector2, c kv.Cursor, quit <-chan struct{}) *AccTrieCursor
func (*AccTrieCursor) AtPrefix ¶
func (c *AccTrieCursor) AtPrefix(prefix []byte) (k, v []byte, hasTree bool, err error)
func (*AccTrieCursor) FirstNotCoveredPrefix ¶
func (c *AccTrieCursor) FirstNotCoveredPrefix() []byte
type BlockWitnessStats ¶
type BlockWitnessStats struct {
// contains filtered or unexported fields
}
func (*BlockWitnessStats) BlockWitnessSize ¶
func (s *BlockWitnessStats) BlockWitnessSize() uint64
func (*BlockWitnessStats) CodesSize ¶
func (s *BlockWitnessStats) CodesSize() uint64
func (*BlockWitnessStats) HashesSize ¶
func (s *BlockWitnessStats) HashesSize() uint64
func (*BlockWitnessStats) LeafKeysSize ¶
func (s *BlockWitnessStats) LeafKeysSize() uint64
func (*BlockWitnessStats) LeafValuesSize ¶
func (s *BlockWitnessStats) LeafValuesSize() uint64
func (*BlockWitnessStats) StructureSize ¶
func (s *BlockWitnessStats) StructureSize() uint64
type ByteArrayWriter ¶
type ByteArrayWriter struct {
// contains filtered or unexported fields
}
func (*ByteArrayWriter) Setup ¶
func (w *ByteArrayWriter) Setup(dest []byte, pos int)
type FlatDBTrieLoader ¶
type FlatDBTrieLoader struct {
// contains filtered or unexported fields
}
FlatDBTrieLoader reads state and intermediate trie hashes in order equal to "Preorder trie traversal" (Preorder - visit Root, visit Left, visit Right)
It produces stream of values and send this stream to `receiver` It skips storage with incorrect incarnations
Each intermediate hash key firstly pass to RetainDecider, only if it returns "false" - such AccTrie can be used.
func NewFlatDBTrieLoader ¶
func NewFlatDBTrieLoader(logPrefix string, rd RetainDeciderWithMarker, hc HashCollector2, shc StorageHashCollector2, trace bool) *FlatDBTrieLoader
func (*FlatDBTrieLoader) CalcTrieRoot ¶
CalcTrieRoot algo:
for iterateIHOfAccounts { if canSkipState goto SkipAccounts for iterateAccounts from prevIH to currentIH { use(account) for iterateIHOfStorage within accountWithIncarnation{ if canSkipState goto SkipStorage for iterateStorage from prevIHOfStorage to currentIHOfStorage { use(storage) } SkipStorage: use(ihStorage) } } SkipAccounts: use(AccTrie) }
func (*FlatDBTrieLoader) SetProofRetainer ¶
func (l *FlatDBTrieLoader) SetProofRetainer(pr *ProofRetainer)
type GenStructStepAccountData ¶
type GenStructStepAccountData struct { FieldSet uint32 Balance uint256.Int Nonce uint64 Incarnation uint64 }
func (GenStructStepAccountData) GenStructStepData ¶
func (GenStructStepAccountData) GenStructStepData()
type GenStructStepData ¶
type GenStructStepData interface {
GenStructStepData()
}
type GenStructStepHashData ¶
func (GenStructStepHashData) GenStructStepData ¶
func (GenStructStepHashData) GenStructStepData()
type GenStructStepLeafData ¶
type GenStructStepLeafData struct {
Value rlphacks.RlpSerializable
}
func (GenStructStepLeafData) GenStructStepData ¶
func (GenStructStepLeafData) GenStructStepData()
type HashBuilder ¶
type HashBuilder struct {
// contains filtered or unexported fields
}
HashBuilder implements the interface `structInfoReceiver` and opcodes that the structural information of the trie is comprised of DESCRIBED: docs/programmers_guide/guide.md#separation-of-keys-and-the-structure
func NewHashBuilder ¶
func NewHashBuilder(trace bool) *HashBuilder
NewHashBuilder creates a new HashBuilder
func (*HashBuilder) Reset ¶
func (hb *HashBuilder) Reset()
Reset makes the HashBuilder suitable for reuse
type HashCollector ¶
hashCollector gets called whenever there might be a need to create intermediate hash record
type HashCollector2 ¶
type HexStdOutWriter ¶
type HexStdOutWriter struct{}
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator helps iterate over a trie according to a given resolve set
func NewIterator ¶
func NewIterator(t *Trie, rl *RetainList, trace bool) *Iterator
NewIterator creates a new iterator from scratch from a given trie and resolve set
type Keybytes ¶
Keybytes represent a packed encoding of hex sequences where 2 nibbles per byte are stored in Data + an additional flag for terminating nodes.
func CompactToKeybytes ¶
CompactToKeybytes translates from COMPACT to KEYBYTES encoding.
func (*Keybytes) DecodeRLP ¶
DecodeRLP implements rlp.Decoder and decodes Keybytes from the COMPACT encoding.
func (*Keybytes) EncodeRLP ¶
EncodeRLP implements rlp.Encoder and encodes Keybytes in the COMPACT encoding.
type LoadFunc ¶
type LoadFunc func(*SubTrieLoader, *RetainList, [][]byte, []int) (SubTries, error)
type LoadRequestForCode ¶
type LoadRequestForCode struct {
// contains filtered or unexported fields
}
LoadRequestForCode Code expresses the need to fetch code from the DB (by its hash) and attach to a specific account leaf in the trie.
func (*LoadRequestForCode) String ¶
func (lrc *LoadRequestForCode) String() string
type MerklePathLimiter ¶
type MerklePathLimiter struct { RetainDecider RetainDecider HashFunc HashNodeFunc }
type MissingNodeError ¶
type MissingNodeError struct { NodeHash libcommon.Hash // hash of the missing node Path []byte // hex-encoded path to the missing node }
MissingNodeError is returned by the trie functions (TryGet, TryUpdate, TryDelete) in the case where a trie node is not present in the local database. It contains information necessary for retrieving the missing node.
func (*MissingNodeError) Error ¶
func (err *MissingNodeError) Error() string
type OperatorBranch ¶
type OperatorBranch struct {
Mask uint32
}
func (*OperatorBranch) LoadFrom ¶
func (o *OperatorBranch) LoadFrom(loader *OperatorUnmarshaller) error
func (*OperatorBranch) WriteTo ¶
func (o *OperatorBranch) WriteTo(output *OperatorMarshaller) error
type OperatorCode ¶
type OperatorCode struct {
Code []byte
}
func (*OperatorCode) LoadFrom ¶
func (o *OperatorCode) LoadFrom(loader *OperatorUnmarshaller) error
func (*OperatorCode) WriteTo ¶
func (o *OperatorCode) WriteTo(output *OperatorMarshaller) error
type OperatorEmptyRoot ¶
type OperatorEmptyRoot struct{}
func (*OperatorEmptyRoot) LoadFrom ¶
func (o *OperatorEmptyRoot) LoadFrom(loader *OperatorUnmarshaller) error
func (*OperatorEmptyRoot) WriteTo ¶
func (o *OperatorEmptyRoot) WriteTo(output *OperatorMarshaller) error
type OperatorExtension ¶
type OperatorExtension struct {
Key []byte
}
func (*OperatorExtension) LoadFrom ¶
func (o *OperatorExtension) LoadFrom(loader *OperatorUnmarshaller) error
func (*OperatorExtension) WriteTo ¶
func (o *OperatorExtension) WriteTo(output *OperatorMarshaller) error
type OperatorHash ¶
func (*OperatorHash) LoadFrom ¶
func (o *OperatorHash) LoadFrom(loader *OperatorUnmarshaller) error
func (*OperatorHash) WriteTo ¶
func (o *OperatorHash) WriteTo(output *OperatorMarshaller) error
type OperatorKindCode ¶
type OperatorKindCode uint8
OperatorKindCode is "enum" type for defining the opcodes of the stack machine that reconstructs the structure of tries from Structure tape
const ( // OpLeaf creates leaf node and pushes it onto the node stack, its hash onto the hash stack OpLeaf OperatorKindCode = iota // OpExtension pops a node from the node stack, constructs extension node from it and its operand's key, and pushes this extension node onto // the node stack, its hash onto the hash stack OpExtension // OpBranch has operand, which is a bitset representing digits in the branch node. Pops the children nodes from the node stack (the number of // children is equal to the number of bits in the bitset), constructs branch node and pushes it onto the node stack, its hash onto the hash stack OpBranch // OpHash and pushes the hash them onto the stack. OpHash // OpCode constructs code node and pushes it onto the node stack, its hash onto the hash stack. OpCode // OpAccountLeaf constructs an account node (without any storage and code) and pushes it onto the node stack, its hash onto the hash stack. OpAccountLeaf // OpEmptyRoot places nil onto the node stack, and empty root hash onto the hash stack. OpEmptyRoot // OpNewTrie stops the processing, because another trie is encoded into the witness. OpNewTrie = OperatorKindCode(0xBB) )
type OperatorLeafAccount ¶
type OperatorLeafAccount struct { Key []byte Nonce uint64 Balance *big.Int HasCode bool HasStorage bool CodeSize uint64 }
func (*OperatorLeafAccount) LoadFrom ¶
func (o *OperatorLeafAccount) LoadFrom(loader *OperatorUnmarshaller) error
func (*OperatorLeafAccount) WriteTo ¶
func (o *OperatorLeafAccount) WriteTo(output *OperatorMarshaller) error
type OperatorLeafValue ¶
func (*OperatorLeafValue) LoadFrom ¶
func (o *OperatorLeafValue) LoadFrom(loader *OperatorUnmarshaller) error
func (*OperatorLeafValue) WriteTo ¶
func (o *OperatorLeafValue) WriteTo(output *OperatorMarshaller) error
type OperatorMarshaller ¶
type OperatorMarshaller struct {
// contains filtered or unexported fields
}
OperatorMarshaller is responsible for encoding operators to a stream and collecting stats IMPORTANT: not thread-safe! use from a single thread only
func NewOperatorMarshaller ¶
func NewOperatorMarshaller(w io.Writer) *OperatorMarshaller
func (*OperatorMarshaller) GetStats ¶
func (w *OperatorMarshaller) GetStats() *BlockWitnessStats
func (*OperatorMarshaller) WithColumn ¶
func (w *OperatorMarshaller) WithColumn(column StatsColumn) *OperatorMarshaller
func (*OperatorMarshaller) WriteByteArrayValue ¶
func (w *OperatorMarshaller) WriteByteArrayValue(value []byte) error
func (*OperatorMarshaller) WriteByteValue ¶
func (w *OperatorMarshaller) WriteByteValue(value byte) error
func (*OperatorMarshaller) WriteCode ¶
func (w *OperatorMarshaller) WriteCode(value []byte) error
func (*OperatorMarshaller) WriteHash ¶
func (w *OperatorMarshaller) WriteHash(hash libcommon.Hash) error
func (*OperatorMarshaller) WriteKey ¶
func (w *OperatorMarshaller) WriteKey(keyNibbles []byte) error
func (*OperatorMarshaller) WriteOpCode ¶
func (w *OperatorMarshaller) WriteOpCode(opcode OperatorKindCode) error
func (*OperatorMarshaller) WriteUint64Value ¶
func (w *OperatorMarshaller) WriteUint64Value(value uint64) error
type OperatorUnmarshaller ¶
type OperatorUnmarshaller struct {
// contains filtered or unexported fields
}
OperatorMarshaller provides all needed primitives to read witness operators from a serialized form.
func NewOperatorUnmarshaller ¶
func NewOperatorUnmarshaller(r io.Reader) *OperatorUnmarshaller
func (*OperatorUnmarshaller) ReadByte ¶
func (l *OperatorUnmarshaller) ReadByte() (byte, error)
func (*OperatorUnmarshaller) ReadByteArray ¶
func (l *OperatorUnmarshaller) ReadByteArray() ([]byte, error)
func (*OperatorUnmarshaller) ReadHash ¶
func (l *OperatorUnmarshaller) ReadHash() (libcommon.Hash, error)
func (*OperatorUnmarshaller) ReadKey ¶
func (l *OperatorUnmarshaller) ReadKey() ([]byte, error)
func (*OperatorUnmarshaller) ReadUInt64 ¶
func (l *OperatorUnmarshaller) ReadUInt64() (uint64, error)
func (*OperatorUnmarshaller) ReadUint32 ¶
func (l *OperatorUnmarshaller) ReadUint32() (uint32, error)
type ProofRetainer ¶
type ProofRetainer struct {
// contains filtered or unexported fields
}
ProofRetainer is a wrapper around the RetainList passed to the trie builder. It is responsible for aggregating proof values from the trie computation and will return a valid accounts.AccProofresult after the trie root hash calculation has completed.
func NewProofRetainer ¶
func NewProofRetainer(addr libcommon.Address, a *accounts.Account, storageKeys []libcommon.Hash, rl *RetainList) (*ProofRetainer, error)
NewProofRetainer creates a new ProofRetainer instance for a given account and set of storage keys. The trie keys corresponding to the account key, and its storage keys are added to the given RetainList. The ProofRetainer should be set onto the FlatDBTrieLoader via SetProofRetainer before performing its Load operation in order to appropriately collect the proof elements.
func (*ProofRetainer) ProofElement ¶
func (pr *ProofRetainer) ProofElement(prefix []byte) *proofElement
ProofElement requests a new proof element for a given prefix. This proof element is retained by the ProofRetainer, and will be utilized to compute the proof after the trie computation has completed. The prefix is the standard nibble encoded prefix used in the rest of the trie computations.
func (*ProofRetainer) ProofResult ¶
func (pr *ProofRetainer) ProofResult() (*accounts.AccProofResult, error)
ProofResult may be invoked only after the Load function of the FlatDBTrieLoader has successfully executed. It will populate the Address, Balance, Nonce, and CodeHash from the account data supplied in the constructor, the StorageHash, storageKey values, and proof elements are supplied by the Load operation of the trie construction.
type RetainDecider ¶
type RetainDeciderWithMarker ¶
type RetainList ¶
type RetainList struct {
// contains filtered or unexported fields
}
RetainList encapsulates the list of keys that are required to be fully available, or loaded (by using `BRANCH` opcode instead of `HASHER`) after processing of the sequence of key-value pairs DESCRIBED: docs/programmers_guide/guide.md#converting-sequence-of-keys-and-value-into-a-multiproof
func NewRetainList ¶
func NewRetainList(minLength int) *RetainList
NewRetainList creates new RetainList
func (*RetainList) AddCodeTouch ¶
func (rl *RetainList) AddCodeTouch(codeHash libcommon.Hash)
AddCodeTouch adds a new code touch into the resolve set
func (*RetainList) AddHex ¶
func (rl *RetainList) AddHex(hex []byte)
AddHex adds a new key (in HEX encoding) to the list
func (*RetainList) AddKey ¶
func (rl *RetainList) AddKey(key []byte) []byte
AddKey adds a new key (in KEY encoding) to the list
func (*RetainList) AddKeyWithMarker ¶
func (rl *RetainList) AddKeyWithMarker(key []byte, marker bool) []byte
func (*RetainList) IsCodeTouched ¶
func (rl *RetainList) IsCodeTouched(codeHash libcommon.Hash) bool
func (*RetainList) Len ¶
func (rl *RetainList) Len() int
func (*RetainList) Less ¶
func (rl *RetainList) Less(i, j int) bool
func (*RetainList) Retain ¶
func (rl *RetainList) Retain(prefix []byte) bool
Retain decides whether to emit `HASHER` or `BRANCH` for a given prefix, by checking if this is prefix of any of the keys added to the set Since keys in the set are sorted, and we expect that the prefixes will come in monotonically ascending order, we optimise for this, though the function would still work if the order is different
func (*RetainList) RetainWithMarker ¶
func (rl *RetainList) RetainWithMarker(prefix []byte) (bool, []byte)
func (*RetainList) Rewind ¶
func (rl *RetainList) Rewind()
Rewind lets us reuse this list from the beginning
func (*RetainList) String ¶
func (rl *RetainList) String() string
func (*RetainList) Swap ¶
func (rl *RetainList) Swap(i, j int)
type RootHashAggregator ¶
type RootHashAggregator struct {
// contains filtered or unexported fields
}
RootHashAggregator - calculates Merkle trie root hash from incoming data stream
func NewRootHashAggregator ¶
func NewRootHashAggregator() *RootHashAggregator
func (*RootHashAggregator) RetainNothing ¶
func (r *RootHashAggregator) RetainNothing(_ []byte) bool
func (*RootHashAggregator) Root ¶
func (r *RootHashAggregator) Root() libcommon.Hash
type StarkStatsBuilder ¶
type StarkStatsBuilder struct {
// contains filtered or unexported fields
}
func NewStarkStatsBuilder ¶
func NewStarkStatsBuilder() *StarkStatsBuilder
type StateCursor ¶
type StateCursor struct {
// contains filtered or unexported fields
}
func NewStateCursor ¶
func NewStateCursor(c kv.Cursor, quit <-chan struct{}) *StateCursor
type StatsColumn ¶
type StatsColumn string
type StorageHashCollector ¶
type StorageHashCollector2 ¶
type StorageTrieCursor ¶
type StorageTrieCursor struct {
// contains filtered or unexported fields
}
StorageTrieCursor - holds logic related to iteration over AccTrie bucket
func StorageTrie ¶
func StorageTrie(canUse func(prefix []byte) (bool, []byte), shc StorageHashCollector2, c kv.Cursor, quit <-chan struct{}) *StorageTrieCursor
func (*StorageTrieCursor) FirstNotCoveredPrefix ¶
func (c *StorageTrieCursor) FirstNotCoveredPrefix() []byte
func (*StorageTrieCursor) Next ¶
func (c *StorageTrieCursor) Next() (k, v []byte, hasTree bool, err error)
func (*StorageTrieCursor) PrevKey ¶
func (c *StorageTrieCursor) PrevKey() []byte
func (*StorageTrieCursor) SeekToAccount ¶
func (c *StorageTrieCursor) SeekToAccount(accWithInc []byte) (k, v []byte, hasTree bool, err error)
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream represents the collection of key-value pairs, sorted by keys, where values may belong to three different types - accounts, strage item leaves, and intermediate hashes
type StreamItem ¶
type StreamItem uint8
StreamItem is an enum type for values that help distinguish different types of key-value pairs in the stream of values produce by function `ToStream`
const ( // NoItem is used to signal the end of iterator NoItem StreamItem = iota // AccountStreamItem used for marking a key-value pair in the stream as belonging to an account AccountStreamItem // StorageStreamItem used for marking a key-value pair in the stream as belonging to a storage item leaf StorageStreamItem // AHashStreamItem used for marking a key-value pair in the stream as belonging to an intermediate hash // within the accounts (main state trie) AHashStreamItem // SHashStreamItem used for marking a key-value pair in the stream as belonging to an intermediate hash // within the storage items (storage tries) SHashStreamItem // CutoffStremItem used for marking the end of the subtrie CutoffStreamItem )
type StreamIterator ¶
type StreamMergeIterator ¶
type StreamMergeIterator struct {
// contains filtered or unexported fields
}
StreamMergeIterator merges an Iterator and a Stream
func NewStreamMergeIterator ¶
func NewStreamMergeIterator(it *Iterator, s *Stream, trace bool) *StreamMergeIterator
NewStreamMergeIterator create a brand new StreamMergeIterator
func (*StreamMergeIterator) Next ¶
func (smi *StreamMergeIterator) Next() (itemType1 StreamItem, hex1 []byte, aValue *accounts.Account, aCode []byte, hash []byte, value []byte)
Next returns the next item in the merged iterator
type SubTrieLoader ¶
type SubTrieLoader struct {
// contains filtered or unexported fields
}
Resolver looks up (resolves) some keys and corresponding values from a database. One resolver per trie (prefix). See also ResolveRequest in trie.go
func NewSubTrieLoader ¶
func NewSubTrieLoader() *SubTrieLoader
func (*SubTrieLoader) AddCodeRequest ¶
func (stl *SubTrieLoader) AddCodeRequest(req *LoadRequestForCode)
AddCodeRequest add a request for code loading
func (*SubTrieLoader) Reset ¶
func (stl *SubTrieLoader) Reset()
type SubTries ¶
type SubTries struct { Hashes []libcommon.Hash // Root hashes of the sub-tries // contains filtered or unexported fields }
SubTrie is a result of loading sub-trie from either flat db or witness db. It encapsulates sub-trie root (which is of the un-exported type `node`) If the loading is done for verification and testing purposes, then usually only sub-tree root hash would be queried
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie is a Merkle Patricia Trie. The zero value is an empty trie with no database. Use New to create a trie that sits on top of a database.
Trie is not safe for concurrent use. Deprecated use package turbo/trie
func New ¶
New creates a trie with an existing root node from db.
If root is the zero hash or the sha3 hash of an empty string, the trie is initially empty and does not require a database. Otherwise, New will panic if db is nil and returns a MissingNodeError if root does not exist in the database. Accessing the trie loads nodes from db on demand. Deprecated use package turbo/trie
func NewTestRLPTrie ¶
NewTestRLPTrie treats all the data provided to `Update` function as rlp-encoded. it is usually used for testing purposes.
func (*Trie) DeepHash ¶
DeepHash returns internal hash of a node reachable by the specified key prefix. Note that if the prefix points into the middle of a key for a leaf node or of an extension node, it will return the hash of a modified leaf node or extension node, where the key prefix is removed from the key. First returned value is `true` if the node with the specified prefix is found.
func (*Trie) Delete ¶
Delete removes any existing value for key from the trie. DESCRIBED: docs/programmers_guide/guide.md#root
func (*Trie) DeleteSubtree ¶
DeleteSubtree removes any existing value for key from the trie. The only difference between Delete and DeleteSubtree is that Delete would delete accountNode too, wherewas DeleteSubtree will keep the accountNode, but will make the storage sub-trie empty
func (*Trie) ExtractWitness ¶
func (t *Trie) ExtractWitness(trace bool, rl RetainDecider) (*Witness, error)
func (*Trie) ExtractWitnessForPrefix ¶
func (*Trie) FindSubTriesToLoad ¶
func (t *Trie) FindSubTriesToLoad(rl RetainDecider) (prefixes [][]byte, fixedbits []int, hooks [][]byte)
FindSubTriesToLoad walks over the trie and creates the list of DB prefixes and corresponding list of valid bits in the prefix (for the cases when prefix contains an odd number of nibbles) that would allow loading the missing information from the database It also create list of `hooks`, the paths in the trie (in nibbles) where the loaded sub-tries need to be inserted.
func (*Trie) Fold ¶
Fold modifies the trie by folding the given set of keys, making sure that they are inaccessible without resolution via DB
func (*Trie) GetAccount ¶
func (*Trie) GetAccountCode ¶
func (*Trie) GetAccountCodeSize ¶
func (*Trie) Hash ¶
Hash returns the root hash of the trie. It does not write to the database and can be used even if the trie doesn't have one. DESCRIBED: docs/programmers_guide/guide.md#root
func (*Trie) NeedLoadCode ¶
func (*Trie) NewLoadRequestForCode ¶
func (*Trie) NumberOfAccounts ¶
func (*Trie) Prove ¶
Prove constructs a merkle proof for key. The result contains all encoded nodes on the path to the value at key. The value itself is also included in the last node and can be retrieved by verifying the proof.
If the trie does not contain a value for key, the returned proof contains all nodes of the longest existing prefix of the key (at least the root node), ending with the node that proves the absence of the key.
func (*Trie) Update ¶
Update associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.
The value bytes must not be modified by the caller while they are stored in the trie. DESCRIBED: docs/programmers_guide/guide.md#root
func (*Trie) UpdateAccountCode ¶
UpdateAccountCode attaches the code node to an account at specified key
type VisualOpts ¶
type VisualOpts struct { Highlights [][]byte // Collection of keys, in the HEX encoding, that need to be highlighted with digits IndexColors []string // Array of colors for representing digits as colored boxes FontColors []string // Array of colors, the same length as indexColors, for the textual digits inside the coloured boxes CutTerminals int // Specifies how many digits to cut from the terminal short node keys for a more convinient display Values bool // Whether to display value nodes (as box with rounded corners) CodeCompressed bool // Whether to turn the code from a large rectangle to a small square for a more convinient display ValCompressed bool // Whether long values (over 10 characters) are shortened using ... in the middle ValHex bool // Whether values should be displayed as hex numbers (otherwise they are displayed as just strings) SameLevel bool // Whether the leaves (and hashes) need to be on the same horizontal level }
VisualOpts contains various configuration options fo the Visual function It has been introduced as a replacement for too many arguments with options
type Witness ¶
type Witness struct { Header WitnessHeader Operators []WitnessOperator }
func ExtractWitnesses ¶
func ExtractWitnesses(subTries SubTries, trace bool, retainDec RetainDecider) ([]*Witness, error)
ExtractWitnesses extracts witnesses for subtries starting from the specified root if retainDec param is nil it will make a witness for the full subtrie, if retainDec param is set to a RetainList instance, it will make a witness for only the accounts/storages that were actually touched; other paths will be hashed.
func NewWitness ¶
func NewWitness(operands []WitnessOperator) *Witness
func NewWitnessFromReader ¶
type WitnessBuilder ¶
type WitnessBuilder struct {
// contains filtered or unexported fields
}
func NewWitnessBuilder ¶
func NewWitnessBuilder(root node, trace bool) *WitnessBuilder
func (*WitnessBuilder) Build ¶
func (b *WitnessBuilder) Build(limiter *MerklePathLimiter) (*Witness, error)
type WitnessHeader ¶
type WitnessHeader struct {
Version uint8
}
WitnessHeader contains version information and maybe some future format bits the version is always the 1st bit.
func (*WitnessHeader) WriteTo ¶
func (h *WitnessHeader) WriteTo(out *OperatorMarshaller) error
type WitnessOperator ¶
type WitnessOperator interface { WriteTo(*OperatorMarshaller) error // LoadFrom always assumes that the opcode value was already read LoadFrom(*OperatorUnmarshaller) error }
WitnessOperator is a single operand in the block witness. It knows how to serialize/deserialize itself.
Source Files ¶
- debug.go
- encoding.go
- errors.go
- gen_struct_step.go
- hack.go
- hashbuilder.go
- hasher.go
- intermediate_hash_receiver.go
- node.go
- proof.go
- retain_list.go
- stark_stats.go
- stream.go
- sub_trie_loader.go
- trie.go
- trie_from_witness.go
- trie_root.go
- trie_transform.go
- trie_witness.go
- utils.go
- visual.go
- witness.go
- witness_builder.go
- witness_marshalling.go
- witness_operators.go
- witness_stats.go