Skip to content

Commit

Permalink
make sure fields are not present when tip is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Sep 11, 2024
1 parent a0c9ce6 commit 97d437f
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions zebra-rpc/src/methods/get_block_template_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,22 +1017,29 @@ where
let chain_tip = self.latest_chain_tip.clone();
let tip_height = chain_tip.best_tip_height().unwrap_or(Height(0)).0;

let mined_tx_ids = chain_tip.best_tip_mined_transaction_ids();
let current_block_tx = (!mined_tx_ids.is_empty()).then(|| mined_tx_ids.len());
let mut current_block_tx = None;
if tip_height > 0 {
let mined_tx_ids = chain_tip.best_tip_mined_transaction_ids();
current_block_tx =
(!mined_tx_ids.is_empty()).then(|| mined_tx_ids.len().saturating_sub(1));
}

let solution_rate_fut = self.get_network_sol_ps(None, None);
async move {
// Get the current block size.
let request = zebra_state::ReadRequest::TipBlockSize;
let response: zebra_state::ReadResponse = state
.ready()
.and_then(|service| service.call(request))
.await
.map_server_error()?;
let current_block_size = match response {
zebra_state::ReadResponse::TipBlockSize(Some(block_size)) => Some(block_size),
_ => None,
};
let mut current_block_size = None;
if tip_height > 0 {
let request = zebra_state::ReadRequest::TipBlockSize;
let response: zebra_state::ReadResponse = state
.ready()
.and_then(|service| service.call(request))
.await
.map_server_error()?;
current_block_size = match response {
zebra_state::ReadResponse::TipBlockSize(Some(block_size)) => Some(block_size),
_ => None,
};
}

Ok(get_mining_info::Response::new(
tip_height,
Expand Down

0 comments on commit 97d437f

Please sign in to comment.