Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Anvil is incorrectly caching responses #4729

@benesjan

Description

@benesjan

Component

Anvil

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

anvil 0.1.0 (5a257ef 2023-04-13T00:15:45.229644000Z)

What command(s) is the bug in?

anvil

Operating System

Linux

Describe the bug

I am fetching logs and I get a log from an older block than fromBlock param on the second request. Here is the log from tcpflow:

127.000.000.001.65151-127.000.000.001.09000: {"jsonrpc":"2.0","id":10,"method":"eth_getLogs","params":[{"address":"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512","topics":["0xb72b85ef2a843244f5ea1955248b0ac363732d2e6a98cc3641084dd5718ad8b5"],"fromBlock":"0x0"}]}
127.000.000.001.09000-127.000.000.001.65151: HTTP/1.1 200 OK
content-type: application/json
content-length: 1429
access-control-allow-origin: *
vary: origin
vary: access-control-request-method
vary: access-control-request-headers
date: Thu, 13 Apr 2023 13:36:03 GMT

{"jsonrpc":"2.0","id":10,"result":[{"address":"0xe7f1725e7734ce288f8367e1bb143e90bb3f0512","topics":["0xb72b85ef2a843244f5ea1955248b0ac363732d2e6a98cc3641084dd5718ad8b5","0x0000000000000000000000000000000000000000000000000000000000000001","0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266"],"data":"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000015400000150588876ebdf5339b8ce4fd13d4c4faf6a7ec069df98f36d16611ea4a781506c16b0869c1cdeb643977de92cb3ab1ae8dc253ca726156580d7f0f435f884f81e4a914d46e4fad88842f125fa579d2be5fbbec7c29943e32a30d2b708062f8ad98749f7629053a9b2f6f4191ac8ae4befa536a4be8fbf2e10537509bfe746ff4ca3d11336ccfc7dacd3d0dcd93f2cf8487060441a7a6cb16f84f39ca65e876498142e011498032e1972700ebefe4fe9bb45e340b1415a04e25f6c85a80030bd8470895d11e735763b5ac6012596de1aa3e2ab0b73967bc2140ed8bd07f548d7a19662126d7c98cbd30d607b36da3d6a697e0696eda204d4029c4b1ac0c67d8ce2613b05f82811ad25cfe148e20657b19411223101418982f59ea0369854cabd2e272e4b5ac71384aea27512fd15414cdc1b2b51f50299056c43d40c6b9d55030c0fe672df5fb763cd844528b7735e1857c9000000000000000000000000","blockHash":"0x3c90e734d4da46ef80431a8547975d111c19ce43be961b24f8029523073a76ee","blockNumber":"0x4","transactionHash":"0xfd6b1d333e0bf0efb0de3fc22a5e02e1931a3e436619bef5ccea080043a01cb8","transactionIndex":"0x0","logIndex":"0x0","transactionLogIndex":"0x0","removed":false}]}
127.000.000.001.65151-127.000.000.001.09000: POST / HTTP/1.1
host: localhost:9000
connection: keep-alive
Content-Type: application/json
accept: */*
accept-language: *
sec-fetch-mode: cors
user-agent: undici
accept-encoding: gzip, deflate
content-length: 141




127.000.000.001.65151-127.000.000.001.09000: {"jsonrpc":"2.0","id":13,"method":"eth_getLogs","params":[{"address":"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512","topics":["0xb72b85ef2a843244f5ea1955248b0ac363732d2e6a98cc3641084dd5718ad8b5"],"fromBlock":"0x5"}]}
127.000.000.001.09000-127.000.000.001.65151: HTTP/1.1 200 OK
content-type: application/json
content-length: 1429
access-control-allow-origin: *
vary: origin
vary: access-control-request-method
vary: access-control-request-headers
date: Thu, 13 Apr 2023 13:36:04 GMT

{"jsonrpc":"2.0","id":13,"result":[{"address":"0xe7f1725e7734ce288f8367e1bb143e90bb3f0512","topics":["0xb72b85ef2a843244f5ea1955248b0ac363732d2e6a98cc3641084dd5718ad8b5","0x0000000000000000000000000000000000000000000000000000000000000001","0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266"],"data":"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000015400000150588876ebdf5339b8ce4fd13d4c4faf6a7ec069df98f36d16611ea4a781506c16b0869c1cdeb643977de92cb3ab1ae8dc253ca726156580d7f0f435f884f81e4a914d46e4fad88842f125fa579d2be5fbbec7c29943e32a30d2b708062f8ad98749f7629053a9b2f6f4191ac8ae4befa536a4be8fbf2e10537509bfe746ff4ca3d11336ccfc7dacd3d0dcd93f2cf8487060441a7a6cb16f84f39ca65e876498142e011498032e1972700ebefe4fe9bb45e340b1415a04e25f6c85a80030bd8470895d11e735763b5ac6012596de1aa3e2ab0b73967bc2140ed8bd07f548d7a19662126d7c98cbd30d607b36da3d6a697e0696eda204d4029c4b1ac0c67d8ce2613b05f82811ad25cfe148e20657b19411223101418982f59ea0369854cabd2e272e4b5ac71384aea27512fd15414cdc1b2b51f50299056c43d40c6b9d55030c0fe672df5fb763cd844528b7735e1857c9000000000000000000000000","blockHash":"0x3c90e734d4da46ef80431a8547975d111c19ce43be961b24f8029523073a76ee","blockNumber":"0x4","transactionHash":"0xfd6b1d333e0bf0efb0de3fc22a5e02e1931a3e436619bef5ccea080043a01cb8","transactionIndex":"0x0","logIndex":"0x0","transactionLogIndex":"0x0","removed":false}]}
127.000.000.001.65151-127.000.000.001.09000: POST / HTTP/1.1
host: localhost:9000
connection: keep-alive
content-type: application/json
accept: */*
accept-language: *
sec-fetch-mode: cors
user-agent: undici
accept-encoding: gzip, deflate
content-length: 48

It took me a while to figure out that it's an issue in Anvil because it seems that when I don't kill the test I am running immediately after the bug occurs the test does further communication with anvil and it makes the bug not occur again. So I managed to only reproduce the bug with curl when I carefully watch the logs and kill the test fast.

Response using the invalid cache when I manage to kill the test fast enough:
image

When I run the test again and do the same request as the one which originally produced the incorrectly cached response I get no logs on the output (I didn't restart Anvil):
image

The issue is present in version from 2023-04-04 as well as in the most recent version. I tested the issue both on M1 Mac and x86_64 Linux.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions