diff --git a/src/miner.h b/src/miner.h --- a/src/miner.h +++ b/src/miner.h @@ -50,6 +50,27 @@ : tx(_tx), txFee(_fees), txSize(_size), txSigOps(_sigOps), packageOrder(1), packageFee(_fees), packageSize(_size), packageSigOps(_sigOps) {} + + // Calculate the feerate for this transaction. Use the minimum of the + // package feerate, or the transaction itself. Parents TXNs should never + // end up "paying for" child transactions. + CFeeRate FeeRate() const { + return int64_t(txSize) * packageFee < int64_t(packageSize) * txFee + ? CFeeRate(packageFee, packageSize) + : CFeeRate(txFee, txSize); + } + +private: + // Include a parent transactions accounting into our own. + // We assume that this is used in topological order by BlockAssembler. + void AccountForParent(CBlockTemplateEntry &parent) { + packageOrder = std::max(parent.packageOrder + 1, packageOrder); + packageFee += parent.packageFee; + packageSize += parent.packageSize; + packageSigOps += parent.packageSigOps; + } + + friend class BlockAssembler; }; struct CBlockTemplate {