dbwrapper: avoid copying unobfuscated iterator values #35247

pull CruzMolina wants to merge 1 commits into bitcoin:master from CruzMolina:dbwrapper-getvalue-spanreader changing 2 files +14 −3
  1. CruzMolina commented at 9:14 PM on May 8, 2026: none

    Motivation

    CDBIterator::GetValue() currently copies the current LevelDB value into a temporary DataStream before deserializing it. This is only needed when database obfuscation is enabled, because deobfuscation mutates the value bytes before they are read.

    Change

    Use SpanReader to deserialize iterator values directly when the database has no obfuscation key. Keep the existing DataStream path for obfuscated databases.

    This mirrors the existing GetKey() borrowed-span path while preserving the old exception-to-false behavior.

    Test

    cmake --build build --target test_bitcoin
    build/bin/test_bitcoin --run_test=dbwrapper_tests
    
  2. dbwrapper: avoid value copy when unobfuscated
    CDBIterator::GetValue() currently copies the current LevelDB value into a DataStream before deserializing it, even when the database is not obfuscated.
    
    Use SpanReader in the no-obfuscation case so the value bytes are read directly from the iterator span. Keep the existing DataStream path when obfuscation is enabled, because that path needs a mutable owning buffer.
    
    Extend the iterator test to cover failed value deserialization without consuming the current iterator entry.
    4348989c78
  3. DrahtBot commented at 9:15 PM on May 8, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. andrewtoth commented at 9:30 PM on May 8, 2026: contributor

    Hi @CruzMolina - this looks like it is already being implemented in #35156. Perhaps you could review that one instead?

  5. CruzMolina commented at 10:18 PM on May 8, 2026: none

    Ah, thanks for pointing that out.

    I'll close this and take a look at #35156.

  6. CruzMolina closed this on May 8, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-11 12:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me