1 suggestion
Optional improvements
[suggestion] · The exception test does not exercise LoadKey's compatibility fallback
This pre-existing coverage gap leaves LoadKey's support for checksum-free legacy key records untested by this assertion; a focused follow-up test would protect that compatibility path.
Location: src/wallet/test/walletdb_tests.cpp:20 (head).
Details and suggested fix
The comment correctly describes the current test's narrow scope: it checks that reading a uint256 from an empty DataStream throws std::ios_base::failure. For a valid legacy key record without the checksum, LoadKey catches that exception, leaves the hash null, validates the private/public key pair, and loads the key. Removing the inner catch would make the outer handler return false and wallet loading classify the record as DBErrors::CORRUPT, while this assertion would still pass. As a test-only follow-up to this documentation change, serialize a valid public key into ssKey and only its DER CPrivKey into ssValue, then call LoadKey and assert success and the key's presence in LegacyDataSPKM.
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
PR #16502 retired OldKey/CWalletKey deserialization because the historical investigation found no code that serialized that record type. The stated rationale was that removing this reader would not break wallets produced by released software—not that all sufficiently old wallet records were unsupported.
This explains why removing the test comment's account of reading a wkey into CWalletKey is historically appropriate, while retaining an explanation of compatibility with old key records. The two record types have different compatibility histories.
The retirement discussion explicitly requested failure on encountering a wkey rather than silently ignoring it. The reason was to ensure that an unexpected wallet containing such a record received a compatibility error instead of having its keys silently disappear.
Unsupported wkey records represent an explicit compatibility boundary protecting key visibility. This is distinct from tolerating a missing checksum in a recognized key record; the latter is not a general policy of silently ignoring unsupported key material.
The historical explanation for adding a hash to key records was performance with backward compatibility: older records stored only the private key, requiring expensive elliptic-curve operations to rederive the public key as a consistency check; newer records appended hash(pubkey, privkey), providing a faster check while retaining compatibility.
This supplies the reason for the missing-checksum exception path described by the revised comment. Absence of that appended hash identifies an older supported encoding of a key record, rather than the unsupported wkey record type.