Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

consider updating persistent cache to get blocks from fork network by tag #3773

@MicaiahReid

Description

@MicaiahReid

The persistent cache's get function doesn't currently allow passing the "earliest" tag to cache that request:

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions