Skip to content

Commit 895f995

Browse files
trie: fix checkpointDb key encoding
1 parent 1a26e39 commit 895f995

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/trie/src/checkpointDb.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ export class CheckpointDB extends DB {
5555
if (value === null) {
5656
batchOp.push({
5757
type: 'del',
58-
key: Buffer.from(key),
58+
key: Buffer.from(key, 'hex'),
5959
})
6060
} else {
6161
batchOp.push({
6262
type: 'put',
63-
key: Buffer.from(key),
63+
key: Buffer.from(key, 'hex'),
6464
value,
6565
})
6666
}
@@ -91,7 +91,7 @@ export class CheckpointDB extends DB {
9191
async get(key: Buffer): Promise<Buffer | null> {
9292
// Lookup the value in our cache. We return the latest checkpointed value (which should be the value on disk)
9393
for (let index = this.checkpoints.length - 1; index >= 0; index--) {
94-
const value = this.checkpoints[index].keyValueMap.get(key.toString())
94+
const value = this.checkpoints[index].keyValueMap.get(key.toString('hex'))
9595
if (value !== undefined) {
9696
return value
9797
}
@@ -109,7 +109,7 @@ export class CheckpointDB extends DB {
109109
async put(key: Buffer, val: Buffer): Promise<void> {
110110
if (this.isCheckpoint) {
111111
// put value in cache
112-
this.checkpoints[this.checkpoints.length - 1].keyValueMap.set(key.toString(), val)
112+
this.checkpoints[this.checkpoints.length - 1].keyValueMap.set(key.toString('hex'), val)
113113
} else {
114114
await super.put(key, val)
115115
}
@@ -122,7 +122,7 @@ export class CheckpointDB extends DB {
122122
async del(key: Buffer): Promise<void> {
123123
if (this.isCheckpoint) {
124124
// delete the value in the current cache
125-
this.checkpoints[this.checkpoints.length - 1].keyValueMap.set(key.toString(), null)
125+
this.checkpoints[this.checkpoints.length - 1].keyValueMap.set(key.toString('hex'), null)
126126
} else {
127127
// delete the value on disk
128128
await this._leveldb.del(key, ENCODING_OPTS)

0 commit comments

Comments
 (0)