Applying a merged update with a txid in both `txid_height_new` and `txid_height_delete` drops its outputs from `unspent`
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Start with Cache::update_unspent in lwk_wollet/src/cache.rs and compare its handling of outputs with update_heights when a txid appears in both update lists. The reproduction in the issue can be added to the cache tests; run it to confirm the failure. Done means the merged update keeps the transaction’s output in unspent and the regression test passes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
A merged update can list the same txid in both txid_height_new and txid_height_delete. Applying it keeps the transaction in heights, but removes its outputs from unspent. The wallet then lists the transaction but not its unspent outputs, so Wollet::utxos() and the balance are lower than they should be.
Version: lwk_wollet 0.20.0, still on master (ea5321528). Found while working on #203; that PR does not change this path.
Cause
Update::merge (lwk_wollet/src/update.rs) computes Um.insert = (U1.insert \ U2.delete) ∪ U2.insert and Um.delete = U1.delete ∪ U2.delete. Merging "A new", "A deleted" and "A new" again gives txid_height_new = [A] and txid_height_delete = [A].
Cache::update handles heights correctly: update_heights deletes first and then inserts, so A stays. Cache::update_unspent (lwk_wollet/src/cache.rs) adds A:0 and then, last, removes the outputs of every txid in deleted_txids, including A. So A:0 is dropped although A is a wallet transaction.
This needs a v4 update to go through update_unspent, that is a wallet whose transaction store is not persisted (the default MemoryStore) and whose persisted updates are merged (merge_threshold). One way to get the three updates is a transaction applied with Wollet::apply_transaction, not yet returned by the next scan, and returned by a later one. Each update applied on its own gives the right result; the wrong unspent shows up when the merged update is replayed, for example after reloading the wallet.
When the transaction store is persisted, updates are upgraded to v5 and unspent comes from the stored snapshot instead, so I don't think that case is affected.
Reproduction
Add to the tests module in lwk_wollet/src/cache.rs:
#[test]
fn test_merged_delete_and_readd_keeps_output() {
use crate::descriptor::Chain;
use elements::bitcoin::bip32::ChildNumber;
use elements::confidential::{AssetBlindingFactor, ValueBlindingFactor};
use elements::{AssetId, OutPoint, Script, TxOut, TxOutSecrets};
let script = Script::from(vec![0x51]);
// A pays one output to a wallet script.
let a = Transaction {
version: 2,
lock_time: elements::LockTime::ZERO,
input: vec![],
output: vec![TxOut {
script_pubkey: script.clone(),
..Default::default()
}],
};
let a_txid = a.txid();
let a0 = OutPoint::new(a_txid, 0);
let mut cache = Cache::default();
cache
.paths
.insert(script.clone(), (Chain::External, ChildNumber::from(0)));
let secrets = TxOutSecrets::new(
AssetId::from_byte_array([1u8; 32]),
AssetBlindingFactor::zero(),
1000,
ValueBlindingFactor::zero(),
);
cache.extend_unblinded([(a0, secrets)]);
// The merge of three updates, "A new", "A deleted" and "A new" again,
// has A both in `txid_height_new` and in `txid_height_delete`
// (see `Update::merge`).
cache
.update(&[(a_txid, Some(100))], &[a_txid], &[(a_txid, a)], false, vec![], false)
.unwrap();
assert!(cache.heights().contains_key(&a_txid));
// Fails: A is a wallet tx again, but A:0 is not unspent.
assert!(cache.unspent().contains_key(&a0));
}
On master the last assertion fails.
Possible fix
When removing the outputs of deleted transactions, skip the txids that are still in heights after the update. Alternatively, Update::merge could drop from txid_height_delete the txids inserted again by a later update.
- Ngôn ngữ chính
- Rust
- Star
- 114
- Fork
- 69
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Blockstream/lwk
-
Ignore entry for RUSTSEC-2020-0168 no longer matches anything (`mach` is no longer in `Cargo.lock`)Có thể đã có người làm @zyl71 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Blockstream/lwk#213 ·
-
wollet: Waterfalls scan sets `last_unused` to a page-relative index past the first pageCó thể đã có người làm @diorwave đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Blockstream/lwk#209 ·
-
C# bindings: all generated types are `internal`, `LiquidWalletKit` 0.8.2 has no usable public APICó thể đã có người làm @lisboaigor đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 25/100
Blockstream/lwk#210 ·
-
Cache `unspent` restores an input of a deleted transaction that a known replacement still spendsĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Blockstream/lwk#204 ·
-
Cache `unspent` re-adds a spent output when its transaction is deleted and then seen againCó thể đã có người làm @Jeon1691 đã nhận 6 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Blockstream/lwk#201 ·
Tất cả issue của Blockstream/lwk
Issue tương tự
-
Ignore entry for RUSTSEC-2026-0002 no longer matches anything (`lru` is no longer in `Cargo.lock`)Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
influxdata/influxdb#27767 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
manuscript-lang/manuscript#6389 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày