Skip to content

Commit

Permalink
Fixed bug in resolving certain accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicletz committed Apr 16, 2024
1 parent b3bf07e commit 71148dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 52 deletions.
47 changes: 4 additions & 43 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,6 @@
# Command line perf testing reference
# 16 Apr 2024

## 21. Feb 2022 - e97191192cc022452d2167beea24f06939cac6f8
dom = "0x5849ea89593cf65e13110690d9339c121801a45c"
bns = "0x8A093E3A83F63A00FFFC4729AA55482845A49294"
RemoteChain.RPCCache.get_account_root(Chains.Moonbeam, bns)

```elixir
rpc = fn method, args -> :timer.tc(fn -> Network.EdgeV2.handle_async_msg([method, Rlpx.num2bin(Chain.peak()) | args], nil) end) end
id = <<237, 217, 116, 65, 255, 170, 122, 217, 206, 132, 246, 126, 210, 93, 83, 13, 230, 107, 130, 135>>
slot1 = <<5, 127, 142, 10, 91, 52, 106, 14, 9, 229, 29, 19, 3, 97, 232, 18, 212, 29, 88, 37, 185, 216, 147, 129, 123, 167, 254, 18, 252, 9, 230, 157>>
slot2 = <<27, 241, 228, 27, 25, 19, 64, 172, 238, 203, 185, 176, 129, 254, 154, 178, 131, 5, 167, 1, 226, 25, 216, 229, 150, 121, 1, 130, 59, 28, 70, 179>>
slot3 = <<27, 241, 228, 27, 25, 19, 64, 172, 238, 203, 185, 176, 129, 254, 154, 178, 131, 5, 167, 1, 226, 25, 216, 229, 150, 121, 1, 130, 59, 28, 70, 180>>
slot4 = <<27, 241, 228, 27, 25, 19, 64, 172, 238, 203, 185, 176, 129, 254, 154, 178, 131, 5, 167, 1, 226, 25, 216, 229, 150, 121, 1, 130, 59, 28, 70, 181>>

> :timer.tc(fn -> Chain.with_peak(&Chain.Block.blockquick_window/1) end) |> elem(0)
324

> rpc.("getstateroots", []) |> elem(0)
124

> rpc.("getaccount", [id]) |> elem(0)
200

> rpc.("getaccountroots", [id]) |> elem(0)
900

> rpc.("getaccountvalue", [id, slot1]) |> elem(0)
> rpc.("getaccountvalue", [id, slot2]) |> elem(0)
900

> rpc.("getaccountvalues", [id, slot1, slot2, slot3, slot4]) |> elem(0)
1000

> :timer.tc(fn ->
rpc.("getaccountvalue", [id, slot1])
rpc.("getaccountvalue", [id, slot2])
rpc.("getaccountvalue", [id, slot3])
rpc.("getaccountvalue", [id, slot4])
end) |> elem(0)
4000

## 2nd Aug 2023 BNS

bns = Hash.to_address(0xAF60FAA5CD840B724742F1AF116168276112D6A6)
rpc.("getaccountroots", [bns]) |> elem(0)

```
16 changes: 10 additions & 6 deletions lib/remote_chain/rpc_cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ defmodule RemoteChain.RPCCache do
result

{:reply, %{"error" => error}} ->
raise "RPC error in get_storage_many(#{inspect({chain, address, slots})}): #{inspect(error)}"
raise "RPC error in get_storage_many(#{inspect({chain, address, slots, block})}): #{inspect(error)}"

{:error, reason} ->
raise "Batch error in get_storage_many(#{inspect({chain, address, slots})}): #{inspect(reason)}"
raise "Batch error in get_storage_many(#{inspect({chain, address, slots, block})}): #{inspect(reason)}"
end)
end

Expand Down Expand Up @@ -104,10 +104,13 @@ defmodule RemoteChain.RPCCache do
# 1) Fetch all account keys
# => because there can be many account keys and fetching them all can be slow
# => we're guessing here on change for more than 20 keys
keys = rpc!(chain, "state_getKeys", [storage_key, block_hash]) |> Enum.sort()
keys =
rpc!(chain, "state_getKeys", [storage_key, block_hash])
|> Enum.map(fn key -> "0x" <> binary_part(key, byte_size(key) - 40, 40) end)
|> Enum.sort()

if length(keys) < 20 do
values = RemoteChain.RPCCache.get_storage_many(chain, address, keys, block)
if length(keys) < 40 do
values = get_storage_many(chain, address, keys, block)

Enum.zip(keys, values)
|> Enum.map(fn {key, value} -> key <> value end)
Expand Down Expand Up @@ -222,7 +225,8 @@ defmodule RemoteChain.RPCCache do
end

def resolve_block(chain, "latest"), do: block_number(chain)
def resolve_block(_chain, block), do: block
def resolve_block(_chain, block) when is_integer(block), do: block
def resolve_block(_chain, "0x" <> _ = block), do: Base16.decode_int(block)

defp name(chain) do
impl = RemoteChain.chainimpl(chain)
Expand Down
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ end
defmodule Diode.Mixfile do
use Mix.Project

@vsn "1.3.0"
@full_vsn "v1.3.0"
@vsn "1.3.1"
@full_vsn "v1.3.1"
@url "https://github.com/diodechain/diode_server"

def project do
Expand All @@ -22,7 +22,7 @@ defmodule Diode.Mixfile do
deps: deps(),
description: "Diode Network Full Blockchain Node implementation",
docs: docs(),
elixir: "~> 1.14",
elixir: "~> 1.13",
elixirc_options: [warnings_as_errors: Mix.target() == :host],
elixirc_paths: elixirc_paths(Mix.env()),
full_version: :persistent_term.get(:full_vsn, @full_vsn),
Expand Down

0 comments on commit 71148dc

Please sign in to comment.