diff --git a/packages/blockchain/README.md b/packages/blockchain/README.md index 22b9689f61..42945a7d10 100644 --- a/packages/blockchain/README.md +++ b/packages/blockchain/README.md @@ -247,7 +247,7 @@ The following initial logger is currently available: | Logger | Description | | ------------------- | ------------------------------------------------------------------------ | -| `blockchain` | Core blockchain operations like when a block or header is put or deleted | +| `blockchain:#` | Core blockchain operations like when a block or header is put or deleted | | `blockchain:clique` | Clique consensus operations like updating the vote and/or signer list | | `blockchain:ethash` | Ethash consensus operations like PoW block or header validation | diff --git a/packages/blockchain/src/blockchain.ts b/packages/blockchain/src/blockchain.ts index 2cb5c8b231..8e1e7c4f70 100644 --- a/packages/blockchain/src/blockchain.ts +++ b/packages/blockchain/src/blockchain.ts @@ -107,7 +107,7 @@ export class Blockchain implements BlockchainInterface { constructor(opts: BlockchainOptions = {}) { this.DEBUG = typeof window === 'undefined' ? (process?.env?.DEBUG?.includes('ethjs') ?? false) : false - this._debug = debugDefault('blockchain') + this._debug = debugDefault('blockchain:#') if (opts.common) { this.common = opts.common @@ -327,7 +327,10 @@ export class Blockchain implements BlockchainInterface { async resetCanonicalHead(canonicalHead: bigint) { let hash: Uint8Array | undefined - const canonicalHeadHash = (await this.getCanonicalHeadHeader()).hash() + let canonicalHeadHash: Uint8Array | undefined + if (this.DEBUG) { + canonicalHeadHash = (await this.getCanonicalHeadHeader()).hash() + } await this.runWithLock(async () => { hash = await this.dbManager.numberToHash(canonicalHead) if (hash === undefined) { @@ -352,7 +355,7 @@ export class Blockchain implements BlockchainInterface { this.DEBUG && this._debug( - `Canonical head set from ${bytesToHex(canonicalHeadHash)} to ${bytesToHex(hash!)} (number ${bigIntToHex(canonicalHead)})`, + `Canonical head set from ${bytesToHex(canonicalHeadHash!)} to ${bytesToHex(hash!)} (number ${bigIntToHex(canonicalHead)})`, ) this._deletedBlocks = [] diff --git a/packages/blockchain/src/constructors.ts b/packages/blockchain/src/constructors.ts index 1dc9f3cac6..615c501e96 100644 --- a/packages/blockchain/src/constructors.ts +++ b/packages/blockchain/src/constructors.ts @@ -17,7 +17,7 @@ import type { Chain } from '@ethereumjs/common' const DEBUG = typeof window === 'undefined' ? (process?.env?.DEBUG?.includes('ethjs') ?? false) : false -const debug = debugDefault('blockchain') +const debug = debugDefault('blockchain:#') export async function createBlockchain(opts: BlockchainOptions = {}) { const blockchain = new Blockchain(opts) diff --git a/packages/client/README.md b/packages/client/README.md index face3bcee8..70b4664b0f 100644 --- a/packages/client/README.md +++ b/packages/client/README.md @@ -466,7 +466,7 @@ The following options are available: | Logger | Description | | ------------------- | ------------------------------------------------ | -| `client:fetcher` | This option enables logging for all fetchers | +| `client:fetcher:#` | This option enables logging for core fetcher operations such as job scheduling | | `client:fetcher:bytecode` | This option enables logging for the snap sync bytecode fetcher | | `client:fetcher:storage` | This option enables logging for the snap sync storage fetcher | | `client:fetcher:trienode` | This option enables logging for the snap sync trienode fetcher | diff --git a/packages/client/src/sync/fetcher/fetcher.ts b/packages/client/src/sync/fetcher/fetcher.ts index 5229b2efc3..ee085c6c4b 100644 --- a/packages/client/src/sync/fetcher/fetcher.ts +++ b/packages/client/src/sync/fetcher/fetcher.ts @@ -82,7 +82,7 @@ export abstract class Fetcher extends Readable typeof window === 'undefined' ? (process?.env?.DEBUG?.includes('ethjs') ?? false) : false this.config = options.config - this.debug = debug('client:fetcher') + this.debug = debug('client:fetcher:#') this.pool = options.pool this.timeout = options.timeout ?? 8000 diff --git a/packages/devp2p/src/util.ts b/packages/devp2p/src/util.ts index e1de5db726..149a96fa53 100644 --- a/packages/devp2p/src/util.ts +++ b/packages/devp2p/src/util.ts @@ -7,7 +7,7 @@ import { secp256k1 } from 'ethereum-cryptography/secp256k1.js' import type { ETH } from './protocol/eth.js' import type { LES } from './protocol/les.js' -export const devp2pDebug = debug('devp2p') +export const devp2pDebug = debug('devp2p:#') export function genPrivateKey(): Uint8Array { const privateKey = secp256k1.utils.randomPrivateKey() diff --git a/packages/trie/README.md b/packages/trie/README.md index 6fb2cbbbe9..6774ea5c4e 100644 --- a/packages/trie/README.md +++ b/packages/trie/README.md @@ -341,12 +341,26 @@ The `Trie` class features optional debug logging. Individual debug selections ca The following options are available: -| Logger | Description | -| ----------------- | ---------------------------------------------- | -| `trie` | minimal info logging for all trie methods | -| `trie:` | debug logging for specific trie method | -| `trie::*` | verbose debug logging for specific trie method | -| `trie:*` | verbose debug logging for all trie methods | +| Logger | Description | +| --------------------------------- | -------------------------------------------------------------------- | +| `trie:#` | minimal info logging for all trie methods | +| `trie:#:put` | a trie put operation has occurred | +| `trie:#:get` | a trie get operation has occurred | +| `trie:#:del` | a trie del operation has occurred | +| `trie:#:find_path` | a node is being searched for | +| `trie:#:find_path:branch_node` | a branch node has been found during a node search | +| `trie:#:find_path:extension_node` | an extension node has been found during a node search | +| `trie:#:lookup_node` | node lookup operations | +| `trie:#:lookup_node:raw_node` | node lookup operations that have hit a raw node | +| `trie:#:lookup_node:by_hash` | node lookup operations that have hit a node hash | +| `trie:#:persist_root` | operations writing the state root to the disk | +| `trie:#:checkpoint` | checkpoint operations | +| `trie:#:commit` | operations committing checkpoints to the disk | +| `trie:#:revert:before` | the stateRoot before reverting committed checkpoints | +| `trie:#:revert:after` | the stateRoot after reverting committed checkpoints | +| `trie:#:flush_checkpoints` | checkpoints are being flushed | +| `trie:#:from_proof` | a trie has been updated from a proof using updateTrieFromMerkleProof | +| `trie:#:create_proof` | a merkle proof has been created using updateTrieFromMerkleProof | To observe the logging in action at different levels: @@ -359,25 +373,25 @@ DEBUG=ethjs,trie npx vitest test/util/log.spec.ts Run with **put** method logging: ```shell -DEBUG=ethjs,trie:PUT npx vitest test/util/log.spec.ts +DEBUG=ethjs,trie:put npx vitest test/util/log.spec.ts ``` Run with **trie** + **put**/**get**/**del** logging: ```shell -DEBUG=ethjs,trie,trie:PUT,trie:GET,trie:DEL npx vitest test/util/log.spec.ts +DEBUG=ethjs,trie,trie:put,trie:get,trie:del npx vitest test/util/log.spec.ts ``` Run with **findPath** debug logging: ```shell -DEBUG=ethjs,trie:FIND_PATH npx vitest test/util/log.spec.ts +DEBUG=ethjs,trie:find_path npx vitest test/util/log.spec.ts ``` Run with **findPath** verbose logging: ```shell -DEBUG=ethjs,trie:FIND_PATH:* npx vitest test/util/log.spec.ts +DEBUG=ethjs,trie:find_path:* npx vitest test/util/log.spec.ts ``` Run with max logging: @@ -389,7 +403,7 @@ DEBUG=ethjs,trie:* npx vitest test/util/log.spec.ts `ethjs` **must** be included in the `DEBUG` environment variables to enable **any** logs. Additional log selections can be added with a comma separated list (no spaces). Logs with extensions can be enabled with a colon `:`, and `*` can be used to include all extensions. -`DEBUG=ethjs,tie:PUT,trie:FIND_PATH:* npx vitest test/proof.spec.ts` +`DEBUG=ethjs,trie:put,trie:find_path:* npx vitest test/proof.spec.ts` ## References diff --git a/packages/trie/src/proof/index.ts b/packages/trie/src/proof/index.ts index c3462c9318..50b7366b7c 100644 --- a/packages/trie/src/proof/index.ts +++ b/packages/trie/src/proof/index.ts @@ -72,12 +72,12 @@ export function verifyTrieRangeProof( * @param key key to create a proof for */ export async function createMerkleProof(trie: Trie, key: Uint8Array): Promise { - trie['DEBUG'] && trie['debug'](`Creating Proof for Key: ${bytesToHex(key)}`, ['CREATE_PROOF']) + trie['DEBUG'] && trie['debug'](`Creating Proof for Key: ${bytesToHex(key)}`, ['create_proof']) const { stack } = await trie.findPath(trie['appliedKey'](key)) const p = stack.map((stackElem) => { return stackElem.serialize() }) - trie['DEBUG'] && trie['debug'](`Proof created with (${stack.length}) nodes`, ['CREATE_PROOF']) + trie['DEBUG'] && trie['debug'](`Proof created with (${stack.length}) nodes`, ['create_proof']) return p } @@ -94,7 +94,7 @@ export async function updateTrieFromMerkleProof( proof: Proof, shouldVerifyRoot: boolean = false, ) { - trie['DEBUG'] && trie['debug'](`Saving (${proof.length}) proof nodes in DB`, ['FROM_PROOF']) + trie['DEBUG'] && trie['debug'](`Saving (${proof.length}) proof nodes in DB`, ['from_proof']) const opStack = proof.map((nodeValue) => { let key = Uint8Array.from(trie['hash'](nodeValue)) key = trie['_opts'].keyPrefix ? concatBytes(trie['_opts'].keyPrefix, key) : key diff --git a/packages/trie/src/trie.ts b/packages/trie/src/trie.ts index 4ab3ef7fb9..15b0a50d10 100644 --- a/packages/trie/src/trie.ts +++ b/packages/trie/src/trie.ts @@ -72,7 +72,7 @@ export class Trie { /** Debug logging */ protected DEBUG: boolean - protected _debug: Debugger = debug('trie') + protected _debug: Debugger = debug('trie:#') protected debug: (...args: any) => void /** @@ -187,13 +187,13 @@ export class Trie { * @returns A Promise that resolves to `Uint8Array` if a value was found or `null` if no value was found. */ async get(key: Uint8Array, throwIfMissing = false): Promise { - this.DEBUG && this.debug(`Key: ${bytesToHex(key)}`, ['GET']) + this.DEBUG && this.debug(`Key: ${bytesToHex(key)}`, ['get']) const { node, remaining } = await this.findPath(this.appliedKey(key), throwIfMissing) let value: Uint8Array | null = null if (node && remaining.length === 0) { value = node.value() } - this.DEBUG && this.debug(`Value: ${value === null ? 'null' : bytesToHex(value)}`, ['GET']) + this.DEBUG && this.debug(`Value: ${value === null ? 'null' : bytesToHex(value)}`, ['get']) return value } @@ -209,8 +209,8 @@ export class Trie { value: Uint8Array | null, skipKeyTransform: boolean = false, ): Promise { - this.DEBUG && this.debug(`Key: ${bytesToHex(key)}`, ['PUT']) - this.DEBUG && this.debug(`Value: ${value === null ? 'null' : bytesToHex(key)}`, ['PUT']) + this.DEBUG && this.debug(`Key: ${bytesToHex(key)}`, ['put']) + this.DEBUG && this.debug(`Value: ${value === null ? 'null' : bytesToHex(key)}`, ['put']) if (this._opts.useRootPersistence && equalsBytes(key, ROOT_DB_KEY) === true) { throw new Error(`Attempted to set '${bytesToUtf8(ROOT_DB_KEY)}' key but it is not allowed.`) } @@ -272,7 +272,7 @@ export class Trie { * @returns A Promise that resolves once value is deleted. */ async del(key: Uint8Array, skipKeyTransform: boolean = false): Promise { - this.DEBUG && this.debug(`Key: ${bytesToHex(key)}`, ['DEL']) + this.DEBUG && this.debug(`Key: ${bytesToHex(key)}`, ['del']) await this._lock.acquire() const appliedKey = skipKeyTransform ? key : this.appliedKey(key) const { node, stack } = await this.findPath(appliedKey) @@ -331,7 +331,7 @@ export class Trie { stack[i] = partialPath.stack[i] progress += stack[i] instanceof BranchNode ? 1 : (stack[i]).keyLength() } - this.DEBUG && this.debug(`Target (${targetKey.length}): [${targetKey}]`, ['FIND_PATH']) + this.DEBUG && this.debug(`Target (${targetKey.length}): [${targetKey}]`, ['find_path']) let result: Path | null = null const onFound: FoundNodeFunction = async (_, node, keyProgress, walkController) => { @@ -343,19 +343,25 @@ export class Trie { const branchIndex = targetKey[progress] this.DEBUG && this.debug(`Looking for node on branch index: [${branchIndex}]`, [ - 'FIND_PATH', - 'BranchNode', + 'find_path', + 'branch_node', ]) const branchNode = node.getBranch(branchIndex) - this.DEBUG && - this.debug( - branchNode === null - ? 'NULL' - : branchNode instanceof Uint8Array + + if (this.DEBUG) { + let debugString: string + if (branchNode === null) { + debugString = 'NULL' + } else { + debugString = `Branch index: ${branchIndex.toString()} - ` + debugString += + branchNode instanceof Uint8Array ? `NodeHash: ${bytesToHex(branchNode)}` - : `Raw_Node: ${branchNode.toString()}`, - ['FIND_PATH', 'BranchNode', branchIndex.toString()], - ) + : `Raw_Node: ${branchNode!.toString()}` + } + + this.debug(debugString, ['find_path', 'branch_node']) + } if (!branchNode) { result = { node: null, remaining: targetKey.slice(progress), stack } } else { @@ -388,11 +394,11 @@ export class Trie { node.key().toString() }] `, - ['FIND_PATH', 'ExtensionNode'], + ['find_path', 'extension_node'], ) const _progress = progress for (const k of node.key()) { - this.DEBUG && this.debug(`NextNode: ${node.value()}`, ['FIND_PATH', 'ExtensionNode']) + this.DEBUG && this.debug(`NextNode: ${node.value()}`, ['find_path', 'extension_node']) if (k !== targetKey[progress]) { result = { node: null, remaining: targetKey.slice(_progress), stack } return @@ -408,7 +414,7 @@ export class Trie { this.DEBUG && this.debug( `Walking trie from ${startingNode === undefined ? 'ROOT' : 'NODE'}: ${bytesToHex(start)}`, - ['FIND_PATH'], + ['find_path'], ) await this.walkTrie(start, onFound) } catch (error: any) { @@ -425,7 +431,7 @@ export class Trie { result.node !== null ? `Target Node FOUND for ${bytesToNibbles(key)}` : `Target Node NOT FOUND`, - ['FIND_PATH'], + ['find_path'], ) result.stack = result.stack.filter((e) => e !== undefined) @@ -436,7 +442,7 @@ export class Trie { || Remaining: [${result.remaining}]\n|| Stack: ${result.stack .map((e) => e.constructor.name) .join(', ')}`, - ['FIND_PATH'], + ['find_path'], ) return result } @@ -503,10 +509,10 @@ export class Trie { async lookupNode(node: Uint8Array | Uint8Array[]): Promise { if (isRawNode(node)) { const decoded = decodeRawNode(node) - this.DEBUG && this.debug(`${decoded.constructor.name}`, ['LOOKUP_NODE', 'RAW_NODE']) + this.DEBUG && this.debug(`${decoded.constructor.name}`, ['lookup_node', 'raw_node']) return decoded } - this.DEBUG && this.debug(`${`${bytesToHex(node)}`}`, ['LOOKUP_NODE', 'BY_HASH']) + this.DEBUG && this.debug(`${`${bytesToHex(node)}`}`, ['lookup_node', 'by_hash']) const key = this._opts.keyPrefix ? concatBytes(this._opts.keyPrefix, node) : node const value = (await this._db.get(key)) ?? null @@ -516,7 +522,7 @@ export class Trie { } const decoded = decodeNode(value) - this.DEBUG && this.debug(`${decoded.constructor.name} found in DB`, ['LOOKUP_NODE', 'BY_HASH']) + this.DEBUG && this.debug(`${decoded.constructor.name} found in DB`, ['lookup_node', 'by_hash']) return decoded } @@ -965,7 +971,7 @@ export class Trie { `Persisting root: \n|| RootHash: ${bytesToHex(this.root())}\n|| RootKey: ${bytesToHex( this.appliedKey(ROOT_DB_KEY), )}`, - ['PERSIST_ROOT'], + ['persist_root'], ) let key = this.appliedKey(ROOT_DB_KEY) key = this._opts.keyPrefix ? concatBytes(this._opts.keyPrefix, key) : key @@ -1020,7 +1026,7 @@ export class Trie { * After this is called, all changes can be reverted until `commit` is called. */ checkpoint() { - this.DEBUG && this.debug(`${bytesToHex(this.root())}`, ['CHECKPOINT']) + this.DEBUG && this.debug(`${bytesToHex(this.root())}`, ['checkpoint']) this._db.checkpoint(this.root()) } @@ -1033,7 +1039,7 @@ export class Trie { if (!this.hasCheckpoints()) { throw new Error('trying to commit when not checkpointed') } - this.DEBUG && this.debug(`${bytesToHex(this.root())}`, ['COMMIT']) + this.DEBUG && this.debug(`${bytesToHex(this.root())}`, ['commit']) await this._lock.acquire() await this._db.commit() await this.persistRoot() @@ -1050,12 +1056,12 @@ export class Trie { throw new Error('trying to revert when not checkpointed') } - this.DEBUG && this.debug(`${bytesToHex(this.root())}`, ['REVERT', 'BEFORE']) + this.DEBUG && this.debug(`${bytesToHex(this.root())}`, ['revert', 'before']) await this._lock.acquire() this.root(await this._db.revert()) await this.persistRoot() this._lock.release() - this.DEBUG && this.debug(`${bytesToHex(this.root())}`, ['REVERT', 'AFTER']) + this.DEBUG && this.debug(`${bytesToHex(this.root())}`, ['revert', 'after']) } /** @@ -1063,7 +1069,7 @@ export class Trie { */ flushCheckpoints() { this.DEBUG && - this.debug(`Deleting ${this._db.checkpoints.length} checkpoints.`, ['FLUSH_CHECKPOINTS']) + this.debug(`Deleting ${this._db.checkpoints.length} checkpoints.`, ['flush_checkpoints']) this._db.checkpoints = [] } diff --git a/packages/verkle/README.md b/packages/verkle/README.md index 71c62c3f63..a37556a722 100644 --- a/packages/verkle/README.md +++ b/packages/verkle/README.md @@ -88,12 +88,14 @@ The `Verkle` class features optional debug logging. Individual debug selections The following options are available: -| Logger | Description | -| ------------------- | ------------------------------------------------ | -| `verkle` | minimal info logging for all verkle methods | -| `verkle:` | debug logging for specific verkle method | -| `verkle::*` | verbose debug logging for specific verkle method | -| `verkle:*` | verbose debug logging for all verkle methods | +| Logger | Description | +| --------------------- | ------------------------------------ | +| `verkle:#` | a core verkle operation has occurred | +| `verkle:#:put` | a verkle put operation has occurred | +| `verkle:#:get` | a verkle get operation has occurred | +| `verkle:#:del` | a verkle del operation has occurred | +| `verkle:#:find_path` | a node is being searched for | +| `verkle:#:initialize` | a verkle object has been initialized | To observe the logging in action at different levels: @@ -106,13 +108,13 @@ DEBUG=ethjs,verkle npx vitest test/verkle.spec.ts Run with **put** method logging: ```shell -DEBUG=ethjs,verkle:PUT npx vitest test/verkle.spec.ts +DEBUG=ethjs,verkle:put npx vitest test/verkle.spec.ts ``` Run with **verkle** + **put**/**get**/**del** logging: ```shell -DEBUG=ethjs,verkle,verkle:PUT,verkle:GET,verkle:DEL npx vitest test/verkle.spec.ts +DEBUG=ethjs,verkle,verkle:put,verkle:get,verkle:del npx vitest test/verkle.spec.ts ``` Run with max logging: @@ -124,7 +126,7 @@ DEBUG=ethjs,verkle:* npx vitest test/verkle.spec.ts `ethjs` **must** be included in the `DEBUG` environment variables to enable **any** logs. Additional log selections can be added with a comma separated list (no spaces). Logs with extensions can be enabled with a colon `:`, and `*` can be used to include all extensions. -`DEBUG=ethjs,tie:PUT,trie:FIND_PATH:* npx vitest test/proof.spec.ts` +`DEBUG=ethjs,tie:put,trie:find_path:* npx vitest test/proof.spec.ts` ## References diff --git a/packages/verkle/src/verkleTree.ts b/packages/verkle/src/verkleTree.ts index d6249d4f6f..e0294a3580 100644 --- a/packages/verkle/src/verkleTree.ts +++ b/packages/verkle/src/verkleTree.ts @@ -55,7 +55,7 @@ export class VerkleTree { /** Debug logging */ protected DEBUG: boolean - protected _debug: Debugger = debug('verkle') + protected _debug: Debugger = debug('verkle:#') protected debug: (...args: any) => void /** * Creates a new verkle tree. @@ -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. @@ -171,7 +171,7 @@ export class VerkleTree { this.DEBUG && this.debug( `Suffix: ${suffix}; Value: ${value === undefined ? 'undefined' : bytesToHex(value)}`, - ['GET'], + ['get'], ) values.push(value) } @@ -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 @@ -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] @@ -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 @@ -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 @@ -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 { - 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())) } /** @@ -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 @@ -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 } @@ -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 { - 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: [], @@ -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 @@ -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() @@ -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 @@ -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] @@ -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 } @@ -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]])