diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex index 0649d5ad0c..6eecc95b04 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/receipt.ex @@ -10,6 +10,11 @@ defmodule EthereumJSONRPC.Receipt do alias EthereumJSONRPC alias EthereumJSONRPC.Logs + # > 21000 gas is charged for any transaction as a "base fee". This covers the cost of an elliptic curve operation to + # > recover the sender address from the signature as well as the disk and bandwidth space of storing the transaction. + # -- https://github.com/ethereum/wiki/wiki/Design-Rationale + @base_fee_gas 21_000 + @type elixir :: %{String.t() => String.t() | non_neg_integer} @typedoc """ @@ -81,6 +86,33 @@ defmodule EthereumJSONRPC.Receipt do * If `"gas"` (supplied by caller from `EthereumJSONRPC.Transaction.elixir`) `==` `"gasUsed"`, then `:status` is `:error` + iex> EthereumJSONRPC.Receipt.elixir_to_params( + ...> %{ + ...> "blockHash" => "0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd", + ...> "blockNumber" => 46147, + ...> "contractAddress" => nil, + ...> "cumulativeGasUsed" => 21001, + ...> "from" => "0xa1e4380a3b1f749673e270229993ee55f35663b4", + ...> "gas" => 21001, + ...> "gasUsed" => 21001, + ...> "logs" => [], + ...> "logsBloom" => "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + ...> "root" => "0x96a8e009d2b88b1483e6941e6812e32263b05683fac202abc622a3e31aed1957", + ...> "to" => "0x5df9b87991262f6ba471f09758cde1c0fc1de734", + ...> "transactionHash" => "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060", + ...> "transactionIndex" => 0 + ...> } + ...> ) + %{ + cumulative_gas_used: 21001, + gas_used: 21001, + status: :error, + transaction_hash: "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060", + transaction_index: 0 + } + + * Except, when it is the base transaction fee (21,000 gas) + iex> EthereumJSONRPC.Receipt.elixir_to_params( ...> %{ ...> "blockHash" => "0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd", @@ -101,7 +133,7 @@ defmodule EthereumJSONRPC.Receipt do %{ cumulative_gas_used: 21000, gas_used: 21000, - status: :error, + status: :ok, transaction_hash: "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060", transaction_index: 0 } @@ -299,6 +331,10 @@ defmodule EthereumJSONRPC.Receipt do end end + # Temporary fix for https://github.com/poanetwork/blockscout/issues/673 as this is the most common gas == gas_used, + # but not failed scenario. Only internal transactions can prove if gas == gas_used means failure pre-Byzantium. + defp pre_byzantium_status(@base_fee_gas, @base_fee_gas), do: :ok + defp pre_byzantium_status(gas, gas_used) when is_integer(gas) and is_integer(gas_used) do if gas_used < gas do :ok diff --git a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/web_socket_test.exs b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/web_socket_test.exs index 29c462d56f..9f932720e4 100644 --- a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/web_socket_test.exs +++ b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/web_socket_test.exs @@ -24,6 +24,8 @@ defmodule EthereumJSONRPC.WebSocketTest do |> WebSocket.json_rpc(transport_options) end + # Infura timeouts on 2018-09-10 + @tag :no_geth test "can get error", %{subscribe_named_arguments: subscribe_named_arguments} do transport_options = subscribe_named_arguments[:transport_options] @@ -79,6 +81,8 @@ defmodule EthereumJSONRPC.WebSocketTest do assert is_binary(subscription_id) end + # Infura timeouts on 2018-09-10 + @tag :no_geth test "delivers new heads to caller", %{ block_interval: block_interval, subscribe_named_arguments: subscribe_named_arguments @@ -132,6 +136,8 @@ defmodule EthereumJSONRPC.WebSocketTest do assert :ok = WebSocket.unsubscribe(subscription) end + # Infura timeouts on 2018-09-10 + @tag :no_geth test "stops messages being sent to subscriber", %{ block_interval: block_interval, subscribe_named_arguments: subscribe_named_arguments diff --git a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc_test.exs b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc_test.exs index d8d43b995a..75447a13a8 100644 --- a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc_test.exs +++ b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc_test.exs @@ -599,6 +599,8 @@ defmodule EthereumJSONRPCTest do end describe "unsubscribe/2" do + # Infura timeouts on 2018-09-10 + @tag :no_geth test "can unsubscribe", %{subscribe_named_arguments: subscribe_named_arguments} do transport = Keyword.fetch!(subscribe_named_arguments, :transport) transport_options = subscribe_named_arguments[:transport_options] @@ -622,6 +624,8 @@ defmodule EthereumJSONRPCTest do assert :ok = EthereumJSONRPC.unsubscribe(subscription) end + # Infura timeouts on 2018-09-10 + @tag :no_geth test "stops messages being sent to subscriber", %{ block_interval: block_interval, subscribe_named_arguments: subscribe_named_arguments