From cea79872d717b395560a344cc4dd0e022c3bd9a9 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Wed, 11 May 2022 18:04:18 -0700 Subject: [PATCH 1/4] Update database tests to verify set_utxo upserts --- src/database/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index e31d3a1e..ac355d7c 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -323,7 +323,8 @@ pub mod test { }; tree.set_utxo(&utxo).unwrap(); - + tree.set_utxo(&utxo).unwrap(); + assert_eq!(tree.iter_utxos().unwrap().len(), 1); assert_eq!(tree.get_utxo(&outpoint).unwrap(), Some(utxo)); } From 0b1a399f4e556a981bb992cc9b1d34318e260a7c Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Wed, 11 May 2022 17:33:32 -0700 Subject: [PATCH 2/4] Update sqlite schema with unique index for utxos, change insert_utxo to upsert --- src/database/sqlite.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/database/sqlite.rs b/src/database/sqlite.rs index 8f57205c..645cda09 100644 --- a/src/database/sqlite.rs +++ b/src/database/sqlite.rs @@ -41,6 +41,16 @@ static MIGRATIONS: &[&str] = &[ "INSERT INTO transaction_details SELECT txid, timestamp, received, sent, fee, height FROM transaction_details_old;", "DROP TABLE transaction_details_old;", "ALTER TABLE utxos ADD COLUMN is_spent;", + // drop all data due to possible inconsistencies with duplicate utxos, re-sync required + "DELETE FROM checksums;", + "DELETE FROM last_derivation_indices;", + "DELETE FROM script_pubkeys;", + "DELETE FROM sync_time;", + "DELETE FROM transaction_details;", + "DELETE FROM transactions;", + "DELETE FROM utxos;", + "DROP INDEX idx_txid_vout;", + "CREATE UNIQUE INDEX idx_utxos_txid_vout ON utxos(txid, vout);" ]; /// Sqlite database stored on filesystem @@ -86,7 +96,7 @@ impl SqliteDatabase { script: &[u8], is_spent: bool, ) -> Result { - let mut statement = self.connection.prepare_cached("INSERT INTO utxos (value, keychain, vout, txid, script, is_spent) VALUES (:value, :keychain, :vout, :txid, :script, :is_spent)")?; + let mut statement = self.connection.prepare_cached("INSERT INTO utxos (value, keychain, vout, txid, script, is_spent) VALUES (:value, :keychain, :vout, :txid, :script, :is_spent) ON CONFLICT(txid, vout) DO UPDATE SET value=:value, keychain=:keychain, script=:script, is_spent=:is_spent")?; statement.execute(named_params! { ":value": value, ":keychain": keychain, From 24719081511969299459d01566b0d669a7b51f7b Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Wed, 18 May 2022 13:44:57 -0700 Subject: [PATCH 3/4] Update CHANGELOG with warning about sqlite-db deleted wallet data --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4564032f..7348f185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New MSRV set to `1.56` - Unpinned tokio to `1` - Add traits to reuse `Blockchain`s across multiple wallets (`BlockchainFactory` and `StatelessBlockchain`). -- Upgrade to rust-bitcoin `0.28` - +- Upgrade to rust-bitcoin `0.28` +- If using the `sqlite-db` feature all cached wallet data is deleted due to a possible UTXO inconsistency, a wallet.sync will recreate it ## [v0.18.0] - [v0.17.0] From 35feb107ed5969720ce54a6aa76b7b2176f6c7c1 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 19 May 2022 14:00:40 -0700 Subject: [PATCH 4/4] [CI] Fix cont_integration test-blockchains to run all tests --- .github/workflows/cont_integration.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 091ba157..4a7c2ea9 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -90,12 +90,16 @@ jobs: matrix: blockchain: - name: electrum + testprefix: blockchain::electrum::test features: test-electrum,verify - name: rpc + testprefix: blockchain::rpc::test features: test-rpc - name: esplora + testprefix: esplora features: test-esplora,use-esplora-reqwest,verify - name: esplora + testprefix: esplora features: test-esplora,use-esplora-ureq,verify steps: - name: Checkout @@ -114,7 +118,7 @@ jobs: toolchain: stable override: true - name: Test - run: cargo test --no-default-features --features ${{ matrix.blockchain.features }} ${{ matrix.blockchain.name }}::bdk_blockchain_tests + run: cargo test --no-default-features --features ${{ matrix.blockchain.features }} ${{ matrix.blockchain.testprefix }}::bdk_blockchain_tests check-wasm: name: Check WASM