Skip to content

Commit

Permalink
Prefer tx entry time order for a block (#950)
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Fieroni <[email protected]>
  • Loading branch information
bvbfan authored Dec 7, 2021
1 parent ebae304 commit 5dd54ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
// transactions for block inclusion.
sortedEntries.clear();
sortedEntries.insert(sortedEntries.begin(), package.begin(), package.end());
std::sort(sortedEntries.begin(), sortedEntries.end(), CompareTxIterByAncestorCount());
std::sort(sortedEntries.begin(), sortedEntries.end(), CompareTxIterByEntryTime());
}

// This transaction selection algorithm orders the mempool based
Expand Down Expand Up @@ -993,4 +993,4 @@ void ThreadStaker::operator()(std::vector<ThreadStaker::Args> args, CChainParams
}
}

}
}
10 changes: 10 additions & 0 deletions src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ struct CompareTxIterByAncestorCount {
}
};

// A comparator that sorts transactions based on tx entry time.
struct CompareTxIterByEntryTime {
bool operator()(const CTxMemPool::txiter &a, const CTxMemPool::txiter &b) const
{
if (a->GetTime() == b->GetTime())
return CompareTxIterByAncestorCount()(a, b);
return CompareTxMemPoolEntryByEntryTime()(*a, *b);
}
};

typedef boost::multi_index_container<
CTxMemPoolModifiedEntry,
boost::multi_index::indexed_by<
Expand Down

0 comments on commit 5dd54ad

Please sign in to comment.