Changeset View
Changeset View
Standalone View
Standalone View
src/miner.h
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
struct CTxMemPoolModifiedEntry { | struct CTxMemPoolModifiedEntry { | ||||
explicit CTxMemPoolModifiedEntry(CTxMemPool::txiter entry) { | explicit CTxMemPoolModifiedEntry(CTxMemPool::txiter entry) { | ||||
iter = entry; | iter = entry; | ||||
nSizeWithAncestors = entry->GetSizeWithAncestors(); | nSizeWithAncestors = entry->GetSizeWithAncestors(); | ||||
nModFeesWithAncestors = entry->GetModFeesWithAncestors(); | nModFeesWithAncestors = entry->GetModFeesWithAncestors(); | ||||
nSigOpCountWithAncestors = entry->GetSigOpCountWithAncestors(); | nSigOpCountWithAncestors = entry->GetSigOpCountWithAncestors(); | ||||
} | } | ||||
Amount GetModifiedFee() const { return iter->GetModifiedFee(); } | |||||
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } | |||||
Amount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } | |||||
size_t GetTxSize() const { return iter->GetTxSize(); } | |||||
const CTransaction &GetTx() const { return iter->GetTx(); } | |||||
CTxMemPool::txiter iter; | CTxMemPool::txiter iter; | ||||
uint64_t nSizeWithAncestors; | uint64_t nSizeWithAncestors; | ||||
Amount nModFeesWithAncestors; | Amount nModFeesWithAncestors; | ||||
int64_t nSigOpCountWithAncestors; | int64_t nSigOpCountWithAncestors; | ||||
}; | }; | ||||
/** | /** | ||||
* Comparator for CTxMemPool::txiter objects. | * Comparator for CTxMemPool::txiter objects. | ||||
Show All 10 Lines | |||||
struct modifiedentry_iter { | struct modifiedentry_iter { | ||||
typedef CTxMemPool::txiter result_type; | typedef CTxMemPool::txiter result_type; | ||||
result_type operator()(const CTxMemPoolModifiedEntry &entry) const { | result_type operator()(const CTxMemPoolModifiedEntry &entry) const { | ||||
return entry.iter; | return entry.iter; | ||||
} | } | ||||
}; | }; | ||||
// This matches the calculation in CompareTxMemPoolEntryByAncestorFee, | |||||
// except operating on CTxMemPoolModifiedEntry. | |||||
// TODO: refactor to avoid duplication of this logic. | |||||
struct CompareModifiedEntry { | |||||
bool operator()(const CTxMemPoolModifiedEntry &a, | |||||
const CTxMemPoolModifiedEntry &b) const { | |||||
double f1 = b.nSizeWithAncestors * (a.nModFeesWithAncestors / SATOSHI); | |||||
double f2 = a.nSizeWithAncestors * (b.nModFeesWithAncestors / SATOSHI); | |||||
if (f1 == f2) { | |||||
return CTxMemPool::CompareIteratorByHash()(a.iter, b.iter); | |||||
} | |||||
return f1 > f2; | |||||
} | |||||
}; | |||||
// A comparator that sorts transactions based on number of ancestors. | // A comparator that sorts transactions based on number of ancestors. | ||||
// 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, | bool operator()(const CTxMemPool::txiter &a, | ||||
const CTxMemPool::txiter &b) const { | 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 CTxMemPool::CompareIteratorByHash()(a, b); | return CTxMemPool::CompareIteratorByHash()(a, b); | ||||
} | } | ||||
}; | }; | ||||
typedef boost::multi_index_container< | typedef boost::multi_index_container< | ||||
CTxMemPoolModifiedEntry, | CTxMemPoolModifiedEntry, | ||||
boost::multi_index::indexed_by< | boost::multi_index::indexed_by< | ||||
boost::multi_index::ordered_unique<modifiedentry_iter, | boost::multi_index::ordered_unique<modifiedentry_iter, | ||||
CompareCTxMemPoolIter>, | CompareCTxMemPoolIter>, | ||||
// sorted by modified ancestor fee rate | // sorted by modified ancestor fee rate | ||||
boost::multi_index::ordered_non_unique< | boost::multi_index::ordered_non_unique< | ||||
// Reuse same tag from CTxMemPool's similar index | // Reuse same tag from CTxMemPool's similar index | ||||
boost::multi_index::tag<ancestor_score>, | boost::multi_index::tag<ancestor_score>, | ||||
boost::multi_index::identity<CTxMemPoolModifiedEntry>, | boost::multi_index::identity<CTxMemPoolModifiedEntry>, | ||||
CompareModifiedEntry>>> | CompareTxMemPoolEntryByAncestorFee>>> | ||||
indexed_modified_transaction_set; | indexed_modified_transaction_set; | ||||
typedef indexed_modified_transaction_set::nth_index<0>::type::iterator | typedef indexed_modified_transaction_set::nth_index<0>::type::iterator | ||||
modtxiter; | modtxiter; | ||||
typedef indexed_modified_transaction_set::index<ancestor_score>::type::iterator | typedef indexed_modified_transaction_set::index<ancestor_score>::type::iterator | ||||
modtxscoreiter; | modtxscoreiter; | ||||
struct update_for_parent_inclusion { | struct update_for_parent_inclusion { | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |