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

limit by-root requests to non-finalized blocks #3293

Merged
merged 2 commits into from
Jan 21, 2022
Merged

limit by-root requests to non-finalized blocks #3293

merged 2 commits into from
Jan 21, 2022

Commits on Jan 20, 2022

  1. limit by-root requests to non-finalized blocks

    Presently, we keep a mapping from block root to `BlockRef` in memory -
    this has simplified reasoning about the dag, but is not sustainable with
    the chain growing.
    
    We can distinguish between two cases where by-root access is useful:
    
    * unfinalized blocks - this is where the beacon chain is operating
    generally, by validating incoming data as interesting for future fork
    choice decisions - bounded by the length of the unfinalized period
    * finalized blocks - historical access in the REST API etc - no bounds,
    really
    
    In this PR, we limit the by-root block index to the first use case:
    finalized chain data can more efficiently be addressed by slot number.
    
    Future work includes:
    
    * limiting the `BlockRef` horizon in general - each instance is 40
    bytes+overhead which adds up - this needs further refactoring to deal
    with the tail vs state problem
    * persisting the finalized slot-to-hash index - this one also keeps
    growing unbounded (albeit slowly)
    
    Anyway, this PR easily shaves ~128mb of memory usage at the time of
    writing.
    
    * No longer honor `BeaconBlocksByRoot` requests outside of the
    non-finalized period - previously, Nimbus would generously return any
    block through this libp2p request - per the spec, finalized blocks
    should be fetched via `BeaconBlocksByRange` instead.
    * return `Opt[BlockRef]` instead of `nil` when blocks can't be found -
    this becomes a lot more common now and thus deserves more attention
    * `dag.blocks` -> `dag.forkBlocks` - this index only carries unfinalized
    blocks from now - `finalizedBlocks` covers the other `BlockRef`
    instances
    * in backfill, verify that the last backfilled block leads back to
    genesis, or panic
    * add backfill timings to log
    * fix missing check that `BlockRef` block can be fetched with
    `getForkedBlock` reliably
    * shortcut doppelganger check when feature is not enabled
    * in REST/JSON-RPC, fetch blocks without involving `BlockRef`
    arnetheduck committed Jan 20, 2022
    Configuration menu
    Copy the full SHA
    ca37661 View commit details
    Browse the repository at this point in the history
  2. fix dag.blocks ref

    arnetheduck committed Jan 20, 2022
    Configuration menu
    Copy the full SHA
    1622233 View commit details
    Browse the repository at this point in the history