diff --git a/packages/trie-db/src/index.ts b/packages/trie-db/src/index.ts index 461d47697..0b682c276 100644 --- a/packages/trie-db/src/index.ts +++ b/packages/trie-db/src/index.ts @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. import { TxDb, ProgressCb } from '@polkadot/db/types'; -import { TrieDb, Node, NodeBranch, NodeEncodedOrEmpty, NodeKv, NodeNotEmpty, NodeType } from './types'; +import { TrieDb, Node, NodeBranch, NodeEncodedOrEmpty, NodeKv, NodeNotEmpty, NodeType, Snapshot } from './types'; import MemoryDb from '@polkadot/db/Memory'; import isNull from '@polkadot/util/is/null'; @@ -18,14 +18,6 @@ import { decodeNibbles, encodeNibbles } from './util/nibbles'; import { getNodeType, decodeNode, encodeNode } from './util/node'; import { EMPTY_HASH, EMPTY_U8A } from './constants'; -type Snapshot = { - root: Uint8Array, - kv: Array<{ - key: Uint8Array, - value: Uint8Array - }> -}; - const l = logger('trie/db'); export default class Trie implements TrieDb { @@ -145,7 +137,10 @@ export default class Trie implements TrieDb { createSnapshot (fn: ProgressCb, hash?: Uint8Array, percent: number = 0, depth: number = 0): Snapshot { const root = hash || this.rootHash || EMPTY_HASH; - l.log('creating current state key/value snapshot'); + if (depth === 0) { + l.log('creating current state key/value snapshot'); + } + l.debug(() => ['getTrie', { hash }]); const node = this._getNode(root); diff --git a/packages/trie-db/src/types.ts b/packages/trie-db/src/types.ts index 6bb9912a8..af6a20019 100644 --- a/packages/trie-db/src/types.ts +++ b/packages/trie-db/src/types.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. -import { TxDb } from '@polkadot/db/types'; +import { TxDb, ProgressCb } from '@polkadot/db/types'; export enum NodeType { EMPTY = 0, @@ -33,7 +33,17 @@ export type NodeNotEmpty = NodeKv | NodeBranch; export type Node = NodeEmpty | NodeNotEmpty; +export type Snapshot = { + root: Uint8Array, + kv: Array<{ + key: Uint8Array, + value: Uint8Array + }> +}; + export interface TrieDb extends TxDb { getRoot (): Uint8Array; setRoot (rootHash: Uint8Array): void; + createSnapshot (fn: ProgressCb): Snapshot; + restoreSnapshot (snapshot: Snapshot, fn: ProgressCb): void; }