1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 01:43:29 +01:00

Add a 'blocks_dir' option analogous to bitcoind's '-blocksdir'

The '-blocksdir' startup option allows one to store blk*.dat on an
external disk, while keeping the index (blocks/index/) on the same disk.

This makes electrs aware of such an option, while still keeping the same
default behaviour (blk*.dat in '<config_dir>/blocks/').

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
Antoine Poinsot 2020-06-30 11:50:05 +02:00
parent fac73dc1bf
commit f1d611fe19
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
5 changed files with 23 additions and 3 deletions

View File

@ -29,6 +29,11 @@ type = "std::path::PathBuf"
doc = "Data directory of Bitcoind (default: ~/.bitcoin/)"
default = "crate::config::default_daemon_dir()"
[[param]]
name = "blocks_dir"
type = "std::path::PathBuf"
doc = "Analogous to bitcoind's -blocksdir option, this specifies the directory containing the raw blocks files (blk*.dat)"
[[param]]
name = "cookie"
type = "String"

View File

@ -21,6 +21,7 @@ fn run() -> Result<()> {
let daemon = Daemon::new(
&config.daemon_dir,
&config.blocks_dir,
config.daemon_rpc_addr,
config.cookie_getter(),
config.network_type,

View File

@ -31,6 +31,7 @@ fn run_server(config: &Config) -> Result<()> {
let daemon = Daemon::new(
&config.daemon_dir,
&config.blocks_dir,
config.daemon_rpc_addr,
config.cookie_getter(),
config.network_type,

View File

@ -128,6 +128,7 @@ pub struct Config {
pub network_type: Network,
pub db_path: PathBuf,
pub daemon_dir: PathBuf,
pub blocks_dir: PathBuf,
pub daemon_rpc_addr: SocketAddr,
pub electrum_rpc_addr: SocketAddr,
pub monitoring_addr: SocketAddr,
@ -152,6 +153,10 @@ fn default_daemon_dir() -> PathBuf {
home
}
fn default_blocks_dir(daemon_dir: &Path) -> PathBuf {
daemon_dir.join("blocks")
}
fn create_cookie_getter(
cookie: Option<String>,
cookie_file: Option<PathBuf>,
@ -230,6 +235,10 @@ impl Config {
Network::Regtest => config.daemon_dir.push("regtest"),
}
let blocks_dir = config.blocks_dir.unwrap_or(
default_blocks_dir(&config.daemon_dir)
);
let cookie_getter =
create_cookie_getter(config.cookie, config.cookie_file, &config.daemon_dir);
@ -260,6 +269,7 @@ impl Config {
network_type: config.network,
db_path: config.db_dir,
daemon_dir: config.daemon_dir,
blocks_dir,
daemon_rpc_addr,
electrum_rpc_addr,
monitoring_addr,
@ -302,6 +312,7 @@ debug_struct! { Config,
network_type,
db_path,
daemon_dir,
blocks_dir,
daemon_rpc_addr,
electrum_rpc_addr,
monitoring_addr,

View File

@ -288,6 +288,7 @@ impl Counter {
pub struct Daemon {
daemon_dir: PathBuf,
blocks_dir: PathBuf,
network: Network,
conn: Mutex<Connection>,
message_id: Counter, // for monotonic JSONRPC 'id'
@ -302,6 +303,7 @@ pub struct Daemon {
impl Daemon {
pub fn new(
daemon_dir: &PathBuf,
blocks_dir: &PathBuf,
daemon_rpc_addr: SocketAddr,
cookie_getter: Arc<dyn CookieGetter>,
network: Network,
@ -311,6 +313,7 @@ impl Daemon {
) -> Result<Daemon> {
let daemon = Daemon {
daemon_dir: daemon_dir.clone(),
blocks_dir: blocks_dir.clone(),
network,
conn: Mutex::new(Connection::new(
daemon_rpc_addr,
@ -360,6 +363,7 @@ impl Daemon {
pub fn reconnect(&self) -> Result<Daemon> {
Ok(Daemon {
daemon_dir: self.daemon_dir.clone(),
blocks_dir: self.blocks_dir.clone(),
network: self.network,
conn: Mutex::new(self.conn.lock().unwrap().reconnect()?),
message_id: Counter::new(),
@ -371,9 +375,7 @@ impl Daemon {
}
pub fn list_blk_files(&self) -> Result<Vec<PathBuf>> {
let mut path = self.daemon_dir.clone();
path.push("blocks");
path.push("blk*.dat");
let path = self.blocks_dir.join("blk*.dat");
info!("listing block files at {:?}", path);
let mut paths: Vec<PathBuf> = glob::glob(path.to_str().unwrap())
.chain_err(|| "failed to list blk*.dat files")?