bitfeed/server/lib/server.ex
Mononaut e845157610 Refactor API/Core bridge & mempool tracking.
API:
- Better RPC handling (cache credentials)
- Process transaction prevouts in dedicated Tasks
- Consume ZMQ sequence msgs
- Track mempool count precisely
- Cache prevouts for mempool transactions
- Send mempool count with every client msg, instead of reconstructing client-side
- Only send block ids over websocket, let clients fetch the full block data via http

Client:
- Simplify transaction queue to avoid setTimeouts
  - improves experience in background tabs
  - no longer need to hold back txs, as duplicates are now handled API-side
- Use API-supplied mempool count, instead of tracking it client-side
- Make mempoolCount a Svelte spring store, so updates transition smoothly
2022-02-18 18:07:58 -06:00

48 lines
1.5 KiB
Elixir

defmodule BitcoinStream.Server do
use Application
def start(_type, _args) do
{ socket_port, "" } = Integer.parse(System.get_env("PORT"));
{ zmq_tx_port, "" } = Integer.parse(System.get_env("BITCOIN_ZMQ_RAWTX_PORT"));
{ zmq_block_port, "" } = Integer.parse(System.get_env("BITCOIN_ZMQ_RAWBLOCK_PORT"));
{ zmq_sequence_port, "" } = Integer.parse(System.get_env("BITCOIN_ZMQ_SEQUENCE_PORT"));
{ rpc_port, "" } = Integer.parse(System.get_env("BITCOIN_RPC_PORT"));
btc_host = System.get_env("BITCOIN_HOST");
children = [
{ BitcoinStream.RPC, [host: btc_host, port: rpc_port, name: :rpc] },
{ BitcoinStream.Mempool, [name: :mempool] },
{ BitcoinStream.BlockData, [name: :block_data] },
BitcoinStream.Metrics.Probe,
Plug.Cowboy.child_spec(
scheme: :http,
plug: BitcoinStream.Router,
options: [
dispatch: dispatch(),
port: socket_port
]
),
Registry.child_spec(
keys: :duplicate,
name: Registry.BitcoinStream
),
BitcoinStream.Bridge.child_spec(host: btc_host, tx_port: zmq_tx_port, block_port: zmq_block_port, sequence_port: zmq_sequence_port)
]
opts = [strategy: :one_for_one, name: BitcoinStream.Application]
Supervisor.start_link(children, opts)
end
defp dispatch do
[
{:_,
[
{"/ws/txs", BitcoinStream.SocketHandler, []},
{"/ws/status", BitcoinStream.Metrics.SocketHandler, []},
{:_, Plug.Cowboy.Handler, {BitcoinStream.Router, []}}
]
}
]
end
end