Skip to content

Commit df562d6

Browse files
committed
Merge bitcoin/bitcoin#23637: miner: Remove uncompiled MTP code
fa46ac4 miner: Remove uncompiled MTP code (MarcoFalke) fa6b7ad style: Add {} to if-bodies in node/miner (MarcoFalke) Pull request description: This removes uncompiled code. Can be checked by inserting `static_assert(STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)` and compiling or by reading the source code. Even if the code was compiled, it would be unsafe to execute, since it is not allowed to include transactions that are locked until some time after the current MTP. Also, rename the member to cause explicit merge conflicts in case there is a patch out there referencing the variable. ACKs for top commit: shaavan: ACK fa46ac4 theStack: Code-review ACK fa46ac4 Tree-SHA512: 0288f45918996b58d0c0060773aa3cb15c828a649439f3d589c5d6b4854d6da1d8c2ea11d5ca06c654532453ab5ce1892de7ca820e284e96e78b959ef87cac5c
2 parents 4633199 + fa46ac4 commit df562d6

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

src/node/miner.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
3030
{
3131
int64_t nOldTime = pblock->nTime;
32-
int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
32+
int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime());
3333

34-
if (nOldTime < nNewTime)
34+
if (nOldTime < nNewTime) {
3535
pblock->nTime = nNewTime;
36+
}
3637

3738
// Updating time can change work required on testnet:
38-
if (consensusParams.fPowAllowMinDifficultyBlocks)
39+
if (consensusParams.fPowAllowMinDifficultyBlocks) {
3940
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
41+
}
4042

4143
return nNewTime - nOldTime;
4244
}
@@ -53,7 +55,8 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
5355
block.hashMerkleRoot = BlockMerkleRoot(block);
5456
}
5557

56-
BlockAssembler::Options::Options() {
58+
BlockAssembler::Options::Options()
59+
{
5760
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
5861
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
5962
}
@@ -108,8 +111,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
108111

109112
pblocktemplate.reset(new CBlockTemplate());
110113

111-
if(!pblocktemplate.get())
114+
if (!pblocktemplate.get()) {
112115
return nullptr;
116+
}
113117
CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
114118

115119
// Add dummy coinbase tx as first transaction
@@ -125,15 +129,12 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
125129
pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
126130
// -regtest only: allow overriding block.nVersion with
127131
// -blockversion=N to test forking scenarios
128-
if (chainparams.MineBlocksOnDemand())
132+
if (chainparams.MineBlocksOnDemand()) {
129133
pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
134+
}
130135

131136
pblock->nTime = GetAdjustedTime();
132-
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
133-
134-
nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
135-
? nMedianTimePast
136-
: pblock->GetBlockTime();
137+
m_lock_time_cutoff = pindexPrev->GetMedianTimePast();
137138

138139
// Decide whether to include witness transactions
139140
// This is only needed in case the witness softfork activation is reverted
@@ -193,8 +194,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
193194
// Only test txs not already in the block
194195
if (inBlock.count(*iit)) {
195196
testSet.erase(iit++);
196-
}
197-
else {
197+
} else {
198198
iit++;
199199
}
200200
}
@@ -203,10 +203,12 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
203203
bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const
204204
{
205205
// TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
206-
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight)
206+
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) {
207207
return false;
208-
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST)
208+
}
209+
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
209210
return false;
211+
}
210212
return true;
211213
}
212214

@@ -217,10 +219,12 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
217219
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
218220
{
219221
for (CTxMemPool::txiter it : package) {
220-
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
222+
if (!IsFinalTx(it->GetTx(), nHeight, m_lock_time_cutoff)) {
221223
return false;
222-
if (!fIncludeWitness && it->GetTx().HasWitness())
224+
}
225+
if (!fIncludeWitness && it->GetTx().HasWitness()) {
223226
return false;
227+
}
224228
}
225229
return true;
226230
}
@@ -253,8 +257,9 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
253257
m_mempool.CalculateDescendants(it, descendants);
254258
// Insert all descendants (not yet in block) into the modified set
255259
for (CTxMemPool::txiter desc : descendants) {
256-
if (alreadyAdded.count(desc))
260+
if (alreadyAdded.count(desc)) {
257261
continue;
262+
}
258263
++nDescendantsUpdated;
259264
modtxiter mit = mapModifiedTx.find(desc);
260265
if (mit == mapModifiedTx.end()) {
@@ -280,7 +285,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
280285
// guaranteed to fail again, but as a belt-and-suspenders check we put it in
281286
// failedTx and avoid re-evaluation, since the re-evaluation would be using
282287
// cached size/sigops/fee values that are not actually correct.
283-
bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, CTxMemPool::setEntries &failedTx)
288+
bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx)
284289
{
285290
assert(it != m_mempool.mapTx.end());
286291
return mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it);
@@ -307,7 +312,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
307312
// Each time through the loop, we compare the best transaction in
308313
// mapModifiedTxs with the next transaction in the mempool to decide what
309314
// transaction package to work on next.
310-
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated)
315+
void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated)
311316
{
312317
// mapModifiedTx will store sorted packages after they are modified
313318
// because some of their txs are already in the block
@@ -423,7 +428,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
423428
std::vector<CTxMemPool::txiter> sortedEntries;
424429
SortForBlock(ancestors, sortedEntries);
425430

426-
for (size_t i=0; i<sortedEntries.size(); ++i) {
431+
for (size_t i = 0; i < sortedEntries.size(); ++i) {
427432
AddToBlock(sortedEntries[i]);
428433
// Erase from the modified set, if present
429434
mapModifiedTx.erase(sortedEntries[i]);
@@ -440,13 +445,12 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
440445
{
441446
// Update nExtraNonce
442447
static uint256 hashPrevBlock;
443-
if (hashPrevBlock != pblock->hashPrevBlock)
444-
{
448+
if (hashPrevBlock != pblock->hashPrevBlock) {
445449
nExtraNonce = 0;
446450
hashPrevBlock = pblock->hashPrevBlock;
447451
}
448452
++nExtraNonce;
449-
unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
453+
unsigned int nHeight = pindexPrev->nHeight + 1; // Height first in coinbase required for block.version=2
450454
CMutableTransaction txCoinbase(*pblock->vtx[0]);
451455
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce));
452456
assert(txCoinbase.vin[0].scriptSig.size() <= 100);

src/node/miner.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ struct modifiedentry_iter {
8080
// This is sufficient to sort an ancestor package in an order that is valid
8181
// to appear in a block.
8282
struct CompareTxIterByAncestorCount {
83-
bool operator()(const CTxMemPool::txiter &a, const CTxMemPool::txiter &b) const
83+
bool operator()(const CTxMemPool::txiter& a, const CTxMemPool::txiter& b) const
8484
{
85-
if (a->GetCountWithAncestors() != b->GetCountWithAncestors())
85+
if (a->GetCountWithAncestors() != b->GetCountWithAncestors()) {
8686
return a->GetCountWithAncestors() < b->GetCountWithAncestors();
87+
}
8788
return CompareIteratorByHash()(a, b);
8889
}
8990
};
@@ -143,7 +144,8 @@ class BlockAssembler
143144

144145
// Chain context for the block
145146
int nHeight;
146-
int64_t nLockTimeCutoff;
147+
int64_t m_lock_time_cutoff;
148+
147149
const CChainParams& chainparams;
148150
const CTxMemPool& m_mempool;
149151
CChainState& m_chainstate;

0 commit comments

Comments
 (0)