Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework validation logic for assumeutxo #27746

Merged

Commits on Jul 14, 2023

  1. Explicitly track maximum block height stored in undo files

    When writing a new block to disk, if we have filled up the current block file,
    then we flush and truncate that block file (to free allocated but unused
    space) before advancing to the next one. When this happens, we have to
    determine whether to also flush and truncate the corresponding undo file.
    
    Undo data is only written when blocks are connected, not when blocks are
    received. Thus it's possible that the corresponding undo file already has all
    the data it will ever have, and we should flush/truncate it as we advance
    files; or it's possible that there is more data we expect to write, and should
    therefore defer flush/truncation until undo data is later written.
    
    Prior to this commit, we made the determination of whether the undo file was
    full of all requisite data by comparing against the chain tip. This patch
    replaces that dependence on validation data structures by instead just tracking
    the highest height of any block written in the undo file as we go.
    sdaftuar committed Jul 14, 2023
    Configuration menu
    Copy the full SHA
    fe86a7c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1cfc887 View commit details
    Browse the repository at this point in the history
  3. Move block-arrival information / preciousblock counters to Chainstate…

    …Manager
    
    Block arrival information (and the preciousblock RPC, a related concept) are
    both chainstate-agnostic, so these are moved to ChainstateManager. This should
    just be a refactor, without any observable behavior changes.
    sdaftuar committed Jul 14, 2023
    Configuration menu
    Copy the full SHA
    471da5f View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    10c0571 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    272fbc3 View commit details
    Browse the repository at this point in the history
  6. test: Clear block index flags when testing snapshots

    When simulating a snapshot, remove the HAVE_DATA status for blocks below the
    snapshot height, to simulate never having downloaded them at all. This makes
    tests more realistic (and more closely match what will happen when using
    assumeutxo).
    sdaftuar committed Jul 14, 2023
    Configuration menu
    Copy the full SHA
    3cfc753 View commit details
    Browse the repository at this point in the history

Commits on Jul 21, 2023

  1. Move block-storage-related logic to ChainstateManager

    Separate the notion of which blocks are stored on disk, and what data is in our
    block index, from what tip a chainstate might be able to get to. We can use
    chainstate-agnostic data to determine when to store a block on disk (primarily,
    an anti-DoS set of criteria) and let the chainstates figure out for themselves
    when a block is of interest for being a candidate tip.
    
    Note: some of the invariants in CheckBlockIndex are modified, but more work is
    needed (ie to move CheckBlockIndex to ChainstateManager, as most of what
    CheckBlockIndex is doing is checking the consistency of the block index, which
    is outside of Chainstate).
    sdaftuar committed Jul 21, 2023
    Configuration menu
    Copy the full SHA
    d0d40ea View commit details
    Browse the repository at this point in the history

Commits on Jul 24, 2023

  1. Tighten requirements for adding elements to setBlockIndexCandidates

    When using assumeutxo, we only need the background chainstate to consider
    blocks that are on the chain leading to the snapshotted block.
    
    Note that this introduces the new invariant that we can only have an assumeutxo
    snapshot where the snapshotted blockhash is in our block index. Unknown block
    hashes that are somehow passed in will cause assertion failures when processing
    new blocks.
    
    Includes test fixes and improvements by Andrew Chow and Fabian Jahr.
    sdaftuar committed Jul 24, 2023
    Configuration menu
    Copy the full SHA
    d43a1f1 View commit details
    Browse the repository at this point in the history
  2. Fix initialization of setBlockIndexCandidates when working with multi…

    …ple chainstates
    
    When using assumeutxo and multiple chainstates are active, the background
    chainstate should consider all HAVE_DATA blocks that are ancestors of the
    snapshotted block and that have more work than the tip as potential candidates.
    sdaftuar committed Jul 24, 2023
    Configuration menu
    Copy the full SHA
    768690b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0ce805b View commit details
    Browse the repository at this point in the history
  4. Move CheckBlockIndex() from Chainstate to ChainstateManager

    Also rewrite CheckBlockIndex() to perform tests on all chainstates.
    
    This increases sanity-check coverage, as any place in our code where we were
    invoke CheckBlockIndex() on a single chainstate will now invoke the sanity
    checks on all chainstates.
    
    This change also tightens up the checks on setBlockIndexCandidates and
    mapBlocksUnlinked, to more precisely match what we aim for even in the presence
    of assumed-valid blocks.
    sdaftuar committed Jul 24, 2023
    Configuration menu
    Copy the full SHA
    3556b85 View commit details
    Browse the repository at this point in the history
  5. Cache block index entry corresponding to assumeutxo snapshot base blo…

    …ckhash
    
    This is to (a) avoid repeated lookups into the block index for an entry that
    should never change and (b) emphasize that the snapshot base should always
    exist when set and not change during the runtime of the program.
    
    Thanks to Russ Yanofsky for suggesting this approach.
    sdaftuar committed Jul 24, 2023
    Configuration menu
    Copy the full SHA
    d4a11ab View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    a733dd7 View commit details
    Browse the repository at this point in the history