Merge pull request #6001 from blockscout/mf-eth-getbalance-archive-disable-env

Disable archive balances by env
np-add-verkle-images-demo
Victor Baranov 2 years ago committed by GitHub
commit 62e3e8dbcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 13
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex
  3. 62
      apps/ethereum_jsonrpc/test/ethereum_jsonrpc_test.exs
  4. 3
      config/runtime.exs
  5. 1
      docker-compose/envs/common-blockscout.env
  6. 3
      docker/Makefile

@ -3,6 +3,7 @@
### Features
- [#5968](https://github.com/blockscout/blockscout/pull/5968) - Add call type in the response of txlistinternal API method
- [#5860](https://github.com/blockscout/blockscout/pull/5860) - Integrate rust verifier micro-service ([blockscout-rs/verifier](https://github.com/blockscout/blockscout-rs/tree/main/verification))
- [#6001](https://github.com/blockscout/blockscout/pull/6001) - Add ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES env var that filters requests and query node only if the block quantity is "latest"
### Fixes
- [#5978](https://github.com/blockscout/blockscout/pull/5978) - Allow timestamp param in the log of eth_getTransactionReceipt method

@ -184,7 +184,18 @@ defmodule EthereumJSONRPC do
) :: {:ok, FetchedBalances.t()} | {:error, reason :: term}
def fetch_balances(params_list, json_rpc_named_arguments)
when is_list(params_list) and is_list(json_rpc_named_arguments) do
id_to_params = id_to_params(params_list)
filtered_params =
if Application.get_env(:ethereum_jsonrpc, :disable_archive_balances?) do
params_list
|> Enum.filter(fn
%{block_quantity: "latest"} -> true
_ -> false
end)
else
params_list
end
id_to_params = id_to_params(filtered_params)
with {:ok, responses} <-
id_to_params

@ -913,3 +913,65 @@ defmodule EthereumJSONRPCTest do
end
end
end
defmodule EthereumJSONRPCSyncTest do
use EthereumJSONRPC.Case, async: false
import EthereumJSONRPC.Case
import Mox
alias EthereumJSONRPC.FetchedBalances
setup :verify_on_exit!
@moduletag :capture_log
describe "fetch_balances/1" do
setup do
initial_env = Application.get_all_env(:indexer)
on_exit(fn -> Application.put_all_env([{:indexer, initial_env}]) end)
end
test "ignores all request with block_quantity != latest when env ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES is true",
%{
json_rpc_named_arguments: json_rpc_named_arguments
} do
hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"
expected_fetched_balance = 1
expect(EthereumJSONRPC.Mox, :json_rpc, 1, fn [
%{
id: 0,
jsonrpc: "2.0",
method: "eth_getBalance",
params: [^hash, "latest"]
}
],
_options ->
{:ok, [%{id: 0, result: EthereumJSONRPC.integer_to_quantity(expected_fetched_balance)}]}
end)
Application.put_env(:ethereum_jsonrpc, :disable_archive_balances?, "true")
assert EthereumJSONRPC.fetch_balances(
[
%{block_quantity: "0x1", hash_data: hash},
%{block_quantity: "0x2", hash_data: hash},
%{block_quantity: "0x3", hash_data: hash},
%{block_quantity: "0x4", hash_data: hash},
%{block_quantity: "latest", hash_data: hash}
],
json_rpc_named_arguments
) ==
{:ok,
%FetchedBalances{
params_list: [
%{
address_hash: hash,
block_number: :error,
value: expected_fetched_balance
}
]
}}
end
end
end

@ -146,7 +146,8 @@ config :block_scout_web, BlockScoutWeb.Chain.Address.CoinBalance,
config :ethereum_jsonrpc,
rpc_transport: if(System.get_env("ETHEREUM_JSONRPC_TRANSPORT", "http") == "http", do: :http, else: :ipc),
ipc_path: System.get_env("IPC_PATH")
ipc_path: System.get_env("IPC_PATH"),
disable_archive_balances?: System.get_env("ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES", "false") == "true"
debug_trace_transaction_timeout = System.get_env("ETHEREUM_JSONRPC_DEBUG_TRACE_TRANSACTION_TIMEOUT", "5s")
config :ethereum_jsonrpc, EthereumJSONRPC.Geth, debug_trace_transaction_timeout: debug_trace_transaction_timeout

@ -9,6 +9,7 @@ LOGO=/images/blockscout_logo.svg
LOGO_FOOTER=/images/blockscout_logo.svg
# ETHEREUM_JSONRPC_WS_URL=
ETHEREUM_JSONRPC_TRANSPORT=http
ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES=false
IPC_PATH=
NETWORK_PATH=/
API_PATH=/

@ -52,6 +52,9 @@ endif
ifdef ETHEREUM_JSONRPC_TRANSPORT
BLOCKSCOUT_CONTAINER_PARAMS += -e 'ETHEREUM_JSONRPC_TRANSPORT=$(ETHEREUM_JSONRPC_TRANSPORT)'
endif
ifdef ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES
BLOCKSCOUT_CONTAINER_PARAMS += -e 'ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES=$(ETHEREUM_JSONRPC_DISABLE_ARCHIVE_BALANCES)'
endif
ifdef IPC_PATH
BLOCKSCOUT_CONTAINER_PARAMS += -e 'IPC_PATH=$(IPC_PATH)'
endif

Loading…
Cancel
Save