mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-10 04:33:59 +01:00
Merge bitcoin/bitcoin#23637: miner: Remove uncompiled MTP code
fa46ac4d9dminer: Remove uncompiled MTP code (MarcoFalke)fa6b7adf96style: 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: ACKfa46ac4d9dtheStack: Code-review ACKfa46ac4d9dTree-SHA512: 0288f45918996b58d0c0060773aa3cb15c828a649439f3d589c5d6b4854d6da1d8c2ea11d5ca06c654532453ab5ce1892de7ca820e284e96e78b959ef87cac5c
This commit is contained in:
@@ -31,12 +31,14 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
|
||||
int64_t nOldTime = pblock->nTime;
|
||||
int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime());
|
||||
|
||||
if (nOldTime < nNewTime)
|
||||
if (nOldTime < nNewTime) {
|
||||
pblock->nTime = nNewTime;
|
||||
}
|
||||
|
||||
// Updating time can change work required on testnet:
|
||||
if (consensusParams.fPowAllowMinDifficultyBlocks)
|
||||
if (consensusParams.fPowAllowMinDifficultyBlocks) {
|
||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
|
||||
}
|
||||
|
||||
return nNewTime - nOldTime;
|
||||
}
|
||||
@@ -53,7 +55,8 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
}
|
||||
|
||||
BlockAssembler::Options::Options() {
|
||||
BlockAssembler::Options::Options()
|
||||
{
|
||||
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
|
||||
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
|
||||
}
|
||||
@@ -108,8 +111,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
|
||||
pblocktemplate.reset(new CBlockTemplate());
|
||||
|
||||
if(!pblocktemplate.get())
|
||||
if (!pblocktemplate.get()) {
|
||||
return nullptr;
|
||||
}
|
||||
CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
|
||||
|
||||
// Add dummy coinbase tx as first transaction
|
||||
@@ -125,15 +129,12 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
|
||||
// -regtest only: allow overriding block.nVersion with
|
||||
// -blockversion=N to test forking scenarios
|
||||
if (chainparams.MineBlocksOnDemand())
|
||||
if (chainparams.MineBlocksOnDemand()) {
|
||||
pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
|
||||
}
|
||||
|
||||
pblock->nTime = GetAdjustedTime();
|
||||
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
||||
|
||||
nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
||||
? nMedianTimePast
|
||||
: pblock->GetBlockTime();
|
||||
m_lock_time_cutoff = pindexPrev->GetMedianTimePast();
|
||||
|
||||
// Decide whether to include witness transactions
|
||||
// This is only needed in case the witness softfork activation is reverted
|
||||
@@ -193,8 +194,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
|
||||
// Only test txs not already in the block
|
||||
if (inBlock.count(*iit)) {
|
||||
testSet.erase(iit++);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
iit++;
|
||||
}
|
||||
}
|
||||
@@ -203,10 +203,12 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
|
||||
bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const
|
||||
{
|
||||
// TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
|
||||
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight)
|
||||
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) {
|
||||
return false;
|
||||
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST)
|
||||
}
|
||||
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -217,11 +219,13 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
|
||||
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
|
||||
{
|
||||
for (CTxMemPool::txiter it : package) {
|
||||
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
|
||||
if (!IsFinalTx(it->GetTx(), nHeight, m_lock_time_cutoff)) {
|
||||
return false;
|
||||
if (!fIncludeWitness && it->GetTx().HasWitness())
|
||||
}
|
||||
if (!fIncludeWitness && it->GetTx().HasWitness()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -253,8 +257,9 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
|
||||
m_mempool.CalculateDescendants(it, descendants);
|
||||
// Insert all descendants (not yet in block) into the modified set
|
||||
for (CTxMemPool::txiter desc : descendants) {
|
||||
if (alreadyAdded.count(desc))
|
||||
if (alreadyAdded.count(desc)) {
|
||||
continue;
|
||||
}
|
||||
++nDescendantsUpdated;
|
||||
modtxiter mit = mapModifiedTx.find(desc);
|
||||
if (mit == mapModifiedTx.end()) {
|
||||
@@ -440,8 +445,7 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
|
||||
{
|
||||
// Update nExtraNonce
|
||||
static uint256 hashPrevBlock;
|
||||
if (hashPrevBlock != pblock->hashPrevBlock)
|
||||
{
|
||||
if (hashPrevBlock != pblock->hashPrevBlock) {
|
||||
nExtraNonce = 0;
|
||||
hashPrevBlock = pblock->hashPrevBlock;
|
||||
}
|
||||
|
||||
@@ -82,8 +82,9 @@ struct modifiedentry_iter {
|
||||
struct CompareTxIterByAncestorCount {
|
||||
bool operator()(const CTxMemPool::txiter& a, const CTxMemPool::txiter& b) const
|
||||
{
|
||||
if (a->GetCountWithAncestors() != b->GetCountWithAncestors())
|
||||
if (a->GetCountWithAncestors() != b->GetCountWithAncestors()) {
|
||||
return a->GetCountWithAncestors() < b->GetCountWithAncestors();
|
||||
}
|
||||
return CompareIteratorByHash()(a, b);
|
||||
}
|
||||
};
|
||||
@@ -143,7 +144,8 @@ private:
|
||||
|
||||
// Chain context for the block
|
||||
int nHeight;
|
||||
int64_t nLockTimeCutoff;
|
||||
int64_t m_lock_time_cutoff;
|
||||
|
||||
const CChainParams& chainparams;
|
||||
const CTxMemPool& m_mempool;
|
||||
CChainState& m_chainstate;
|
||||
|
||||
Reference in New Issue
Block a user