diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -611,27 +611,34 @@ // In flight request accounting. for (const auto &p : timedout_items) { const CInv &inv = p.first; - if (inv.type != MSG_BLOCK) { - continue; - } + if (inv.IsMsgBlk()) { + CBlockIndex *pindex; - CBlockIndex *pindex; + { + LOCK(cs_main); + pindex = LookupBlockIndex(BlockHash(inv.hash)); + if (!pindex) { + continue; + } + } - { - LOCK(cs_main); - pindex = LookupBlockIndex(BlockHash(inv.hash)); - if (!pindex) { + auto w = blockVoteRecords.getWriteView(); + auto it = w->find(pindex); + if (it == w.end()) { continue; } - } - auto w = blockVoteRecords.getWriteView(); - auto it = w->find(pindex); - if (it == w.end()) { - continue; + it->second.clearInflightRequest(p.second); } - it->second.clearInflightRequest(p.second); + if (inv.IsMsgProof()) { + auto w = proofVoteRecords.getWriteView(); + for (auto it = w.begin(); it != w.end(); it++) { + if (it->first->getId() == inv.hash) { + it->second.clearInflightRequest(p.second); + } + } + } } } diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/processor_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -837,19 +837,16 @@ BOOST_CHECK_EQUAL(updates.size(), 0); } -BOOST_AUTO_TEST_CASE(poll_inflight_timeout, *boost::unit_test::timeout(60)) { - std::vector updates; +BOOST_TEST_DECORATOR(*boost::unit_test::timeout(60)) +BOOST_AUTO_TEST_CASE_TEMPLATE(poll_inflight_timeout, T, + voteItemTestingContexts) { + T context(this); - CBlock block = CreateAndProcessBlock({}, CScript()); - const BlockHash blockHash = block.GetHash(); - const CBlockIndex *pindex; - { - LOCK(cs_main); - pindex = LookupBlockIndex(blockHash); - } + const auto item = context.buildVoteItem(); + const auto itemid = context.getVoteItemId(item); - // Add the block - BOOST_CHECK(m_processor->addBlockToReconcile(pindex)); + // Add the item + BOOST_CHECK(context.addToReconcile(item)); // Create a node that supports avalanche. auto avanode = ConnectNode(NODE_AVALANCHE); @@ -860,7 +857,7 @@ auto queryTimeDuration = std::chrono::milliseconds(10); m_processor->setQueryTimeoutDuration(queryTimeDuration); for (int i = 0; i < 10; i++) { - Response resp = {getRound(), 0, {Vote(0, blockHash)}}; + Response resp = {getRound(), 0, {Vote(0, itemid)}}; auto start = std::chrono::steady_clock::now(); runEventLoop(); @@ -869,7 +866,7 @@ std::this_thread::sleep_for(std::chrono::milliseconds(1)); runEventLoop(); - bool ret = registerVotes(avanodeid, next(resp), updates); + bool ret = context.registerVotes(avanodeid, next(resp)); if (std::chrono::steady_clock::now() > start + queryTimeDuration) { // We waited for too long, bail. Because we can't know for sure when // previous steps ran, ret is not deterministic and we do not check @@ -885,7 +882,7 @@ runEventLoop(); std::this_thread::sleep_for(queryTimeDuration); runEventLoop(); - BOOST_CHECK(!registerVotes(avanodeid, next(resp), updates)); + BOOST_CHECK(!context.registerVotes(avanodeid, next(resp))); } }