Review report

core: PR #36697

3 suggestions

Earlier concerns neither republished nor resolved: 3 suggestions. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · Candidate scans and private descriptor expansion repeat under the wallet lock

For a Taproot export, work grows with candidate keys times cached pubkeys, plus a full private expansion per local candidate; this holds cs_wallet, though wall-clock impact is unmeasured.

Location: src/wallet/export.cpp:198 (head).

Details and suggested fix

For a Taproot destination, ExportAddressKeys calls GetExportPubKeys once per manager, then calls it again for every x-only candidate on every manager. Each call scans the manager’s full m_map_pubkeys and roots. For each entry, add_match computes P2PKH, P2WPKH, and P2SH-P2WPKH hashes and checks IsFullyValid, although Taproot lookup needs only the x-only comparison. The scans also occur in taproot_output mode, even though leaf-only candidates are discarded later.

The records loop calls ExportKey(pubkey) for each candidate on each manager. For every candidate found in a manager’s m_map_pubkeys, this repeats ExpandFromCache, retrieves each held root with GetKey (which decrypts keys on encrypted wallets), and runs ExpandPrivateChecked over the whole descriptor to return one scalar. This also affects P2WSH and P2SH multisig exports.

With C x-only candidates and P cached pubkeys across managers, discovery performs about (C+1)·P key matches. K local keys in one descriptor cause K full private expansions. The default keypool is 1000 per ranged descriptor. These counts follow from the loop structure, but their wall-clock impact has not been measured. All this work runs while the RPC holds cs_wallet.

Collect the x-only candidates first and scan each manager once against them, or build a request-local x-only-to-SEC index. Compute only the hash form needed for the destination, and memoize checked private expansion per (manager, index) within the call. The commitment and exact-identity checks can remain unchanged.


Link

[suggestion] · Address-type-dependent aliases duplicate private-key response fields

The top-level private_key_hex and compressed fields have no earlier Bitcoin Core contract, but removing them after release would require a deprecation cycle.

Location: src/wallet/export.cpp:273 (head).

Details and suggested fix

For P2PKH and P2WPKH wallet-mode results, legacy_aliases makes AddressKeyToJSON add top-level private_key_hex and compressed fields that duplicate keys[0]. The code comment calls this the “original RPC contract,” and the help describes them as compatibility aliases. However, exportaddresskey does not exist at the comparison base, so the only earlier contract is the Bitcoin Roots fork’s.

The response shape therefore depends on address type, and the secret appears twice in those responses. The RPCResult schema and tests must also keep both forms in sync. After release, removing the aliases would require a -deprecatedrpc cycle. Return only keys before the RPC first ships; clients expecting the fork’s shape can read keys[0].


Link

[suggestion] · The p2p_segwit synchronization change is unrelated and duplicates a broader fix

The first commit addresses a block-relay race unrelated to key export, while PR #36703 adds synchronization more generally.

Location: test/functional/p2p_segwit.py:1467 (head).

Details and suggested fix

Commit e6d9e842 adds self.sync_blocks() after four test_witness_block calls in test_uncompressed_pubkey to avoid intermittent block-relay lag between the nodes. In this version, test_witness_block sends the block and checks the tip but does not synchronize blocks. Open PR #36703 adds synchronization inside test_witness_block, covering every caller. Keeping both changes would duplicate the fix and add an unrelated file to a large wallet PR. Drop this commit and rely on #36703, or split it out if this PR’s CI needs the fix first.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.