Changeset View
Changeset View
Standalone View
Standalone View
src/miner.h
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | struct CBlockTemplateEntry { | ||||
uint64_t packageOrder; | uint64_t packageOrder; | ||||
//!< Estimated package fees (This is guaranteed to be >= real fees) | //!< Estimated package fees (This is guaranteed to be >= real fees) | ||||
Amount packageFee; | Amount packageFee; | ||||
//!< Estimated package size (This is guaranteed to be >= real size) | //!< Estimated package size (This is guaranteed to be >= real size) | ||||
size_t packageSize; | size_t packageSize; | ||||
//!< Estimated package sigops (This is guaranteed to be >= real sigops) | //!< Estimated package sigops (This is guaranteed to be >= real sigops) | ||||
uint64_t packageSigOps; | uint64_t packageSigOps; | ||||
//!< These values are used the fee and size for the package with the | |||||
//!< greatest fee-rate seen thus far. | |||||
Amount maxPackageFee; | |||||
size_t maxPackageSize; | |||||
CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, Amount _modFees, | CBlockTemplateEntry(CTransactionRef _tx, Amount _fees, Amount _modFees, | ||||
uint64_t _size, int64_t _sigOps) | uint64_t _size, int64_t _sigOps) | ||||
: tx(_tx), txFee(_fees), txModFee(_modFees), txSize(_size), | : tx(_tx), txFee(_fees), txModFee(_modFees), txSize(_size), | ||||
txSigOps(_sigOps), packageOrder(0), packageFee(_modFees), | txSigOps(_sigOps), packageOrder(0), packageFee(_modFees), | ||||
packageSize(_size), packageSigOps(_sigOps) {} | 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 { | ||||
// In order to avoid numerical errors, we reorder to use multiplication | // If we are order 0, we know we can include the entire package for this | ||||
// instead of vision. | // fee rate. As there is no other package with a higher feerate, that we | ||||
return int64_t(txSize) * packageFee < int64_t(packageSize) * txModFee | // depend upon. | ||||
? CFeeRate(packageFee, packageSize) | if (GetOrder() == 0) { | ||||
: CFeeRate(txModFee, txSize); | return CFeeRate(packageFee, packageSize); | ||||
} | |||||
return CFeeRate(txModFee, txSize); | |||||
} | |||||
size_t GetOrder() const { | |||||
// If we're the end of a maximum fee package thus far, set our maximum | |||||
// to our package fee, and reset our order. | |||||
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 an order of '0' | |||||
return 0; | |||||
} | |||||
return packageOrder; | |||||
} | } | ||||
private: | private: | ||||
// Include a parent transactions accounting into our own. | // Include a parent transactions accounting into our own. | ||||
// We assume that this is used in topological order by BlockAssembler. | // We assume that this is used in topological order by BlockAssembler. | ||||
void AccountForParent(const CBlockTemplateEntry &parent) { | void AccountForParent(const 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; | ||||
friend struct CBlockTemplateEntryTest; | friend struct CBlockTemplateEntryTest; | ||||
}; | }; | ||||
struct CBlockTemplate { | struct CBlockTemplate { | ||||
CBlock block; | CBlock block; | ||||
▲ Show 20 Lines • Show All 204 Lines • Show Last 20 Lines |