diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c247002..36e23eab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,16 +13,18 @@ env: RUST_BACKTRACE: "full" # Increase thread stack size to 8 megabytes. RUST_MIN_STACK: 8000000 + # Fail on documentation warnings. + RUSTDOCFLAGS: '-D warnings' jobs: # Run format separately. + # + # This will fast-cancel other CI early if this fails. + # + # `cargo fmt` checks _all_ code, regardless of the OS + # or any `#[cfg]`'s, so this only needs to run on Linux. fmt: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [windows-latest, macos-latest, ubuntu-latest] - + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -31,6 +33,16 @@ jobs: - name: Format run: cargo fmt --all --check + # Run typo checker separately. + # This will fast-cancel other CI early if this fails. + typo: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Spell Check + uses: crate-ci/typos@master + # All other CI. ci: runs-on: ${{ matrix.os }} @@ -84,19 +96,23 @@ jobs: update: true install: mingw-w64-x86_64-toolchain mingw-w64-x86_64-boost msys2-runtime-devel git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja + - name: Update Rust (UNIX) + if: matrix.os != 'windows-latest' + run: rustup update + - name: Switch target (Windows) if: matrix.os == 'windows-latest' run: rustup toolchain install stable-x86_64-pc-windows-gnu -c clippy && rustup set default-host x86_64-pc-windows-gnu && rustup default stable-x86_64-pc-windows-gnu - - name: Update Rust - run: rustup update + - name: Documentation + run: cargo doc --workspace --all-features - name: Clippy (fail on warnings) - run: cargo clippy --workspace --all-targets --all-features -- -D warnings + run: cargo clippy --workspace --all-features --all-targets -- -D warnings - name: Test - run: cargo test --all-features --workspace --all-targets + run: cargo test --all-features --workspace # TODO: upload binaries with `actions/upload-artifact@v3` - name: Build - run: cargo build --all-features --all-targets --workspace \ No newline at end of file + run: cargo build --all-features --all-targets --workspace diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6758830a..dc07f0c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,13 +14,21 @@ When you are at a stage where you would like feedback you can open a draft PR, k Once your PR is at the stage where you feel it's ready to go, open it for review. ## Passing CI +The first 3 steps to CI are formatting, typo, and documentation checking. -To pass CI make sure all these successfully run: +Check if your changes are formatted, typo-free, and documented correctly by running: +- `cargo fmt --all --check` +- `typos` +- `RUSTDOCFLAGS='-D warnings' cargo doc --workspace --all-features` -- `cargo clippy --workspace --all-targets --all-features -- -D warnings` +`typos` can be installed with `cargo` from: https://github.com/crate-ci/typos. + +After that, ensure all lints, tests, and builds are successful by running: + +- `cargo clippy --workspace --all-features --all-targets -- -D warnings` - `cargo fmt --all` -- `cargo test` -- `cargo build` +- `cargo test --all-features --workspace` +- `cargo build --all-features --all-targets --workspace` ## Coding guidelines diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml index a109144f..bfe70fa5 100644 --- a/consensus/Cargo.toml +++ b/consensus/Cargo.toml @@ -2,7 +2,7 @@ name = "cuprate-consensus" version = "0.1.0" edition = "2021" -description = "A crate implimenting all Moneros consensus rules." +description = "A crate implementing all Moneros consensus rules." license = "MIT" authors = ["Boog900"] repository = "https://github.com/Cuprate/cuprate/tree/main/consensus" diff --git a/consensus/src/batch_verifier.rs b/consensus/src/batch_verifier.rs index 57fb997d..d86d1979 100644 --- a/consensus/src/batch_verifier.rs +++ b/consensus/src/batch_verifier.rs @@ -41,7 +41,7 @@ impl MultiThreadedBatchVerifier { .into_iter() .map(UnsafeCell::into_inner) .par_bridge() - .find_any(|batch_verifer| !batch_verifer.verify_vartime()) + .find_any(|batch_verifier| !batch_verifier.verify_vartime()) .is_none() } } diff --git a/consensus/src/bin/scan_chain.rs b/consensus/src/bin/scan_chain.rs index e0a4c896..e1699dcb 100644 --- a/consensus/src/bin/scan_chain.rs +++ b/consensus/src/bin/scan_chain.rs @@ -213,7 +213,7 @@ mod bin { #[arg(short, long, default_value = "mainnet")] network: String, /// A list of RPC nodes we should use. - /// Example: http://xmr-node.cakewallet.com:18081 + /// Example: #[arg(long)] rpc_nodes: Vec, /// Stops the scanner from including the default list of nodes, this is not diff --git a/consensus/src/context/rx_vms.rs b/consensus/src/context/rx_vms.rs index 5631206a..ce086027 100644 --- a/consensus/src/context/rx_vms.rs +++ b/consensus/src/context/rx_vms.rs @@ -165,7 +165,7 @@ pub(crate) fn get_last_rx_seed_heights(mut last_height: u64, mut amount: usize) return seeds; } - // We don't include the lag as we only want seeds not the specific seed fo this height. + // We don't include the lag as we only want seeds not the specific seed for this height. let seed_height = (last_height - 1) & !(RX_SEEDHASH_EPOCH_BLOCKS - 1); seeds.push(seed_height); last_height = seed_height diff --git a/consensus/src/tests/context/difficulty.rs b/consensus/src/tests/context/difficulty.rs index 0e4af492..b070d7a1 100644 --- a/consensus/src/tests/context/difficulty.rs +++ b/consensus/src/tests/context/difficulty.rs @@ -144,7 +144,7 @@ proptest! { } #[test] - fn next_difficulty_consistant(diff_cache in arb_difficulty_cache(TEST_TOTAL_ACCOUNTED_BLOCKS), hf in any::()) { + fn next_difficulty_consistent(diff_cache in arb_difficulty_cache(TEST_TOTAL_ACCOUNTED_BLOCKS), hf in any::()) { let first_call = diff_cache.next_difficulty(&hf); prop_assert_eq!(first_call, diff_cache.next_difficulty(&hf)); prop_assert_eq!(first_call, diff_cache.next_difficulty(&hf)); diff --git a/consensus/src/transactions/contextual_data.rs b/consensus/src/transactions/contextual_data.rs index aa1b0a61..2a90acbb 100644 --- a/consensus/src/transactions/contextual_data.rs +++ b/consensus/src/transactions/contextual_data.rs @@ -107,7 +107,7 @@ pub async fn batch_refresh_ring_member_info<'a, D: Database + Clone + Send + Syn Ok(()) } -/// This function returns the transaction verification datas that need refreshing. +/// This function returns the transaction verification data that need refreshing. /// /// The first returned vec needs a full refresh. /// The second returned vec only needs a partial refresh. diff --git a/cryptonight/c/skein_port.h b/cryptonight/c/skein_port.h index 6ba83d3d..8ef6d66e 100644 --- a/cryptonight/c/skein_port.h +++ b/cryptonight/c/skein_port.h @@ -76,7 +76,7 @@ multiple of size / 8) ptr_cast(x,size) casts a pointer to a pointer to a - varaiable of length 'size' bits + variable of length 'size' bits */ #define ui_type(size) uint##size##_t diff --git a/cryptonight/c/slow-hash.c b/cryptonight/c/slow-hash.c index 25e60cc6..2bdc7d7f 100644 --- a/cryptonight/c/slow-hash.c +++ b/cryptonight/c/slow-hash.c @@ -1454,7 +1454,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int } #else /* aarch64 && crypto */ -// ND: Some minor optimizations for ARMv7 (raspberrry pi 2), effect seems to be ~40-50% faster. +// ND: Some minor optimizations for ARMv7 (raspberry pi 2), effect seems to be ~40-50% faster. // Needs more work. #ifdef NO_OPTIMIZED_MULTIPLY_ON_ARM diff --git a/misc/ENVIRONMENT-ADIVE.md b/misc/ENVIRONMENT-ADVICE.md similarity index 100% rename from misc/ENVIRONMENT-ADIVE.md rename to misc/ENVIRONMENT-ADVICE.md diff --git a/net/epee-encoding/README.md b/net/epee-encoding/README.md index d1825246..89c336dc 100644 --- a/net/epee-encoding/README.md +++ b/net/epee-encoding/README.md @@ -146,7 +146,7 @@ example: #[derive(EpeeObject)] pub struct HandshakeR { #[epee_alt_name("node_data")] - pub node_daa: BasicNodeData, + pub node_data: BasicNodeData, } ``` diff --git a/net/epee-encoding/src/lib.rs b/net/epee-encoding/src/lib.rs index f9f354da..1960f28b 100644 --- a/net/epee-encoding/src/lib.rs +++ b/net/epee-encoding/src/lib.rs @@ -217,7 +217,7 @@ fn read_object(r: &mut B, skipped_objects: &mut u8) -> Re object_builder.finish() } -/// Read a marker from the [`Read`], this function should only be used for +/// Read a marker from the [`Buf`], this function should only be used for /// custom serialisation based on the marker otherwise just use [`read_epee_value`]. pub fn read_marker(r: &mut B) -> Result { Marker::try_from(checked_read_primitive(r, Buf::get_u8)?) diff --git a/net/epee-encoding/tests/flattend.rs b/net/epee-encoding/tests/flattened.rs similarity index 100% rename from net/epee-encoding/tests/flattend.rs rename to net/epee-encoding/tests/flattened.rs diff --git a/net/epee-encoding/tests/stack_overflow.rs b/net/epee-encoding/tests/stack_overflow.rs index 1f71abf8..395b7570 100644 --- a/net/epee-encoding/tests/stack_overflow.rs +++ b/net/epee-encoding/tests/stack_overflow.rs @@ -20,7 +20,7 @@ epee_object!( ); #[test] -fn stack_overlfow() { +fn stack_overflow() { let bytes = vec![ 1, 17, 1, 1, 1, 1, 2, 1, 1, 8, 3, 114, 101, 113, 8, 3, 1, 100, 12, 8, 3, 118, 97, 108, 8, 7, 1, 100, 12, 8, 3, 118, 97, 108, 8, 7, 1, 100, 12, 8, 3, 118, 97, 108, 8, 7, 1, 100, 12, diff --git a/net/fixed-bytes/src/lib.rs b/net/fixed-bytes/src/lib.rs index a88e23ef..c7b71151 100644 --- a/net/fixed-bytes/src/lib.rs +++ b/net/fixed-bytes/src/lib.rs @@ -39,7 +39,7 @@ impl Debug for FixedByteError { /// A fixed size byte slice. /// -/// Internally this is just a wrapper around [`Bytes`], with the constructors checking that the length is equal to [`N`]. +/// Internally this is just a wrapper around [`Bytes`], with the constructors checking that the length is equal to `N`. /// This implements [`Deref`] with the target being `[u8; N]`. #[derive(Debug, Clone, Eq, PartialEq)] pub struct ByteArray(Bytes); diff --git a/old_database/src/interface.rs b/old_database/src/interface.rs index cacd0fd6..cde8c0ad 100644 --- a/old_database/src/interface.rs +++ b/old_database/src/interface.rs @@ -194,7 +194,7 @@ impl<'service, D: Database<'service>> Interface<'service, D> { cursor_blockmetadata.del()?; - // Then we delete all its revelent txs + // Then we delete all its relevant txs for tx_hash in blk.tx_hashes.iter() { // 1 more condition in monerod TODO: self.remove_transaction(*tx_hash)?; @@ -684,9 +684,9 @@ impl<'service, D: Database<'service>> Interface<'service, D> { /// `get_tx_list` fetches the transactions with given hashes. /// /// Should return a vector with the requested transactions. In case of failures, a DB_FAILURES will be return. - /// Precisly, a HASH_DNE error will be returned with the correspondig hash of transaction that is not found in the DB. + /// Precisely, a HASH_DNE error will be returned with the corresponding hash of transaction that is not found in the DB. /// - /// `hlist`: is the given collection of hashes correspondig to the transactions to fetch. + /// `hlist`: is the given collection of hashes corresponding to the transactions to fetch. fn get_tx_list( &'service self, hash_list: Vec, diff --git a/old_database/src/lib.rs b/old_database/src/lib.rs index 1d880f5e..d410b67f 100644 --- a/old_database/src/lib.rs +++ b/old_database/src/lib.rs @@ -20,7 +20,7 @@ //! At the moment, the only storage engine available is MDBX. //! The next storage engine planned is HSE (Heteregeonous Storage Engine) from Micron. //! -//! For more informations, please consult this docs: +//! For more information, please consult this docs: #![deny(unused_attributes)] #![forbid(unsafe_code)] @@ -54,7 +54,7 @@ const BINCODE_CONFIG: bincode::config::Configuration< pub mod database { //! This module contains the Database abstraction trait. Any key/value storage engine implemented need - //! to fullfil these associated types and functions, in order to be usable. This module also contains the + //! to fulfil these associated types and functions, in order to be usable. This module also contains the //! Interface struct which is used by the DB Reactor to interact with the database. use crate::{ diff --git a/old_database/src/table.rs b/old_database/src/table.rs index aaa71a28..0b2f38ac 100644 --- a/old_database/src/table.rs +++ b/old_database/src/table.rs @@ -137,7 +137,7 @@ impl_duptable!( ); impl_duptable!( - /// `txsidentifier` is a table defining a relation between the hash of a transaction and its transaction Indexes. Its primarly used to quickly find tx's ID by its hash. + /// `txsidentifier` is a table defining a relation between the hash of a transaction and its transaction Indexes. Its primarily used to quickly find tx's ID by its hash. txsidentifier, Compat, (), diff --git a/old_database/src/types.rs b/old_database/src/types.rs index a4ca8b8c..f4f806ae 100644 --- a/old_database/src/types.rs +++ b/old_database/src/types.rs @@ -37,7 +37,7 @@ pub struct BlockMetadata { } #[derive(Clone, Debug, Encode, Decode)] -/// [`AltBlock`] is a struct contaning an alternative `block` (defining an alternative mainchain) and its metadata (`block_height`, `cumulative_weight`, +/// [`AltBlock`] is a struct containing an alternative `block` (defining an alternative mainchain) and its metadata (`block_height`, `cumulative_weight`, /// `cumulative_difficulty_low`, `cumulative_difficulty_high`, `already_generated_coins`). /// This struct is used in [`crate::table::altblock`] table. pub struct AltBlock { @@ -317,7 +317,7 @@ pub struct OutputMetadata { //#[derive(Clone, Debug, Encode, Decode)] //// [`OutAmountIdx`] is a struct tuple used to contain the two keys used in [`crate::table::outputamounts`] table. //// In monerod, the database key is the amount while the *cursor key* (the amount index) is the prefix of the actual data being returned. -//// As we prefere to note use cursor with partial data, we prefer to concat these two into a unique key +//// As we prefer to note use cursor with partial data, we prefer to concat these two into a unique key //pub struct OutAmountIdx(u64,u64); // MAYBE NOT FINALLY diff --git a/p2p/monero-p2p/src/client.rs b/p2p/monero-p2p/src/client.rs index 5df55823..8e3ca488 100644 --- a/p2p/monero-p2p/src/client.rs +++ b/p2p/monero-p2p/src/client.rs @@ -15,11 +15,11 @@ use crate::{ handles::ConnectionHandle, NetworkZone, PeerError, PeerRequest, PeerResponse, SharedError, }; -mod conector; mod connection; +mod connector; pub mod handshaker; -pub use conector::{ConnectRequest, Connector}; +pub use connector::{ConnectRequest, Connector}; pub use handshaker::{DoHandshakeRequest, HandShaker, HandshakeError}; /// An internal identifier for a given peer, will be their address if known diff --git a/p2p/monero-p2p/src/client/connection.rs b/p2p/monero-p2p/src/client/connection.rs index 82b05f77..1b49454c 100644 --- a/p2p/monero-p2p/src/client/connection.rs +++ b/p2p/monero-p2p/src/client/connection.rs @@ -161,7 +161,7 @@ where tracing::debug!("waiting for peer/client request."); tokio::select! { biased; - bradcast_req = self.broadcast_rx.next() => { + broadcast_req = self.broadcast_rx.next() => { todo!() } client_req = self.client_rx.next() => { @@ -188,7 +188,7 @@ where tracing::debug!("waiting for peer response.."); tokio::select! { biased; - bradcast_req = self.broadcast_rx.next() => { + broadcast_req = self.broadcast_rx.next() => { todo!() } peer_message = stream.next() => { diff --git a/p2p/monero-p2p/src/client/conector.rs b/p2p/monero-p2p/src/client/connector.rs similarity index 100% rename from p2p/monero-p2p/src/client/conector.rs rename to p2p/monero-p2p/src/client/connector.rs diff --git a/p2p/monero-p2p/src/client/handshaker.rs b/p2p/monero-p2p/src/client/handshaker.rs index fdfa6a41..6ea828d9 100644 --- a/p2p/monero-p2p/src/client/handshaker.rs +++ b/p2p/monero-p2p/src/client/handshaker.rs @@ -418,7 +418,7 @@ async fn wait_for_message( eager_protocol_messages.push(protocol_message); if eager_protocol_messages.len() > MAX_EAGER_PROTOCOL_MESSAGES { tracing::debug!( - "Peer sent too many protocl messages before a handshake response." + "Peer sent too many protocol messages before a handshake response." ); return Err(HandshakeError::PeerSentInvalidMessage( "Peer sent too many protocol messages", diff --git a/test-utils/src/monerod.rs b/test-utils/src/monerod.rs index 6b103aca..dd870143 100644 --- a/test-utils/src/monerod.rs +++ b/test-utils/src/monerod.rs @@ -39,14 +39,14 @@ pub async fn monerod(flags: Vec, mutable: bool) -> (SocketAddr, SocketAd // We only actually need these channels on first run so this might be wasteful let (tx, rx) = mpsc::channel(3); - let mut should_spwan = false; + let mut should_spawn = false; let monero_handler_tx = MONEROD_HANDLER_CHANNEL.get_or_init(|| { - should_spwan = true; + should_spawn = true; tx }); - if should_spwan { + if should_spawn { // If this call was the first call to start a monerod instance then start the handler. let manager = MoneroDManager::new().await; tokio::task::spawn(manager.run(rx)); @@ -73,7 +73,7 @@ struct MoneroDRequest { } /// A struct representing a spawned monerod. -struct SpwanedMoneroD { +struct SpawnedMoneroD { /// A marker for if the test that spawned this monerod is going to mutate it. mutable: bool, /// A handle to the monerod process, monerod will be stopped when this is dropped. @@ -88,7 +88,7 @@ struct SpwanedMoneroD { /// A manger of spawned monerods. struct MoneroDManager { /// A map of start flags to monerods. - monerods: HashMap, Vec>, + monerods: HashMap, Vec>, /// The path to the monerod binary. path_to_monerod: PathBuf, } @@ -116,7 +116,7 @@ impl MoneroDManager { } } - /// Trys to get a current monerod instance or spans one if there is not an appropriate one to use. + /// Tries to get a current monerod instance or spans one if there is not an appropriate one to use. /// Returns the p2p port and then the RPC port of the spawned monerd. fn get_monerod_with_flags(&mut self, flags: Vec, mutable: bool) -> (u16, u16) { // If we need to mutate monerod's blockchain then we can't reuse one. @@ -147,7 +147,7 @@ impl MoneroDManager { .spawn() .unwrap(); - let spawned_monerd = SpwanedMoneroD { + let spawned_monerod = SpawnedMoneroD { mutable, process: monerod, rpc_port, @@ -157,7 +157,7 @@ impl MoneroDManager { self.monerods .entry(flags.clone()) .or_default() - .push(spawned_monerd); + .push(spawned_monerod); let Some(monerods) = self.monerods.get(&flags) else { unreachable!() }; diff --git a/typos.toml b/typos.toml new file mode 100644 index 00000000..299b8eb8 --- /dev/null +++ b/typos.toml @@ -0,0 +1,16 @@ +[default] +# False positive patterns. +extend-ignore-identifiers-re = [ + "ND", + "DNE", + # in file: `/cryptonight/c/oaes_lib.c:1213` + # not sure if false-positive or not. + "InvMixColums", +] + +[files] +# False positive files. +extend-exclude = [ + "/misc/gpg_keys/", + "cryptonight/", +]