Skip to content

Commit 66aa28a

Browse files
vm: fix blockchain tests crashing
trie: save key-values read from disk in cache
1 parent a4e2053 commit 66aa28a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/trie/src/checkpointDb.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ export class CheckpointDB extends DB {
9797
}
9898
}
9999
// Nothing has been found in cache, look up from disk
100-
// TODO: put value in cache if we are a checkpoint.
101-
return await super.get(key)
100+
101+
const value = await super.get(key)
102+
if (this.isCheckpoint) {
103+
// Since we are a checkpoint, put this value in cache, so future `get` calls will not look the key up again from disk.
104+
this.checkpoints[this.checkpoints.length - 1].keyValueMap.set(key.toString('hex'), value)
105+
}
106+
107+
return value
102108
}
103109

104110
/**

packages/vm/tests/BlockchainTestsRunner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export default async function runBlockchainTest(options: any, testData: any, t:
7373
common,
7474
})
7575

76+
// Need to await the init promise: in some tests, we do not run the iterator (which awaits the initPromise)
77+
// If the initPromise does not finish, the `rawHead` of `blockchain.meta()` is still `undefined`.
78+
await blockchain.initPromise
79+
7680
// set up pre-state
7781
await setupPreConditions(vm.stateManager._trie, testData)
7882

0 commit comments

Comments
 (0)