Changeset View
Changeset View
Standalone View
Standalone View
src/miner.h
Show All 23 Lines | |||||
static const bool DEFAULT_PRINTPRIORITY = false; | static const bool DEFAULT_PRINTPRIORITY = false; | ||||
struct CBlockTemplateEntry { | struct CBlockTemplateEntry { | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
//!< Total real fees paid by the transaction and cached to avoid parent | //!< Total real fees paid by the transaction and cached to avoid parent | ||||
//!< lookup | //!< lookup | ||||
Amount txFee; | Amount txFee; | ||||
//!< Modified fees from mempool. Set by the prioritisetransaction rpc. | |||||
//!< We need this for ordering, but the above txFee for proper coinbase | |||||
//!< calculations. | |||||
Amount txModFee; | |||||
//!< Cached total size of the transaction to avoid reserializing transaction | //!< Cached total size of the transaction to avoid reserializing transaction | ||||
size_t txSize; | size_t txSize; | ||||
//!< Cached total number of SigOps | //!< Cached total number of SigOps | ||||
uint64_t txSigOps; | uint64_t txSigOps; | ||||
//!< Track the "order" of a transaction in a package. | //!< Track the "order" of a transaction in a package. | ||||
//!< Higher means it has more dependencies. | //!< Higher means it has more dependencies. | ||||
uint64_t packageOrder; | uint64_t packageOrder; | ||||
//!< Estimated package fees (>= real size. Note: This will be offset by | //!< Estimated package fees (>= real size. Note: This will be offset by | ||||
//!< double counting size as well in certain cases) | //!< double counting size as well in certain cases) | ||||
Amount packageFee; | Amount packageFee; | ||||
//!< Estimated package size (>= real size) | //!< Estimated package size (>= real size) | ||||
size_t packageSize; | size_t packageSize; | ||||
//!< Estimated package Sigops (>= real size) | //!< Estimated package Sigops (>= real size) | ||||
uint64_t packageSigOps; | uint64_t packageSigOps; | ||||
CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, uint64_t _size, | Amount maxPackageFee; | ||||
int64_t _sigOps) | size_t maxPackageSize; | ||||
: tx(_tx), txFee(_fees), txSize(_size), txSigOps(_sigOps), | |||||
packageOrder(1), packageFee(_fees), packageSize(_size), | CBlockTemplateEntry(CTransactionRef _tx, Amount _realFees, Amount _modFees, | ||||
packageSigOps(_sigOps) {} | uint64_t _size, int64_t _sigOps) | ||||
: tx(_tx), txFee(_realFees), txModFee(_modFees), txSize(_size), | |||||
txSigOps(_sigOps), packageOrder(0), packageFee(_modFees), | |||||
packageSize(_size), packageSigOps(_sigOps), | |||||
maxPackageFee(Amount::zero()), maxPackageSize(0) {} | |||||
// Calculate the feerate for this transaction. Use the minimum of the | // Calculate the feerate for this transaction. Use the minimum of the | ||||
// package feerate, or the transaction itself. Parents TXNs should never | // package feerate, or the transaction itself. Parents TXNs should never | ||||
// end up "paying for" child transactions. | // end up "paying for" child transactions. | ||||
CFeeRate FeeRate() const { | CFeeRate FeeRate() const { | ||||
return int64_t(txSize) * packageFee < int64_t(packageSize) * txFee | // If we are order 0, we know we can include the entire package for this | ||||
? CFeeRate(packageFee, packageSize) | // fee rate. As there is no other package with a higher feerate, that we | ||||
: CFeeRate(txFee, txSize); | // depend upon. | ||||
if (GetOrder() == 0) { | |||||
return CFeeRate(packageFee, packageSize); | |||||
} | |||||
return CFeeRate(txModFee, txSize); | |||||
} | |||||
size_t GetOrder() const { | |||||
// If we're the maximum fee of the package, set our maximum to our fee, | |||||
// and reset our ordeer. | |||||
if (int64_t(packageSize) * maxPackageFee < | |||||
int64_t(maxPackageSize) * packageFee) { | |||||
// This package, is the highest feerate package. Nothing that this | |||||
// depends on could go in first. | |||||
return 0; | |||||
} | |||||
return packageOrder; | |||||
} | } | ||||
private: | private: | ||||
// Include a parent transactions accounting into our own. | |||||
// We assume that this is used in topological order by BlockAssembler. | |||||
void AccountForParent(CBlockTemplateEntry &parent) { | void AccountForParent(CBlockTemplateEntry &parent) { | ||||
packageOrder = std::max(parent.packageOrder + 1, packageOrder); | packageOrder = std::max(parent.packageOrder + 1, packageOrder); | ||||
packageFee += parent.packageFee; | packageFee += parent.packageFee; | ||||
packageSize += parent.packageSize; | packageSize += parent.packageSize; | ||||
packageSigOps += parent.packageSigOps; | packageSigOps += parent.packageSigOps; | ||||
// Propagate the maximum package fee, if it's bigger than anything we've | |||||
// already found. We know that AT LEAST this package would get in before | |||||
// us if we simply sort by package order. NOTE: Less than or equal to is | |||||
// important here, both sides are equal to zero upon first pass. | |||||
if (int64_t(parent.packageSize) * maxPackageFee <= | |||||
int64_t(maxPackageSize) * parent.packageFee) { | |||||
maxPackageFee = parent.packageFee; | |||||
maxPackageSize = parent.packageSize; | |||||
} | |||||
} | } | ||||
friend class BlockAssembler; | friend class BlockAssembler; | ||||
}; | }; | ||||
struct CBlockTemplate { | struct CBlockTemplate { | ||||
CBlock block; | CBlock block; | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | private: | ||||
// 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(); | ||||
/** 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(int &nPackagesSelected, int &nDescendantsUpdated); | ||||
// Old version of addPackageTxs | |||||
// TODO: DELET THIS ONII-CHAN | |||||
void accuratelyAddPackageTxs(int &nPackagesSelected, | |||||
int &nDescendantsUpdated); | |||||
/** 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, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |