net_processing: re-allow fetching of genesis block via `getblockfrompeer` #28205

pull theStack wants to merge 2 commits into bitcoin:master from theStack:202308-netprocessing-reallow_fetching_of_genesis_block changing 2 files +9 −1
  1. theStack commented at 11:40 PM on August 2, 2023: contributor

    Since commit ed6cddd98e32263fc116a4380af6d66da20da990 (PR #25717) incoming BLOCK messages have to pass an anti-DoS check in order to be accepted. Passing this check is currently only possible if there's a previous block available, which is obviously not the case for the genesis block, so it is denied:

    ERROR: ProcessNewBlock: AcceptBlock FAILED (too-little-chainwork)

    Fix that by adding the special case for the genesis block, so fetching it via getblockfrompeer on pruned nodes (which was possible pre v24.0) is working again. Inspiration for looking into this was the following twitter post: https://twitter.com/colemaktypo/status/1686423428155297796 as I vaguely remembered that this was possible in the past. The practical relevance of all this is of course debatable; on the long-term it might make more sense to put an exception on the getblock RPC to return the genesis block directly as embedded in the code, rather than trying to read it from disk, so fetching it from other peers is not needed in the first place (if we care about having it available on pruned nodes at all).

  2. net_processing: re-allow fetching of genesis block via `getblockfrompeer`
    Since commit ed6cddd98e32263fc116a4380af6d66da20da990 (PR #25717) incoming
    BLOCK messages have to pass an anti-DoS check in order to be accepted.
    Passing this check is only possible if there's a previous block available,
    which is obviously not the case for the genesis block, so it is denied:
    
    `ERROR: ProcessNewBlock: AcceptBlock FAILED (too-little-chainwork)`
    
    Fix that by adding the special case for the genesis block, so fetching
    it via `getblockfrompeer` on pruned nodes (which was possible pre v24.0)
    is working again.
    ad5a5af916
  3. test: add `getblockfrompeer` test for fetching genesis block 0412301dfa
  4. DrahtBot commented at 11:40 PM on August 2, 2023: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept NACK ajtowns

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #27837 (net: introduce block tracker to retry to download blocks after failure 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.

  5. furszy commented at 11:59 PM on August 2, 2023: member

    I don't think that the capability to fetch the genesis block from the network is relevant enough to add an exception to the anti-DoS check. Sounds weird to have nodes wasting resources asking for and responding to genesis block requests. As you said, the genesis block is hardcoded on all nodes. Better to add the exception onto the getblock() RPC command to always retrieve it instead.

  6. Sjors commented at 8:59 AM on August 3, 2023: member

    Or even simpler: have getblockfrompeer fail immediately if you ask it for the genesis block.

    Better to add the exception onto the getblock() RPC command to always retrieve it instead.

    That also makes sense, though seems like a different PR.

  7. ajtowns commented at 2:45 AM on August 9, 2023: contributor

    Concept NACK, I think -- why use the network to retrieve something that's already hardcoded? Easy to special case this in getblock I think:

    static CBlock GetBlockChecked(BlockManager& blockman, const CBlockIndex* pblockindex)
    {
        CBlock block;
        {
            LOCK(cs_main);
            if (blockman.IsBlockPruned(pblockindex)) {
                if (pblockindex->nHeight == 0) {
                    return blockman.GetParams().GenesisBlock();
                }
                throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)");
            }
        }
        ...
    

    (requires making BlockManager::GetParams public, cf #27570 (review))

  8. theStack commented at 12:11 AM on August 19, 2023: contributor

    Thanks for the feedback, I agree that fetching something we already have from somewhere else is kind of nonsensical, so closing. If anyone wants to work on the proposed getblock special-case solution, feel free to ping me as reviewer.

  9. theStack closed this on Aug 19, 2023

  10. bitcoin locked this on Aug 18, 2024

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-04-14 21:13 UTC

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