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.
This commit is contained in:
Antoine Poinsot 2022-10-17 09:54:06 +02:00
parent 92f7ef1225
commit 57add1d86b
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
3 changed files with 9 additions and 3 deletions

View File

@ -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 |

View File

@ -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(),

View File

@ -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"]