Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions changelog.d/rpc-core-header-shape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Fixed

- **Block header and block RPC match Bitcoin Core's JSON for inactive
headers, genesis, and difficulty text.** `getblockheader` and `getblock`
return a stored header that is no longer on the active chain
(`confirmations: -1`, its own `previousblockhash`, and a Class A body when
one exists). Genesis omits `previousblockhash`. `getblockheader` includes
`nextblockhash` and `target`. `getblockchaininfo` includes `bits` and
`target`. Difficulty uses 16 significant digits. `validateaddress` reports
`isscript` for P2TR and P2A and omits witness fields on pay-to-anchor.
`getmempoolinfo` includes `fullrbf`, `maxdatacarriersize` (null), and the
cluster limits. BTC amounts print as 8-decimal numbers.
2 changes: 1 addition & 1 deletion crates/rbitcoin-mempool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub use fee_est::{
pub use fee_flow::FeeFlowMeter;
pub use graph::{
frontier_feerate_from_chunks, weight_above_from_chunks, Chunk, Cluster, MempoolGraphStats,
SelectBudget, Selected, TxEntry, TxGraph,
SelectBudget, Selected, TxEntry, TxGraph, MAX_CLUSTER_COUNT, MAX_CLUSTER_VSIZE,
};
pub use orphanage::{OrphanSnapshot, Orphanage};
pub use packed::VinAux;
Expand Down
17 changes: 17 additions & 0 deletions crates/rbitcoin-net/src/tx_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3071,6 +3071,23 @@ impl MempoolHub {
Some((stats, a_mod, d_mod, chunk_fee, chunk_w))
}

/// Core `-limitclustercount` and `-limitclustersize` (count, vbytes).
pub fn cluster_limits(&self) -> (u32, u64) {
let g = self.lock_read();
(
g.graph.cluster_count_limit() as u32,
g.graph.cluster_vsize_limit(),
)
}

/// Defaults when no hub is attached (`MAX_CLUSTER_COUNT`, `MAX_CLUSTER_VSIZE`).
pub fn default_cluster_limits() -> (u32, u64) {
(
rbitcoin_mempool::MAX_CLUSTER_COUNT as u32,
rbitcoin_mempool::MAX_CLUSTER_VSIZE,
)
}

/// Cluster count/size overlay (`None` = keep default).
pub fn set_cluster_limits(&self, count: Option<u32>, size_kvb: Option<u32>) {
self.lock_write().set_cluster_limits(count, size_kvb);
Expand Down
4 changes: 1 addition & 3 deletions crates/rbitcoin-node/src/health/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ fn chain_gauges(out: &mut Exposition, chain: &ChainHub, sh_index: bool) {
"Seconds since the tip block time.",
age,
);
let difficulty = rec.map_or(0.0, |(_, rec)| {
rbitcoin_consensus::difficulty_from_bits(rec.bits)
});
let difficulty = rec.map_or(0.0, |(_, rec)| rbitcoin_rpc::difficulty_rpc_f64(rec.bits));
out.gauge(
"rbitcoin_difficulty",
"Tip difficulty (getblockchaininfo.difficulty).",
Expand Down
16 changes: 16 additions & 0 deletions crates/rbitcoin-query/src/chain_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ impl Query {
Ok(g.map.get(hash).copied().map(Height))
}

/// Active-chain height of a hash already loaded from the header archive.
///
/// Skips the extra header read in [`Self::height_of_hash`]. An ancestry
/// walk then costs one `prev_fk` read per step plus this index.
pub fn confirmed_height_of_hash(&self, hash: &[u8; 32]) -> Result<Option<Height>, QueryError> {
let Some(tip) = self.tip_height() else {
return Ok(None);
};
self.ensure_height_by_hash_index(tip)?;
let g = self
.height_by_hash
.lock()
.unwrap_or_else(|e| e.into_inner());
Ok(g.map.get(hash).copied().map(Height))
}

/// Ensure height index matches `tip`.
///
/// Incremental for any `new_tip ≠ prev_tip`. Full walk only when the map
Expand Down
2 changes: 1 addition & 1 deletion crates/rbitcoin-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tower = { workspace = true }
tower-http = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_json = { workspace = true, features = ["arbitrary_precision"] }
getrandom = "0.4"
base64 = "0.23"

Expand Down
3 changes: 2 additions & 1 deletion crates/rbitcoin-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ mod server;

pub use auth::{default_socket_path, default_token_path, read_cookie_file, RpcAuth};
pub use methods::{
gbt_template, submit_received_block, RpcActive, RpcContext, RpcRegtest, SubmitBlockOutcome,
difficulty_rpc_f64, gbt_template, submit_received_block, RpcActive, RpcContext, RpcRegtest,
SubmitBlockOutcome,
};
pub use server::{run_rpc, RpcConfig, RpcHandle, DEFAULT_RPC_WORK_QUEUE, RPC_MAX_HTTP_BODY};

Expand Down
Loading
Loading