From 0a35207dd73662df24d0ae9cb4a761f4be3b44ab Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 16 May 2022 17:39:51 +0000 Subject: [PATCH] Make rocksdb dependency optional --- client/src/components/TxViz.svelte | 2 +- server/README.md | 25 ++++++++++++++++++++++++- server/lib/server.ex | 2 +- server/lib/spend_index.ex | 12 ++++++------ server/mix.exs | 2 +- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/client/src/components/TxViz.svelte b/client/src/components/TxViz.svelte index 636fc45..99b87cc 100644 --- a/client/src/components/TxViz.svelte +++ b/client/src/components/TxViz.svelte @@ -575,7 +575,7 @@ {/if} {#if $loading} -
+

loading

diff --git a/server/README.md b/server/README.md index 6719bcf..ab9751d 100644 --- a/server/README.md +++ b/server/README.md @@ -11,6 +11,30 @@ #### 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 mix do deps.get 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" | | 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) | -| 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_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) | diff --git a/server/lib/server.ex b/server/lib/server.ex index 74db95c..e5fc49f 100644 --- a/server/lib/server.ex +++ b/server/lib/server.ex @@ -13,7 +13,7 @@ defmodule BitcoinStream.Server do { rpc_pool_size, "" } = Integer.parse(System.get_env("RPC_POOL_SIZE") || "16"); log_level = System.get_env("LOG_LEVEL"); btc_host = System.get_env("BITCOIN_HOST"); - indexed = System.get_env("INDEXED") + indexed = Mix.target == "public"; case log_level do "debug" -> diff --git a/server/lib/spend_index.ex b/server/lib/spend_index.ex index 0b49bab..632dd41 100644 --- a/server/lib/spend_index.ex +++ b/server/lib/spend_index.ex @@ -17,7 +17,7 @@ defmodule BitcoinStream.Index.Spend do @impl true def init([indexed]) do :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]); Process.send_after(self(), :sync, 2000); {:ok, [dbref, indexed, false]} @@ -28,14 +28,14 @@ defmodule BitcoinStream.Index.Spend do @impl true def terminate(_reason, [dbref, indexed, _done]) do - if (indexed != nil) do + if (indexed) do :rocksdb.close(dbref) end end @impl true def handle_info(:sync, [dbref, indexed, done]) do - if (indexed != nil) do + if (indexed) do case sync(dbref) do true -> {:noreply, [dbref, indexed, true]} @@ -57,7 +57,7 @@ defmodule BitcoinStream.Index.Spend do @impl true 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} -> {:reply, {:ok, spends}, [dbref, indexed, done]} @@ -69,7 +69,7 @@ defmodule BitcoinStream.Index.Spend do @impl true def handle_cast(:new_block, [dbref, indexed, done]) do - if (indexed != nil and done) do + if (indexed and done) do case sync(dbref) do true -> {:noreply, [dbref, indexed, true]} @@ -86,7 +86,7 @@ defmodule BitcoinStream.Index.Spend do @impl true def handle_cast({:block_disconnected, hash}, [dbref, indexed, done]) do Logger.info("block disconnected: #{hash}"); - if (indexed != nil and done) do + if (indexed and done) do block_disconnected(dbref, hash) end {:noreply, [dbref, indexed, done]} diff --git a/server/mix.exs b/server/mix.exs index d89f64d..8150563 100644 --- a/server/mix.exs +++ b/server/mix.exs @@ -42,7 +42,7 @@ defmodule BitcoinStream.MixProject do {:corsica, "~> 1.0"}, {:plug_cowboy, "~> 2.0"}, {:jason, "~> 1.1"}, - {:rocksdb, "~> 1.6"} + {:rocksdb, "~> 1.6", targets: :public} ] end end