Make rocksdb dependency optional

This commit is contained in:
Mononaut 2022-05-16 17:39:51 +00:00
parent 79145d653c
commit 0a35207dd7
5 changed files with 33 additions and 10 deletions

View File

@ -575,7 +575,7 @@
{/if} {/if}
{#if $loading} {#if $loading}
<div class="loading-overlay" in:fade={{ delay: 500, duration: 500 }} out:fade={{ duration: 200 }}> <div class="loading-overlay" in:fade={{ delay: 1000, duration: 500 }} out:fade={{ duration: 200 }}>
<div class="loading-wrapper"> <div class="loading-wrapper">
<LoadingAnimation /> <LoadingAnimation />
<p class="loading-msg">loading</p> <p class="loading-msg">loading</p>

View File

@ -11,6 +11,30 @@
#### Installation #### Installation
Set the `MIX_TARGET` environment variable to choose a build target (defaults to "personal")
"personal" - tailored to low traffic personal deployments. resource-intensive features & dependencies disabled
```shell
export MIX_TARGET=personal
```
or
"public" - tailored to high traffic, high performance public deployments.
```shell
export MIX_TARGET=public
```
✅❌
| feature | "public" | "personal" |
|---|---|---|
| Spend index | ✅ | ❌ |
```shell ```shell
mix do deps.get mix do deps.get
mix do deps.compile mix do deps.compile
@ -27,7 +51,6 @@ The API server expects the following environment variables to be set:
| LOG_LEVEL | Tailor logging verbosity. either "error", "info" (default) or "debug" | | LOG_LEVEL | Tailor logging verbosity. either "error", "info" (default) or "debug" |
| RPC_POOLS | Number of connection pools for RPC requests to Bitcoin Core | | RPC_POOLS | Number of connection pools for RPC requests to Bitcoin Core |
| RPC_POOL_SIZE | Number of connections maintained per pool (RPC_POOLS x RPC_POOL_SIZE should be substantially lower than `rpcworkqueue` in bitcoin.conf) | | RPC_POOL_SIZE | Number of connections maintained per pool (RPC_POOLS x RPC_POOL_SIZE should be substantially lower than `rpcworkqueue` in bitcoin.conf) |
| INDEXED | 'true' to build indexes required for certain features (see [INDEXES.md](https://github.com/bitfeed-project/block/master/server/INDEXES.md) for details). Omit this variable to disable indexing |
| BITCOIN_HOST | Bitcoin node host address | | BITCOIN_HOST | Bitcoin node host address |
| BITCOIN_ZMQ_RAWBLOCK_PORT | Bitcoin node ZMQ port for block events (to match `zmqpubrawblock` in bitcoin.conf) | | BITCOIN_ZMQ_RAWBLOCK_PORT | Bitcoin node ZMQ port for block events (to match `zmqpubrawblock` in bitcoin.conf) |
| BITCOIN_ZMQ_RAWTX_PORT | Bitcoin node ZMQ port for transaction events (to match `zmqpubrawtx` in bitcoin.conf) | | BITCOIN_ZMQ_RAWTX_PORT | Bitcoin node ZMQ port for transaction events (to match `zmqpubrawtx` in bitcoin.conf) |

View File

@ -13,7 +13,7 @@ defmodule BitcoinStream.Server do
{ rpc_pool_size, "" } = Integer.parse(System.get_env("RPC_POOL_SIZE") || "16"); { rpc_pool_size, "" } = Integer.parse(System.get_env("RPC_POOL_SIZE") || "16");
log_level = System.get_env("LOG_LEVEL"); log_level = System.get_env("LOG_LEVEL");
btc_host = System.get_env("BITCOIN_HOST"); btc_host = System.get_env("BITCOIN_HOST");
indexed = System.get_env("INDEXED") indexed = Mix.target == "public";
case log_level do case log_level do
"debug" -> "debug" ->

View File

@ -17,7 +17,7 @@ defmodule BitcoinStream.Index.Spend do
@impl true @impl true
def init([indexed]) do def init([indexed]) do
:ets.new(:spend_cache, [:set, :public, :named_table]); :ets.new(:spend_cache, [:set, :public, :named_table]);
if (indexed != nil) do if (indexed) do
{:ok, dbref} = :rocksdb.open(String.to_charlist("data/index/spend"), [create_if_missing: true]); {:ok, dbref} = :rocksdb.open(String.to_charlist("data/index/spend"), [create_if_missing: true]);
Process.send_after(self(), :sync, 2000); Process.send_after(self(), :sync, 2000);
{:ok, [dbref, indexed, false]} {:ok, [dbref, indexed, false]}
@ -28,14 +28,14 @@ defmodule BitcoinStream.Index.Spend do
@impl true @impl true
def terminate(_reason, [dbref, indexed, _done]) do def terminate(_reason, [dbref, indexed, _done]) do
if (indexed != nil) do if (indexed) do
:rocksdb.close(dbref) :rocksdb.close(dbref)
end end
end end
@impl true @impl true
def handle_info(:sync, [dbref, indexed, done]) do def handle_info(:sync, [dbref, indexed, done]) do
if (indexed != nil) do if (indexed) do
case sync(dbref) do case sync(dbref) do
true -> true ->
{:noreply, [dbref, indexed, true]} {:noreply, [dbref, indexed, true]}
@ -57,7 +57,7 @@ defmodule BitcoinStream.Index.Spend do
@impl true @impl true
def handle_call({:get_tx_spends, txid}, _from, [dbref, indexed, done]) do def handle_call({:get_tx_spends, txid}, _from, [dbref, indexed, done]) do
case get_transaction_spends(dbref, txid, (indexed != nil)) do case get_transaction_spends(dbref, txid, (indexed)) do
{:ok, spends} -> {:ok, spends} ->
{:reply, {:ok, spends}, [dbref, indexed, done]} {:reply, {:ok, spends}, [dbref, indexed, done]}
@ -69,7 +69,7 @@ defmodule BitcoinStream.Index.Spend do
@impl true @impl true
def handle_cast(:new_block, [dbref, indexed, done]) do def handle_cast(:new_block, [dbref, indexed, done]) do
if (indexed != nil and done) do if (indexed and done) do
case sync(dbref) do case sync(dbref) do
true -> true ->
{:noreply, [dbref, indexed, true]} {:noreply, [dbref, indexed, true]}
@ -86,7 +86,7 @@ defmodule BitcoinStream.Index.Spend do
@impl true @impl true
def handle_cast({:block_disconnected, hash}, [dbref, indexed, done]) do def handle_cast({:block_disconnected, hash}, [dbref, indexed, done]) do
Logger.info("block disconnected: #{hash}"); Logger.info("block disconnected: #{hash}");
if (indexed != nil and done) do if (indexed and done) do
block_disconnected(dbref, hash) block_disconnected(dbref, hash)
end end
{:noreply, [dbref, indexed, done]} {:noreply, [dbref, indexed, done]}

View File

@ -42,7 +42,7 @@ defmodule BitcoinStream.MixProject do
{:corsica, "~> 1.0"}, {:corsica, "~> 1.0"},
{:plug_cowboy, "~> 2.0"}, {:plug_cowboy, "~> 2.0"},
{:jason, "~> 1.1"}, {:jason, "~> 1.1"},
{:rocksdb, "~> 1.6"} {:rocksdb, "~> 1.6", targets: :public}
] ]
end end
end end