mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 23:42:33 +02:00
style: Add {} to if-bodies in node/miner
Can be reviewed with --word-diff-regex=. --ignore-all-space
This commit is contained in:
parent
9174bcf7da
commit
fa6b7adf96
@ -29,14 +29,16 @@
|
|||||||
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
|
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
|
||||||
{
|
{
|
||||||
int64_t nOldTime = pblock->nTime;
|
int64_t nOldTime = pblock->nTime;
|
||||||
int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime());
|
||||||
|
|
||||||
if (nOldTime < nNewTime)
|
if (nOldTime < nNewTime) {
|
||||||
pblock->nTime = nNewTime;
|
pblock->nTime = nNewTime;
|
||||||
|
}
|
||||||
|
|
||||||
// Updating time can change work required on testnet:
|
// Updating time can change work required on testnet:
|
||||||
if (consensusParams.fPowAllowMinDifficultyBlocks)
|
if (consensusParams.fPowAllowMinDifficultyBlocks) {
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
|
||||||
|
}
|
||||||
|
|
||||||
return nNewTime - nOldTime;
|
return nNewTime - nOldTime;
|
||||||
}
|
}
|
||||||
@ -53,7 +55,8 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
|
|||||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockAssembler::Options::Options() {
|
BlockAssembler::Options::Options()
|
||||||
|
{
|
||||||
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
|
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
|
||||||
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
|
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
|
||||||
}
|
}
|
||||||
@ -108,8 +111,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
|||||||
|
|
||||||
pblocktemplate.reset(new CBlockTemplate());
|
pblocktemplate.reset(new CBlockTemplate());
|
||||||
|
|
||||||
if(!pblocktemplate.get())
|
if (!pblocktemplate.get()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
|
CBlock* const pblock = &pblocktemplate->block; // pointer for convenience
|
||||||
|
|
||||||
// Add dummy coinbase tx as first transaction
|
// Add dummy coinbase tx as first transaction
|
||||||
@ -125,8 +129,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
|||||||
pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
|
pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
|
||||||
// -regtest only: allow overriding block.nVersion with
|
// -regtest only: allow overriding block.nVersion with
|
||||||
// -blockversion=N to test forking scenarios
|
// -blockversion=N to test forking scenarios
|
||||||
if (chainparams.MineBlocksOnDemand())
|
if (chainparams.MineBlocksOnDemand()) {
|
||||||
pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
|
pblock->nVersion = gArgs.GetIntArg("-blockversion", pblock->nVersion);
|
||||||
|
}
|
||||||
|
|
||||||
pblock->nTime = GetAdjustedTime();
|
pblock->nTime = GetAdjustedTime();
|
||||||
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
||||||
@ -193,8 +198,7 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
|
|||||||
// Only test txs not already in the block
|
// Only test txs not already in the block
|
||||||
if (inBlock.count(*iit)) {
|
if (inBlock.count(*iit)) {
|
||||||
testSet.erase(iit++);
|
testSet.erase(iit++);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
iit++;
|
iit++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,10 +207,12 @@ void BlockAssembler::onlyUnconfirmed(CTxMemPool::setEntries& testSet)
|
|||||||
bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const
|
bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const
|
||||||
{
|
{
|
||||||
// TODO: switch to weight-based accounting for packages instead of vsize-based accounting.
|
// 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;
|
return false;
|
||||||
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST)
|
}
|
||||||
|
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,10 +223,12 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
|
|||||||
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
|
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
|
||||||
{
|
{
|
||||||
for (CTxMemPool::txiter it : package) {
|
for (CTxMemPool::txiter it : package) {
|
||||||
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
|
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff)) {
|
||||||
return false;
|
return false;
|
||||||
if (!fIncludeWitness && it->GetTx().HasWitness())
|
}
|
||||||
|
if (!fIncludeWitness && it->GetTx().HasWitness()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -253,8 +261,9 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
|
|||||||
m_mempool.CalculateDescendants(it, descendants);
|
m_mempool.CalculateDescendants(it, descendants);
|
||||||
// Insert all descendants (not yet in block) into the modified set
|
// Insert all descendants (not yet in block) into the modified set
|
||||||
for (CTxMemPool::txiter desc : descendants) {
|
for (CTxMemPool::txiter desc : descendants) {
|
||||||
if (alreadyAdded.count(desc))
|
if (alreadyAdded.count(desc)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
++nDescendantsUpdated;
|
++nDescendantsUpdated;
|
||||||
modtxiter mit = mapModifiedTx.find(desc);
|
modtxiter mit = mapModifiedTx.find(desc);
|
||||||
if (mit == mapModifiedTx.end()) {
|
if (mit == mapModifiedTx.end()) {
|
||||||
@ -280,7 +289,7 @@ int BlockAssembler::UpdatePackagesForAdded(const CTxMemPool::setEntries& already
|
|||||||
// guaranteed to fail again, but as a belt-and-suspenders check we put it in
|
// guaranteed to fail again, but as a belt-and-suspenders check we put it in
|
||||||
// failedTx and avoid re-evaluation, since the re-evaluation would be using
|
// failedTx and avoid re-evaluation, since the re-evaluation would be using
|
||||||
// cached size/sigops/fee values that are not actually correct.
|
// cached size/sigops/fee values that are not actually correct.
|
||||||
bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, CTxMemPool::setEntries &failedTx)
|
bool BlockAssembler::SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set& mapModifiedTx, CTxMemPool::setEntries& failedTx)
|
||||||
{
|
{
|
||||||
assert(it != m_mempool.mapTx.end());
|
assert(it != m_mempool.mapTx.end());
|
||||||
return mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it);
|
return mapModifiedTx.count(it) || inBlock.count(it) || failedTx.count(it);
|
||||||
@ -307,7 +316,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
|
|||||||
// Each time through the loop, we compare the best transaction in
|
// Each time through the loop, we compare the best transaction in
|
||||||
// mapModifiedTxs with the next transaction in the mempool to decide what
|
// mapModifiedTxs with the next transaction in the mempool to decide what
|
||||||
// transaction package to work on next.
|
// transaction package to work on next.
|
||||||
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated)
|
void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpdated)
|
||||||
{
|
{
|
||||||
// mapModifiedTx will store sorted packages after they are modified
|
// mapModifiedTx will store sorted packages after they are modified
|
||||||
// because some of their txs are already in the block
|
// because some of their txs are already in the block
|
||||||
@ -423,7 +432,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
|
|||||||
std::vector<CTxMemPool::txiter> sortedEntries;
|
std::vector<CTxMemPool::txiter> sortedEntries;
|
||||||
SortForBlock(ancestors, sortedEntries);
|
SortForBlock(ancestors, sortedEntries);
|
||||||
|
|
||||||
for (size_t i=0; i<sortedEntries.size(); ++i) {
|
for (size_t i = 0; i < sortedEntries.size(); ++i) {
|
||||||
AddToBlock(sortedEntries[i]);
|
AddToBlock(sortedEntries[i]);
|
||||||
// Erase from the modified set, if present
|
// Erase from the modified set, if present
|
||||||
mapModifiedTx.erase(sortedEntries[i]);
|
mapModifiedTx.erase(sortedEntries[i]);
|
||||||
@ -440,13 +449,12 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
|
|||||||
{
|
{
|
||||||
// Update nExtraNonce
|
// Update nExtraNonce
|
||||||
static uint256 hashPrevBlock;
|
static uint256 hashPrevBlock;
|
||||||
if (hashPrevBlock != pblock->hashPrevBlock)
|
if (hashPrevBlock != pblock->hashPrevBlock) {
|
||||||
{
|
|
||||||
nExtraNonce = 0;
|
nExtraNonce = 0;
|
||||||
hashPrevBlock = pblock->hashPrevBlock;
|
hashPrevBlock = pblock->hashPrevBlock;
|
||||||
}
|
}
|
||||||
++nExtraNonce;
|
++nExtraNonce;
|
||||||
unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
|
unsigned int nHeight = pindexPrev->nHeight + 1; // Height first in coinbase required for block.version=2
|
||||||
CMutableTransaction txCoinbase(*pblock->vtx[0]);
|
CMutableTransaction txCoinbase(*pblock->vtx[0]);
|
||||||
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce));
|
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce));
|
||||||
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
||||||
|
@ -80,10 +80,11 @@ struct modifiedentry_iter {
|
|||||||
// This is sufficient to sort an ancestor package in an order that is valid
|
// This is sufficient to sort an ancestor package in an order that is valid
|
||||||
// to appear in a block.
|
// to appear in a block.
|
||||||
struct CompareTxIterByAncestorCount {
|
struct CompareTxIterByAncestorCount {
|
||||||
bool operator()(const CTxMemPool::txiter &a, const CTxMemPool::txiter &b) const
|
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 a->GetCountWithAncestors() < b->GetCountWithAncestors();
|
||||||
|
}
|
||||||
return CompareIteratorByHash()(a, b);
|
return CompareIteratorByHash()(a, b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user