Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer tx entry time order for a block #950

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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