Skip to content

Commit 5ff8c44

Browse files
committed
mining: add -coinbaselocktime
On by default. Allow Stratum v2 miners to opt out, pending more discussion on the BIP.
1 parent f616f3e commit 5ff8c44

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
663663
argsman.AddArg("-blockreservedweight=<n>", strprintf("Reserve space for the fixed-size block header plus the largest coinbase transaction the mining software may add to the block. (default: %d).", DEFAULT_BLOCK_RESERVED_WEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
664664
argsman.AddArg("-blockmintxfee=<amt>", strprintf("Set lowest fee rate (in %s/kvB) for transactions to be included in block creation. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
665665
argsman.AddArg("-blockversion=<n>", "Override block version to test forking scenarios", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::BLOCK_CREATION);
666+
argsman.AddArg("-coinbaselocktime", strprintf("Set nLockTime to the current block height and nSequence to enforce it (default: %d)", DEFAULT_COINBASE_LOCKTIME), ArgsManager::ALLOW_ANY, OptionsCategory::BLOCK_CREATION);
666667

667668
argsman.AddArg("-rest", strprintf("Accept public REST requests (default: %u)", DEFAULT_REST_ENABLE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
668669
argsman.AddArg("-rpcallowip=<ip>", "Allow JSON-RPC connections from specified source. Valid values for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0), a network/CIDR (e.g. 1.2.3.4/24), all ipv4 (0.0.0.0/0), or all ipv6 (::/0). RFC4193 is allowed only if -cjdnsreachable=0. This option can be specified multiple times", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);

src/node/miner.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void ApplyArgsManOptions(const ArgsManager& args, BlockAssembler::Options& optio
103103
}
104104
options.print_modified_fee = args.GetBoolArg("-printpriority", options.print_modified_fee);
105105
options.block_reserved_weight = args.GetIntArg("-blockreservedweight", options.block_reserved_weight);
106+
options.coinbase_locktime = args.GetBoolArg("-coinbaselocktime", DEFAULT_COINBASE_LOCKTIME);
106107
}
107108

108109
void BlockAssembler::resetBlock()
@@ -161,13 +162,17 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock()
161162
CMutableTransaction coinbaseTx;
162163
coinbaseTx.vin.resize(1);
163164
coinbaseTx.vin[0].prevout.SetNull();
164-
coinbaseTx.vin[0].nSequence = CTxIn::MAX_SEQUENCE_NONFINAL; // Make sure timelock is enforced.
165+
if (m_options.coinbase_locktime) {
166+
coinbaseTx.vin[0].nSequence = CTxIn::MAX_SEQUENCE_NONFINAL; // Make sure timelock is enforced.
167+
}
165168
coinbaseTx.vout.resize(1);
166169
coinbaseTx.vout[0].scriptPubKey = m_options.coinbase_output_script;
167170
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
168171
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
169172
Assert(nHeight > 0);
170-
coinbaseTx.nLockTime = static_cast<uint32_t>(nHeight - 1);
173+
if (m_options.coinbase_locktime) {
174+
coinbaseTx.nLockTime = static_cast<uint32_t>(nHeight - 1);
175+
}
171176
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
172177
pblocktemplate->vchCoinbaseCommitment = m_chainstate.m_chainman.GenerateCoinbaseCommitment(*pblock, pindexPrev);
173178

src/node/miner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class BlockAssembler
173173
// Configuration parameters for the block size
174174
size_t nBlockMaxWeight{DEFAULT_BLOCK_MAX_WEIGHT};
175175
CFeeRate blockMinFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
176+
// Whether to set nLockTime to the current height
177+
bool coinbase_locktime{DEFAULT_COINBASE_LOCKTIME};
176178
// Whether to call TestBlockValidity() at the end of CreateNewBlock().
177179
bool test_block_validity{true};
178180
bool print_modified_fee{DEFAULT_PRINT_MODIFIED_FEE};

src/policy/policy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ static constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT{8000};
3030
static constexpr unsigned int MINIMUM_BLOCK_RESERVED_WEIGHT{2000};
3131
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
3232
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1000};
33+
/** Default for -coinbaselocktime, which sets the coinbase nLockTime (and nSequence) in blocks created by mining code **/
34+
static constexpr bool DEFAULT_COINBASE_LOCKTIME{true};
3335
/** The maximum weight for transactions we're willing to relay/mine */
3436
static constexpr int32_t MAX_STANDARD_TX_WEIGHT{400000};
3537
/** The minimum non-witness size for transactions we're willing to relay/mine: one larger than 64 */

0 commit comments

Comments
 (0)