commit 7b62eb839c99aa99868858fd5a974197510ad748
parent 3e9cedbee0943e46927342b443adffe1d07634eb
Author: Antoine A <>
Date: Tue, 15 Mar 2022 18:19:02 +0100
Catch bootstrap error
Diffstat:
7 files changed, 78 insertions(+), 79 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -324,9 +324,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
-version = "0.5.2"
+version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa"
+checksum = "fdbfe11fe19ff083c48923cf179540e8cd0535903dc35e178a1fdeeb59aef51f"
dependencies = [
"cfg-if",
"crossbeam-utils",
@@ -345,10 +345,11 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
-version = "0.9.7"
+version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c00d6d2ea26e8b151d99093005cb442fb9a37aeaca582a03ec70946f49ab5ed9"
+checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c"
dependencies = [
+ "autocfg",
"cfg-if",
"crossbeam-utils",
"lazy_static",
@@ -358,9 +359,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
-version = "0.8.7"
+version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6"
+checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
dependencies = [
"cfg-if",
"lazy_static",
@@ -721,7 +722,7 @@ checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [
"cfg-if",
"libc",
- "wasi",
+ "wasi 0.10.2+wasi-snapshot-preview1",
]
[[package]]
@@ -943,9 +944,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.119"
+version = "0.2.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
+checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09"
[[package]]
name = "listenfd"
@@ -1027,14 +1028,15 @@ dependencies = [
[[package]]
name = "mio"
-version = "0.8.0"
+version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2"
+checksum = "7ba42135c6a5917b9db9cd7b293e5409e1c6b041e6f9825e92e55a894c63b6f8"
dependencies = [
"libc",
"log",
"miow",
"ntapi",
+ "wasi 0.11.0+wasi-snapshot-preview1",
"winapi",
]
@@ -1087,9 +1089,9 @@ dependencies = [
[[package]]
name = "num_threads"
-version = "0.1.3"
+version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97ba99ba6393e2c3734791401b66902d981cb03bf190af674ca69949b6d5fb15"
+checksum = "c539a50b93a303167eded6e8dff5220cd39447409fb659f4cd24b1f72fe4f133"
dependencies = [
"libc",
]
@@ -1727,9 +1729,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
-version = "1.0.86"
+version = "1.0.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
+checksum = "ebd69e719f31e88618baa1eaa6ee2de5c9a1c004f1e9ecdb58e8352a13f20a01"
dependencies = [
"proc-macro2",
"quote",
@@ -2066,6 +2068,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
+name = "wasi"
+version = "0.11.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+
+[[package]]
name = "wasm-bindgen"
version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/btc-wire/src/lib.rs b/btc-wire/src/lib.rs
@@ -164,7 +164,7 @@ impl WireState {
pub fn load_taler_config(file: Option<&Path>) -> Self {
let (taler_config, path, currency) = load_taler_config(file);
let btc_config =
- BitcoinConfig::load(path, currency).expect("Failed to read bitcoin configuration file");
+ BitcoinConfig::load(path, currency).or_fail(|e| format!("bitcoin config: {}", e));
let init_confirmation = taler_config.confirmation().unwrap_or(DEFAULT_CONFIRMATION) as u32;
Self {
confirmation: AtomicU32::new(init_confirmation),
diff --git a/btc-wire/src/loops.rs b/btc-wire/src/loops.rs
@@ -25,9 +25,9 @@ pub mod worker;
#[derive(Debug, thiserror::Error)]
pub enum LoopError {
- #[error(transparent)]
+ #[error("RPC {0}")]
Rpc(#[from] rpc::Error),
- #[error(transparent)]
+ #[error("DB {0}")]
DB(#[from] postgres::Error),
#[error("Another btc-wire process is running concurrently")]
Concurrency,
diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs
@@ -22,11 +22,18 @@ use btc_wire::{
};
use clap::StructOpt;
use common::{
- log::log::info, named_spawn, password, postgres::NoTls, reconnect::auto_reconnect_db,
+ log::{log::info, OrFail},
+ named_spawn, password,
+ postgres::NoTls,
+ reconnect::auto_reconnect_db,
};
+use loops::LoopResult;
use std::path::PathBuf;
-use crate::loops::{analysis::analysis, watcher::watcher, worker::worker};
+use crate::{
+ loops::{analysis::analysis, watcher::watcher, worker::worker},
+ sql::sql_addr,
+};
mod fail_point;
mod loops;
@@ -57,45 +64,38 @@ fn main() {
let args = Args::parse();
match args.init {
- Some(cmd) => init(args.config, cmd),
+ Some(cmd) => init(args.config, cmd).or_fail(|e| format!("{}", e)),
None => run(args.config),
}
}
-fn init(config: Option<PathBuf>, init: Init) {
+fn init(config: Option<PathBuf>, init: Init) -> LoopResult<()> {
// Parse taler config
let (taler_config, path, currency) = load_taler_config(config.as_deref());
-
// Connect to database
- let mut db = taler_config
- .db_config()
- .connect(NoTls)
- .expect("Failed to connect to database");
+ let mut db = taler_config.db_config().connect(NoTls)?;
// Parse bitcoin config
let btc_conf =
- BitcoinConfig::load(path, currency).expect("Failed to load bitcoin configuration");
+ BitcoinConfig::load(path, currency).or_fail(|e| format!("bitcoin config: {}", e));
// Connect to bitcoin node
- let mut rpc = Rpc::common(&btc_conf).expect("Failed to connect to bitcoin RPC server");
+ let mut rpc = Rpc::common(&btc_conf).or_fail(|e| format!("rpc connect: {}", e));
match init {
Init::Initdb => {
// Load schema
- db.batch_execute(include_str!("../../db/btc.sql"))
- .expect("Failed to load database schema");
+ db.batch_execute(include_str!("../../db/btc.sql"))?;
// Init status to true
db
.execute(
"INSERT INTO state (name, value) VALUES ('status', $1) ON CONFLICT (name) DO NOTHING",
&[&[1u8].as_ref()],
- )
- .expect("Failed to initialise database state");
+ )?;
// Init last_hash if not already set
- let genesis_hash = rpc.get_genesis().expect("Failed to get genesis hash");
+ let genesis_hash = rpc.get_genesis()?;
db
.execute(
"INSERT INTO state (name, value) VALUES ('last_hash', $1) ON CONFLICT (name) DO NOTHING",
&[&genesis_hash.as_ref()],
- )
- .expect("Failed to update database state");
+ )?;
println!("Database initialised");
}
Init::Initwallet => {
@@ -110,23 +110,18 @@ fn init(config: Option<PathBuf>, init: Init) {
rpc.load_wallet(WIRE_WALLET_NAME).ok();
// Load previous address
- let prev_addr = db
- .query_opt("SELECT value FROM state WHERE name = 'addr'", &[])
- .expect("Failed to query database state");
+ let prev_addr = db.query_opt("SELECT value FROM state WHERE name = 'addr'", &[])?;
let addr = if let Some(row) = prev_addr {
- String::from_utf8(row.get(0)).expect("Stored address is not a valid string")
+ sql_addr(&row, 0)
} else {
// Or generate a new one
let new = Rpc::wallet(&btc_conf, WIRE_WALLET_NAME)
- .expect("Failed to connect to wallet bitcoin RPC server")
- .gen_addr()
- .expect("Failed to generate new address")
- .to_string();
+ .or_fail(|e| format!("rpc connect: {}", e))
+ .gen_addr()?;
db.execute(
"INSERT INTO state (name, value) VALUES ('addr', $1)",
- &[&new.as_bytes()],
- )
- .expect("Failed to update database state");
+ &[&new.to_string().as_bytes()],
+ )?;
new
};
@@ -142,6 +137,7 @@ fn init(config: Option<PathBuf>, init: Init) {
println!("PAYTO = payto://bitcoin/{}", addr);
}
}
+ Ok(())
}
fn run(config: Option<PathBuf>) {
diff --git a/common/src/config.rs b/common/src/config.rs
@@ -54,7 +54,7 @@ impl TalerConfig {
}
// Parse ini config
let conf = ini::Ini::load_from_str(&String::from_utf8_lossy(&output.stdout))
- .expect("Failed to parse config");
+ .or_fail(|e| format!("config format: {}", e));
let taler = section(&conf, "taler");
let currency = required(taler, "CURRENCY", string);
let currency = Currency::from_str(¤cy)
diff --git a/eth-wire/src/loops.rs b/eth-wire/src/loops.rs
@@ -25,9 +25,9 @@ pub mod worker;
#[derive(Debug, thiserror::Error)]
pub enum LoopError {
- #[error(transparent)]
+ #[error("RPC {0}")]
RPC(#[from] rpc::Error),
- #[error(transparent)]
+ #[error("DB {0}")]
DB(#[from] postgres::Error),
#[error("Another eth-wire process is running concurrently")]
Concurrency,
diff --git a/eth-wire/src/main.rs b/eth-wire/src/main.rs
@@ -17,14 +17,19 @@
use std::path::PathBuf;
use clap::StructOpt;
-use common::{named_spawn, password, postgres::NoTls, reconnect::auto_reconnect_db, log::log::info};
+use common::{
+ log::{log::info, OrFail},
+ named_spawn, password,
+ postgres::NoTls,
+ reconnect::auto_reconnect_db,
+};
use eth_wire::{
load_taler_config,
rpc::{auto_rpc_common, auto_rpc_wallet, Rpc, RpcClient},
SyncState, WireState,
};
use ethereum_types::H160;
-use loops::{analysis::analysis, watcher::watcher, worker::worker};
+use loops::{analysis::analysis, watcher::watcher, worker::worker, LoopResult};
mod fail_point;
mod loops;
@@ -53,36 +58,31 @@ fn main() {
let args = Args::parse();
match args.init {
- Some(cmd) => init(args.config, cmd),
+ Some(cmd) => init(args.config, cmd).or_fail(|e| format!("{}", e)),
None => run(args.config),
}
}
-fn init(config: Option<PathBuf>, init: Init) {
+fn init(config: Option<PathBuf>, init: Init) -> LoopResult<()> {
// Parse taler config
let (taler_config, ipc_path, _) = load_taler_config(config.as_deref());
// Connect to database
- let mut db = taler_config
- .db_config()
- .connect(NoTls)
- .expect("Failed to connect to database");
+ let mut db = taler_config.db_config().connect(NoTls)?;
// Connect to ethereum node
- let mut rpc = Rpc::new(ipc_path).expect("Failed to connect to ethereum RPC server");
+ let mut rpc = Rpc::new(ipc_path).or_fail(|e| format!("rpc connect: {}", e));
match init {
Init::Initdb => {
// Load schema
- db.batch_execute(include_str!("../../db/eth.sql"))
- .expect("Failed to load database schema");
+ db.batch_execute(include_str!("../../db/eth.sql"))?;
// Init status to true
db
.execute(
"INSERT INTO state (name, value) VALUES ('status', $1) ON CONFLICT (name) DO NOTHING",
&[&[1u8].as_ref()],
- )
- .expect("Failed to initialise database state");
+ )?;
// Init sync if not already set
- let block = rpc.earliest_block().expect("Failed to get earliest block");
+ let block = rpc.earliest_block()?;
let state = SyncState {
tip_hash: block.hash.unwrap(),
tip_height: block.number.unwrap(),
@@ -91,38 +91,32 @@ fn init(config: Option<PathBuf>, init: Init) {
db.execute(
"INSERT INTO state (name, value) VALUES ('sync', $1) ON CONFLICT (name) DO NOTHING",
&[&state.to_bytes().as_ref()],
- )
- .expect("Failed to update database state");
+ )?;
println!("Database initialised");
}
Init::Initwallet => {
// Skip previous blocks
- let block = rpc.latest_block().expect("Failed to get latest block");
+ let block = rpc.latest_block()?;
let state = SyncState {
tip_hash: block.hash.unwrap(),
tip_height: block.number.unwrap(),
conf_height: block.number.unwrap(),
};
- let prev_addr = db
- .query_opt("SELECT value FROM state WHERE name = 'addr'", &[])
- .expect("Failed to query database state");
+ let prev_addr = db.query_opt("SELECT value FROM state WHERE name = 'addr'", &[])?;
let (addr, created) = if let Some(row) = prev_addr {
(H160::from_slice(row.get(0)), false)
} else {
// Or generate a new one
let passwd = password();
- let new = rpc.new_account(&passwd).expect("Failed creating account");
+ let new = rpc.new_account(&passwd)?;
db.execute(
"INSERT INTO state (name, value) VALUES ('addr', $1)",
&[&new.as_bytes()],
- )
- .expect("Failed to update database state");
- let nb_row = db
- .execute(
- "UPDATE state SET value=$1 WHERE name='sync'",
- &[&state.to_bytes().as_ref()],
- )
- .expect("Failed to update database state");
+ )?;
+ let nb_row = db.execute(
+ "UPDATE state SET value=$1 WHERE name='sync'",
+ &[&state.to_bytes().as_ref()],
+ )?;
if nb_row > 0 {
println!("Skipped {} previous block", state.conf_height);
}
@@ -143,6 +137,7 @@ fn init(config: Option<PathBuf>, init: Init) {
println!("PAYTO = payto://ethereum/{}", addr);
}
}
+ Ok(())
}
fn run(config: Option<PathBuf>) {