-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
tx_pool: update internal data structure to boost::bimap. #9376
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,9 @@ | |
#include <queue> | ||
#include <boost/serialization/version.hpp> | ||
#include <boost/utility.hpp> | ||
#include <boost/bimap.hpp> | ||
#include <boost/bimap/set_of.hpp> | ||
#include <boost/bimap/multiset_of.hpp> | ||
|
||
#include "span.h" | ||
#include "string_tools.h" | ||
|
@@ -62,24 +65,33 @@ namespace cryptonote | |
//! pair of <transaction fee, transaction hash> for organization | ||
typedef std::pair<std::pair<double, std::time_t>, crypto::hash> tx_by_fee_and_receive_time_entry; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure that typedef is not needed anymore and can be deleted, in the interest of clean code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your comment. Yes. it was not needed. But didn't want to make any unnecessary changes. |
||
|
||
class txCompare | ||
class txFeeCompare | ||
{ | ||
public: | ||
bool operator()(const tx_by_fee_and_receive_time_entry& a, const tx_by_fee_and_receive_time_entry& b) const | ||
bool operator()(const std::pair<double, std::time_t>& a, const std::pair<double, std::time_t>& b) const | ||
{ | ||
// sort by greatest first, not least | ||
if (a.first.first > b.first.first) return true; | ||
if (a.first.first < b.first.first) return false; | ||
if (a.first > b.first) return true; | ||
if (a.first < b.first) return false; | ||
|
||
if (a.first.second < b.first.second) return true; | ||
if (a.first.second > b.first.second) return false; | ||
if (a.second < b.second) return true; | ||
return false; | ||
} | ||
}; | ||
|
||
return memcmp(a.second.data, b.second.data, sizeof(crypto::hash)) < 0; | ||
class hashCompare | ||
{ | ||
public: | ||
bool operator()(const crypto::hash& a, const crypto::hash& b) const | ||
{ | ||
return memcmp(a.data, b.data, sizeof(crypto::hash)) < 0; | ||
} | ||
}; | ||
|
||
//! container for sorting transactions by fee per unit size | ||
typedef std::set<tx_by_fee_and_receive_time_entry, txCompare> sorted_tx_container; | ||
typedef boost::bimap<boost::bimaps::multiset_of<std::pair<double, std::time_t>, txFeeCompare>, | ||
boost::bimaps::set_of<crypto::hash, hashCompare>> sorted_tx_container; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think? At this point it comes to the design choices, I am perfectly happy to change it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Search times are a bit lower with an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot for detailed explanation. |
||
|
||
|
||
/** | ||
* @brief Transaction pool, handles transactions which are not part of a block | ||
|
@@ -653,7 +665,7 @@ namespace cryptonote | |
* | ||
* @return an iterator, possibly to the end of the container if not found | ||
*/ | ||
sorted_tx_container::iterator find_tx_in_sorted_container(const crypto::hash& id) const; | ||
sorted_tx_container::iterator find_tx_in_sorted_container(const crypto::hash& id); | ||
|
||
//! cache/call Blockchain::check_tx_inputs results | ||
bool check_tx_inputs(const std::function<cryptonote::transaction&(void)> &get_tx, const crypto::hash &txid, uint64_t &max_used_block_height, crypto::hash &max_used_block_id, tx_verification_context &tvc, bool kept_by_block = false) const; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the documentation, and it looks like this function can remain
const
? What broke this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that
iterator
has to be returned, so presumably the reason isfind
andproject_up
returnconst_iterator
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right. If it remains
const
then thefind
will returnconst_iterator
and that is causing a lot headache. We want to use that iterator inerase
which doesn't acceptconst_iterator
, and no easy way of turningconst_iterator
toiterator
in boost.