Repository navigation
Conversation
A merged update can list a txid both in `txid_height_new` and in `txid_height_delete`, for example the merge of "A new", "A deleted" and "A new" again. `update_heights` deletes before inserting, so the tx stays in the wallet, but `update_unspent` then removed the outputs of every deleted txid, including the re-added one. `Wollet::utxos()` and the balance missed them while the tx was listed. Keep the outputs of the txids that the update also adds. Fixes Blockstream#205
Apply an update that lists a tx both as new and as deleted, as a merged update can do, and check that the tx output stays unspent.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #205.
Problem
Update::mergecomputesUm.insert = (U1.insert \ U2.delete) ∪ U2.insertandUm.delete = U1.delete ∪ U2.delete, so a merged update can list the same txid in bothtxid_height_newandtxid_height_delete, for example the merge of "A new", "A deleted" and "A new" again.Cache::updatekeepsAinheights, sinceupdate_heightsdeletes before inserting.Cache::update_unspentthen removes the outputs of every txid indeleted_txidsas its last step, includingA. The wallet listsAbutWollet::utxos()and the balance miss its outputs.This needs a v4 update going through
update_unspent: a wallet with merged updates (WolletBuilder::with_merge_threshold(), orWolletBuilder::with_stores()with a store that is not persisted) and a non-persisted transaction store (the defaultMemoryStore), when the persisted updates are applied again, for example on reload. With a persisted transaction store the updates are upgraded to v5 andunspentcomes from the stored snapshot.Change
When removing the outputs of deleted txids, keep the ones of txids that the same update also adds. This gives
unspentthe same "delete, then insert" meaning thatupdate_heightsalready givesheights.I did not change
Update::mergeinstead: merged updates that list a txid in both vectors may already be persisted, and fixing the cache also applies them correctly. I can also drop re-inserted txids fromtxid_height_deleteinmergeif you prefer both.The inputs of such a tx are already consistent:
inputs_to_restoreadds them back as inputs of a deleted tx, andinputs_newremoves them again as inputs of a new tx.Tests
test_merged_delete_and_readd_keeps_outputincache.rsapplies an update listing a tx both as new and as deleted, and checks that its output stays unspent. It fails onmasterat the last assertion.cargo test -p lwk_wollet --lib: 141 passed.cargo clippy -p lwk_wollet --all-targets -- -D warnings,cargo fmt --check: clean.cargo test -p lwk_wollet --test e2e, on aarch64-linux with the same setup as wollet: cache: keep outputs spent by known txs #203: 129 passed, 19 ignored, 9 failed.AMP2_MOCK_EXEC(amp2::test_amp2_flow,amp2::test_elip153_flow,test_jade::emul_elip153_flow),LIGHTNINGD_EXEC,ASSET_REGISTRY_EXEC.registry::test_registry_v2times out against the emulated registry container, also onmaster, andtest_zmq_endpointis flaky in this VM on both branches, as reported in wollet: cache: keep outputs spent by known txs #203.ct_discountandtest_merge_tx_updatefailed while starting the test environment (test_env.rs:390, the electrs header subscription returned an invalid reply) and pass 3/3 when run alone; both passed in a full run before the last review change, which only builds the removed txids as a set.Notes
cache.rsmerges cleanly and the unit tests pass, only the twoCHANGELOG.mdentries conflict.unspentrestores an input of a deleted transaction that a known replacement still spends #204, the other bug found while working on wollet: cache: keep outputs spent by known txs #203, reuses the helper added there, so I will open it after wollet: cache: keep outputs spent by known txs #203.