-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanups the evm process fork specific files and other improvements
- write block_result in temporary files powered by Briefly.
- Loading branch information
1 parent
d216ee3
commit 303da13
Showing
11 changed files
with
42 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,14 @@ | ||
# Block Processor | ||
|
||
## supervision tree | ||
## evm server | ||
|
||
```txt | ||
We use the evm tool which is expected to be setup as a http server in order to serve requests. | ||
To run the http server, follow instructions in the [covalenthq/erigon](https://github.com/covalenthq/erigon/pull/11/files#diff-d74525d4a32983b50da784e0960ab0b7a8adb537dba1535e893bfc1b60dc2427) | ||
|
||
PoolSupervisor | ||
/ \ | ||
/ \ (dynamically gen) | ||
Server WorkerSupervisor | ||
(permanent) (temporary) | ||
\ | ||
\ | ||
Executor | ||
(transient) | ||
e.g. (copied from `covalenthq/erigon`) | ||
|
||
``` | ||
|
||
Executor does it's job successfully (status code from evm 0 or otherwise), it has to send `:success` or `:failure` to the GenServer. | ||
|
||
If there's some error in the executor like evm cli wrongly invoked or executable not present etc. The whole chain upto the PoolSupervisor is probably not useful (concluded after some process crashes), and should - send an exit signal which indicates that the evm processor can't be worked with now. | ||
|
||
There should be some way to update the code. | ||
|
||
Also, some persistence of request queue (like mnesia??) so that restarts of PoolSupervisor can resume from unprocessed blocks. | ||
|
||
```bash | ||
➜ curl -v -F filedata=@/Users/user/repos/rudder/test-data/block-specimen/15892740.specimen.json http://127.0.0.1:3002/process | ||
``` | ||
|
||
test/evm has 2 evm executables which are used in unit tests - | ||
evm : normal evm which is used in production...it's a symlinked version of $REPO_ROOT/evm/evm | ||
evm-with-exit12 : The latter is a special executable which just exits with status code 12. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,56 @@ | ||
defmodule Rudder.BlockProcessor.Server do | ||
defmodule Rudder.BlockProcessor do | ||
use GenServer | ||
require Logger | ||
alias Rudder.BlockProcessor.Struct | ||
alias Multipart.Part | ||
alias Rudder.Events | ||
|
||
def start_link(opts) do | ||
GenServer.start_link(__MODULE__, :ok, opts) | ||
def start_link([evm_server_url | opts]) do | ||
GenServer.start_link(__MODULE__, evm_server_url, opts) | ||
end | ||
|
||
@impl true | ||
def init(:ok) do | ||
{:ok, []} | ||
def init(evm_server_url) do | ||
{:ok, "#{evm_server_url}/process"} | ||
end | ||
|
||
@impl true | ||
def handle_call({:process, block_specimen_content}, _from, state) do | ||
evm_server_url = Application.get_env(:rudder, :evm_server_url) | ||
url = "#{evm_server_url}/process" | ||
|
||
# multipart = | ||
# Multipart.new() | ||
# |> Multipart.add_part(Part.binary_body("first body")) | ||
# |> Multipart.add_part(Part.binary_body("second body", [{"content-type", "text/plain"}])) | ||
# |> Multipart.add_part(Part.binary_body("<p>third body</p>", [{"content-type", "text/html"}])) | ||
|
||
# body_stream = Multipart.body_stream(multipart) | ||
# content_length = Multipart.content_length(multipart) | ||
# content_type = Multipart.content_type(multipart, "multipart/mixed") | ||
|
||
# headers = [{"Content-Type", content_type}, {"Content-Length", to_string(content_length)}] | ||
|
||
# Finch.build("POST", "https://example.org/", headers, {:stream, body_stream}) | ||
# |> Finch.request(MyFinch) | ||
|
||
evm_server_url = state | ||
multipart = Multipart.new() |> Multipart.add_part(Part.binary_body(block_specimen_content)) | ||
body_stream = Multipart.body_stream(multipart) | ||
content_length = Multipart.content_length(multipart) | ||
content_type = Multipart.content_type(multipart, "multipart/form-data") | ||
headers = [{"Content-Type", content_type}, {"Content-Length", to_string(content_length)}] | ||
|
||
{:ok, %Finch.Response{body: body, headers: _, status: _}} = | ||
Finch.build("POST", url, headers, {:stream, body_stream}) | ||
Finch.build("POST", evm_server_url, headers, {:stream, body_stream}) | ||
|> Finch.request(Rudder.Finch) | ||
|
||
body_map = body |> Poison.decode!() | ||
|
||
case body_map do | ||
%{"error" => error} -> {:reply, {:error, error}, state} | ||
block_result -> {:reply, {:ok, block_result}, state} | ||
_ -> {:reply, {:ok, body}, state} | ||
end | ||
end | ||
|
||
def sync_queue(%Rudder.BlockSpecimen{} = block_specimen) do | ||
Logger.info("submitting #{block_specimen.block_height} to evm plugin...") | ||
GenServer.call(Rudder.BlockProcessor.Server, {:process, block_specimen.contents}, :infinity) | ||
|
||
start_execute_ms = System.monotonic_time(:millisecond) | ||
|
||
{:ok, block_result} = | ||
GenServer.call(Rudder.BlockProcessor, {:process, block_specimen.contents}, 60_000) | ||
|
||
block_result_path = Briefly.create!() | ||
File.write!(block_result_path, block_result) | ||
Events.bsp_execute(System.monotonic_time(:millisecond) - start_execute_ms) | ||
Logger.info("writing block result into #{inspect(block_result_path)}") | ||
{:ok, block_result_path} | ||
end | ||
|
||
@impl true | ||
def terminate(reason, _state) do | ||
Logger.info("terminating blockprocessor.server: #{reason}") | ||
Logger.info("terminating blockprocessor: #{reason}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters