@ethereumjs/binarytree
Version:
Implementation of binary trees as used in Ethereum.
88 lines • 2.23 kB
TypeScript
import { LRUCache } from 'lru-cache';
import type { BatchDBOp, DB } from '@ethereumjs/util';
import type { Checkpoint, CheckpointDBOpts } from '../types.ts';
/**
* Checkpoint-aware DB wrapper with optional LRU node cache for binary trees.
*/
export declare class CheckpointDB implements DB {
checkpoints: Checkpoint[];
db: DB<string, string | Uint8Array>;
readonly cacheSize: number;
private readonly valueEncoding;
protected _cache?: LRUCache<string, Uint8Array>;
_stats: {
cache: {
reads: number;
hits: number;
writes: number;
};
db: {
reads: number;
hits: number;
writes: number;
};
};
/**
* Initialize a DB instance.
*/
constructor(opts: CheckpointDBOpts);
/**
* Replace the checkpoint stack with a copy of the given checkpoints.
*
* @param checkpoints Checkpoints to adopt (maps are cloned)
*/
setCheckpoints(checkpoints: Checkpoint[]): void;
/**
* Is the DB during a checkpoint phase?
*/
hasCheckpoints(): boolean;
/**
* Push a new checkpoint onto the stack.
*
* @param root Tree root hash at this checkpoint boundary
*/
checkpoint(root: Uint8Array): void;
/**
* Commits the latest checkpoint
*/
commit(): Promise<void>;
/**
* Reverts the latest checkpoint
*/
revert(): Promise<Uint8Array<ArrayBufferLike>>;
/**
* @inheritDoc
*/
get(key: Uint8Array): Promise<Uint8Array | undefined>;
/**
* @inheritDoc
*/
put(key: Uint8Array, value: Uint8Array): Promise<void>;
/**
* @inheritDoc
*/
del(key: Uint8Array): Promise<void>;
/**
* @inheritDoc
*/
batch(opStack: BatchDBOp[]): Promise<void>;
stats(reset?: boolean): {
size: number;
cache: {
reads: number;
hits: number;
writes: number;
};
db: {
reads: number;
hits: number;
writes: number;
};
};
/**
* @inheritDoc
*/
shallowCopy(): CheckpointDB;
open(): Promise<void>;
}
//# sourceMappingURL=checkpoint.d.ts.map