Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Only allow up to 1024 dropped transactions in the transaction queue #5687

Merged
merged 7 commits into from
Aug 2, 2019

Conversation

halfalicious
Copy link
Contributor

@halfalicious halfalicious commented Jul 22, 2019

Fix #5688

@halfalicious
Copy link
Contributor Author

halfalicious commented Jul 22, 2019

clang6 failures aren't due to my changes (fairly certain I've seen these failures before), will file a new issue:

Test Case "saveNodes": 
/home/builder/project/test/unittests/libp2p/peer.cpp(188): error: in "libp2p/p2p/saveNodes": check host.peerCount() == c_peers has failed [0 != 5]
/home/builder/project/test/unittests/libp2p/peer.cpp(189): error: in "libp2p/p2p/saveNodes": check host2.peerCount() == c_peers has failed [4 != 5]
/home/builder/project/test/unittests/libp2p/peer.cpp(215): fatal error: in "libp2p/p2p/saveNodes": critical check r[2].itemCount() >= c_nodes has failed

*** 3 failures are detected (5 failures are expected) in the test module "Master Test Suite"

[Edit] Filed #5689

@codecov-io
Copy link

codecov-io commented Jul 22, 2019

Codecov Report

Merging #5687 into master will increase coverage by 0.13%.
The diff coverage is 92.22%.

Impacted file tree graph

@@            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

<< c_maxDroppedTransactionCount
<< "), removing dropped transaction from list (txhash: "
<< *m_dropped.begin() << ")";
m_dropped.erase(m_dropped.begin());
Copy link
Member

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?

Copy link
Contributor Author

@halfalicious halfalicious Jul 22, 2019

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.

Copy link
Member

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.

Copy link
Member

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

@halfalicious halfalicious changed the title Only allow up to 1024 dropped transactions in the transaction queue [WIP] Only allow up to 1024 dropped transactions in the transaction queue Jul 22, 2019
@halfalicious halfalicious force-pushed the tq-maxdropped branch 4 times, most recently from 2813173 to c7e5f2f Compare July 30, 2019 04:29
@halfalicious halfalicious changed the title [WIP] Only allow up to 1024 dropped transactions in the transaction queue Only allow up to 1024 dropped transactions in the transaction queue Jul 30, 2019
@halfalicious
Copy link
Contributor Author

cc @chfast / @gumb0 : Ready for review

@@ -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)
Copy link
Member

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.

template <class Key, class Value>
class LruCache
{
typedef Key key_type;
Copy link
Member

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

Copy link
Contributor Author

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

public:
explicit LruCache(size_t _capacity) : m_capacity(_capacity) {}

LruCache(LruCache<key_type, value_type> const& _l)
Copy link
Member

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.

@halfalicious
Copy link
Contributor Author

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.
@halfalicious
Copy link
Contributor Author

Squashed some commits

Copy link
Member

@gumb0 gumb0 left a 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);
Copy link
Member

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

@halfalicious
Copy link
Contributor Author

Looks good to me, one minor thing: you could make empty(), size(), capacity(), clear() and iterator getters noexcept.

@gumb0: Thanks for calling this out

@halfalicious halfalicious merged commit d57e0d2 into master Aug 2, 2019
@gumb0 gumb0 deleted the tq-maxdropped branch August 7, 2019 16:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aleth never clears transaction queue's "dropped transactions" list
4 participants