Skip to content

Commit f1afd72

Browse files
committed
rpc: show coinbase reservations in getblocktemplate
Behind the debug flag.
1 parent aa0176a commit f1afd72

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/node/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ void BlockAssembler::resetBlock()
9595
inBlock.clear();
9696

9797
// Reserve space for coinbase tx
98-
nBlockWeight = 4000;
99-
nBlockSigOpsCost = 400;
98+
nBlockWeight = COINBASE_RESERVED_WEIGHT;
99+
nBlockSigOpsCost = COINBASE_RESERVED_SIGOPS;
100100

101101
// These counters do not include coinbase tx
102102
nBlockTx = 0;

src/node/miner.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class ChainstateManager;
2929

3030
namespace Consensus { struct Params; };
3131

32+
static const uint64_t COINBASE_RESERVED_WEIGHT = 4000;
33+
static const uint64_t COINBASE_RESERVED_SIGOPS = 400;
34+
3235
namespace node {
3336
static const bool DEFAULT_PRINTPRIORITY = false;
3437

src/rpc/mining.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,11 @@ static RPCHelpMan getblocktemplate()
623623
}},
624624
{RPCResult::Type::STR_HEX, "noncerange", "A range of valid nonces"},
625625
{RPCResult::Type::NUM, "sigops", /*optional=*/true, "number of sigops in the next block (debug only)"},
626+
{RPCResult::Type::NUM, "coinbase_reserved_sigops", /*optional=*/true, "number of sigops the coinbase can safely use (debug only)"},
626627
{RPCResult::Type::NUM, "sigoplimit", "limit of sigops in blocks"},
627628
{RPCResult::Type::NUM, "sizelimit", "limit of block size"},
628-
{RPCResult::Type::NUM, "weightlimit", /*optional=*/true, "limit of block weight"},
629+
{RPCResult::Type::NUM, "weightlimit", "limit of block weight"},
630+
{RPCResult::Type::NUM, "coinbase_reserved_weight", /*optional=*/true, "maximum weight the coinbase can safely use (debug only)"},
629631
{RPCResult::Type::NUM_TIME, "curtime", "current timestamp in " + UNIX_EPOCH_TIME},
630632
{RPCResult::Type::STR, "bits", "compressed target of next block"},
631633
{RPCResult::Type::NUM, "height", "The height of the next block"},
@@ -930,13 +932,15 @@ static RPCHelpMan getblocktemplate()
930932

931933
// Belt-and-suspenders check for the sigops limit:
932934
const int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST;
933-
CHECK_NONFATAL(block_sigops <= MAX_BLOCK_SIGOPS_COST);
935+
CHECK_NONFATAL(block_sigops + COINBASE_RESERVED_SIGOPS <= MAX_BLOCK_SIGOPS_COST);
934936
if (debug) result.pushKV("sigops", block_sigops);
937+
if (debug) result.pushKV("coinbase_reserved_sigops", COINBASE_RESERVED_SIGOPS);
935938
result.pushKV("sigoplimit", nSigOpLimit);
936939

937940
int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE;
938941
result.pushKV("sizelimit", nSizeLimit);
939942
result.pushKV("weightlimit", (int64_t)MAX_BLOCK_WEIGHT);
943+
if (debug) result.pushKV("coinbase_reserved_weight", COINBASE_RESERVED_WEIGHT);
940944
result.pushKV("curtime", pblock->GetBlockTime());
941945
result.pushKV("bits", strprintf("%08x", pblock->nBits));
942946
result.pushKV("height", (int64_t)(pindexPrev->nHeight+1));

0 commit comments

Comments
 (0)