Skip to content

Conversation

mzumsande
Copy link
Contributor

@mzumsande mzumsande commented Jul 16, 2025

The logic for DBHashKey / DBHeightKey handling and lookup of entries is shared by coinstatsindex and blockfilterindex, leading to many lines of duplicated code. De-duplicate this by moving the logic to index/db_key.h (using templates for the index-specific DBVal).

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 16, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32997.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK fjahr

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #31308 (ci, iwyu: Treat warnings as errors for specific directories by hebasto)
  • #26966 (index: initial sync speedup, parallelize process by furszy)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • “an different” -> “a different” [incorrect article use]

drahtbot_id_4_m

@fjahr
Copy link
Contributor

fjahr commented Jul 17, 2025

Concept ACK on the deduplication parts

@mzumsande mzumsande force-pushed the 202507_dedup_hashheight branch from 6988e01 to 03b67a2 Compare July 17, 2025 15:34
Copy link
Contributor

@fjahr fjahr 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, aside from the documentation cleanup in blockfilterindex.cpp you can consider my comments optional.

src/index/key.h Outdated
@@ -76,4 +76,24 @@ template <typename DBVal>
return true;
}

template <typename DBVal>
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockRef& block, DBVal& result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could do IWYU I guess, even though this wasn't followed that well in the index cpp files.

#include <dbwrapper.h>
#include <interfaces/types.h>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added these and serialize.h, hope that'll do. (never got iwyu running locally and the tidy job didn't cover the new file for some reason).

@@ -30,8 +31,6 @@
* as big-endian so that sequential reads of filters by height are fast.
* Keys for the hash index have the type [DB_BLOCK_HASH, uint256].
*/
constexpr uint8_t DB_BLOCK_HASH{'s'};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above here still talks about three items stored for each block but after the change only one of the values is here. This would need to be adopted somehow and probably some of the docs moved over to index/key.h.

EDIT: Maybe the current comment can be left almost untouched but there needs to be a reference to where the keys are now.

Copy link
Contributor Author

@mzumsande mzumsande Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think the part with the "three items" is still correct, it talks about the values of the index, not the keys.
I replaced the part about the key from blockfilterindex.cpp by a reference to db_key.h

src/index/key.h Outdated
#include <stdexcept>
#include <utility>

static constexpr uint8_t DB_BLOCK_HASH{'s'};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the documentation moving necessary mentioned above maybe there could be 1-2 general sentences here that this deals with the hash/height keys and that it's mostly relevant to indexes that use these.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, very minor naming nit: File could be called db_key.h since we have other kinds of keys but I don't feel too strongly about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - I added a comment to the file, using parts from blockfilterindex.cpp.
I agree that db_key.h is nicer, changed it to that.

The code was largely duplicated between coinstatsindex
and blockfilterindex.
Deduplicate it by moving it to a shared file.

slight change in behavior: the index name is no longer
part of the error msg in case of (un)serialization errors.
LookUpOne is used by both coinstatsindex and blockfilterindex,
the two implementations had already started to deviate slightly
for no apparent reason.
@mzumsande mzumsande force-pushed the 202507_dedup_hashheight branch from 03b67a2 to 936bd87 Compare July 25, 2025 19:15
@mzumsande
Copy link
Contributor Author

03b67a2 to 936bd87:
Addressed feedback by @fjahr.

@fjahr
Copy link
Contributor

fjahr commented Jul 25, 2025

utACK 936bd87

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since DBHeightKey and DBHashKey are pretty similar. What do you think about a generic template for both? furszy@e5dd2b0.
(Only needed to specialize the serialization for the value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants