Repository navigation
backup: restore LND key family indexes - #2225
GeorgeTsagk wants to merge 5 commits into
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Just a drive-by comment: We face the same problem for static addresses in loop as well. Instead of modifying the backup file we will go for a hd-wallet style recovery with index gap limits. While this functionality is not in place yet we provide a single command line tool to recover specific on-chain outputs that the client identifies manually. |
|
Idea: Maybe a lnd supported tapscript wallet recovery feature would be nice that scans for generic tapscript outputs on-chain during recovery, additionally to the normal wallet outputs... |
jtobin
left a comment
There was a problem hiding this comment.
LGTM. 👍 👍
(A couple of nits maybe worth addressing but I don't think they block anything.)
| // maxKeyIndexAdvance bounds the number of DeriveNextKey RPCs an import | ||
| // can trigger for one family. This protects against resource exhaustion | ||
| // from a backup with a valid-looking but unreasonable marker. | ||
| maxKeyIndexAdvance = 10_000 |
There was a problem hiding this comment.
Nit: Fable argued this could probably stand to be bumped up ("each address consumes two keys, so ~5k addresses exceed the bound"). Seems reasonable? Arguably it could be dropped entirely as an "attacker" would already have the seed IIUC.
|
|
||
| // maxKeyFamilyMarkers bounds the number of key-family markers decoded | ||
| // from an untrusted backup. | ||
| maxKeyFamilyMarkers = 100 |
There was a problem hiding this comment.
Nit: Fable points out that "every tapd key lives in only one family (212) and the export writes only one marker." The generality is probably unnecessary.
|
I thought the CI failure was a flake, but looks like it's related to the changes. Looks like the test just needs a quick fix (Fable):
|
|
Adding a complementary LND PR for this which should also close lightningnetwork/lnd#8698 |
d1d4ccf to
c3e936a
Compare
There was a problem hiding this comment.
@GeorgeTsagk does this one require lightningnetwork/lnd#11095 and lightninglabs/lndclient#288 before merge after the recent updates?
(EDIT: confirmed it does out-of-band.)
|
@jtobin: review reminder |
1 similar comment
|
@jtobin: review reminder |
|
@jtobin: review reminder |
|
@jtobin: review reminder |
4 similar comments
|
@jtobin: review reminder |
|
@jtobin: review reminder |
|
@jtobin: review reminder |
|
@jtobin: review reminder |
The seed restore test wipes Bob before restoring LND, which it did by stopping the tapd harness. Stopping a harness only removes its base directory though. The sqlite database file lives in there, so the wipe is real on that backend, but a postgres database lives in a fixture that is only torn down at test cleanup, so nothing was wiped there at all. On postgres, Bob therefore came back up with every asset still present, the backup import skipped all of them as already known, and the test failed on its own NumImported assertion. We now stand up a genuinely fresh tapd, which provisions its own database, for the restored node.
Exporting a backup called DeriveNextKey purely to learn the key family's current index. That permanently consumed one index per export, and it recorded the *next* key rather than the last one actually used, so the marker was always one index ahead of the true watermark. The index is now read through ListAccounts, and the marker key itself is derived read-only, which leaves the wallet untouched. The seed restore itest asserts both properties directly: that an export does not move the key family's index, and that the recorded marker is the last index the family actually consumed.
Recording a key in LND implies recording every key that precedes it, so restoring a key family's index is one DeriveAndStoreKey call per family instead of one DeriveNextKey per index. LND keeps that operation monotonic and bounds the number of keys it derives, so the local advance loop, the rewind guard and the maxKeyIndexAdvance limit are no longer needed here. Requires an LND with the DeriveAndStoreKey RPC (lightningnetwork/lnd#11095) and the lndclient wrapper for it (lightninglabs/lndclient#288).
c3e936a to
62c0895
Compare
|
@jtobin: review reminder |
Description
After restoring LND from aezeed, LND has no record of the derivation indexes previously consumed by tapd’s key family. This can cause newly generated Taproot Asset addresses to reuse historical script or internal keys.
This PR adds an optional key-family high-water marker to asset wallet backups. During backup import, tapd verifies that each marker belongs to the connected LND seed and advances LND’s key-family counter through the recorded index using
DeriveNextKey.The marker is encoded as a trailing, checksummed extension, preserving compatibility:
Recovery is monotonic and never rewinds LND’s counter. Markers belonging to another seed are ignored, and advancement is bounded to prevent excessive derivation work.
Tests
Tests cover:
Other
Closes #2221