Documentation

Overview

Package trie implements Merkle Patricia Tries.

Visualisation of Merkle Patricia Tries.

Index

Constants

View Source
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

View Source
const (
	ColumnStructure  = StatsColumn("structure")
	ColumnHashes     = StatsColumn("hashes")
	ColumnCodes      = StatsColumn("codes")
	ColumnLeafKeys   = StatsColumn("leaf_keys")
	ColumnLeafValues = StatsColumn("leaf_values")
	ColumnTotal      = StatsColumn("total_witness_size")
)
View Source
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

View Source
var EmptyCodeHash = crypto.Keccak256Hash(nil)
View Source
var (
	// EmptyRoot is the known root hash of an empty trie.
	// DESCRIBED: docs/programmers_guide/guide.md#root
	EmptyRoot = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
)

Functions

func AddrHashFromCodeKey

func AddrHashFromCodeKey(codeKey []byte) []byte

func CodeHexFromHex

func CodeHexFromHex(hex []byte) []byte

func CodeKeyFromAddrHash

func CodeKeyFromAddrHash(addrHash []byte) []byte

func CompressNibbles

func CompressNibbles(nibbles []byte, out *[]byte)

CompressNibbles - supports only even number of nibbles This method supports only arrays of even nibbles

HI_NIBBLE(b) = (b >> 4) & 0x0F LO_NIBBLE(b) = b & 0x0F

func DecompressNibbles

func DecompressNibbles(in []byte, out *[]byte)

DecompressNibbles - supports only even number of nibbles

HI_NIBBLE(b) = (b >> 4) & 0x0F LO_NIBBLE(b) = b & 0x0F

func EncodeAsValue

func EncodeAsValue(data []byte) ([]byte, error)

func FullKeys

func FullKeys(t *Trie) []string

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 FullNode1

func FullNode1()

func FullNode2

func FullNode2()

func FullNode3

func FullNode3()

func FullNode4

func FullNode4()

func GenStructStep

func GenStructStep(
	retain func(prefix []byte) bool,
	curr, succ []byte,
	e structInfoReceiver,
	h HashCollector,
	data GenStructStepData,
	groups []uint16,
	trace bool,
) ([]uint16, error)

GenStructStep is one step of the algorithm that generates the structural information based on the sequence of keys. `retain` parameter is the function that, called for a certain prefix, determines whether the trie node for that prefix needs to be compressed into just hash (if `false` is returned), or constructed (if `true` is returned). Usually the `retain` function is implemented in such a way to guarantee that certain keys are always accessible in the resulting trie (see RetainList.Retain function). `buildExtensions` is set to true if the algorithm's step is invoked recursively, i.e. not after a freshly provided leaf or hash `curr`, `succ` are two full keys or prefixes that are currently visible to the algorithm. By comparing these, the algorithm makes decisions about the local structure, i.e. the presense of the prefix groups. `e` parameter is the trie builder, which uses the structure information to assemble trie on the stack and compute its hash. `h` parameter is the hash collector, which is notified whenever branch node is constructed. `data` parameter specified if a hash or a binary string or an account should be emitted. `groups` parameter is the map of the stack. each element of the `groups` slice is a bitmask, one bit per element currently on the stack. Whenever a `BRANCH` or `BRANCHHASH` opcode is emitted, the set of digits is taken from the corresponding `groups` item, which is then removed from the slice. This signifies the usage of the number of the stack items by the `BRANCH` or `BRANCHHASH` opcode. DESCRIBED: docs/programmers_guide/guide.md#separation-of-keys-and-the-structure

func Hash1

func Hash1()

func Hash2

func Hash2()

func Hash3

func Hash3()

func Hash4

func Hash4()

func Hash5

func Hash5()

func Hash6

func Hash6()

func Hash7

func Hash7()

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,
) (common.Hash, error)

HashWithModifications computes the hash of the would-be modified trie, but without any modifications

func IsPointingToCode

func IsPointingToCode(key []byte) bool

func KeyToQuad

func KeyToQuad(key []byte) []byte

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 NewShortNode

func NewShortNode(key []byte, value node) *shortNode

func ShortNode1

func ShortNode1()

func ShortNode2

func ShortNode2()

func StarkStats

func StarkStats(witness *Witness, w io.Writer, trace bool) error

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) (common.Hash, error)

StreamHash computes the hash of a stream, as if it was a trie

func Visual

func Visual(t *Trie, w io.Writer, opts *VisualOpts)

Visual creates visualisation of trie with highlighting

Types

type AccountEvicter

type AccountEvicter interface {
	EvictNode([]byte)
}

type BinaryTrie

type BinaryTrie Trie

BinaryTrie is a binary trie represnentation. Extracted to simplify type checks, etc

func HexToBin

func HexToBin(hexTrie *Trie) *BinaryTrie

HexToBin transforms a hexary trie into binary representation (where the keys can only contain symbols [0,1])

func (*BinaryTrie) Trie

func (b *BinaryTrie) Trie() *Trie

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)

func (*ByteArrayWriter) Write

func (w *ByteArrayWriter) Write(data []byte) (int, error)

type Database

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

Database is an intermediate write layer between the trie data structures and the disk database. The aim is to accumulate trie writes in-memory and only periodically flush a couple tries to disk, garbage collecting the remainder.

Note, the trie Database is **not** thread safe in its mutations, but it **is** thread safe in providing individual, independent node access. The rationale behind this split design is to provide read access to RPC handlers and sync servers even while the trie is executing expensive garbage collection.

func NewDatabase

func NewDatabase(diskdb ethdb.Database) *Database

NewDatabase creates a new trie database to store ephemeral trie content before its written out to disk or garbage collected. No read cache is created, so all data retrievals will hit the underlying disk database.

func NewDatabaseWithCache

func NewDatabaseWithCache(diskdb ethdb.Database, cache int, journal string) *Database

NewDatabaseWithCache creates a new trie database to store ephemeral trie content before its written out to disk or garbage collected. It also acts as a read cache for nodes loaded from disk.

func (*Database) Cap

func (db *Database) Cap(limit common.StorageSize) error

Cap iteratively flushes old but still referenced trie nodes until the total memory usage goes below the given threshold.

Note, this method is a non-synchronized mutator. It is unsafe to call this concurrently with other mutators.

func (*Database) Commit

func (db *Database) Commit(node common.Hash, report bool) error

Commit iterates over all the children of a particular node, writes them out to disk, forcefully tearing down all references in both directions. As a side effect, all pre-images accumulated up to this point are also written.

Note, this method is a non-synchronized mutator. It is unsafe to call this concurrently with other mutators.

func (*Database) Dereference

func (db *Database) Dereference(root common.Hash)

Dereference removes an existing reference from a root node.

func (*Database) DiskDB

func (db *Database) DiskDB() ethdb.Database

DiskDB retrieves the persistent storage backing the trie database. FIXME: maybe a more restrictive interface?

func (*Database) InsertBlob

func (db *Database) InsertBlob(hash common.Hash, blob []byte)

InsertBlob writes a new reference tracked blob to the memory database if it's yet unknown. This method should only be used for non-trie nodes that require reference counting, since trie nodes are garbage collected directly through their embedded children.

func (*Database) Nodes

func (db *Database) Nodes() []common.Hash

Nodes retrieves the hashes of all the nodes cached within the memory database. This method is extremely expensive and should only be used to validate internal states in test code.

func (*Database) Reference

func (db *Database) Reference(child common.Hash, parent common.Hash)

Reference adds a new reference from a parent node to a child node.

func (*Database) SaveCache

func (db *Database) SaveCache(dir string) error

SaveCache atomically saves fast cache data to the given dir using all available CPU cores.

func (*Database) SaveCachePeriodically

func (db *Database) SaveCachePeriodically(dir string, interval time.Duration, stopCh <-chan struct{})

SaveCachePeriodically atomically saves fast cache data to the given dir with the specified interval. All dump operation will only use a single CPU core.

func (*Database) Size

Size returns the current storage size of the memory cache in front of the persistent database layer.

type DatabaseReader

type DatabaseReader interface {
	// Get retrieves the value associated with key from the database.
	Get(bucket, key []byte) (value []byte, err error)

	GetAsOf(bucket, hBucket, key []byte, timestamp uint64) ([]byte, error)

	// Has retrieves whether a key is present in the database.
	Has(bucket, key []byte) (bool, error)

	Walk(bucket, key []byte, keybits uint, walker func([]byte, []byte) (bool, error)) error
}

DatabaseReader wraps the Get method of a backing store for the trie.

type DefaultReceiver

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

func NewDefaultReceiver

func NewDefaultReceiver() *DefaultReceiver

func (*DefaultReceiver) Receive

func (dr *DefaultReceiver) Receive(itemType StreamItem,
	accountKey []byte,
	storageKey []byte,
	accountValue *accounts.Account,
	storageValue []byte,
	hash []byte,
	cutoff int,
) error

func (*DefaultReceiver) Reset

func (dr *DefaultReceiver) Reset(rl RetainDecider, hc HashCollector, trace bool)

func (*DefaultReceiver) Result

func (dr *DefaultReceiver) Result() SubTries

func (*DefaultReceiver) Root

func (dr *DefaultReceiver) Root() common.Hash

type Eviction

type Eviction struct {
	NoopObserver // make sure that we don't need to implement unnecessary observer methods
	// contains filtered or unexported fields
}

func NewEviction

func NewEviction() *Eviction

func (*Eviction) BlockNumber

func (tp *Eviction) BlockNumber() uint64

func (*Eviction) BranchNodeCreated

func (tp *Eviction) BranchNodeCreated(hex []byte)

func (*Eviction) BranchNodeDeleted

func (tp *Eviction) BranchNodeDeleted(hex []byte)

func (*Eviction) BranchNodeTouched

func (tp *Eviction) BranchNodeTouched(hex []byte)

func (*Eviction) CodeNodeCreated

func (tp *Eviction) CodeNodeCreated(hex []byte, size uint)

func (*Eviction) CodeNodeDeleted

func (tp *Eviction) CodeNodeDeleted(hex []byte)

func (*Eviction) CodeNodeSizeChanged

func (tp *Eviction) CodeNodeSizeChanged(hex []byte, newSize uint)

func (*Eviction) CodeNodeTouched

func (tp *Eviction) CodeNodeTouched(hex []byte)

func (*Eviction) DebugDump

func (tp *Eviction) DebugDump() string

func (*Eviction) EvictToFitSize

func (tp *Eviction) EvictToFitSize(
	evicter AccountEvicter,
	threshold uint64,
) bool

EvictToFitSize evicts mininum number of generations necessary so that the total size of accounts left is fits into the provided threshold

func (*Eviction) NumberOf

func (tp *Eviction) NumberOf() uint64

func (*Eviction) SetBlockNumber

func (tp *Eviction) SetBlockNumber(blockNumber uint64)

func (*Eviction) TotalSize

func (tp *Eviction) TotalSize() uint64

type FilterCursor

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

FilterCursor - call .filter() and if it returns false - skip element

func Filter

func Filter(filter func(k []byte) (bool, error), c ethdb.Cursor) *FilterCursor

func (*FilterCursor) Seek

func (c *FilterCursor) Seek(seek []byte) ([]byte, []byte, error)

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 `defaultReceiver` It skips storage with incorrect incarnations

Each intermediate hash key firstly pass to RetainDecider, only if it returns "false" - such IH can be used.

func NewFlatDBTrieLoader

func NewFlatDBTrieLoader(stateBucket, intermediateHashesBucket string) *FlatDBTrieLoader

func (*FlatDBTrieLoader) CalcTrieRoot

func (l *FlatDBTrieLoader) CalcTrieRoot(db ethdb.Database) (common.Hash, error)

CalcTrieRoot - spawn 2 cursors (IntermediateHashes and HashedState) Wrap IntermediateHashes cursor to IH class - this class will return only keys which passed RetainDecider check If RetainDecider check not passed, then such key must be deleted - HashCollector receiving nil for such key.

func (*FlatDBTrieLoader) Reset

func (l *FlatDBTrieLoader) Reset(rd RetainDecider, hc HashCollector, trace bool) error

Reset prepares the loader for reuse

func (*FlatDBTrieLoader) SetStreamReceiver

func (l *FlatDBTrieLoader) SetStreamReceiver(receiver StreamReceiver)

type FlatDbSubTrieLoader

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

func NewFlatDbSubTrieLoader

func NewFlatDbSubTrieLoader() *FlatDbSubTrieLoader

func (*FlatDbSubTrieLoader) AttachRequestedCode

func (fstl *FlatDbSubTrieLoader) AttachRequestedCode(db ethdb.Getter, requests []*LoadRequestForCode) error

func (*FlatDbSubTrieLoader) LoadSubTries

func (fstl *FlatDbSubTrieLoader) LoadSubTries() (SubTries, error)

func (*FlatDbSubTrieLoader) Reset

func (fstl *FlatDbSubTrieLoader) Reset(db ethdb.Database, rl RetainDecider, receiverDecider RetainDecider, hc HashCollector, dbPrefixes [][]byte, fixedbits []int, trace bool) error

Reset prepares the loader for reuse

func (*FlatDbSubTrieLoader) SetStreamReceiver

func (fstl *FlatDbSubTrieLoader) SetStreamReceiver(receiver StreamReceiver)

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

type GenStructStepHashData struct {
	Hash common.Hash
}

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

func (*HashBuilder) RootHash

func (hb *HashBuilder) RootHash() (common.Hash, error)

type HashCollector

type HashCollector func(keyHex []byte, hash []byte) error

hashCollector gets called whenever there might be a need to create intermediate hash record

type HashNodeFunc

type HashNodeFunc func(node, bool, []byte) (int, error)

type HexStdOutWriter

type HexStdOutWriter struct{}

func (*HexStdOutWriter) Write

func (*HexStdOutWriter) Write(p []byte) (n int, err error)

type IHCursor

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

IHCursor - holds logic related to iteration over IH bucket

func IH

func IH(c *FilterCursor) *IHCursor

func (*IHCursor) Seek

func (c *IHCursor) Seek(seek []byte) ([]byte, []byte, bool, error)

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

func (*Iterator) Next

func (it *Iterator) Next() (itemType StreamItem, hex1 []byte, aValue *accounts.Account, hash []byte, value []byte)

Next delivers the next item from the iterator

func (*Iterator) Reset

func (it *Iterator) Reset(t *Trie, rl *RetainList, trace bool)

Reset prepares iterator to be reused

type Keybytes

type Keybytes struct {
	Data        []byte
	Odd         bool
	Terminating bool
}

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

func CompactToKeybytes(c []byte) Keybytes

CompactToKeybytes translates from COMPACT to KEYBYTES encoding.

func (*Keybytes) DecodeRLP

func (x *Keybytes) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder and decodes Keybytes from the COMPACT encoding.

func (*Keybytes) EncodeRLP

func (x *Keybytes) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder and encodes Keybytes in the COMPACT encoding.

func (*Keybytes) Nibbles

func (x *Keybytes) Nibbles() int

Nibbles returns the number of nibbles.

func (*Keybytes) ToCompact

func (x *Keybytes) ToCompact() []byte

ToCompact translates from KEYBYTES to COMPACT encoding.

func (*Keybytes) ToHex

func (x *Keybytes) ToHex() []byte

ToHex translates from KEYBYTES to HEX 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 common.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 NoopObserver

type NoopObserver struct{}

NoopTrieObserver might be used to emulate optional methods in observers

func (*NoopObserver) BranchNodeCreated

func (*NoopObserver) BranchNodeCreated(_ []byte)

func (*NoopObserver) BranchNodeDeleted

func (*NoopObserver) BranchNodeDeleted(_ []byte)

func (*NoopObserver) BranchNodeLoaded

func (*NoopObserver) BranchNodeLoaded(_ []byte, _ uint64)

func (*NoopObserver) BranchNodeTouched

func (*NoopObserver) BranchNodeTouched(_ []byte)

func (*NoopObserver) CodeNodeCreated

func (*NoopObserver) CodeNodeCreated(_ []byte, _ uint)

func (*NoopObserver) CodeNodeDeleted

func (*NoopObserver) CodeNodeDeleted(_ []byte)

func (*NoopObserver) CodeNodeSizeChanged

func (*NoopObserver) CodeNodeSizeChanged(_ []byte, _ uint)

func (*NoopObserver) CodeNodeTouched

func (*NoopObserver) CodeNodeTouched(_ []byte)

func (*NoopObserver) WillUnloadBranchNode

func (*NoopObserver) WillUnloadBranchNode(_ []byte, _ common.Hash, _ uint64)

func (*NoopObserver) WillUnloadNode

func (*NoopObserver) WillUnloadNode(_ []byte, _ common.Hash)

type Observer

type Observer interface {
	BranchNodeCreated(hex []byte)
	BranchNodeDeleted(hex []byte)
	BranchNodeTouched(hex []byte)

	CodeNodeCreated(hex []byte, size uint)
	CodeNodeDeleted(hex []byte)
	CodeNodeTouched(hex []byte)
	CodeNodeSizeChanged(hex []byte, newSize uint)

	WillUnloadBranchNode(key []byte, nodeHash common.Hash, incarnation uint64)
	WillUnloadNode(key []byte, nodeHash common.Hash)
	BranchNodeLoaded(prefixAsNibbles []byte, incarnation uint64)
}

type ObserverMux

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

TrieObserverMux multiplies the callback methods and sends them to all it's children.

func NewTrieObserverMux

func NewTrieObserverMux() *ObserverMux

func (*ObserverMux) AddChild

func (mux *ObserverMux) AddChild(child Observer)

func (*ObserverMux) BranchNodeCreated

func (mux *ObserverMux) BranchNodeCreated(hex []byte)

func (*ObserverMux) BranchNodeDeleted

func (mux *ObserverMux) BranchNodeDeleted(hex []byte)

func (*ObserverMux) BranchNodeLoaded

func (mux *ObserverMux) BranchNodeLoaded(prefixAsNibbles []byte, incarnation uint64)

func (*ObserverMux) BranchNodeTouched

func (mux *ObserverMux) BranchNodeTouched(hex []byte)

func (*ObserverMux) CodeNodeCreated

func (mux *ObserverMux) CodeNodeCreated(hex []byte, size uint)

func (*ObserverMux) CodeNodeDeleted

func (mux *ObserverMux) CodeNodeDeleted(hex []byte)

func (*ObserverMux) CodeNodeSizeChanged

func (mux *ObserverMux) CodeNodeSizeChanged(hex []byte, newSize uint)

func (*ObserverMux) CodeNodeTouched

func (mux *ObserverMux) CodeNodeTouched(hex []byte)

func (*ObserverMux) WillUnloadBranchNode

func (mux *ObserverMux) WillUnloadBranchNode(key []byte, nodeHash common.Hash, incarnation uint64)

func (*ObserverMux) WillUnloadNode

func (mux *ObserverMux) WillUnloadNode(key []byte, nodeHash common.Hash)

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

type OperatorHash struct {
	Hash common.Hash
}

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

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

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

func (w *OperatorMarshaller) Write(p []byte) (int, error)

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 common.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() (common.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 RetainAll

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

RetainAll - returns true to any prefix

func NewRetainAll

func NewRetainAll(decider RetainDecider) *RetainAll

NewRetainAll creates new NewRetainRange to=nil - means no upper bound

func (*RetainAll) AddCodeTouch

func (rr *RetainAll) AddCodeTouch(codeHash common.Hash)

AddCodeTouch adds a new code touch into the resolve set

func (*RetainAll) IsCodeTouched

func (rr *RetainAll) IsCodeTouched(codeHash common.Hash) bool

func (*RetainAll) Retain

func (rr *RetainAll) Retain(prefix []byte) (retain bool)

func (*RetainAll) String

func (rr *RetainAll) String() string

type RetainDecider

type RetainDecider interface {
	Retain([]byte) bool
	IsCodeTouched(common.Hash) bool
}

type RetainLevels

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

RetainLevels - returns true to any prefix shorter than `levels`

func NewRetainLevels

func NewRetainLevels(decider RetainDecider, levels int) *RetainLevels

NewRetainLevels creates new NewRetainRange to=nil - means no upper bound

func (*RetainLevels) AddCodeTouch

func (rr *RetainLevels) AddCodeTouch(codeHash common.Hash)

AddCodeTouch adds a new code touch into the resolve set

func (*RetainLevels) IsCodeTouched

func (rr *RetainLevels) IsCodeTouched(codeHash common.Hash) bool

func (*RetainLevels) Retain

func (rr *RetainLevels) Retain(prefix []byte) (retain bool)

func (*RetainLevels) String

func (rr *RetainLevels) String() string

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 NewBinaryRetainList

func NewBinaryRetainList(minLength int) *RetainList

func NewRetainList

func NewRetainList(minLength int) *RetainList

NewRetainList creates new RetainList

func (*RetainList) AddCodeTouch

func (rl *RetainList) AddCodeTouch(codeHash common.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)

AddKey adds a new key (in KEY encoding) to the list

func (*RetainList) IsCodeTouched

func (rl *RetainList) IsCodeTouched(codeHash common.Hash) 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) Rewind

func (rl *RetainList) Rewind()

Rewind lets us reuse this list from the beginning

func (*RetainList) String

func (rl *RetainList) String() string

type RetainListBuilder

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

RetainListBuilder is the structure that accumulates the list of keys that were read or changes (touched) during the execution of a block. It also tracks the contract codes that were created and used during the execution of a block

func NewRetainListBuilder

func NewRetainListBuilder() *RetainListBuilder

NewRetainListBuilder creates new ProofGenerator and initialised its maps

func (*RetainListBuilder) AddStorageTouch

func (rlb *RetainListBuilder) AddStorageTouch(touch []byte)

AddStorageTouch adds a key (in KEY encoding) into the read/change set of storage keys

func (*RetainListBuilder) AddTouch

func (rlb *RetainListBuilder) AddTouch(touch []byte)

AddTouch adds a key (in KEY encoding) into the read/change set of account keys

func (*RetainListBuilder) Build

func (rlb *RetainListBuilder) Build(isBinary bool) *RetainList

func (*RetainListBuilder) CreateCode

func (rlb *RetainListBuilder) CreateCode(codeHash common.Hash)

CreateCode registers that given contract code has been created (deployed) during current block's execution

func (*RetainListBuilder) ExtractTouches

func (rlb *RetainListBuilder) ExtractTouches() ([][]byte, [][]byte)

ExtractTouches returns accumulated read/change sets and clears them for the next block's execution

func (*RetainListBuilder) ReadCode

func (rlb *RetainListBuilder) ReadCode(codeHash common.Hash)

ReadCode registers that given contract code has been accessed during current block's execution

type RetainRange

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

RetainRange encapsulates the range 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 NewRetainRange

func NewRetainRange(from, to []byte) *RetainRange

NewRetainRange creates new NewRetainRange to=nil - means no upper bound

func (*RetainRange) AddCodeTouch

func (rr *RetainRange) AddCodeTouch(codeHash common.Hash)

AddCodeTouch adds a new code touch into the resolve set

func (*RetainRange) IsCodeTouched

func (rr *RetainRange) IsCodeTouched(codeHash common.Hash) bool

func (*RetainRange) Retain

func (rr *RetainRange) Retain(prefix []byte) (retain 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 it returns True:

	- for keys between from and to
 - for keys which are prefixes of from and to
 - for keys which are contains from and to as a prefix

func (*RetainRange) String

func (rr *RetainRange) String() string

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

func (r *RootHashAggregator) Receive(itemType StreamItem,
	accountKey []byte,
	storageKey []byte,
	accountValue *accounts.Account,
	storageValue []byte,
	hash []byte,
	cutoff int,
) error

func (*RootHashAggregator) Reset

func (r *RootHashAggregator) Reset(hc HashCollector, trace bool)

func (*RootHashAggregator) Result

func (r *RootHashAggregator) Result() SubTries

func (*RootHashAggregator) RetainNothing

func (r *RootHashAggregator) RetainNothing(prefix []byte) bool

func (*RootHashAggregator) Root

func (r *RootHashAggregator) Root() common.Hash

type StarkStatsBuilder

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

func NewStarkStatsBuilder

func NewStarkStatsBuilder() *StarkStatsBuilder

type StatsColumn

type StatsColumn string

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

func (*Stream) Reset

func (s *Stream) Reset()

Reset sets all slices to zero sizes, without de-allocating

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 StreamIterator interface {
	Next() (itemType StreamItem, hex1 []byte, aValue *accounts.Account, hash []byte, value []byte)
}

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

func (*StreamMergeIterator) Reset

func (smi *StreamMergeIterator) Reset(it *Iterator, s *Stream, trace bool)

Reset prepares StreamMergeIterator for reuse

type StreamReceiver

type StreamReceiver interface {
	Receive(
		itemType StreamItem,
		accountKey []byte,
		storageKey []byte,
		accountValue *accounts.Account,
		storageValue []byte,
		hash []byte,
		cutoff int,
	) error

	Result() SubTries
	Root() common.Hash
}

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(blockNr uint64) *SubTrieLoader

func (*SubTrieLoader) AddCodeRequest

func (stl *SubTrieLoader) AddCodeRequest(req *LoadRequestForCode)

AddCodeRequest add a request for code loading

func (*SubTrieLoader) LoadFromFlatDB

func (stl *SubTrieLoader) LoadFromFlatDB(db ethdb.Database, rl RetainDecider, hc HashCollector, dbPrefixes [][]byte, fixedbits []int, trace bool) (SubTries, error)

func (*SubTrieLoader) LoadFromWitnessDb

func (stl *SubTrieLoader) LoadFromWitnessDb(db WitnessStorage, blockNr uint64, trieLimit uint32, startPos int64, count int) (SubTries, int64, error)

LoadFromWitnessDb loads subtries from a witnesses database instead of a state DB.

func (*SubTrieLoader) LoadSubTries

func (stl *SubTrieLoader) LoadSubTries(db ethdb.Database, blockNr uint64, rl RetainDecider, hc HashCollector, dbPrefixes [][]byte, fixedbits []int, trace bool) (SubTries, error)

LoadFromDb loads subtries from a state database.

func (*SubTrieLoader) Reset

func (stl *SubTrieLoader) Reset(blockNr uint64)

type SubTries

type SubTries struct {
	Hashes []common.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 {
	Version uint8
	// 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.

func BuildTrieFromWitness

func BuildTrieFromWitness(witness *Witness, isBinary bool, trace bool) (*Trie, error)

func HexToQuad

func HexToQuad(t *Trie) *Trie

HexToQuad converts hexary trie to quad trie with the same set of keys

func Load

func Load(r io.Reader) (*Trie, error)

func New

func New(root common.Hash) *Trie

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.

func NewBinary

func NewBinary(root common.Hash) *Trie

func NewTestRLPTrie

func NewTestRLPTrie(root common.Hash) *Trie

NewTestRLPTrie treats all the data provided to `Update` function as rlp-encoded. it is usually used for testing purposes.

func (*Trie) AddObserver

func (t *Trie) AddObserver(observer Observer)

func (*Trie) DeepHash

func (t *Trie) DeepHash(keyPrefix []byte) (bool, common.Hash)

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 extention 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

func (t *Trie) Delete(key []byte)

Delete removes any existing value for key from the trie. DESCRIBED: docs/programmers_guide/guide.md#root

func (*Trie) DeleteSubtree

func (t *Trie) DeleteSubtree(keyPrefix []byte)

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

func (t *Trie) EvictNode(hex []byte)

func (*Trie) ExtractWitness

func (t *Trie) ExtractWitness(trace bool, rl RetainDecider) (*Witness, error)

func (*Trie) ExtractWitnessForPrefix

func (t *Trie) ExtractWitnessForPrefix(prefix []byte, trace bool, rl RetainDecider) (*Witness, error)

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

func (t *Trie) Fold(keys [][]byte)

Fold modifies the trie by folding the given set of keys, making sure that they are inaccessible without resolution via DB

func (*Trie) Get

func (t *Trie) Get(key []byte) (value []byte, gotValue bool)

Get returns the value for key stored in the trie.

func (*Trie) GetAccount

func (t *Trie) GetAccount(key []byte) (value *accounts.Account, gotValue bool)

func (*Trie) GetAccountCode

func (t *Trie) GetAccountCode(key []byte) (value []byte, gotValue bool)

func (*Trie) GetAccountCodeSize

func (t *Trie) GetAccountCodeSize(key []byte) (value int, gotValue bool)

func (*Trie) GetNodeByHash

func (t *Trie) GetNodeByHash(hash common.Hash) []byte

GetNodeByHash gets node's RLP by hash.

func (*Trie) Hash

func (t *Trie) Hash() common.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) HashMapSize

func (t *Trie) HashMapSize() int

HashMapSize returns the number of entries in trie's hash map.

func (*Trie) HashOfHexKey

func (t *Trie) HashOfHexKey(hexKey []byte) (common.Hash, error)

func (*Trie) HookSubTries

func (t *Trie) HookSubTries(subTries SubTries, hooks [][]byte) error

func (*Trie) NeedLoadCode

func (t *Trie) NeedLoadCode(addrHash common.Hash, codeHash common.Hash, bytecode bool) (bool, *LoadRequestForCode)

func (*Trie) NewLoadRequestForCode

func (t *Trie) NewLoadRequestForCode(addrHash common.Hash, codeHash common.Hash, bytecode bool) *LoadRequestForCode

func (*Trie) NumberOfAccounts

func (t *Trie) NumberOfAccounts() int

func (*Trie) Print

func (t *Trie) Print(w io.Writer)

func (*Trie) PrintDiff

func (t *Trie) PrintDiff(t2 *Trie, w io.Writer)

func (*Trie) PrintTrie

func (t *Trie) PrintTrie()

func (*Trie) Prove

func (t *Trie) Prove(key []byte, fromLevel int, storage bool) ([][]byte, error)

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

func (t *Trie) Reset()

func (*Trie) Root

func (t *Trie) Root() []byte

Root returns the root hash of the trie. Deprecated: use Hash instead.

func (*Trie) TrieSize

func (t *Trie) TrieSize() int

func (*Trie) Update

func (t *Trie) Update(key, value []byte)

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

func (t *Trie) UpdateAccount(key []byte, acc *accounts.Account)

func (*Trie) UpdateAccountCode

func (t *Trie) UpdateAccountCode(key []byte, code codeNode) error

UpdateAccountCode attaches the code node to an account at specified key

func (*Trie) UpdateAccountCodeSize

func (t *Trie) UpdateAccountCodeSize(key []byte, codeSize int) error

UpdateAccountCodeSize attaches the code size to the account

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 rectange 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

func NewWitnessFromReader(input io.Reader, trace bool) (*Witness, error)

func (*Witness) WriteDiff

func (w *Witness) WriteDiff(w2 *Witness, output io.Writer)

func (*Witness) WriteTo

func (w *Witness) WriteTo(out io.Writer) (*BlockWitnessStats, error)

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 WitnessDbSubTrieLoader

type WitnessDbSubTrieLoader struct {
}

func NewWitnessDbSubTrieLoader

func NewWitnessDbSubTrieLoader() *WitnessDbSubTrieLoader

func (*WitnessDbSubTrieLoader) LoadSubTries

func (wstl *WitnessDbSubTrieLoader) LoadSubTries(db WitnessStorage, blockNr uint64, trieLimit uint32, startPos int64, count int) (SubTries, int64, 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) LoadFrom

func (h *WitnessHeader) LoadFrom(input io.Reader) error

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.

type WitnessStorage

type WitnessStorage interface {
	GetWitnessesForBlock(uint64, uint32) ([]byte, error)
}

WitnessStorage is an interface representing a single

Directories

Path Synopsis
rlphacks