You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge bitcoin/bitcoin#31583: rpc: add target to getmininginfo field and show next block info
a4df123 doc: add release notes (Sjors Provoost)
c75872f test: use DIFF_1_N_BITS in tool_signet_miner (tdb3)
4131f32 test: check difficulty adjustment using alternate mainnet (Sjors Provoost)
c4f68c1 Use OP_0 for BIP34 padding in signet and tests (Sjors Provoost)
cf0a628 rpc: add next to getmininginfo (Sjors Provoost)
2d18a07 rpc: add target and bits to getchainstates (Sjors Provoost)
f153f57 rpc: add target and bits to getblockchaininfo (Sjors Provoost)
baa504f rpc: add target to getmininginfo result (Sjors Provoost)
2a7bfeb Add target to getblock(header) in RPC and REST (Sjors Provoost)
341f932 rpc: add GetTarget helper (Sjors Provoost)
d20d96f test: use REGTEST_N_BITS in feature_block (tdb3)
7ddbed4 rpc: add nBits to getmininginfo (Sjors Provoost)
ba7b9f3 build: move pow and chain to bitcoin_common (Sjors Provoost)
c4cc9e3 consensus: add DeriveTarget() to pow.h (Sjors Provoost)
Pull request description:
**tl&dr for consensus-code only reviewers**: the first commit splits `CheckProofOfWorkImpl()` in order to create a `DeriveTarget()` helper. The rest of this PR does not touch consensus code.
There are three ways to represent the proof-of-work in a block:
1. nBits
2. Difficulty
3. Target
The latter notation is useful when you want to compare share work against either the pool target (to get paid) or network difficulty (found an actual block). E.g. for difficulty 1 which corresponds to an nBits value of `0x00ffff`:
```
share hash: f6b973257df982284715b0c7a20640dad709d22b0b1a58f2f88d35886ea5ac45
target: 7fffff0000000000000000000000000000000000000000000000000000000000
```
It's immediately clear that the share is invalid because the hash is above the target.
This type of logging is mostly done by the pool software. It's a nice extra convenience, but not very important. It impacts the following RPC calls:
1. `getmininginfo` displays the `target` for the tip block
2. `getblock` and `getblockheader` display the `target` for a specific block (ditto for their REST equivalents)
The `getdifficulty` method is a bit useless in its current state, because what miners really want to know if the difficulty for the _next_ block. So I added a boolean argument `next` to `getdifficulty`. (These values are typically the same, except for the first block in a retarget period. On testnet3 / testnet4 they change when no block is found after 20 minutes).
Similarly I added a `next` object to `getmininginfo` which shows `bit`, `difficulty` and `target` for the next block.
In order to test the difficulty transition, an alternate mainnet chain with 2016 blocks was generated and used in `mining_mainnet.py`. The chain is deterministic except for its timestamp and nonce values, which are stored in `mainnet_alt.json`.
As described at the top, this PR introduces a helper method `DeriveTarget()` which is split out from `CheckProofOfWorkImpl`. The proposed `checkblock` RPC in #31564 needs this helper method internally to figure out the consensus target.
Finally, this PR moves `pow.cpp` and `chain.cpp` from `bitcoin_node` to `bitcoin_common`, in order to give `rpc/util.cpp` (which lives in `bitcoin_common`) access to `pow.h`.
ACKs for top commit:
ismaelsadeeq:
re-ACK a4df123
tdb3:
code review re ACK a4df123
ryanofsky:
Code review ACK a4df123. Only overall changes since last review were dropping new `gettarget` method and dropping changes to `getdifficulty`, but there were also various internal changes splitting and rearranging commits.
Tree-SHA512: edef5633590379c4be007ac96fd1deda8a5b9562ca6ff19fe377cb552b5166f3890d158554c249ab8345977a06da5df07866c9f42ac43ee83dfe3830c61cd169
-`getmininginfo` now returns `nBits` and the current target in the `target` field. It also returns a `next` object which specifies the `height`, `nBits`, `difficulty`, and `target` for the next block.
4
+
-`getblock` and `getblockheader` now return the current target in the `target` field
5
+
-`getblockchaininfo` and `getchainstates` now return `nBits` and the current target in the `target` field
6
+
7
+
REST interface
8
+
---
9
+
-`GET /rest/block/<BLOCK-HASH>.json` and `GET /rest/headers/<BLOCK-HASH>.json` now return the current target in the `target` field
{RPCResult::Type::NUM, "blocks", "The current block"},
422
422
{RPCResult::Type::NUM, "currentblockweight", /*optional=*/true, "The block weight of the last assembled block (only present if a block was ever assembled)"},
423
423
{RPCResult::Type::NUM, "currentblocktx", /*optional=*/true, "The number of block transactions of the last assembled block (only present if a block was ever assembled)"},
424
+
{RPCResult::Type::STR_HEX, "bits", "The current nBits, compact representation of the block difficulty target"},
424
425
{RPCResult::Type::NUM, "difficulty", "The current difficulty"},
426
+
{RPCResult::Type::STR_HEX, "target", "The current target"},
425
427
{RPCResult::Type::NUM, "networkhashps", "The network hashes per second"},
426
428
{RPCResult::Type::NUM, "pooledtx", "The size of the mempool"},
427
429
{RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"},
428
430
{RPCResult::Type::STR_HEX, "signet_challenge", /*optional=*/true, "The block challenge (aka. block script), in hexadecimal (only present if the current network is a signet)"},
431
+
{RPCResult::Type::OBJ, "next", "The next block",
432
+
{
433
+
{RPCResult::Type::NUM, "height", "The next height"},
434
+
{RPCResult::Type::STR_HEX, "bits", "The next target nBits"},
435
+
{RPCResult::Type::NUM, "difficulty", "The next difficulty"},
436
+
{RPCResult::Type::STR_HEX, "target", "The next target"}
437
+
}},
429
438
(IsDeprecatedRPCEnabled("warnings") ?
430
439
RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} :
431
440
RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)",
0 commit comments