node: don't throw bad_optional_access on a snapshot network mismatch #36568

pull Ravan002 wants to merge 1 commits into bitcoin:master from Ravan002:snapshot-network-custom-signet changing 2 files +17 −1
  1. Ravan002 commented at 7:52 PM on October 18, 2026: none

    When a snapshot's network magic doesn't match the node's, SnapshotMetadata::Unserialize builds an error message with the names of both networks. The node's name comes from GetNetworkForMagic(m_network_magic).value(), which is empty on a custom signet because its magic is derived from the challenge and is not one of the built-in ones. loadtxoutset with a snapshot made for another network then fails with bad_optional_access instead of the message.

    The node side now falls back to "custom signet", the only case where the lookup can be empty.

    before: Unable to parse metadata: bad_optional_access
    after:  Unable to parse metadata: The network of the snapshot (main) does not match the network of this node (custom signet).
    

    New unit test snapshot_metadata_network_mismatch_custom_signet fails on master with std::bad_optional_access. validation_chainstatemanager_tests and feature_assumeutxo.py pass.

  2. node: don't throw bad_optional_access on a snapshot network mismatch
    SnapshotMetadata::Unserialize looked up the name of the node's network
    with node_network.value(). On a custom signet the magic matches no
    built-in network, so loading a snapshot made for another network threw
    std::bad_optional_access instead of the intended message.
    6e8ccff446
  3. DrahtBot commented at 7:17 AM on October 19, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Approach ACK Husteem

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

  4. Husteem commented at 11:42 AM on October 19, 2026: none

    Concept ACK / Approach ACK

    Verified the failure on master prior to this patch and confirmed the new test passes with this fix.

    Empirical Reproduction on master Before this patch, running loadtxoutset on a custom signet node against a mainnet snapshot threw an uncaught std::bad_optional_access out of GetNetworkForMagic(m_network_magic).value().

    Because loadtxoutset in src/rpc/blockchain.cpp specifically catches const std::ios_base::failure&, std::bad_optional_access bypassed the deserialization error handler and bubbled up to CRPCTable::execute as a generic RPC_MISC_ERROR ("std::bad_optional_access") rather than the intended RPC_DESERIALIZATION_ERROR.

    While the fix and the new unit test resolve this issue. I left one small wording suggestion inline.

  5. in src/node/utxo_snapshot.h:97 in 6e8ccff446
      92 | @@ -93,7 +93,8 @@ class SnapshotMetadata
      93 |              if (metadata_network) {
      94 |                  std::string network_string{ChainTypeToString(metadata_network.value())};
      95 |                  auto node_network{GetNetworkForMagic(m_network_magic)};
      96 | -                std::string node_network_string{ChainTypeToString(node_network.value())};
      97 | +                // a custom signet has a magic that matches no built-in network
      98 | +                std::string node_network_string{node_network ? ChainTypeToString(*node_network) : "custom signet"};
    


    fjahr commented at 8:50 AM on October 20, 2026:

    It should just be unknown since we don't know if it's really a custom signet we are dealing with here. The comment also isn't needed.

  6. fjahr commented at 8:52 AM on October 20, 2026: contributor

    Concept ~0

    Pretty minor edge case but improving the error message doesn't hurt.

  7. maflcko commented at 9:06 AM on October 20, 2026: member

    Closing for now due to controversy.

  8. maflcko closed this on Oct 20, 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-10-28 15:51 UTC

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