API server startup tweaks for umbrel release

This commit is contained in:
Mononaut 2022-02-19 23:39:13 -06:00
parent c0703a7a21
commit 561cc30aa6
2 changed files with 15 additions and 5 deletions

View File

@ -37,20 +37,19 @@ defmodule BitcoinStream.RPC do
case status do
# if node is connected and finished with the initial block download
{:ok, %{"initialblockdownload" => false}} ->
IO.puts("Bitcoin Core connected and fully synced");
# notify all listening processes
notify_listeners(listeners);
Process.send_after(self(), :check_status, 60 * 1000);
Process.send_after(self(), :check_status, 300 * 1000);
{:noreply, {host, port, status, creds, []}}
{:ok, %{"initialblockdownload" => true}} ->
IO.puts("Bitcoin Core connected, waiting for initial block download");
Process.send_after(self(), :check_status, 60 * 1000);
Process.send_after(self(), :check_status, 30 * 1000);
{:noreply, {host, port, status, creds, listeners}}
_ ->
IO.puts("Waiting to connect to Bitcoin Core");
Process.send_after(self(), :check_status, 60 * 1000);
Process.send_after(self(), :check_status, 10 * 1000);
{:noreply, {host, port, status, creds, listeners}}
end
end

View File

@ -305,7 +305,18 @@ defmodule BitcoinStream.Mempool do
sync_queue(pid, tail)
end
defp wait_for_ibd() do
case RPC.get_node_status(:rpc) do
{:ok, %{"initialblockdownload" => false}} -> true
_ ->
RPC.notify_on_ready(:rpc)
end
end
def sync(pid) do
IO.puts("Waiting for node to come online and fully sync before synchronizing mempool");
wait_for_ibd();
IO.puts("Preparing mempool sync");
with {:ok, 200, %{"mempool_sequence" => sequence, "txids" => txns}} <- RPC.request(:rpc, "getrawmempool", [false, true]) do
set_seq(pid, sequence);
@ -327,7 +338,7 @@ defmodule BitcoinStream.Mempool do
IO.puts("Pool sync failed");
IO.inspect(err);
#retry after 30 seconds
:timer.sleep(30000);
:timer.sleep(10000);
sync(pid)
end
end