From 1bdb8c116645a2b072c9382e82895530a5512693 Mon Sep 17 00:00:00 2001 From: Sebastian Abondano Date: Fri, 30 Nov 2018 07:24:09 -0500 Subject: [PATCH] Ganache ignores internal transactions Why: * We were using the `EthereumJSONRPC.Geth` variant for Ganache but we recently learned that it doesn't support the `tracer` option for [debug_traceTransaction](https://github.com/ethereum/go-ethereum/wiki/Management-APIs#debug_tracetransaction). This `tracer` option is what we currently use to fetch internal transactions for Geth. This was the cause of errors as shown on issue 1152 (link below). * Issue link: https://github.com/poanetwork/blockscout/issues/1152 This change addresses the need by: * Creating `EthereumJSONRPC.Ganache`. It ignores fetching beneficiaries, internal transactions, and pending transactions. * Editing ganache config to use the `EthereumJSONRPC.Ganache` variant instead of `EthereumJSONRPC.Geth`. * Updating inaccurate doc in `EthereumJSONRPC.Geth`. It previously said fetching internal transactions was not supported for Geth which is inaccurate. --- .../lib/ethereum_jsonrpc/ganache.ex | 31 +++++++++++++++++++ .../lib/ethereum_jsonrpc/geth.ex | 4 +-- apps/explorer/config/dev/ganache.exs | 4 +-- apps/explorer/config/prod/ganache.exs | 4 +-- apps/explorer/config/test/ganache.exs | 4 +-- apps/indexer/config/dev/ganache.exs | 2 +- apps/indexer/config/prod/ganache.exs | 2 +- 7 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ganache.ex diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ganache.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ganache.ex new file mode 100644 index 0000000000..71353c6e30 --- /dev/null +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ganache.ex @@ -0,0 +1,31 @@ +defmodule EthereumJSONRPC.Ganache do + @moduledoc """ + Ethereum JSONRPC methods that are only supported by [Ganache](https://github.com/trufflesuite/ganache-core#implemented-methods). + """ + + @behaviour EthereumJSONRPC.Variant + + @doc """ + Block reward contract beneficiary fetching is not supported currently for Ganache. + + To signal to the caller that fetching is not supported, `:ignore` is returned. + """ + @impl EthereumJSONRPC.Variant + def fetch_beneficiaries(_block_range, _json_rpc_named_arguments), do: :ignore + + @doc """ + Internal transaction fetching is not currently supported for Ganache. + + To signal to the caller that fetching is not supported, `:ignore` is returned. + """ + @impl EthereumJSONRPC.Variant + def fetch_internal_transactions(_transactions_params, _json_rpc_named_arguments), do: :ignore + + @doc """ + Pending transaction fetching is not supported currently for Ganache. + + To signal to the caller that fetching is not supported, `:ignore` is returned. + """ + @impl EthereumJSONRPC.Variant + def fetch_pending_transactions(_json_rpc_named_arguments), do: :ignore +end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex index 46ff56c64e..246c4005ad 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex @@ -18,9 +18,7 @@ defmodule EthereumJSONRPC.Geth do def fetch_beneficiaries(_block_range, _json_rpc_named_arguments), do: :ignore @doc """ - Internal transaction fetching is not supported currently for Geth. - - To signal to the caller that fetching is not supported, `:ignore` is returned. + Fetches the `t:Explorer.Chain.InternalTransaction.changeset/2` params. """ @impl EthereumJSONRPC.Variant def fetch_internal_transactions(transactions_params, json_rpc_named_arguments) when is_list(transactions_params) do diff --git a/apps/explorer/config/dev/ganache.exs b/apps/explorer/config/dev/ganache.exs index 3067ac0c68..f9ed96fb0e 100644 --- a/apps/explorer/config/dev/ganache.exs +++ b/apps/explorer/config/dev/ganache.exs @@ -8,7 +8,7 @@ config :explorer, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", http_options: [recv_timeout: 60_000, timeout: 60_000, hackney: [pool: :ethereum_jsonrpc]] ], - variant: EthereumJSONRPC.Geth + variant: EthereumJSONRPC.Ganache ], subscribe_named_arguments: [ transport: EthereumJSONRPC.WebSocket, @@ -16,5 +16,5 @@ config :explorer, web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:7545" ], - variant: EthereumJSONRPC.Geth + variant: EthereumJSONRPC.Ganache ] diff --git a/apps/explorer/config/prod/ganache.exs b/apps/explorer/config/prod/ganache.exs index 3067ac0c68..f9ed96fb0e 100644 --- a/apps/explorer/config/prod/ganache.exs +++ b/apps/explorer/config/prod/ganache.exs @@ -8,7 +8,7 @@ config :explorer, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", http_options: [recv_timeout: 60_000, timeout: 60_000, hackney: [pool: :ethereum_jsonrpc]] ], - variant: EthereumJSONRPC.Geth + variant: EthereumJSONRPC.Ganache ], subscribe_named_arguments: [ transport: EthereumJSONRPC.WebSocket, @@ -16,5 +16,5 @@ config :explorer, web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, url: System.get_env("ETHEREUM_JSONRPC_WS_URL") || "ws://localhost:7545" ], - variant: EthereumJSONRPC.Geth + variant: EthereumJSONRPC.Ganache ] diff --git a/apps/explorer/config/test/ganache.exs b/apps/explorer/config/test/ganache.exs index 73869e31a3..abb61a0632 100644 --- a/apps/explorer/config/test/ganache.exs +++ b/apps/explorer/config/test/ganache.exs @@ -4,10 +4,10 @@ config :explorer, json_rpc_named_arguments: [ transport: EthereumJSONRPC.Mox, transport_options: [], - variant: EthereumJSONRPC.Geth + variant: EthereumJSONRPC.Ganache ], subscribe_named_arguments: [ transport: EthereumJSONRPC.Mox, transport_options: [], - variant: EthereumJSONRPC.Geth + variant: EthereumJSONRPC.Ganache ] diff --git a/apps/indexer/config/dev/ganache.exs b/apps/indexer/config/dev/ganache.exs index 9c8512e246..174ba47d4f 100644 --- a/apps/indexer/config/dev/ganache.exs +++ b/apps/indexer/config/dev/ganache.exs @@ -9,7 +9,7 @@ config :indexer, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", http_options: [recv_timeout: 60_000, timeout: 60_000, hackney: [pool: :ethereum_jsonrpc]] ], - variant: EthereumJSONRPC.Geth + variant: EthereumJSONRPC.Ganache ], subscribe_named_arguments: [ transport: EthereumJSONRPC.WebSocket, diff --git a/apps/indexer/config/prod/ganache.exs b/apps/indexer/config/prod/ganache.exs index 9c8512e246..174ba47d4f 100644 --- a/apps/indexer/config/prod/ganache.exs +++ b/apps/indexer/config/prod/ganache.exs @@ -9,7 +9,7 @@ config :indexer, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", http_options: [recv_timeout: 60_000, timeout: 60_000, hackney: [pool: :ethereum_jsonrpc]] ], - variant: EthereumJSONRPC.Geth + variant: EthereumJSONRPC.Ganache ], subscribe_named_arguments: [ transport: EthereumJSONRPC.WebSocket,