From cb80e62ac05e29fc13b62f27161fe309a581d5a0 Mon Sep 17 00:00:00 2001 From: Einherjar Date: Fri, 20 Oct 2023 17:37:28 -0300 Subject: [PATCH] ci(nix): pre-commit-checks with typos fixed --- .github/workflows/cont_integration.yml | 3 + .gitignore | 3 + .typos.toml | 7 + CHANGELOG.md | 2 +- crates/bdk/src/descriptor/policy.rs | 2 +- crates/bdk/src/wallet/mod.rs | 2 +- crates/bdk/src/wallet/signer.rs | 2 +- crates/bdk/src/wallet/tx_builder.rs | 2 +- crates/bdk/tests/wallet.rs | 4 +- crates/bitcoind_rpc/tests/test_emitter.rs | 6 +- crates/chain/src/indexed_tx_graph.rs | 4 +- crates/chain/src/tx_graph.rs | 2 +- crates/chain/tests/test_tx_graph.rs | 4 +- .../example_bitcoind_rpc_polling/src/main.rs | 10 +- example-crates/example_cli/src/lib.rs | 6 +- example-crates/example_esplora/src/main.rs | 2 +- flake.lock | 125 ++++++++++++++++++ flake.nix | 58 +++++++- nursery/tmp_plan/src/lib.rs | 2 +- 19 files changed, 220 insertions(+), 26 deletions(-) create mode 100644 .typos.toml diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 83721df40f..f5eda823f8 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -28,6 +28,9 @@ jobs: name: bitcoindevkit authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' continue-on-error: true # for forks outside of bitcoindevkit GH org + # Commit checks + - name: Pre-commit checks + run: nix build -L .#ci.pre-commit-check --keep-failed # Cache Builds - name: Build and Cache latest Rust run: nix build -L . --keep-failed diff --git a/.gitignore b/.gitignore index f2738186e2..35e59ccad8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ # Example persisted files. *.db + +# pre-commit-hooks.nix +.pre-commit-config.yaml diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000000..72da312faa --- /dev/null +++ b/.typos.toml @@ -0,0 +1,7 @@ +[default] +extend-ignore-re = [ + "\\b[0-9A-Za-z+/]{91}(=|==)?\\b", # base64 strings + "[0-9a-fA-F]{7,}", # git commit hashes + "\\b[0-9A-Za-z+/]{33,}(=|==)?\\b", # SHA/tpub/adresses etc strings + "flate2", # crate +] diff --git a/CHANGELOG.md b/CHANGELOG.md index 929501a183..854a40660a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -517,7 +517,7 @@ final transaction is created by calling `finish` on the builder. - Default to SIGHASH_ALL if not specified - Replace ChangeSpendPolicy::filter_utxos with a predicate - Make 'unspendable' into a HashSet -- Stop implicitly enforcing manaul selection by .add_utxo +- Stop implicitly enforcing manual selection by .add_utxo - Rename DumbCS to LargestFirstCoinSelection - Rename must_use_utxos to required_utxos - Rename may_use_utxos to optional_uxtos diff --git a/crates/bdk/src/descriptor/policy.rs b/crates/bdk/src/descriptor/policy.rs index 14b2459ebe..008bbe9aed 100644 --- a/crates/bdk/src/descriptor/policy.rs +++ b/crates/bdk/src/descriptor/policy.rs @@ -521,7 +521,7 @@ pub enum PolicyError { impl fmt::Display for PolicyError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::NotEnoughItemsSelected(err) => write!(f, "Not enought items selected: {}", err), + Self::NotEnoughItemsSelected(err) => write!(f, "Not enough items selected: {}", err), Self::IndexOutOfRange(index) => write!(f, "Index out of range: {}", index), Self::AddOnLeaf => write!(f, "Add on leaf"), Self::AddOnPartialComplete => write!(f, "Add on partial complete"), diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index 659da90a26..43d0f52679 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -1190,7 +1190,7 @@ impl Wallet { }; // TODO: We should pay attention when adding a new output: this might increase - // the lenght of the "number of vouts" parameter by 2 bytes, potentially making + // the length of the "number of vouts" parameter by 2 bytes, potentially making // our feerate too low tx.output.push(drain_output); } diff --git a/crates/bdk/src/wallet/signer.rs b/crates/bdk/src/wallet/signer.rs index 68b2ecb154..8b55753d49 100644 --- a/crates/bdk/src/wallet/signer.rs +++ b/crates/bdk/src/wallet/signer.rs @@ -751,7 +751,7 @@ pub struct SignOptions { /// Whether the signer should trust the `witness_utxo`, if the `non_witness_utxo` hasn't been /// provided /// - /// Defaults to `false` to mitigate the "SegWit bug" which chould trick the wallet into + /// Defaults to `false` to mitigate the "SegWit bug" which should trick the wallet into /// paying a fee larger than expected. /// /// Some wallets, especially if relatively old, might not provide the `non_witness_utxo` for diff --git a/crates/bdk/src/wallet/tx_builder.rs b/crates/bdk/src/wallet/tx_builder.rs index ea61894567..dd679062c4 100644 --- a/crates/bdk/src/wallet/tx_builder.rs +++ b/crates/bdk/src/wallet/tx_builder.rs @@ -182,7 +182,7 @@ impl<'a, D, Cs: Clone, Ctx> Clone for TxBuilder<'a, D, Cs, Ctx> { impl<'a, D, Cs: CoinSelectionAlgorithm, Ctx: TxBuilderContext> TxBuilder<'a, D, Cs, Ctx> { /// Set a custom fee rate /// The fee_rate method sets the mining fee paid by the transaction as a rate on its size. - /// This means that the total fee paid is equal to this rate * size of the transaction in virtual Bytes (vB) or Weigth Unit (wu). + /// This means that the total fee paid is equal to this rate * size of the transaction in virtual Bytes (vB) or Weight Unit (wu). /// This rate is internally expressed in satoshis-per-virtual-bytes (sats/vB) using FeeRate::from_sat_per_vb, but can also be set by: /// * sats/kvB (1000 sats/kvB == 1 sats/vB) using FeeRate::from_sat_per_kvb /// * btc/kvB (0.00001000 btc/kvB == 1 sats/vB) using FeeRate::from_btc_per_kvb diff --git a/crates/bdk/tests/wallet.rs b/crates/bdk/tests/wallet.rs index aad8c2db25..e8f40168ff 100644 --- a/crates/bdk/tests/wallet.rs +++ b/crates/bdk/tests/wallet.rs @@ -1197,7 +1197,7 @@ fn test_add_foreign_utxo_where_outpoint_doesnt_match_psbt_input() { satisfaction_weight ) .is_ok(), - "shoulld be ok when outpoint does match psbt_input" + "should be ok when outpoint does match psbt_input" ); } @@ -1917,7 +1917,7 @@ fn test_bump_fee_add_input_change_dust() { let mut tx = psbt.extract_tx(); for txin in &mut tx.input { - txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // to get realisitc weight + txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // to get realistic weight } let original_tx_weight = tx.weight(); assert_eq!(tx.input.len(), 1); diff --git a/crates/bitcoind_rpc/tests/test_emitter.rs b/crates/bitcoind_rpc/tests/test_emitter.rs index 4ea4ab0b28..b9c25a4be8 100644 --- a/crates/bitcoind_rpc/tests/test_emitter.rs +++ b/crates/bitcoind_rpc/tests/test_emitter.rs @@ -703,7 +703,7 @@ fn mempool_during_reorg() -> anyhow::Result<()> { "first mempool emission should include all txs", ); - // perform reorgs at different heights, these reorgs will not comfirm transactions in the + // perform reorgs at different heights, these reorgs will not confirm transactions in the // mempool for reorg_count in 1..TIP_DIFF { println!("REORG COUNT: {}", reorg_count); @@ -776,10 +776,10 @@ fn mempool_during_reorg() -> anyhow::Result<()> { /// If blockchain re-org includes the start height, emit new start height block /// /// 1. mine 101 blocks -/// 2. emmit blocks 99a, 100a +/// 2. emit blocks 99a, 100a /// 3. invalidate blocks 99a, 100a, 101a /// 4. mine new blocks 99b, 100b, 101b -/// 5. emmit block 99b +/// 5. emit block 99b /// /// The block hash of 99b should be different than 99a, but their previous block hashes should /// be the same. diff --git a/crates/chain/src/indexed_tx_graph.rs b/crates/chain/src/indexed_tx_graph.rs index 0e2620e0d1..68e7846b6e 100644 --- a/crates/chain/src/indexed_tx_graph.rs +++ b/crates/chain/src/indexed_tx_graph.rs @@ -160,7 +160,7 @@ where /// Batch insert unconfirmed transactions, filtering out those that are irrelevant. /// /// Relevancy is determined by the internal [`Indexer::is_tx_relevant`] implementation of `I`. - /// Irrelevant tansactions in `txs` will be ignored. + /// Irrelevant transactions in `txs` will be ignored. /// /// Items of `txs` are tuples containing the transaction and a *last seen* timestamp. The /// *last seen* communicates when the transaction is last seen in the mempool which is used for @@ -223,7 +223,7 @@ where /// [`AnchorFromBlockPosition::from_block_position`]. /// /// Relevancy is determined by the internal [`Indexer::is_tx_relevant`] implementation of `I`. - /// Irrelevant tansactions in `txs` will be ignored. + /// Irrelevant transactions in `txs` will be ignored. pub fn apply_block_relevant( &mut self, block: Block, diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index 1f7bcdb122..e06d1ef9ea 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -480,7 +480,7 @@ impl TxGraph { /// Inserts the given `seen_at` for `txid` into [`TxGraph`]. /// - /// Note that [`TxGraph`] only keeps track of the lastest `seen_at`. + /// Note that [`TxGraph`] only keeps track of the latest `seen_at`. pub fn insert_seen_at(&mut self, txid: Txid, seen_at: u64) -> ChangeSet { let mut update = Self::default(); let (_, _, update_last_seen) = update.txs.entry(txid).or_default(); diff --git a/crates/chain/tests/test_tx_graph.rs b/crates/chain/tests/test_tx_graph.rs index a0efd1004c..6fd31fa97a 100644 --- a/crates/chain/tests/test_tx_graph.rs +++ b/crates/chain/tests/test_tx_graph.rs @@ -15,7 +15,7 @@ use std::vec; #[test] fn insert_txouts() { - // 2 (Outpoint, TxOut) tupples that denotes original data in the graph, as partial transactions. + // 2 (Outpoint, TxOut) tuples that denotes original data in the graph, as partial transactions. let original_ops = [ ( OutPoint::new(h!("tx1"), 1), @@ -33,7 +33,7 @@ fn insert_txouts() { ), ]; - // Another (OutPoint, TxOut) tupple to be used as update as partial transaction. + // Another (OutPoint, TxOut) tuple to be used as update as partial transaction. let update_ops = [( OutPoint::new(h!("tx2"), 0), TxOut { diff --git a/example-crates/example_bitcoind_rpc_polling/src/main.rs b/example-crates/example_bitcoind_rpc_polling/src/main.rs index 32735022db..0d1163a0c9 100644 --- a/example-crates/example_bitcoind_rpc_polling/src/main.rs +++ b/example-crates/example_bitcoind_rpc_polling/src/main.rs @@ -32,7 +32,7 @@ const CHANNEL_BOUND: usize = 10; const STDOUT_PRINT_DELAY: Duration = Duration::from_secs(6); /// Delay between mempool emissions. const MEMPOOL_EMIT_DELAY: Duration = Duration::from_secs(30); -/// Delay for committing to persistance. +/// Delay for committing to persistence. const DB_COMMIT_DELAY: Duration = Duration::from_secs(60); type ChangeSet = ( @@ -187,7 +187,7 @@ fn main() -> anyhow::Result<()> { CheckPoint::from_header(&block.header, height).into_update(false); let chain_changeset = chain .apply_update(chain_update) - .expect("must always apply as we recieve blocks in order from emitter"); + .expect("must always apply as we receive blocks in order from emitter"); let graph_changeset = graph.apply_block_relevant(block, height); db.stage((chain_changeset, graph_changeset)); @@ -196,7 +196,7 @@ fn main() -> anyhow::Result<()> { last_db_commit = Instant::now(); db.commit()?; println!( - "[{:>10}s] commited to db (took {}s)", + "[{:>10}s] committed to db (took {}s)", start.elapsed().as_secs_f32(), last_db_commit.elapsed().as_secs_f32() ); @@ -305,7 +305,7 @@ fn main() -> anyhow::Result<()> { CheckPoint::from_header(&block.header, height).into_update(false); let chain_changeset = chain .apply_update(chain_update) - .expect("must always apply as we recieve blocks in order from emitter"); + .expect("must always apply as we receive blocks in order from emitter"); let graph_changeset = graph.apply_block_relevant(block, height); (chain_changeset, graph_changeset) } @@ -327,7 +327,7 @@ fn main() -> anyhow::Result<()> { last_db_commit = Instant::now(); db.commit()?; println!( - "[{:>10}s] commited to db (took {}s)", + "[{:>10}s] committed to db (took {}s)", start.elapsed().as_secs_f32(), last_db_commit.elapsed().as_secs_f32() ); diff --git a/example-crates/example_cli/src/lib.rs b/example-crates/example_cli/src/lib.rs index 9e572a8929..9495d896ea 100644 --- a/example-crates/example_cli/src/lib.rs +++ b/example-crates/example_cli/src/lib.rs @@ -78,7 +78,7 @@ pub enum Commands { #[clap(short, default_value = "bnb")] coin_select: CoinSelectionAlgo, #[clap(flatten)] - chain_specfic: S, + chain_specific: S, }, } @@ -587,7 +587,7 @@ where value, address, coin_select, - chain_specfic, + chain_specific, } => { let chain = &*chain.lock().unwrap(); let address = address.require_network(network)?; @@ -620,7 +620,7 @@ where } }; - match (broadcast)(chain_specfic, &transaction) { + match (broadcast)(chain_specific, &transaction) { Ok(_) => { println!("Broadcasted Tx : {}", transaction.txid()); diff --git a/example-crates/example_esplora/src/main.rs b/example-crates/example_esplora/src/main.rs index d2ba62d0bb..e132645536 100644 --- a/example-crates/example_esplora/src/main.rs +++ b/example-crates/example_esplora/src/main.rs @@ -104,7 +104,7 @@ fn main() -> anyhow::Result<()> { let (init_chain_changeset, init_indexed_tx_graph_changeset) = init_changeset; - // Contruct `IndexedTxGraph` and `LocalChain` with our initial changeset. They are wrapped in + // Construct `IndexedTxGraph` and `LocalChain` with our initial changeset. They are wrapped in // `Mutex` to display how they can be used in a multithreaded context. Technically the mutexes // aren't strictly needed here. let graph = Mutex::new({ diff --git a/flake.lock b/flake.lock index c90e9e9ad2..b9b94b6be9 100644 --- a/flake.lock +++ b/flake.lock @@ -55,6 +55,22 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -91,6 +107,45 @@ "type": "github" } }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1697226376, @@ -139,6 +194,60 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1689261696, + "narHash": "sha256-LzfUtFs9MQRvIoQ3MfgSuipBVMXslMPH/vZ+nM40LkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "df1eee2aa65052a18121ed4971081576b25d6b5c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": "flake-utils_3", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1697746376, + "narHash": "sha256-gu77VkgdfaHgNCVufeb6WP9oqFLjwK4jHcoPZmBVF3E=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "8cc349bfd082da8782b989cad2158c9ad5bd70fd", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "advisory-db": "advisory-db", @@ -147,6 +256,7 @@ "nixpkgs": "nixpkgs", "nixpkgs-bitcoind": "nixpkgs-bitcoind", "nixpkgs-kitman": "nixpkgs-kitman", + "pre-commit-hooks": "pre-commit-hooks", "rust-overlay": "rust-overlay_2" } }, @@ -227,6 +337,21 @@ "repo": "default", "type": "github" } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 999e6a544c..39529bac93 100644 --- a/flake.nix +++ b/flake.nix @@ -28,9 +28,10 @@ url = "github:rustsec/advisory-db"; flake = false; }; + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; }; - outputs = { self, nixpkgs, nixpkgs-bitcoind, nixpkgs-kitman, crane, rust-overlay, flake-utils, advisory-db, ... }: + outputs = { self, nixpkgs, nixpkgs-bitcoind, nixpkgs-kitman, crane, rust-overlay, flake-utils, advisory-db, pre-commit-hooks, ... }: flake-utils.lib.eachDefaultSystem (system: let overlays = [ (import rust-overlay) ]; @@ -54,6 +55,29 @@ inherit system; }; + # Signed Commits + signed-commits = pkgs.writeShellApplication { + name = "signed-commits"; + runtimeInputs = [ pkgs.git ]; + text = '' + # Function to verify the signature of the last commit + verify_signature() { + local commit_hash + commit_hash=$(git rev-parse HEAD) + if ! git verify-commit "$commit_hash"; then + echo "Error: Last commit ($commit_hash) is not signed." + exit 1 + fi + } + + # Verify the signature of the last commit + verify_signature + + # Allow the push to proceed if the signature is valid + exit 0 + ''; + }; + # Toolchains # latest stable rustTarget = pkgs.rust-bin.stable.latest.default; @@ -252,6 +276,26 @@ audit = craneLib.cargoAudit (commonArgs // { inherit advisory-db; }); + + # Pre-commit checks + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + nixpkgs-fmt.enable = true; + rustfmt.enable = true; + typos.enable = true; + commitizen.enable = true; # conventional commits + signedcommits = { + enable = true; + name = "signed-commits"; + description = "Check whether the current commit message is signed"; + stages = [ "push" ]; + entry = "${signed-commits}/bin/signed-commits"; + language = "system"; + pass_filenames = false; + }; + }; + }; }; packages = { @@ -268,6 +312,7 @@ }; legacyPackages = { ci = { + pre-commit-check = checks.pre-commit-check; clippy = checks.clippy; fmt = checks.fmt; audit = checks.audit; @@ -317,7 +362,10 @@ pkgs.ripgrep rustTarget ]; + # pre-commit-checks + inherit (self.checks.${system}.pre-commit-check) shellHook; + # env vars BITCOIND_EXEC = commonArgs.BITCOIND_EXEC; ELECTRS_EXEC = commonArgs.ELECTRS_EXEC; }; @@ -343,6 +391,10 @@ rustMSRVTarget ]; + # pre-commit-checks + inherit (self.checks.${system}.pre-commit-check) shellHook; + + # env vars BITCOIND_EXEC = commonArgs.BITCOIND_EXEC; ELECTRS_EXEC = commonArgs.ELECTRS_EXEC; }; @@ -367,6 +419,10 @@ rustWASMTarget ]; + # pre-commit-checks + inherit (self.checks.${system}.pre-commit-check) shellHook; + + # env vars BITCOIND_EXEC = commonArgs.BITCOIND_EXEC; ELECTRS_EXEC = commonArgs.ELECTRS_EXEC; CARGO_BUILD_TARGET = WASMArgs.CARGO_BUILD_TARGET; diff --git a/nursery/tmp_plan/src/lib.rs b/nursery/tmp_plan/src/lib.rs index dce190143f..226ce8b599 100644 --- a/nursery/tmp_plan/src/lib.rs +++ b/nursery/tmp_plan/src/lib.rs @@ -315,7 +315,7 @@ where self.set_sequence.clone() } - /// The minmum required transaction version required on the transaction using the plan. + /// The minimum required transaction version required on the transaction using the plan. pub fn min_version(&self) -> Option { if let Some(_) = self.set_sequence { Some(2)