-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Only allow up to 1024 dropped transactions in the transaction queue #5687
Conversation
0df25d7
to
4612963
Compare
clang6 failures aren't due to my changes (fairly certain I've seen these failures before), will file a new issue:
[Edit] Filed #5689 |
Codecov Report
@@ Coverage Diff @@
## master #5687 +/- ##
==========================================
+ Coverage 62.98% 63.11% +0.13%
==========================================
Files 351 353 +2
Lines 30026 30111 +85
Branches 3370 3378 +8
==========================================
+ Hits 18912 19005 +93
+ Misses 9893 9877 -16
- Partials 1221 1229 +8 |
libethereum/TransactionQueue.cpp
Outdated
<< c_maxDroppedTransactionCount | ||
<< "), removing dropped transaction from list (txhash: " | ||
<< *m_dropped.begin() << ")"; | ||
m_dropped.erase(m_dropped.begin()); |
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.
This way it removes random transaction. As @chfast pointed out in the issue, it would be nicer to have some kind of LRU cache here, what do you think?
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.
This way it removes random transaction. As @chfast pointed out in the issue, it would be nicer to have some kind of LRU cache here, what do you think?
@gumb0 Agreed, didn't go with that in the first place since it increases the storage requirements and wasn't sure it was necessary but I'll go ahead and add that in.
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 don't care so much any more. I think it is ok to merge it as it is and fill additional issue.
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'm fine if we merge this as is, too
2813173
to
c7e5f2f
Compare
libethereum/TransactionQueue.cpp
Outdated
@@ -70,7 +58,7 @@ ImportResult TransactionQueue::check_WITH_LOCK(h256 const& _h, IfDropped _ik) | |||
if (m_known.count(_h)) | |||
return ImportResult::AlreadyKnown; | |||
|
|||
if (m_dropped.count(_h) && _ik == IfDropped::Ignore) | |||
if (m_dropped.contains(_h) && _ik == IfDropped::Ignore) |
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 think tx should also be touched here, if it's found.
libdevcore/LruCache.h
Outdated
template <class Key, class Value> | ||
class LruCache | ||
{ | ||
typedef Key key_type; |
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.
Better to use using key_type = Key;
instead of typedef
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.
Agreed, much more intuitive / readable
libdevcore/LruCache.h
Outdated
public: | ||
explicit LruCache(size_t _capacity) : m_capacity(_capacity) {} | ||
|
||
LruCache(LruCache<key_type, value_type> const& _l) |
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 think default-generated copy and move constructors and assignment operators should be enough.
03fe17e
to
b4885f0
Compare
Rebased to address CHANGELOG merge conflict |
Boost::compute LRU cache was used as inspiration
Use LruCache to manage dropped transactions
Use using instead of typedef for LruCache custom types Touch dropped transaction hash in LRU cache when checking for dropped transaction during transaction queue import. Remove copy/move ctors/assignment operators from LruCache since the default ones provide the same functionality.
b4885f0
to
1fdb02a
Compare
Squashed some commits |
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.
Looks good to me, one minor thing: you could make empty()
, size()
, capacity()
, clear()
and iterator getters noexcept
.
auto iter = _lruCache.begin(); | ||
while (iter != _lruCache.cend() && i < _data.size()) | ||
{ | ||
EXPECT_EQ(iter->first, _data[i].first); |
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.
Probably EXPECT_EQ(*iter, _data[i])
should work
@gumb0: Thanks for calling this out |
Fix #5688