Skip to content

Commit 2d18a07

Browse files
committed
rpc: add target and bits to getchainstates
1 parent f153f57 commit 2d18a07

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/rpc/blockchain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,6 +3308,8 @@ static RPCHelpMan loadtxoutset()
33083308
const std::vector<RPCResult> RPCHelpForChainstate{
33093309
{RPCResult::Type::NUM, "blocks", "number of blocks in this chainstate"},
33103310
{RPCResult::Type::STR_HEX, "bestblockhash", "blockhash of the tip"},
3311+
{RPCResult::Type::STR_HEX, "bits", "nBits: compact representation of the block difficulty target"},
3312+
{RPCResult::Type::STR_HEX, "target", "The difficulty target"},
33113313
{RPCResult::Type::NUM, "difficulty", "difficulty of the tip"},
33123314
{RPCResult::Type::NUM, "verificationprogress", "progress towards the network tip"},
33133315
{RPCResult::Type::STR_HEX, "snapshot_blockhash", /*optional=*/true, "the base block of the snapshot this chainstate is based on, if any"},
@@ -3350,6 +3352,8 @@ return RPCHelpMan{
33503352

33513353
data.pushKV("blocks", (int)chain.Height());
33523354
data.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
3355+
data.pushKV("bits", strprintf("%08x", tip->nBits));
3356+
data.pushKV("target", GetTarget(*tip, chainman.GetConsensus().powLimit).GetHex());
33533357
data.pushKV("difficulty", GetDifficulty(*tip));
33543358
data.pushKV("verificationprogress", chainman.GuessVerificationProgress(tip));
33553359
data.pushKV("coins_db_cache_bytes", cs.m_coinsdb_cache_size_bytes);

test/functional/feature_assumeutxo.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
getnewdestination,
3939
MiniWallet,
4040
)
41+
from test_framework.blocktools import (
42+
REGTEST_N_BITS,
43+
REGTEST_TARGET,
44+
nbits_str,
45+
target_str,
46+
)
4147

4248
START_HEIGHT = 199
4349
SNAPSHOT_BASE_HEIGHT = 299
@@ -229,6 +235,12 @@ def test_snapshot_in_a_divergent_chain(self, dump_output_path):
229235
assert_equal(normal['blocks'], START_HEIGHT + 99)
230236
assert_equal(snapshot['blocks'], SNAPSHOT_BASE_HEIGHT)
231237

238+
# Both states should have the same nBits and target
239+
assert_equal(normal['bits'], nbits_str(REGTEST_N_BITS))
240+
assert_equal(normal['bits'], snapshot['bits'])
241+
assert_equal(normal['target'], target_str(REGTEST_TARGET))
242+
assert_equal(normal['target'], snapshot['target'])
243+
232244
# Now lets sync the nodes and wait for the background validation to finish
233245
self.connect_nodes(0, 3)
234246
self.sync_blocks(nodes=(n0, n3))

0 commit comments

Comments
 (0)