Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CachedMerklePatriciaTree<K, V>

Type parameters

  • K

  • V

Hierarchy

Implements

Index

Constructors

constructor

Properties

maxCacheDepth

maxCacheDepth: number

options

rootNode

The root node of the tree.

Accessors

root

  • get root(): Buffer

rootHash

  • get rootHash(): bigint

Methods

batch

  • batch(putOps: Array<BatchPut<K, V>>, delOps?: K[]): Buffer
  • Execute a batch of put and delete operations. The execution is batched, so calling this function with multiple updates provides more opportunities for optimization and can be faster than call put() and del() multiple times.

    Parameters

    • putOps: Array<BatchPut<K, V>>

      An array of put operations on the tree, of type BatchPut.

    • Default value delOps: K[] = []

      An optional array of keys to delete from the tree.

    Returns Buffer

    The root that results from this set of operations.

batchCOW

  • Execute a batch of put and delete operations. The execution of batch operations are performed in a copy on write (cow) fashion.

    Parameters

    • putOps: Array<BatchPut<K, V>>

      An array of put operations on the tree, of type BatchPut.

    • Default value delOps: K[] = []

      An optional array of keys to delete from the tree.

    Returns MerklePatriciaTree<K, V>

    A new MerklePatriciaTree updated in a cow manner.

batchCOWwithNodeBag

  • Updates CachedMerklePatriciaTree in a copy-on-write fashion

    Parameters

    • putOps: Array<BatchPut<K, V>>

      Key value pairs to be updated

    • nodesUsed: Set<bigint> | undefined

      Nodes in the nodeBags that become stale due to the updates

    • Rest ...nodeBag: Array<Map<bigint, MerklePatriciaTreeNode<V>>>

      A list of maps indexing MerkleNodes with their hashes

    Returns CachedMerklePatriciaTree<K, V>

batchGet

  • batchGet(keys: K[]): Array<Witness<V>>

copyTreePaths

del

  • del(key: K): void
  • Given a key, delete any mapping that exists for that key.

    Parameters

    • key: K

      The key to unmap.

    Returns void

get

getFromCache

  • getFromCache(key: K, bagNodesUsed: Set<bigint> | undefined, ...nodeMap: Array<Map<bigint, MerklePatriciaTreeNode<V>>>): V
  • getFromCache returns the value corresponding to the key using nodeMap

    Parameters

    • key: K

      : key to get from the CachedMerklePatriciaTree

    • bagNodesUsed: Set<bigint> | undefined
    • Rest ...nodeMap: Array<Map<bigint, MerklePatriciaTreeNode<V>>>

      : Bag of recent MerklePatriciaTree nodes from the client

    Returns V

    value corresponding to the key if present; null if otherwise

getNodeCopy

getmaxCacheDepth

  • getmaxCacheDepth(): number
  • Returns the maxCacheDepth

    Returns number

insert

  • Insert a node with the given value after a search.

    Parameters

    • stack: Array<MerklePatriciaTreeNode<V>>

      The stack as a result of the search

    • remainder: number[]

      The remainder as a result of the search

    • value: V

      The value to insert.

    Returns void

multiSearch

  • multiSearch(putOps: Array<BatchPut<K, V>>, delOps: K[], flag: boolean): void
  • multiSearch searches the tree for all keys and marks nodes for copy

    Parameters

    • putOps: Array<BatchPut<K, V>>

      : List of key, value pairs

    • delOps: K[]

      : List of keys

    • flag: boolean

      : True if we want to mark the nodes for copy

    Returns void

nodeCount

  • nodeCount(count?: number): number

pruneStateCache

  • Recursively prunes the cachedStateTree to maxCacheDepth by adding HashNodes

    Parameters

    • Default value currNode: MerklePatriciaTreeNode<V> = this.rootNode

      current node at a depth, starting from rootNode at depth = 1

    • Default value depth: number = 1

      Ranges from 1 to maxCacheDepth

    Returns void

put

  • put(key: K, val: V): void
  • Insert a new mapping into the tree. If the key is already mapped in the tree, it is updated with the new value.

    Parameters

    • key: K

      The key to insert.

    • val: V

      A Buffer representing the value.

    Returns void

putWithNodeBag

  • putWithNodeBag(key: K, value: V, usedNodes: Set<bigint> | undefined, ...nodeBag: Array<Map<bigint, MerklePatriciaTreeNode<V>>>): void
  • putWithNodeBag inserts k,v pairs and rebuilds the pruned CachedMerklePatriciaTree if needed

    Parameters

    • key: K

      : key to insert or modify

    • value: V

      : value corresponding to the key

    • usedNodes: Set<bigint> | undefined

      : A list of nodes used from the nodeBag for rebuilding the cached tree The usedNodes hashes change due to the insertion of the k, v pair into the tree

    • Rest ...nodeBag: Array<Map<bigint, MerklePatriciaTreeNode<V>>>

      : A Map of nodes indexed by their hashes

    Returns void

rlpSerializeWitness

rlpToMerkleNode

  • Given the rlpEncoded serialization of the node and a valueConverter function, rlpToMerkleNode returns the decoded MerklePatriciaTreeNode

    Parameters

    • raw: Buffer

      : rlpEncoded serialized MerklePatriciaNode

    • valueConverter: function

      : Converts a Buffer value into type V

        • (val: Buffer): V
        • Parameters

          • val: Buffer

          Returns V

    Returns MerklePatriciaTreeNode<V>

    MerkleNode : Decoded MerklePatriciaNode

search

size

  • size(): number

verifyAndAddWitness

  • verifyAndAddWitness(root: Buffer, key: K, witness: Witness<V>): void

Generated using TypeDoc