From a3cb309e7c31853f272bffaa65fb6ab0a7cc4083 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 29 May 2024 14:51:50 +0000 Subject: [PATCH] refactor: use recommended type hiding on multi_index types Recommended by boost docs: https://www.boost.org/doc/libs/1_85_0/libs/multi_index/doc/compiler_specifics.html#type_hiding This significantly reduces the size of the symbol name lengths that end up in the binaries as well as in compiler warnings/errors. Otherwise there should be no functional change. Example before: 0000000000000000 W unsigned long boost::multi_index::detail::hashed_index, boost::multi_index::detail::nth_layer<1, CTxMemPoolEntry, boost::multi_index::indexed_by, boost::multi_index::hashed_unique, mempoolentry_wtxid, SaltedTxidHasher, mpl_::na>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByDescendantScore>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByEntryTime>, boost::multi_index::ordered_non_unique, boost::multi_index::identity, CompareTxMemPoolEntryByAncestorFee>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator >, boost::mpl::vector0, boost::multi_index::detail::hashed_unique_tag>::count >(uint256 const&, SaltedTxidHasher const&, std::equal_to const&, mpl_::bool_) const After: 0000000000000000 W unsigned long boost::multi_index::detail::hashed_index, boost::multi_index::detail::nth_layer<1, CTxMemPoolEntry, CTxMemPool::CTxMemPoolEntry_Indicies, std::allocator >, boost::mpl::vector0, boost::multi_index::detail::hashed_unique_tag>::count >(uint256 const&, SaltedTxidHasher const&, std::equal_to const&, mpl_::bool_) const --- src/node/miner.h | 30 +++++++++++++++++------------- src/txmempool.h | 8 +++++--- src/txrequest.cpp | 13 ++++++++----- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/node/miner.h b/src/node/miner.h index 06a917228dccc..445ccc13da29c 100644 --- a/src/node/miner.h +++ b/src/node/miner.h @@ -96,21 +96,25 @@ struct CompareTxIterByAncestorCount { } }; + +struct CTxMemPoolModifiedEntry_Indices final : boost::multi_index::indexed_by< + boost::multi_index::ordered_unique< + modifiedentry_iter, + CompareCTxMemPoolIter + >, + // sorted by modified ancestor fee rate + boost::multi_index::ordered_non_unique< + // Reuse same tag from CTxMemPool's similar index + boost::multi_index::tag, + boost::multi_index::identity, + CompareTxMemPoolEntryByAncestorFee + > +> +{}; + typedef boost::multi_index_container< CTxMemPoolModifiedEntry, - boost::multi_index::indexed_by< - boost::multi_index::ordered_unique< - modifiedentry_iter, - CompareCTxMemPoolIter - >, - // sorted by modified ancestor fee rate - boost::multi_index::ordered_non_unique< - // Reuse same tag from CTxMemPool's similar index - boost::multi_index::tag, - boost::multi_index::identity, - CompareTxMemPoolEntryByAncestorFee - > - > + CTxMemPoolModifiedEntry_Indices > indexed_modified_transaction_set; typedef indexed_modified_transaction_set::nth_index<0>::type::iterator modtxiter; diff --git a/src/txmempool.h b/src/txmempool.h index c9f6cdbfac8fe..7a55f2a963a02 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -327,9 +327,7 @@ class CTxMemPool static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing - typedef boost::multi_index_container< - CTxMemPoolEntry, - boost::multi_index::indexed_by< + struct CTxMemPoolEntry_Indices final : boost::multi_index::indexed_by< // sorted by txid boost::multi_index::hashed_unique, // sorted by wtxid @@ -357,6 +355,10 @@ class CTxMemPool CompareTxMemPoolEntryByAncestorFee > > + {}; + typedef boost::multi_index_container< + CTxMemPoolEntry, + CTxMemPoolEntry_Indices > indexed_transaction_set; /** diff --git a/src/txrequest.cpp b/src/txrequest.cpp index ce5fbd9a7f992..259f651e9ef14 100644 --- a/src/txrequest.cpp +++ b/src/txrequest.cpp @@ -212,14 +212,17 @@ struct ByTimeViewExtractor } }; +struct Announcement_Indices final : boost::multi_index::indexed_by< + boost::multi_index::ordered_unique, ByPeerViewExtractor>, + boost::multi_index::ordered_non_unique, ByTxHashViewExtractor>, + boost::multi_index::ordered_non_unique, ByTimeViewExtractor> +> +{}; + /** Data type for the main data structure (Announcement objects with ByPeer/ByTxHash/ByTime indexes). */ using Index = boost::multi_index_container< Announcement, - boost::multi_index::indexed_by< - boost::multi_index::ordered_unique, ByPeerViewExtractor>, - boost::multi_index::ordered_non_unique, ByTxHashViewExtractor>, - boost::multi_index::ordered_non_unique, ByTimeViewExtractor> - > + Announcement_Indices >; /** Helper type to simplify syntax of iterator types. */