mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
rpc: add target and bits to getchainstates
This commit is contained in:
parent
590d3ab92c
commit
4463b0e04c
2 changed files with 16 additions and 0 deletions
|
@ -3357,6 +3357,8 @@ static RPCHelpMan loadtxoutset()
|
|||
const std::vector<RPCResult> RPCHelpForChainstate{
|
||||
{RPCResult::Type::NUM, "blocks", "number of blocks in this chainstate"},
|
||||
{RPCResult::Type::STR_HEX, "bestblockhash", "blockhash of the tip"},
|
||||
{RPCResult::Type::STR_HEX, "bits", "nBits: compact representation of the block difficulty target"},
|
||||
{RPCResult::Type::STR_HEX, "target", "The difficulty target"},
|
||||
{RPCResult::Type::NUM, "difficulty", "difficulty of the tip"},
|
||||
{RPCResult::Type::NUM, "verificationprogress", "progress towards the network tip"},
|
||||
{RPCResult::Type::STR_HEX, "snapshot_blockhash", /*optional=*/true, "the base block of the snapshot this chainstate is based on, if any"},
|
||||
|
@ -3399,6 +3401,8 @@ return RPCHelpMan{
|
|||
|
||||
data.pushKV("blocks", (int)chain.Height());
|
||||
data.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
|
||||
data.pushKV("bits", strprintf("%08x", tip->nBits));
|
||||
data.pushKV("target", GetTarget(*tip, chainman.GetConsensus().powLimit).GetHex());
|
||||
data.pushKV("difficulty", GetDifficulty(*tip));
|
||||
data.pushKV("verificationprogress", chainman.GuessVerificationProgress(tip));
|
||||
data.pushKV("coins_db_cache_bytes", cs.m_coinsdb_cache_size_bytes);
|
||||
|
|
|
@ -38,6 +38,12 @@ from test_framework.wallet import (
|
|||
getnewdestination,
|
||||
MiniWallet,
|
||||
)
|
||||
from test_framework.blocktools import (
|
||||
REGTEST_N_BITS,
|
||||
REGTEST_TARGET,
|
||||
nbits_str,
|
||||
target_str,
|
||||
)
|
||||
|
||||
START_HEIGHT = 199
|
||||
SNAPSHOT_BASE_HEIGHT = 299
|
||||
|
@ -229,6 +235,12 @@ class AssumeutxoTest(BitcoinTestFramework):
|
|||
assert_equal(normal['blocks'], START_HEIGHT + 99)
|
||||
assert_equal(snapshot['blocks'], SNAPSHOT_BASE_HEIGHT)
|
||||
|
||||
# Both states should have the same nBits and target
|
||||
assert_equal(normal['bits'], nbits_str(REGTEST_N_BITS))
|
||||
assert_equal(normal['bits'], snapshot['bits'])
|
||||
assert_equal(normal['target'], target_str(REGTEST_TARGET))
|
||||
assert_equal(normal['target'], snapshot['target'])
|
||||
|
||||
# Now lets sync the nodes and wait for the background validation to finish
|
||||
self.connect_nodes(0, 3)
|
||||
self.sync_blocks(nodes=(n0, n3))
|
||||
|
|
Loading…
Reference in a new issue