diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index 52bfb1ac1..5be04684b 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -14,7 +14,7 @@ jobs: Codecov: name: Code Coverage if: false # disabled - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 env: RUSTFLAGS: "-Cinstrument-coverage" RUSTDOCFLAGS: "-Cinstrument-coverage" diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index a7f12c393..605997c30 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -14,7 +14,7 @@ jobs: build-test: name: Build and test - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: rust: @@ -64,8 +64,9 @@ jobs: cargo update -p regex --precise "1.7.3" cargo update -p security-framework-sys --precise "2.11.1" cargo update -p url --precise "2.5.0" - cargo update -p rustls@0.23.18 --precise "0.23.17" - cargo update -p hashbrown@0.15.1 --precise "0.15.0" + cargo update -p rustls@0.23.20 --precise "0.23.19" + cargo update -p hashbrown@0.15.2 --precise "0.15.0" + cargo update -p ureq --precise "2.10.1" - name: Build run: cargo build --features bitcoin/std,miniscript/std,${{ matrix.features }} --no-default-features - name: Clippy @@ -76,7 +77,7 @@ jobs: test-readme-examples: name: Test README.md examples - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: checkout uses: actions/checkout@v4 @@ -166,7 +167,7 @@ jobs: fmt: name: Rust fmt - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/nightly_docs.yml b/.github/workflows/nightly_docs.yml index 1156c9dcf..9301dad16 100644 --- a/.github/workflows/nightly_docs.yml +++ b/.github/workflows/nightly_docs.yml @@ -13,7 +13,7 @@ on: jobs: build_docs: name: Build docs - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout sources uses: actions/checkout@v4 @@ -28,7 +28,9 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@nightly with: - components: clippy + components: clippy, rustfmt + - name: Cargo update + run: cargo update - name: Build docs run: cargo rustdoc --verbose --features=compiler,electrum,esplora,use-esplora-blocking,compact_filters,rpc,key-value-db,sqlite,all-keys,verify,hardware-signer -- --cfg docsrs -Dwarnings - name: Upload artifact @@ -41,7 +43,7 @@ jobs: name: 'Publish docs' if: github.ref == 'refs/heads/master' needs: [build_docs] - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout `bitcoindevkit.org` uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index 95a503bab..4e33f6adb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -130,7 +130,7 @@ path = "examples/policy.rs" [[example]] name = "rpcwallet" path = "examples/rpcwallet.rs" -required-features = ["keys-bip39", "key-value-db", "rpc", "electrsd/bitcoind_22_0"] +required-features = ["keys-bip39", "key-value-db", "rpc", "electrsd/bitcoind_22_1"] [[example]] name = "psbt_signer" diff --git a/README.md b/README.md index 1e68f70ff..446166f3c 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,7 @@ cargo update -p home --precise "0.5.5" cargo update -p regex --precise "1.7.3" cargo update -p security-framework-sys --precise "2.11.1" cargo update -p url --precise "2.5.0" -cargo update -p rustls@0.23.18 --precise "0.23.17" -cargo update -p hashbrown@0.15.1 --precise "0.15.0" +cargo update -p rustls@0.23.20 --precise "0.23.19" +cargo update -p hashbrown@0.15.2 --precise "0.15.0" +cargo update -p ureq --precise "2.10.1" ``` diff --git a/examples/compiler.rs b/examples/compiler.rs index e17feb3ad..2773545ee 100644 --- a/examples/compiler.rs +++ b/examples/compiler.rs @@ -35,7 +35,6 @@ use bdk::{KeychainKind, Wallet}; /// can be derived from the policy. /// /// This example demonstrates the interaction between a bdk wallet and miniscript policy. - fn main() -> Result<(), Box> { env_logger::init_from_env( env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"), diff --git a/examples/policy.rs b/examples/policy.rs index 64e17825b..1dcd38987 100644 --- a/examples/policy.rs +++ b/examples/policy.rs @@ -27,7 +27,6 @@ use bdk::wallet::signer::SignersContainer; /// /// This example demos a Policy output for a 2of2 multisig between between 2 parties, where the wallet holds /// one of the Extend Private key. - fn main() -> Result<(), Box> { env_logger::init_from_env( env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"), diff --git a/src/blockchain/electrum.rs b/src/blockchain/electrum.rs index 70e8eca30..5bfd51ef8 100644 --- a/src/blockchain/electrum.rs +++ b/src/blockchain/electrum.rs @@ -168,7 +168,7 @@ impl WalletSync for ElectrumBlockchain { let needs_block_height = conftime_req .request() .filter_map(|txid| txid_to_height.get(txid).cloned()) - .filter(|height| block_times.contains_key(height)) + .filter(|height| !block_times.contains_key(height)) .take(chunk_size) .collect::>(); diff --git a/src/database/keyvalue.rs b/src/database/keyvalue.rs index 7c20b2194..6087fa670 100644 --- a/src/database/keyvalue.rs +++ b/src/database/keyvalue.rs @@ -405,12 +405,13 @@ impl BatchDatabase for Tree { #[cfg(test)] mod test { use lazy_static::lazy_static; + use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Condvar, Mutex, Once}; use std::time::{SystemTime, UNIX_EPOCH}; use sled::{Db, Tree}; - static mut COUNT: usize = 0; + static COUNT: AtomicUsize = AtomicUsize::new(0); lazy_static! { static ref DB: Arc<(Mutex>, Condvar)> = @@ -419,33 +420,31 @@ mod test { } fn get_tree() -> Tree { - unsafe { - let cloned = DB.clone(); - let (mutex, cvar) = &*cloned; + let cloned = DB.clone(); + let (mutex, cvar) = &*cloned; - INIT.call_once(|| { - let mut db = mutex.lock().unwrap(); + INIT.call_once(|| { + let mut db = mutex.lock().unwrap(); - let time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); - let mut dir = std::env::temp_dir(); - dir.push(format!("mbw_{}", time.as_nanos())); + let time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); + let mut dir = std::env::temp_dir(); + dir.push(format!("mbw_{}", time.as_nanos())); - *db = Some(sled::open(dir).unwrap()); - cvar.notify_all(); - }); + *db = Some(sled::open(dir).unwrap()); + cvar.notify_all(); + }); - let mut db = mutex.lock().unwrap(); - while !db.is_some() { - db = cvar.wait(db).unwrap(); - } + let mut db = mutex.lock().unwrap(); + while !db.is_some() { + db = cvar.wait(db).unwrap(); + } - COUNT += 1; + COUNT.fetch_add(1, Ordering::Relaxed); - db.as_ref() - .unwrap() - .open_tree(format!("tree_{}", COUNT)) - .unwrap() - } + db.as_ref() + .unwrap() + .open_tree(format!("tree_{}", COUNT.load(Ordering::Relaxed))) + .unwrap() } #[test] diff --git a/src/database/mod.rs b/src/database/mod.rs index 27d6e4dbf..134cb6b77 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -214,6 +214,7 @@ pub(crate) trait DatabaseUtils: Database { impl DatabaseUtils for T {} #[cfg(test)] +#[allow(missing_docs)] pub mod test { use bitcoin::consensus::encode::deserialize; use bitcoin::consensus::serialize; diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index dfb7bcc5f..17c5800dc 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -134,9 +134,7 @@ impl IntoWalletDescriptor for (ExtendedDescriptor, KeyMap) { network: Network, } - impl<'s, 'd> miniscript::Translator - for Translator<'s, 'd> - { + impl miniscript::Translator for Translator<'_, '_> { fn pk(&mut self, pk: &DescriptorPublicKey) -> Result { let secp = &self.secp; diff --git a/src/keys/mod.rs b/src/keys/mod.rs index 140f7dfdc..ac7ff57aa 100644 --- a/src/keys/mod.rs +++ b/src/keys/mod.rs @@ -949,7 +949,7 @@ impl std::fmt::Display for KeyError { impl std::error::Error for KeyError {} #[cfg(test)] -pub mod test { +mod test { use bitcoin::bip32; use super::*; diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index 8eaf31121..0d35f7e10 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -119,8 +119,11 @@ use std::convert::TryInto; /// overridden #[cfg(not(test))] pub type DefaultCoinSelectionAlgorithm = BranchAndBoundCoinSelection; + +/// Default deterministic coin selection algorithm for testing used by [`TxBuilder`](super::tx_builder::TxBuilder) if not +/// overridden #[cfg(test)] -pub type DefaultCoinSelectionAlgorithm = LargestFirstCoinSelection; // make the tests more predictable +pub type DefaultCoinSelectionAlgorithm = LargestFirstCoinSelection; // Base weight of a Txin, not counting the weight needed for satisfying it. // prev_txid (32 bytes) + prev_vout (4 bytes) + sequence (4 bytes) @@ -868,7 +871,7 @@ mod test { vec![utxo; utxos_number] } - fn sum_random_utxos(mut rng: &mut StdRng, utxos: &mut Vec) -> u64 { + fn sum_random_utxos(mut rng: &mut StdRng, utxos: &mut [WeightedUtxo]) -> u64 { let utxos_picked_len = rng.gen_range(2..utxos.len() / 2); utxos.shuffle(&mut rng); utxos[..utxos_picked_len] diff --git a/src/wallet/tx_builder.rs b/src/wallet/tx_builder.rs index 9ce101217..cdbcee0a4 100644 --- a/src/wallet/tx_builder.rs +++ b/src/wallet/tx_builder.rs @@ -167,7 +167,7 @@ impl std::default::Default for FeePolicy { } } -impl<'a, Cs: Clone, Ctx, D> Clone for TxBuilder<'a, D, Cs, Ctx> { +impl Clone for TxBuilder<'_, D, Cs, Ctx> { fn clone(&self) -> Self { TxBuilder { wallet: self.wallet, @@ -584,7 +584,7 @@ impl<'a, D: BatchDatabase, Cs: CoinSelectionAlgorithm, Ctx: TxBuilderContext> } } -impl<'a, D: BatchDatabase, Cs: CoinSelectionAlgorithm> TxBuilder<'a, D, Cs, CreateTx> { +impl> TxBuilder<'_, D, Cs, CreateTx> { /// Replace the recipients already added with a new list pub fn set_recipients(&mut self, recipients: Vec<(ScriptBuf, u64)>) -> &mut Self { self.params.recipients = recipients; @@ -658,7 +658,7 @@ impl<'a, D: BatchDatabase, Cs: CoinSelectionAlgorithm> TxBuilder<'a, D, Cs, C } // methods supported only by bump_fee -impl<'a, D: BatchDatabase> TxBuilder<'a, D, DefaultCoinSelectionAlgorithm, BumpFee> { +impl TxBuilder<'_, D, DefaultCoinSelectionAlgorithm, BumpFee> { /// Explicitly tells the wallet that it is allowed to reduce the amount of the output matching this /// `script_pubkey` in order to bump the transaction fee. Without specifying this the wallet /// will attempt to find a change output to shrink instead.