forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin#28955: index: block filters sync, reduce disk read oper…
…ations by caching last header 99afb9d refactor: init, simplify index shutdown code (furszy) 0faafb5 index: decrease ThreadSync cs_main contention (furszy) f1469eb index: cache last block filter header (furszy) a6756ec index: blockfilter, decouple header lookup into its own function (furszy) 331f044 index: blockfilter, decouple Write into its own function (furszy) bcbd7eb bench: basic block filter index initial sync (furszy) Pull request description: Work decoupled from bitcoin#26966 per request. The aim is to remove an unnecessary disk read operation that currently takes place with every new arriving block (or scanned block during background sync). Instead of reading the last filter header from disk merely to access its hash for constructing the next filter, this work caches it, occupying just 32 more bytes in memory. Also, reduces `cs_main` lock contention during the index initial sync process. And, simplifies the indexes initialization and shutdown procedure. Testing Note: To compare the changes, added a pretty basic benchmark in the second commit. Alternatively, could also test the changes by timing the block filter sync from scratch on any network; start the node with `-blockfilterindex` and monitor the logs until the syncing process finish. Local Benchmark Results: *Master (c252a0f): | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 132,042,516.60 | 7.57 | 0.3% | 7.79 | `BlockFilterIndexSync` *PR (43a212c): | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 126,915,841.60 | 7.88 | 0.6% | 7.51 | `BlockFilterIndexSync` ACKs for top commit: Sjors: re-ACK 99afb9d achow101: ACK 99afb9d TheCharlatan: Re-ACK 99afb9d andrewtoth: ACK 99afb9d Tree-SHA512: 927daadd68f4ee1ca781a89519539b895f5185a76ebaf525fbc246ea8dcf40d44a82def00ac34b188640802844b312270067f1b33e65a2479e06be9169c616de
- Loading branch information
Showing
7 changed files
with
119 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2023-present The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or https://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <bench/bench.h> | ||
|
||
#include <addresstype.h> | ||
#include <index/blockfilterindex.h> | ||
#include <node/chainstate.h> | ||
#include <node/context.h> | ||
#include <test/util/setup_common.h> | ||
#include <util/strencodings.h> | ||
|
||
// Very simple block filter index sync benchmark, only using coinbase outputs. | ||
static void BlockFilterIndexSync(benchmark::Bench& bench) | ||
{ | ||
const auto test_setup = MakeNoLogFileContext<TestChain100Setup>(); | ||
|
||
// Create more blocks | ||
int CHAIN_SIZE = 600; | ||
CPubKey pubkey{ParseHex("02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9")}; | ||
CScript script = GetScriptForDestination(WitnessV0KeyHash(pubkey)); | ||
std::vector<CMutableTransaction> noTxns; | ||
for (int i = 0; i < CHAIN_SIZE - 100; i++) { | ||
test_setup->CreateAndProcessBlock(noTxns, script); | ||
SetMockTime(GetTime() + 1); | ||
} | ||
assert(WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE)); | ||
|
||
bench.minEpochIterations(5).run([&] { | ||
BlockFilterIndex filter_index(interfaces::MakeChain(test_setup->m_node), BlockFilterType::BASIC, | ||
/*n_cache_size=*/0, /*f_memory=*/false, /*f_wipe=*/true); | ||
assert(filter_index.Init()); | ||
assert(!filter_index.BlockUntilSyncedToCurrentChain()); | ||
filter_index.Sync(); | ||
|
||
IndexSummary summary = filter_index.GetSummary(); | ||
assert(summary.synced); | ||
assert(summary.best_block_hash == WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveTip()->GetBlockHash())); | ||
}); | ||
} | ||
|
||
BENCHMARK(BlockFilterIndexSync, benchmark::PriorityLevel::HIGH); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters