From 57add1d86bb734b0f5291b2f266ef5652c93bc8d Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Mon, 17 Oct 2022 09:54:06 +0200 Subject: [PATCH] commands: return the DB's block height in 'getinfo' It makes more sense than to return the Bitcoin backend's. And it's helpful to wait for sync in functional tests. --- doc/API.md | 2 +- src/commands/mod.rs | 8 +++++++- tests/test_rpc.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/doc/API.md b/doc/API.md index 691ca44b..5c2cdb9b 100644 --- a/doc/API.md +++ b/doc/API.md @@ -45,7 +45,7 @@ This command does not take any parameter for now. | -------------------- | ------- | -------------------------------------------------------------------------------------------- | | `version` | string | Version following the [SimVer](http://www.simver.org/) format | | `network` | string | Answer can be `mainnet`, `testnet`, `regtest` | -| `blockheight` | integer | Current block height | +| `blockheight` | integer | The block height we are synced at. | | `sync` | float | The synchronization progress as percentage (`0 < sync < 1`) | | `descriptors` | object | Object with the name of the descriptor as key and the descriptor string as value | diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 284b2715..b237998e 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -167,10 +167,16 @@ impl DaemonControl { impl DaemonControl { /// Get information about the current state of the daemon pub fn get_info(&self) -> GetInfoResult { + let mut db_conn = self.db.connection(); + + let blockheight = db_conn + .chain_tip() + .map(|tip| tip.height) + .unwrap_or(0); GetInfoResult { version: VERSION.to_string(), network: self.config.bitcoin_config.network, - blockheight: self.bitcoin.chain_tip().height, + blockheight, sync: self.bitcoin.sync_progress(), descriptors: GetInfoDescriptors { main: self.config.main_descriptor.clone(), diff --git a/tests/test_rpc.py b/tests/test_rpc.py index 89030860..93ec85ab 100644 --- a/tests/test_rpc.py +++ b/tests/test_rpc.py @@ -7,7 +7,7 @@ def test_getinfo(minisafed): res = minisafed.rpc.getinfo() assert res["version"] == "0.1" assert res["network"] == "regtest" - assert res["blockheight"] == 101 + wait_for(lambda: res["blockheight"] == 101) assert res["sync"] == 1.0 assert "main" in res["descriptors"]