Changeset View
Changeset View
Standalone View
Standalone View
src/miner.h
Show First 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | private: | ||||
Amount nFees; | Amount nFees; | ||||
CTxMemPool::setEntries inBlock; | CTxMemPool::setEntries inBlock; | ||||
// Chain context for the block | // Chain context for the block | ||||
int nHeight; | int nHeight; | ||||
int64_t nLockTimeCutoff; | int64_t nLockTimeCutoff; | ||||
int64_t nMedianTimePast; | int64_t nMedianTimePast; | ||||
const Config *config; | |||||
const CTxMemPool *mempool; | const CTxMemPool *mempool; | ||||
// Variables used for addPriorityTxs | // Variables used for addPriorityTxs | ||||
int lastFewTxs; | int lastFewTxs; | ||||
public: | public: | ||||
BlockAssembler(const Config &_config, const CTxMemPool &mempool); | BlockAssembler(const Config &config, const CTxMemPool &mempool); | ||||
/** Construct a new block template with coinbase to scriptPubKeyIn */ | /** Construct a new block template with coinbase to scriptPubKeyIn */ | ||||
std::unique_ptr<CBlockTemplate> | std::unique_ptr<CBlockTemplate> | ||||
CreateNewBlock(const CScript &scriptPubKeyIn); | CreateNewBlock(const Config &config, const CScript &scriptPubKeyIn); | ||||
uint64_t GetMaxGeneratedBlockSize() const { return nMaxGeneratedBlockSize; } | uint64_t GetMaxGeneratedBlockSize() const { return nMaxGeneratedBlockSize; } | ||||
private: | private: | ||||
// utility functions | // utility functions | ||||
/** Clear the block's state and prepare for assembling a new block */ | /** Clear the block's state and prepare for assembling a new block */ | ||||
void resetBlock(); | void resetBlock(); | ||||
/** Add a tx to the block */ | /** Add a tx to the block */ | ||||
void AddToBlock(CTxMemPool::txiter iter); | void AddToBlock(CTxMemPool::txiter iter); | ||||
// Methods for how to add transactions to a block. | // Methods for how to add transactions to a block. | ||||
/** Add transactions based on tx "priority" */ | /** Add transactions based on tx "priority" */ | ||||
void addPriorityTxs(); | void addPriorityTxs(const Config &config); | ||||
/** | /** | ||||
* Add transactions based on feerate including unconfirmed ancestors. | * Add transactions based on feerate including unconfirmed ancestors. | ||||
* Increments nPackagesSelected / nDescendantsUpdated with corresponding | * Increments nPackagesSelected / nDescendantsUpdated with corresponding | ||||
* statistics from the package selection (for logging statistics). | * statistics from the package selection (for logging statistics). | ||||
*/ | */ | ||||
void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated) | void addPackageTxs(const Config &config, int &nPackagesSelected, | ||||
int &nDescendantsUpdated) | |||||
EXCLUSIVE_LOCKS_REQUIRED(mempool->cs); | EXCLUSIVE_LOCKS_REQUIRED(mempool->cs); | ||||
/** Enum for the results from TestForBlock */ | /** Enum for the results from TestForBlock */ | ||||
enum class TestForBlockResult : uint8_t { | enum class TestForBlockResult : uint8_t { | ||||
TXFits = 0, | TXFits = 0, | ||||
TXCantFit = 1, | TXCantFit = 1, | ||||
BlockFinished = 3, | BlockFinished = 3, | ||||
}; | }; | ||||
// helper function for addPriorityTxs | // helper function for addPriorityTxs | ||||
/** Test if tx will still "fit" in the block */ | /** Test if tx will still "fit" in the block */ | ||||
TestForBlockResult TestForBlock(CTxMemPool::txiter iter); | TestForBlockResult TestForBlock(const Config &config, | ||||
CTxMemPool::txiter iter); | |||||
/** Test if tx still has unconfirmed parents not yet in block */ | /** Test if tx still has unconfirmed parents not yet in block */ | ||||
bool isStillDependent(CTxMemPool::txiter iter); | bool isStillDependent(CTxMemPool::txiter iter); | ||||
// helper functions for addPackageTxs() | // helper functions for addPackageTxs() | ||||
/** Remove confirmed (inBlock) entries from given set */ | /** Remove confirmed (inBlock) entries from given set */ | ||||
void onlyUnconfirmed(CTxMemPool::setEntries &testSet); | void onlyUnconfirmed(CTxMemPool::setEntries &testSet); | ||||
/** Test if a new package would "fit" in the block */ | /** Test if a new package would "fit" in the block */ | ||||
bool TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const; | bool TestPackage(uint64_t packageSize, int64_t packageSigOpsCost) const; | ||||
/** | /** | ||||
* Perform checks on each transaction in a package: | * Perform checks on each transaction in a package: | ||||
* locktime, serialized size (if necessary). These checks should always | * locktime, serialized size (if necessary). These checks should always | ||||
* succeed, and they're here only as an extra check in case of suboptimal | * succeed, and they're here only as an extra check in case of suboptimal | ||||
* node configuration. | * node configuration. | ||||
*/ | */ | ||||
bool TestPackageTransactions(const CTxMemPool::setEntries &package); | bool TestPackageTransactions(const Config &config, | ||||
const CTxMemPool::setEntries &package); | |||||
/** | /** | ||||
* Return true if given transaction from mapTx has already been evaluated, | * Return true if given transaction from mapTx has already been evaluated, | ||||
* or if the transaction's cached data in mapTx is incorrect. | * or if the transaction's cached data in mapTx is incorrect. | ||||
*/ | */ | ||||
bool SkipMapTxEntry(CTxMemPool::txiter it, | bool SkipMapTxEntry(CTxMemPool::txiter it, | ||||
indexed_modified_transaction_set &mapModifiedTx, | indexed_modified_transaction_set &mapModifiedTx, | ||||
CTxMemPool::setEntries &failedTx) | CTxMemPool::setEntries &failedTx) | ||||
EXCLUSIVE_LOCKS_REQUIRED(mempool->cs); | EXCLUSIVE_LOCKS_REQUIRED(mempool->cs); | ||||
Show All 21 Lines |