Skip to content

Commit

Permalink
Merge pull request #3898 from bradleystachurski/devimint-get-block-count
Browse files Browse the repository at this point in the history
refactor(devimint): add get_block_count to bitcoind
  • Loading branch information
elsirion committed Dec 9, 2023
2 parents 747585f + 022a8a6 commit 5ac87ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 9 additions & 0 deletions devimint/src/external.rs
Expand Up @@ -120,6 +120,15 @@ impl Bitcoind {
self.client.clone()
}

/// Returns the total number of blocks in the chain.
///
/// Fedimint's IBitcoindRpc considers block count the total number of
/// blocks, where bitcoind's rpc returns the height. Since the genesis
/// block has height 0, we need to add 1 to get the total block count.
pub fn get_block_count(&self) -> Result<u64> {
Ok(self.client().get_block_count()? + 1)
}

pub async fn mine_blocks(&self, block_num: u64) -> Result<()> {
info!(target: LOG_DEVIMINT, ?block_num, "Mining bitcoin blocks");
let client = self.client();
Expand Down
6 changes: 1 addition & 5 deletions devimint/src/federation.rs
Expand Up @@ -5,7 +5,6 @@ use std::{env, fs};

use anyhow::{anyhow, bail, Context, Result};
use bitcoincore_rpc::bitcoin::Network;
use bitcoincore_rpc::RpcApi;
use fedimint_core::admin_client::{
ConfigGenConnectionsRequest, ConfigGenParamsRequest, WsAdminClient,
};
Expand Down Expand Up @@ -219,10 +218,7 @@ impl Federation {

pub async fn await_block_sync(&self) -> Result<u64> {
let finality_delay = self.get_finality_delay().await?;
// Fedimint's IBitcoindRpc considers block count the total number of blocks,
// where bitcoind's rpc returns the height. Since the genesis block has height
// 0, we need to add 1 to get the total block count.
let block_count = self.bitcoind.client().get_block_count()? + 1;
let block_count = self.bitcoind.get_block_count()?;
let expected = block_count.saturating_sub(finality_delay.into());
cmd!(self, "dev", "wait-block-count", expected)
.run()
Expand Down

0 comments on commit 5ac87ab

Please sign in to comment.