Skip to content

Commit

Permalink
Make all debug logger tags in verkle package use lower casing
Browse files Browse the repository at this point in the history
  • Loading branch information
scorbajio committed Sep 20, 2024
1 parent 458f560 commit f97c3f8
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions packages/verkle/src/verkleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class VerkleTree {
*/
async get(stem: Uint8Array, suffixes: number[]): Promise<(Uint8Array | undefined)[]> {
if (stem.length !== 31) throw new Error(`expected stem with length 31; got ${stem.length}`)
this.DEBUG && this.debug(`Stem: ${bytesToHex(stem)}; Suffix: ${suffixes}`, ['GET'])
this.DEBUG && this.debug(`Stem: ${bytesToHex(stem)}; Suffix: ${suffixes}`, ['get'])
const res = await this.findPath(stem)
if (res.node instanceof LeafNode) {
// The retrieved leaf node contains an array of 256 possible values.
Expand All @@ -171,7 +171,7 @@ export class VerkleTree {
this.DEBUG &&
this.debug(
`Suffix: ${suffix}; Value: ${value === undefined ? 'undefined' : bytesToHex(value)}`,
['GET'],
['get'],
)
values.push(value)
}
Expand All @@ -194,7 +194,7 @@ export class VerkleTree {
// Must have an equal number of values and suffixes
throw new Error(`expected number of values; ${values.length} to equal ${suffixes.length}`)
}
this.DEBUG && this.debug(`Stem: ${bytesToHex(stem)}`, ['PUT'])
this.DEBUG && this.debug(`Stem: ${bytesToHex(stem)}`, ['put'])

const putStack: [Uint8Array, VerkleNode][] = []
// Find path to nearest node
Expand Down Expand Up @@ -227,7 +227,7 @@ export class VerkleTree {
} else {
// Leaf node doesn't exist, create a new one
leafNode = await LeafNode.create(stem, this.verkleCrypto)
this.DEBUG && this.debug(`Creating new leaf node at stem: ${bytesToHex(stem)}`, ['PUT'])
this.DEBUG && this.debug(`Creating new leaf node at stem: ${bytesToHex(stem)}`, ['put'])
}
for (let i = 0; i < values.length; i++) {
const value = values[i]
Expand All @@ -243,7 +243,7 @@ export class VerkleTree {
this.DEBUG &&
this.debug(
`Updating value for suffix: ${suffix} at leaf node with stem: ${bytesToHex(stem)}`,
['PUT'],
['put'],
)
}
// Push new/updated leafNode to putStack
Expand Down Expand Up @@ -278,7 +278,7 @@ export class VerkleTree {
`Updating child reference for node with path: ${bytesToHex(
lastPath,
)} at index ${childIndex} in internal node at path ${bytesToHex(nextPath)}`,
['PUT'],
['put'],
)
// Hold onto `path` to current node for updating next parent node child index
lastPath = nextPath
Expand All @@ -298,15 +298,15 @@ export class VerkleTree {
`Updating child reference for node with path: ${bytesToHex(lastPath)} at index ${
lastPath[0]
} in root node`,
['PUT'],
['put'],
)
this.DEBUG && this.debug(`Updating root node hash to ${bytesToHex(this._root)}`, ['PUT'])
this.DEBUG && this.debug(`Updating root node hash to ${bytesToHex(this._root)}`, ['put'])
putStack.push([this._root, rootNode])
await this.saveStack(putStack)
}

async del(stem: Uint8Array, suffixes: number[]): Promise<void> {
this.DEBUG && this.debug(`Stem: ${bytesToHex(stem)}; Suffix(es): ${suffixes}`, ['DEL'])
this.DEBUG && this.debug(`Stem: ${bytesToHex(stem)}; Suffix(es): ${suffixes}`, ['del'])
await this.put(stem, suffixes, new Array(suffixes.length).fill(createDeletedLeafValue()))
}
/**
Expand Down Expand Up @@ -341,7 +341,7 @@ export class VerkleTree {
// Find the path to the new internal node (the matching portion of the leaf node and next node's stems)
pathToNode = leafNode.stem.slice(0, partialMatchingStemIndex)
this.DEBUG &&
this.debug(`Creating new internal node at path ${bytesToHex(pathToNode)}`, ['PUT'])
this.debug(`Creating new internal node at path ${bytesToHex(pathToNode)}`, ['put'])
} else {
// Nearest node is an internal node. We need to update the appropriate child reference
// to the new leaf node
Expand All @@ -359,7 +359,7 @@ export class VerkleTree {
} in internal node at path ${bytesToHex(
leafNode.stem.slice(0, partialMatchingStemIndex),
)}`,
['PUT'],
['put'],
)
}
return { node: internalNode, lastPath: pathToNode }
Expand All @@ -371,7 +371,7 @@ export class VerkleTree {
* @param throwIfMissing - if true, throws if any nodes are missing. Used for verifying proofs. (default: false)
*/
async findPath(key: Uint8Array): Promise<Path> {
this.DEBUG && this.debug(`Path (${key.length}): [${bytesToHex(key)}]`, ['FIND_PATH'])
this.DEBUG && this.debug(`Path (${key.length}): [${bytesToHex(key)}]`, ['find_path'])
const result: Path = {
node: null,
stack: [],
Expand All @@ -387,13 +387,13 @@ export class VerkleTree {

const rootNode = decodeNode(rawNode, this.verkleCrypto) as InternalNode

this.DEBUG && this.debug(`Starting with Root Node: [${bytesToHex(this.root())}]`, ['FIND_PATH'])
this.DEBUG && this.debug(`Starting with Root Node: [${bytesToHex(this.root())}]`, ['find_path'])
result.stack.push([rootNode, this.root()])
let child = rootNode.children[key[0]]

// Root node doesn't contain a child node's commitment on the first byte of the path so we're done
if (child === null) {
this.DEBUG && this.debug(`Partial Path ${intToHex(key[0])} - found no child.`, ['FIND_PATH'])
this.DEBUG && this.debug(`Partial Path ${intToHex(key[0])} - found no child.`, ['find_path'])
return result
}
let finished = false
Expand All @@ -420,7 +420,7 @@ export class VerkleTree {
`Path ${bytesToHex(key)} - found full path to node ${bytesToHex(
decodedNode.hash(),
)}.`,
['FIND_PATH'],
['find_path'],
)
result.node = decodedNode
result.remaining = new Uint8Array()
Expand All @@ -435,7 +435,7 @@ export class VerkleTree {
`Path ${bytesToHex(pathToNearestNode)} - found path to nearest node ${bytesToHex(
decodedNode.hash(),
)} but target node not found.`,
['FIND_PATH'],
['find_path'],
)
result.stack.push([decodedNode, pathToNearestNode])
return result
Expand All @@ -447,7 +447,7 @@ export class VerkleTree {
`Partial Path ${bytesToHex(
key.slice(0, matchingKeyLength),
)} - found next node in path ${bytesToHex(decodedNode.hash())}.`,
['FIND_PATH'],
['find_path'],
)
// Get the next child node in the path
const childIndex = key[matchingKeyLength]
Expand All @@ -458,7 +458,7 @@ export class VerkleTree {
`Found partial path ${key.slice(
31 - result.remaining.length,
)} but sought node is not present in trie.`,
['FIND_PATH'],
['find_path'],
)
return result
}
Expand All @@ -474,7 +474,7 @@ export class VerkleTree {
verkleCrypto: this.verkleCrypto,
})

this.DEBUG && this.debug(`No root node. Creating new root node`, ['INITIALIZE'])
this.DEBUG && this.debug(`No root node. Creating new root node`, ['initialize'])
// Set trie root to serialized (aka compressed) commitment for later use in verkle proof
this.root(this.verkleCrypto.serializeCommitment(rootNode.commitment))
await this.saveStack([[this.root(), rootNode]])
Expand Down

0 comments on commit f97c3f8

Please sign in to comment.