Skip to content

Commit 9f2da31

Browse files
fix: bug where finalized and safe tags are cached (#2927)
* Fixes bug where finalized and safe tags are cached Signed-off-by: Konstantina Blazhukova <[email protected]> * Adds acceptance test for blockByNumber endpoint Signed-off-by: Konstantina Blazhukova <[email protected]> * fix: reused Utils.wait() Signed-off-by: Logan Nguyen <[email protected]> --------- Signed-off-by: Konstantina Blazhukova <[email protected]> Signed-off-by: Logan Nguyen <[email protected]> Co-authored-by: Logan Nguyen <[email protected]>
1 parent a835525 commit 9f2da31

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ export class EthImpl implements Eth {
12301230
);
12311231
});
12321232

1233-
if (blockNumOrTag != EthImpl.blockLatest && blockNumOrTag != EthImpl.blockPending) {
1233+
if (!this.common.blockTagIsLatestOrPending(blockNumOrTag)) {
12341234
await this.cacheService.set(cacheKey, block, EthImpl.ethGetBlockByNumber, undefined, requestIdPrefix);
12351235
}
12361236
}

packages/server/tests/acceptance/rpc_batch1.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,70 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
544544
Assertions.block(blockResult, mirrorBlock, mirrorTransactions, expectedGasPrice, false);
545545
});
546546

547+
it('should not cache "latest" block in "eth_getBlockByNumber" ', async function () {
548+
const blockResult = await relay.call(
549+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,
550+
['latest', false],
551+
requestId,
552+
);
553+
await Utils.wait(1000);
554+
555+
const blockResult2 = await relay.call(
556+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,
557+
['latest', false],
558+
requestId,
559+
);
560+
expect(blockResult).to.not.deep.equal(blockResult2);
561+
});
562+
563+
it('should not cache "finalized" block in "eth_getBlockByNumber" ', async function () {
564+
const blockResult = await relay.call(
565+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,
566+
['finalized', false],
567+
requestId,
568+
);
569+
await Utils.wait(1000);
570+
571+
const blockResult2 = await relay.call(
572+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,
573+
['finalized', false],
574+
requestId,
575+
);
576+
expect(blockResult).to.not.deep.equal(blockResult2);
577+
});
578+
579+
it('should not cache "safe" block in "eth_getBlockByNumber" ', async function () {
580+
const blockResult = await relay.call(
581+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,
582+
['safe', false],
583+
requestId,
584+
);
585+
await Utils.wait(1000);
586+
587+
const blockResult2 = await relay.call(
588+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,
589+
['safe', false],
590+
requestId,
591+
);
592+
expect(blockResult).to.not.deep.equal(blockResult2);
593+
});
594+
595+
it('should not cache "pending" block in "eth_getBlockByNumber" ', async function () {
596+
const blockResult = await relay.call(
597+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,
598+
['pending', false],
599+
requestId,
600+
);
601+
await Utils.wait(1000);
602+
603+
const blockResult2 = await relay.call(
604+
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,
605+
['pending', false],
606+
requestId,
607+
);
608+
expect(blockResult).to.not.deep.equal(blockResult2);
609+
});
610+
547611
it('@release should execute "eth_getBlockByNumber", hydrated transactions = true', async function () {
548612
const blockResult = await relay.call(
549613
RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_BY_NUMBER,

0 commit comments

Comments
 (0)