emeraldpay / dshackle

Fault Tolerant Load Balancer for Ethereum and Bitcoin APIs
Apache License 2.0
298 stars 65 forks source link

Cache doesn't work for me #269

Closed ohrab-hacken closed 8 months ago

ohrab-hacken commented 9 months ago

I am running dshackle v0.14.0. I want to test caching mechanism. The idea is to run local socat wich point to my private ethereum node and point dshackle to socat, instead of ethereum node. Make curl request to dshackle 2 times. First time I should see log in the socat as dshackle need to request it from ethereum node, second time I should not see the log in the socat, as web3_proxy should return result from cache. It doesn't work for me, as I see all curl requests in the socat log.

How to reproduce

With the following command I am running websocket:

nohup socat -v -d tcp-listen:8546,reuseaddr,fork tcp:eth.hckn.dev:8545 &

Where eth.hckn.dev - private ethereum node.

Also, I running dshackle with the following config:

version: v1
host: 0.0.0.0 # (1)
port: 2449
tls: # (2)
  enabled: false
proxy:
  host: 0.0.0.0 # (3)
  port: 1111
  routes:
    - id: eth
      blockchain: ethereum
cluster:
  upstreams: # (4)
    - id: local-eth # (9)
      blockchain: ethereum
      connection:
        ethereum:
          rpc:
            url: "http://10.1.193.177:8546"

Also, I've tried redis cache:

version: v1
host: 0.0.0.0 # (1)
port: 2449
tls: # (2)
  enabled: false
cache:
  redis:
    enabled: true
    host: 10.1.193.177
    port: 6379
proxy:
  host: 0.0.0.0 # (3)
  port: 1111
  routes:
    - id: eth
      blockchain: ethereum
cluster:
  upstreams: # (4)
    - id: local-eth # (9)
      blockchain: ethereum
      connection:
        ethereum:
          rpc:
            url: "http://10.1.193.177:8546" # (10)

Where http://10.1.193.177:8546 is the address of local websocket. Redis running in the docker container.

The command to run dshackle:

docker run -d -p 2449:2449 -p 1111:1111 -v $(pwd):/etc/dshackle emeraldpay/dshackle:0.14

Make the following curl request to dshackle:

curl --request POST   --url http://10.1.193.177:1111/eth   --header 'content-type: application/json'   --data '{"jsonrpc":"2.0", "method":"eth_getBalance", "id":1, "params":["0x690b2bdf41f33f9f251ae0459e5898b856ed96be", "latest"]}'

where 10.1.193.177 - ip address of the server where dshackle is running.

Take a look to the socat log with:

tail -f nohup.out

{"jsonrpc":"2.0", "method":"eth_getBalance", "id":1, "params":["0x690b2bdf41f33f9f251ae0459e5898b856ed96be", "latest"]}< 2023/10/09 13:15:36.697561  length=162 from=0 to=161
HTTP/1.1 200 OK\r
Content-Type: application/json\r
Vary: Origin\r
Date: Mon, 09 Oct 2023 13:15:36 GMT\r
Content-Length: 40\r
\r
{"jsonrpc":"2.0","id":1,"result":"0x0"}
> 2023/10/09 13:15:56.674576  length=251 from=0 to=250
POST / HTTP/1.1\r
Host: localhost:8545\r
User-Agent: curl/7.81.0\r
Accept: */*\r
content-type: application/json\r
Content-Length: 119\r
\r
{"jsonrpc":"2.0", "method":"eth_getBalance", "id":1, "params":["0x690b2bdf41f33f9f251ae0459e5898b856ed96be", "latest"]}< 2023/10/09 13:15:56.675642  length=162 from=0 to=161
HTTP/1.1 200 OK\r
Content-Type: application/json\r
Vary: Origin\r
Date: Mon, 09 Oct 2023 13:15:56 GMT\r
Content-Length: 40\r
\r
{"jsonrpc":"2.0","id":1,"result":"0x0"}

Make curl requests multiple times. In the socat log you will see all the requests, but should see only the first one. As I understand cache mechanism doesn't work. Tried both with and without reds

Could you please help me to understand what I am doing wrong, or it's expected behavior?

splix commented 8 months ago

fixed in [03dc870feca3f3f68396c404fdd6223624076aca]