mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 07:39:08 +01:00
refactor(headerssync): Process spans of headers
More lightweight than vectors which needed to be copied in tests. Also good to get rid of headers_batch-vector before breaking up test.
This commit is contained in:
@@ -92,16 +92,12 @@ BOOST_AUTO_TEST_CASE(headers_sync_state)
|
||||
|
||||
std::unique_ptr<HeadersSyncState> hss;
|
||||
|
||||
std::vector<CBlockHeader> headers_batch;
|
||||
|
||||
// Feed the first chain to HeadersSyncState, by delivering 1 header
|
||||
// initially and then the rest.
|
||||
headers_batch.insert(headers_batch.end(), std::next(first_chain.begin()), first_chain.end());
|
||||
|
||||
hss.reset(new HeadersSyncState(0, Params().GetConsensus(), chain_start, CHAIN_WORK));
|
||||
(void)hss->ProcessNextHeaders({first_chain.front()}, true);
|
||||
(void)hss->ProcessNextHeaders({{first_chain.front()}}, true);
|
||||
// Pretend the first header is still "full", so we don't abort.
|
||||
auto result = hss->ProcessNextHeaders(headers_batch, true);
|
||||
auto result = hss->ProcessNextHeaders(std::span{first_chain}.subspan(1), true);
|
||||
|
||||
// This chain should look valid, and we should have met the proof-of-work
|
||||
// requirement.
|
||||
@@ -132,15 +128,13 @@ BOOST_AUTO_TEST_CASE(headers_sync_state)
|
||||
hss.reset(new HeadersSyncState(0, Params().GetConsensus(), chain_start, CHAIN_WORK));
|
||||
BOOST_CHECK(hss->GetState() == HeadersSyncState::State::PRESYNC);
|
||||
// Pretend just the first message is "full", so we don't abort.
|
||||
(void)hss->ProcessNextHeaders({second_chain.front()}, true);
|
||||
(void)hss->ProcessNextHeaders({{second_chain.front()}}, true);
|
||||
BOOST_CHECK(hss->GetState() == HeadersSyncState::State::PRESYNC);
|
||||
|
||||
headers_batch.clear();
|
||||
headers_batch.insert(headers_batch.end(), std::next(second_chain.begin(), 1), second_chain.end());
|
||||
// Tell the sync logic that the headers message was not full, implying no
|
||||
// more headers can be requested. For a low-work-chain, this should causes
|
||||
// the sync to end with no headers for acceptance.
|
||||
result = hss->ProcessNextHeaders(headers_batch, false);
|
||||
result = hss->ProcessNextHeaders(std::span{second_chain}.subspan(1), false);
|
||||
BOOST_CHECK(hss->GetState() == HeadersSyncState::State::FINAL);
|
||||
BOOST_CHECK(result.pow_validated_headers.empty());
|
||||
BOOST_CHECK(!result.request_more);
|
||||
|
||||
Reference in New Issue
Block a user