From 2b89197c245c4ea27a2e57b247e0613c2a0edb9c Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Sat, 23 Oct 2021 01:06:53 +0200 Subject: [PATCH 1/2] tests: reduce the bitcoind poll interval --- tests/test_framework/revaultd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_framework/revaultd.py b/tests/test_framework/revaultd.py index f0f7b151..6dd4cb72 100644 --- a/tests/test_framework/revaultd.py +++ b/tests/test_framework/revaultd.py @@ -68,7 +68,7 @@ def __init__( f.write('network = "regtest"\n') f.write(f"cookie_path = '{bitcoind_cookie}'\n") f.write(f"addr = '127.0.0.1:{bitcoind.rpcport}'\n") - f.write("poll_interval_secs = 10\n") + f.write("poll_interval_secs = 2\n") if stk_config is not None: f.write("[stakeholder_config]\n") From 57d61be710e6332c3dc1e7f501184b1099a184cb Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Sat, 23 Oct 2021 19:29:57 +0200 Subject: [PATCH 2/2] WIP bitcoind --- src/daemon/bitcoind/poller.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/daemon/bitcoind/poller.rs b/src/daemon/bitcoind/poller.rs index 42641e2f..477df179 100644 --- a/src/daemon/bitcoind/poller.rs +++ b/src/daemon/bitcoind/poller.rs @@ -903,11 +903,22 @@ fn update_tip( if tip.height > current_tip.height { // May just be a new (set of) block(s), make sure we are on the same chain - let bit_curr_hash = bitcoind.getblockhash(current_tip.height)?; - if bit_curr_hash == current_tip.hash || current_tip.height == 0 { - // We moved forward, everything is fine. - new_tip_event(&revaultd, bitcoind, &tip, unvaults_cache)?; - return Ok(current_tip); + match bitcoind.getblockhash(current_tip.height) { + Ok(bit_curr_hash) => { + if bit_curr_hash == current_tip.hash || current_tip.height == 0 { + // We moved forward, everything is fine. + new_tip_event(&revaultd, bitcoind, &tip, unvaults_cache)?; + return Ok(current_tip); + } + } + Err(e) => { + // Edge case: the last block *might* (very unlikely but our functional + // tests are exercing this) have been reorged out and the call to `getblockhash` + // would fail telling the height is out of range. + log::error!("Error while fetching block hash in update tip: '{}'", e); + thread::sleep(Duration::from_secs(5)); + return update_tip(revaultd, bitcoind, deposits_cache, unvaults_cache); + } } } @@ -1240,8 +1251,8 @@ fn handle_confirmed_deposit( Ok(()) } -// Called when a deposit UTXO disappears from the listunspent result, ie it was spent. This tries -// to figure out where it went. +// Called when a deposit UTXO disappears from the listunspent result, ie it was spent (or reorg'ed +// out). This tries to figure out where it went. fn handle_spent_deposit( revaultd: &mut Arc>, db_path: &Path,