Merge #160: commands: remove discrepancy between blockheight and block_height

dc61a1c3bdc1b77a6dfd857bec65db687709bc55 commands: remove discrepancy between blockheight and block_height (Antoine Poinsot)

Pull request description:

  This removes one inconsistencies. Quickly skimming through the doc i didn't find any other.

  Fixes #64.

ACKs for top commit:
  edouardparis:
    utACK dc61a1c3bdc1b77a6dfd857bec65db687709bc55

Tree-SHA512: dccff594673ffe34048ab5ad931005c7927e0835501b8377e0b0c8fac9a8d3e5a5f8b3372bd89b3ec33b5f377aecd47164f54ee1a622c9cb375227f4c2009f1b
This commit is contained in:
Antoine Poinsot 2022-12-08 10:09:07 +01:00
commit 801efa3440
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
5 changed files with 22 additions and 22 deletions

View File

@ -50,7 +50,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 | The block height we are synced at. |
| `block_height` | 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 |
| `rescan_progress` | float or null | Progress of an ongoing rescan as a percentage (between 0 and 1) if there is any |
@ -91,7 +91,7 @@ This command does not take any parameter for now.
| -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------ |
| `amount` | int | Value of the TxO in satoshis. |
| `outpoint` | string | Transaction id and output index of this coin. |
| `block_height` | int or null | Blockheight the transaction was confirmed at, or `null`. |
| `block_height` | int or null | Block height the transaction was confirmed at, or `null`. |
| `spend_info` | object | Information about the transaction spending this coin. See [Spending transaction info](#spending_transaction_info). |

View File

@ -201,14 +201,14 @@ impl DaemonControl {
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);
let block_height = db_conn.chain_tip().map(|tip| tip.height).unwrap_or(0);
let rescan_progress = db_conn
.rescan_timestamp()
.map(|_| self.bitcoin.rescan_progress().unwrap_or(1.0));
GetInfoResult {
version: VERSION.to_string(),
network: self.config.bitcoin_config.network,
blockheight,
block_height,
sync: self.bitcoin.sync_progress(),
descriptors: GetInfoDescriptors {
main: self.config.main_descriptor.clone(),
@ -615,7 +615,7 @@ pub struct GetInfoDescriptors {
pub struct GetInfoResult {
pub version: String,
pub network: bitcoin::Network,
pub blockheight: i32,
pub block_height: i32,
pub sync: f64,
pub descriptors: GetInfoDescriptors,
/// The progress as a percentage (between 0 and 1) of an ongoing rescan if there is any

View File

@ -15,41 +15,41 @@ def get_coin(lianad, outpoint_or_txid):
def test_reorg_detection(lianad, bitcoind):
"""Test we detect block chain reorganization under various conditions."""
initial_height = bitcoind.rpc.getblockcount()
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == initial_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == initial_height)
# Re-mine the last block. We should detect it as a reorg.
bitcoind.invalidate_remine(initial_height)
lianad.wait_for_logs(
["Block chain reorganization detected.", "Tip was rolled back."]
)
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == initial_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == initial_height)
# Same if we re-mine the next-to-last block.
bitcoind.invalidate_remine(initial_height - 1)
lianad.wait_for_logs(
["Block chain reorganization detected.", "Tip was rolled back."]
)
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == initial_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == initial_height)
# Same if we re-mine a deep block.
bitcoind.invalidate_remine(initial_height - 50)
lianad.wait_for_logs(
["Block chain reorganization detected.", "Tip was rolled back."]
)
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == initial_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == initial_height)
# Same if the new chain is longer.
bitcoind.simple_reorg(initial_height - 10, shift=20)
lianad.wait_for_logs(
["Block chain reorganization detected.", "Tip was rolled back."]
)
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == initial_height + 10)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == initial_height + 10)
def test_reorg_exclusion(lianad, bitcoind):
"""Test the unconfirmation by a reorg of a coin in various states."""
initial_height = bitcoind.rpc.getblockcount()
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == initial_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == initial_height)
# A confirmed received coin
addr = lianad.rpc.getnewaddress()["address"]
@ -78,7 +78,7 @@ def test_reorg_exclusion(lianad, bitcoind):
# Reorg the chain down to the initial height, excluding all transactions.
current_height = bitcoind.rpc.getblockcount()
bitcoind.simple_reorg(initial_height, shift=-1)
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == current_height + 1)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == current_height + 1)
# They must all be marked as unconfirmed.
new_coin_a = get_coin(lianad, coin_a["outpoint"])
@ -99,7 +99,7 @@ def test_reorg_exclusion(lianad, bitcoind):
bitcoind.rpc.sendrawtransaction(c_spend_tx)
bitcoind.generate_block(1, wait_for_mempool=5)
new_height = bitcoind.rpc.getblockcount()
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == new_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == new_height)
assert all(
c["block_height"] == new_height for c in lianad.rpc.listcoins()["coins"]
), (lianad.rpc.listcoins()["coins"], new_height)
@ -145,7 +145,7 @@ def test_reorg_status_recovery(lianad, bitcoind):
txids = [bitcoind.rpc.sendtoaddress(addr, 0.5670) for addr in addresses]
bitcoind.generate_block(1, wait_for_mempool=txids)
initial_height = bitcoind.rpc.getblockcount()
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == initial_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == initial_height)
# Both coins are confirmed. Spend the second one then get their infos.
wait_for(lambda: len(list_coins()) == 2)
@ -162,7 +162,7 @@ def test_reorg_status_recovery(lianad, bitcoind):
# spending the second coin will be mined at the height the reorg happened).
bitcoind.simple_reorg(initial_height, shift=0)
new_height = bitcoind.rpc.getblockcount()
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == new_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == new_height)
new_coin_a = get_coin(lianad, coin_a["outpoint"])
assert coin_a == new_coin_a
new_coin_b = get_coin(lianad, coin_b["outpoint"])
@ -178,7 +178,7 @@ def test_rescan_edge_cases(lianad, bitcoind):
list_coins = lambda: lianad.rpc.listcoins()["coins"]
sorted_coins = lambda: sorted(list_coins(), key=lambda c: c["outpoint"])
wait_synced = lambda: wait_for(
lambda: lianad.rpc.getinfo()["blockheight"] == bitcoind.rpc.getblockcount()
lambda: lianad.rpc.getinfo()["block_height"] == bitcoind.rpc.getblockcount()
)
def reorg_shift(height, txs):

View File

@ -157,7 +157,7 @@ class Lianad(TailableProc):
bitcoind.node_rpc.unloadwallet(wallet_path)
self.start()
wait_for(
lambda: self.rpc.getinfo()["blockheight"] == bitcoind.rpc.getblockcount()
lambda: self.rpc.getinfo()["block_height"] == bitcoind.rpc.getblockcount()
)
def start(self):

View File

@ -11,7 +11,7 @@ def test_getinfo(lianad):
res = lianad.rpc.getinfo()
assert res["version"] == "0.1"
assert res["network"] == "regtest"
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == 101)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == 101)
res = lianad.rpc.getinfo()
assert res["sync"] == 1.0
assert "main" in res["descriptors"]
@ -58,7 +58,7 @@ def test_listcoins(lianad, bitcoind):
# And if this spending tx gets confirmed.
bitcoind.generate_block(1, wait_for_mempool=spend_txid)
curr_height = bitcoind.rpc.getblockcount()
wait_for(lambda: lianad.rpc.getinfo()["blockheight"] == curr_height)
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == curr_height)
spend_info = lianad.rpc.listcoins()["coins"][0]["spend_info"]
assert spend_info["txid"] == spend_txid
assert spend_info["height"] == curr_height
@ -315,7 +315,7 @@ def test_start_rescan(lianad, bitcoind):
bitcoind.generate_block(random.randint(1, 5), wait_for_mempool=2)
wait_for(lambda: all_spent(to_spend))
wait_for(
lambda: lianad.rpc.getinfo()["blockheight"] == bitcoind.rpc.getblockcount()
lambda: lianad.rpc.getinfo()["block_height"] == bitcoind.rpc.getblockcount()
)
# Receiving addresses are derived at much higher indexes now.
@ -345,7 +345,7 @@ def test_start_rescan(lianad, bitcoind):
assert rescan_progress is None or 0 <= rescan_progress <= 1
wait_for(lambda: lianad.rpc.getinfo()["rescan_progress"] is None)
wait_for(
lambda: lianad.rpc.getinfo()["blockheight"] == bitcoind.rpc.getblockcount()
lambda: lianad.rpc.getinfo()["block_height"] == bitcoind.rpc.getblockcount()
)
assert coins_before == sorted_coins()
@ -366,7 +366,7 @@ def test_listtransactions(lianad, bitcoind):
def wait_synced():
wait_for(
lambda: lianad.rpc.getinfo()["blockheight"] == bitcoind.rpc.getblockcount()
lambda: lianad.rpc.getinfo()["block_height"] == bitcoind.rpc.getblockcount()
)
best_block = bitcoind.rpc.getbestblockhash()