mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-19 14:24:47 -07:00
global: big snapshot
This commit is contained in:
@@ -17,7 +17,7 @@ brk_logger = { workspace = true }
|
||||
brk_mempool = { workspace = true }
|
||||
brk_query = { workspace = true }
|
||||
brk_reader = { workspace = true }
|
||||
brk_rpc = { workspace = true, features = ["corepc"] }
|
||||
brk_rpc = { workspace = true }
|
||||
brk_server = { workspace = true }
|
||||
brk_types = { workspace = true }
|
||||
lexopt = "0.3"
|
||||
|
||||
@@ -5,7 +5,9 @@ use std::{
|
||||
|
||||
use brk_error::{Error, Result};
|
||||
use brk_rpc::{Auth, Client};
|
||||
use brk_server::Website;
|
||||
use brk_server::{
|
||||
CdnCacheMode, DEFAULT_CACHE_SIZE, DEFAULT_MAX_WEIGHT, DEFAULT_MAX_WEIGHT_LOCALHOST, Website,
|
||||
};
|
||||
use brk_types::Port;
|
||||
use owo_colors::OwoColorize;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
@@ -23,6 +25,18 @@ pub struct Config {
|
||||
#[serde(default, deserialize_with = "default_on_error")]
|
||||
website: Option<Website>,
|
||||
|
||||
#[serde(default, deserialize_with = "default_on_error")]
|
||||
cdn: Option<bool>,
|
||||
|
||||
#[serde(default, deserialize_with = "default_on_error")]
|
||||
maxweight: Option<usize>,
|
||||
|
||||
#[serde(default, deserialize_with = "default_on_error")]
|
||||
maxweightlocal: Option<usize>,
|
||||
|
||||
#[serde(default, deserialize_with = "default_on_error")]
|
||||
cachesize: Option<usize>,
|
||||
|
||||
#[serde(default, deserialize_with = "default_on_error")]
|
||||
bitcoindir: Option<String>,
|
||||
|
||||
@@ -66,6 +80,18 @@ impl Config {
|
||||
if let Some(v) = config_args.website {
|
||||
config.website = Some(v);
|
||||
}
|
||||
if let Some(v) = config_args.cdn {
|
||||
config.cdn = Some(v);
|
||||
}
|
||||
if let Some(v) = config_args.maxweight {
|
||||
config.maxweight = Some(v);
|
||||
}
|
||||
if let Some(v) = config_args.maxweightlocal {
|
||||
config.maxweightlocal = Some(v);
|
||||
}
|
||||
if let Some(v) = config_args.cachesize {
|
||||
config.cachesize = Some(v);
|
||||
}
|
||||
if let Some(v) = config_args.bitcoindir {
|
||||
config.bitcoindir = Some(v);
|
||||
}
|
||||
@@ -112,6 +138,16 @@ impl Config {
|
||||
Long("brkdir") => config.brkdir = Some(parser.value().unwrap().parse().unwrap()),
|
||||
Long("brkport") => config.brkport = Some(parser.value().unwrap().parse().unwrap()),
|
||||
Long("website") => config.website = Some(parser.value().unwrap().parse().unwrap()),
|
||||
Long("cdn") => config.cdn = Some(parser.value().unwrap().parse().unwrap()),
|
||||
Long("maxweight") => {
|
||||
config.maxweight = Some(parser.value().unwrap().parse().unwrap())
|
||||
}
|
||||
Long("maxweightlocal") => {
|
||||
config.maxweightlocal = Some(parser.value().unwrap().parse().unwrap())
|
||||
}
|
||||
Long("cachesize") => {
|
||||
config.cachesize = Some(parser.value().unwrap().parse().unwrap())
|
||||
}
|
||||
Long("bitcoindir") => {
|
||||
config.bitcoindir = Some(parser.value().unwrap().parse().unwrap())
|
||||
}
|
||||
@@ -171,6 +207,26 @@ impl Config {
|
||||
"<BOOL|PATH>".bright_black(),
|
||||
"[true]".bright_black()
|
||||
);
|
||||
println!(
|
||||
" --cdn {} Aggressive CDN cache, requires purge on deploy {}",
|
||||
"<BOOL>".bright_black(),
|
||||
"[false]".bright_black()
|
||||
);
|
||||
println!(
|
||||
" --maxweight {} Max series response weight in bytes for external clients {}",
|
||||
"<BYTES>".bright_black(),
|
||||
format!("[{}]", DEFAULT_MAX_WEIGHT).bright_black()
|
||||
);
|
||||
println!(
|
||||
" --maxweightlocal {} Max series response weight in bytes for loopback clients {}",
|
||||
"<BYTES>".bright_black(),
|
||||
format!("[{}]", DEFAULT_MAX_WEIGHT_LOCALHOST).bright_black()
|
||||
);
|
||||
println!(
|
||||
" --cachesize {} LRU capacity for the in-process response cache {}",
|
||||
"<ENTRIES>".bright_black(),
|
||||
format!("[{}]", DEFAULT_CACHE_SIZE).bright_black()
|
||||
);
|
||||
println!();
|
||||
println!(
|
||||
" --bitcoindir {} Bitcoin directory {}",
|
||||
@@ -333,6 +389,26 @@ Finally, you can run the program with '-h' for help."
|
||||
self.website.clone().unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn cdn_cache_mode(&self) -> CdnCacheMode {
|
||||
if self.cdn.unwrap_or(false) {
|
||||
CdnCacheMode::Aggressive
|
||||
} else {
|
||||
CdnCacheMode::Live
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_weight(&self) -> usize {
|
||||
self.maxweight.unwrap_or(DEFAULT_MAX_WEIGHT)
|
||||
}
|
||||
|
||||
pub fn max_weight_localhost(&self) -> usize {
|
||||
self.maxweightlocal.unwrap_or(DEFAULT_MAX_WEIGHT_LOCALHOST)
|
||||
}
|
||||
|
||||
pub fn cache_size(&self) -> usize {
|
||||
self.cachesize.unwrap_or(DEFAULT_CACHE_SIZE)
|
||||
}
|
||||
|
||||
pub fn brkport(&self) -> Option<Port> {
|
||||
self.brkport
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use brk_indexer::Indexer;
|
||||
use brk_mempool::Mempool;
|
||||
use brk_query::AsyncQuery;
|
||||
use brk_reader::Reader;
|
||||
use brk_server::Server;
|
||||
use brk_server::{Server, ServerConfig};
|
||||
use tracing::info;
|
||||
use vecdb::Exit;
|
||||
|
||||
@@ -60,21 +60,29 @@ pub fn main() -> anyhow::Result<()> {
|
||||
|
||||
let mempool = Mempool::new(&client);
|
||||
|
||||
let query = AsyncQuery::build(&reader, &indexer, &computer, Some(mempool.clone()));
|
||||
|
||||
let mempool_clone = mempool.clone();
|
||||
let query_clone = query.clone();
|
||||
thread::spawn(move || {
|
||||
mempool_clone.start();
|
||||
mempool_clone.start_with(|| {
|
||||
query_clone.sync(|q| q.fill_mempool_prevouts());
|
||||
});
|
||||
});
|
||||
|
||||
let query = AsyncQuery::build(&reader, &indexer, &computer, Some(mempool));
|
||||
|
||||
let data_path = config.brkdir();
|
||||
|
||||
let website = config.website();
|
||||
let server_config = ServerConfig {
|
||||
data_path: config.brkdir(),
|
||||
website: config.website(),
|
||||
cdn_cache_mode: config.cdn_cache_mode(),
|
||||
max_weight: config.max_weight(),
|
||||
max_weight_localhost: config.max_weight_localhost(),
|
||||
cache_size: config.cache_size(),
|
||||
};
|
||||
|
||||
let port = config.brkport();
|
||||
|
||||
let future = async move {
|
||||
let server = Server::new(&query, data_path, website);
|
||||
let server = Server::new(&query, server_config);
|
||||
|
||||
tokio::spawn(async move {
|
||||
server.serve(port).await.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user