-
Notifications
You must be signed in to change notification settings - Fork 685
consider updating persistent cache to get blocks from fork network by tag #3773
Description
The persistent cache's get
function doesn't currently allow passing the "earliest" tag to cache that request:
ganache/src/chains/ethereum/ethereum/src/forking/persistent-cache/persistent-cache.ts
Lines 323 to 351 in 2ec04fa
async get(method: string, params: any[], key: string) { | |
const blockNumber = getBlockNumberFromParams(method, params); | |
if (blockNumber == null) return; | |
const height = Quantity.from(blockNumber); | |
const bufKey = Buffer.from(key); | |
const start = lexico.encode([height.toBuffer(), bufKey]); | |
const end = Buffer.concat([start, maxValueByteBuffer]); | |
const readStream = this.cacheDb.createReadStream({ | |
gt: start, | |
lt: end, | |
keys: true, | |
values: true | |
}); | |
for await (const data of readStream) { | |
const { key: k, value } = data as any as { key: Buffer; value: Buffer }; | |
const [_height, _key, blockHash] = lexico.decode(k); | |
// if our key no longer matches make sure we don't keep searching | |
if (!_key.equals(bufKey)) return; | |
if ( | |
this.hashBuffer.equals(blockHash) || | |
(await this.ancestry.has(blockHash)) | |
) { | |
return value; | |
} | |
} | |
} |
This is kind of tricky to work around because of the way we lexicographically encode the requests to store/retrieve them efficiently in the database.
Because the persistent cache always needs to fetch the earliest block (to validate ancestry of the fork), we should cache this block in memory.
When the block manager is started, we are currently disabling the cache, so we should fix this once this issue is resolved.
https://github.com/trufflesuite/ganache/pull/3755/files#r989390078
Metadata
Metadata
Assignees
Labels
Type
Projects
Status