Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/fmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Format

on:
push:
branches: [ main, develop ]
pull_request:

jobs:
format:
name: Format using nightly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: rustfmt
- name: rustfmt
run: make check-format
12 changes: 4 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: lint
name: Lint

on:
push:
Expand All @@ -18,12 +18,8 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.84
components: rustfmt, clippy
- name: rustfmt
run: cargo fmt --all -- --check
components: clippy, rustfmt
- name: check
run: cargo check --all-targets
env:
RUSTFLAGS: -D warnings
run: make check
- name: clippy
run: cargo clippy --all-targets -- -D warnings --allow clippy::mutable_key_type
run: make lint
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
indent_style = "Block"
imports_granularity = "Crate"
reorder_imports = true
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ build-wasm: ## Build WebAssembly node
check: ## Check code for compilation errors
cargo check --all-targets

.PHONY: check-format
check-format: ## Check code formatting
cargo +nightly fmt -- --check

.PHONY: clean
clean: ## Clean build artifacts
cargo clean

.PHONY: fmt
fmt: ## Format code using rustfmt
cargo fmt --all
.PHONY: format
format: ## Format code using rustfmt
cargo +nightly fmt

.PHONY: lint
lint: ## Run linter (clippy)
Expand Down
3 changes: 1 addition & 2 deletions cli/src/commands/misc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use libp2p_identity::PeerId;
use node::account::AccountSecretKey;
use node::p2p::identity::SecretKey;
use node::{account::AccountSecretKey, p2p::identity::SecretKey};

#[derive(Debug, clap::Args)]
pub struct Misc {
Expand Down
11 changes: 6 additions & 5 deletions cli/src/commands/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use node::{
use openmina_node_account::AccountPublicKey;
use reqwest::Url;

use node::core::log::inner::Level;
use node::p2p::connection::outgoing::P2pConnectionOutgoingInitOpts;
use node::p2p::identity::SecretKey;
use node::service::Recorder;
use node::SnarkerStrategy;
use node::{
core::log::inner::Level,
p2p::{connection::outgoing::P2pConnectionOutgoingInitOpts, identity::SecretKey},
service::Recorder,
SnarkerStrategy,
};

use openmina_node_native::{archive::config::ArchiveStorageOptions, tracing, NodeBuilder};

Expand Down
3 changes: 1 addition & 2 deletions cli/src/exit_with_error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use console::style;
use std::fmt::Display;
use std::process;
use std::{fmt::Display, process};

pub fn exit_with_error<E: Display>(error: E) -> ! {
eprintln!("{} {:#}", style("[ERROR]").red().bold(), error,);
Expand Down
3 changes: 1 addition & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ fn setup_var_from_single_and_only_thread() {
/// We store (+ display) panics in non-main threads, and display them all when the main thread panics.
#[cfg(not(target_family = "wasm"))]
fn new_hook(info: &PanicHookInfo<'_>) {
use std::any::Any;
use std::io::Write;
use std::{any::Any, io::Write};

fn payload_as_str(payload: &dyn Any) -> &str {
if let Some(&s) = payload.downcast_ref::<&'static str>() {
Expand Down
6 changes: 3 additions & 3 deletions core/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub mod genesis;

use std::sync::Arc;

pub use mina_p2p_messages::v2::MinaBlockBlockStableV2 as Block;
pub use mina_p2p_messages::v2::MinaBlockHeaderStableV2 as BlockHeader;
pub use mina_p2p_messages::v2::StateHash as BlockHash;
pub use mina_p2p_messages::v2::{
MinaBlockBlockStableV2 as Block, MinaBlockHeaderStableV2 as BlockHeader, StateHash as BlockHash,
};

pub type ArcBlock = Arc<Block>;
pub type ArcBlockWithHash = BlockWithHash<Arc<Block>>;
3 changes: 1 addition & 2 deletions core/src/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use mina_p2p_messages::v2::{
MinaBaseProtocolConstantsCheckedValueStableV1, StateHash, UnsignedExtendedUInt32StableV1,
};
use multihash::{Blake2b256, Hasher};
use time::macros::format_description;
use time::OffsetDateTime;
use time::{macros::format_description, OffsetDateTime};

use std::{
fmt::{self, Debug, Display, Formatter},
Expand Down
7 changes: 2 additions & 5 deletions core/src/distributed_pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::cmp::Ord;
use std::collections::BTreeMap;
use std::ops::RangeBounds;
use std::{cmp::Ord, collections::BTreeMap, ops::RangeBounds};

use crate::bug_condition;

Expand Down Expand Up @@ -161,8 +159,7 @@ where

mod ser {
use super::*;
use serde::ser::SerializeStruct;
use serde::{Deserialize, Serialize};
use serde::{ser::SerializeStruct, Deserialize, Serialize};

#[derive(Deserialize)]
struct Pool<State> {
Expand Down
9 changes: 5 additions & 4 deletions core/src/encrypted_key.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::fs;
use std::path::Path;
use std::{fs, path::Path};

use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
use base64::Engine;
use crypto_secretbox::aead::{Aead, OsRng};
use crypto_secretbox::{AeadCore, KeyInit, XSalsa20Poly1305};
use crypto_secretbox::{
aead::{Aead, OsRng},
AeadCore, KeyInit, XSalsa20Poly1305,
};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions core/src/requests/request_id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fmt;
use std::marker::PhantomData;
use std::{fmt, marker::PhantomData};

pub trait RequestIdType {
fn request_id_type() -> &'static str;
Expand Down
18 changes: 10 additions & 8 deletions core/src/snark/snark.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::sync::Arc;

use malloc_size_of::MallocSizeOf;
use mina_p2p_messages::binprot::macros::{BinProtRead, BinProtWrite};
use mina_p2p_messages::v2::{
CurrencyFeeStableV1, MinaBaseFeeWithProverStableV1,
MinaStateBlockchainStateValueStableV2LedgerProofStatement, MinaStateSnarkedLedgerStateStableV2,
MinaStateSnarkedLedgerStateWithSokStableV2,
NetworkPoolSnarkPoolDiffVersionedStableV2AddSolvedWork1, NonZeroCurvePoint,
TransactionSnarkWorkStatementStableV2, TransactionSnarkWorkTStableV2,
TransactionSnarkWorkTStableV2Proofs,
use mina_p2p_messages::{
binprot::macros::{BinProtRead, BinProtWrite},
v2::{
CurrencyFeeStableV1, MinaBaseFeeWithProverStableV1,
MinaStateBlockchainStateValueStableV2LedgerProofStatement,
MinaStateSnarkedLedgerStateStableV2, MinaStateSnarkedLedgerStateWithSokStableV2,
NetworkPoolSnarkPoolDiffVersionedStableV2AddSolvedWork1, NonZeroCurvePoint,
TransactionSnarkWorkStatementStableV2, TransactionSnarkWorkTStableV2,
TransactionSnarkWorkTStableV2Proofs,
},
};
use serde::{Deserialize, Serialize};

Expand Down
6 changes: 4 additions & 2 deletions core/src/snark/snark_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use mina_p2p_messages::binprot::macros::{BinProtRead, BinProtWrite};
use mina_p2p_messages::v2::{CurrencyFeeStableV1, NonZeroCurvePoint};
use mina_p2p_messages::{
binprot::macros::{BinProtRead, BinProtWrite},
v2::{CurrencyFeeStableV1, NonZeroCurvePoint},
};
use serde::{Deserialize, Serialize};

use super::SnarkJobId;
Expand Down
6 changes: 4 additions & 2 deletions core/src/snark/snark_job_commitment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use mina_p2p_messages::binprot::macros::{BinProtRead, BinProtWrite};
use mina_p2p_messages::v2::{CurrencyFeeStableV1, NonZeroCurvePoint};
use mina_p2p_messages::{
binprot::macros::{BinProtRead, BinProtWrite},
v2::{CurrencyFeeStableV1, NonZeroCurvePoint},
};
use redux::Timestamp;
use serde::{Deserialize, Serialize};

Expand Down
10 changes: 6 additions & 4 deletions core/src/snark/snark_job_id.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::str::FromStr;

use mina_p2p_messages::binprot::macros::{BinProtRead, BinProtWrite};
use mina_p2p_messages::v2::{
LedgerHash, MinaStateBlockchainStateValueStableV2LedgerProofStatementSource,
TransactionSnarkWorkTStableV2Proofs,
use mina_p2p_messages::{
binprot::macros::{BinProtRead, BinProtWrite},
v2::{
LedgerHash, MinaStateBlockchainStateValueStableV2LedgerProofStatementSource,
TransactionSnarkWorkTStableV2Proofs,
},
};
use serde::{ser::SerializeStruct, Deserialize, Serialize};

Expand Down
10 changes: 6 additions & 4 deletions core/src/transaction/transaction_info.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use mina_p2p_messages::binprot::{
self,
macros::{BinProtRead, BinProtWrite},
use mina_p2p_messages::{
binprot::{
self,
macros::{BinProtRead, BinProtWrite},
},
v2::NonZeroCurvePoint,
};
use mina_p2p_messages::v2::NonZeroCurvePoint;
use serde::{Deserialize, Serialize};

use super::{Transaction, TransactionHash};
Expand Down
3 changes: 1 addition & 2 deletions ledger/src/account/legacy.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::borrow::Cow;

use ark_ff::Zero;
use mina_hasher::Fp;
use mina_hasher::{create_legacy, Hashable, Hasher, ROInput};
use mina_hasher::{create_legacy, Fp, Hashable, Hasher, ROInput};
use mina_signer::CompressedPubKey;
use o1_utils::FieldHelpers;

Expand Down
6 changes: 2 additions & 4 deletions ledger/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ macro_rules! cache_one {
// See comments in `cache` above
// Here we don't support generic

use std::cell::RefCell;
use std::mem::ManuallyDrop;
use std::{cell::RefCell, mem::ManuallyDrop};

thread_local! {
static CACHE: ManuallyDrop<RefCell<Option<Box<$F>>>> =
Expand All @@ -72,8 +71,7 @@ mod tests {
use crate::proofs::field::FieldWitness;
use ark_ec::short_weierstrass_jacobian::GroupAffine;
use poly_commitment::srs::endos;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};

#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;
Expand Down
3 changes: 1 addition & 2 deletions ledger/src/dummy/for_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use mina_p2p_messages::binprot::BinProtRead;
use mina_p2p_messages::v2::MinaBaseUserCommandStableV2;
use mina_p2p_messages::{binprot::BinProtRead, v2::MinaBaseUserCommandStableV2};

use crate::scan_state::transaction_logic::valid;

Expand Down
3 changes: 1 addition & 2 deletions ledger/src/dummy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Arc;

use mina_p2p_messages::binprot::BinProtRead;
use mina_p2p_messages::v2::PicklesProofProofsVerifiedMaxStableV2;
use mina_p2p_messages::{binprot::BinProtRead, v2::PicklesProofProofsVerifiedMaxStableV2};

pub use openmina_core::dummy::*;

Expand Down
2 changes: 1 addition & 1 deletion ledger/src/ffi/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::{
use ark_ff::BigInteger256;
use binprot::BinProtWrite;
use mina_hasher::Fp;
use mina_p2p_messages::binprot;
use mina_p2p_messages::{
bigint::BigInt,
binprot,
v2::{MinaBaseAccountUpdateTStableV1, NonZeroCurvePointUncompressedStableV1},
};
use ocaml_interop::{
Expand Down
3 changes: 1 addition & 2 deletions ledger/src/ffi/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use crate::{
account::{Account, AccountId},
address::Address,
base::{AccountIndex, BaseLedger, MerklePath},
ffi::util::*,
ffi::DatabaseFFI,
ffi::{util::*, DatabaseFFI},
short_backtrace, Mask, UnregisterBehavior,
};

Expand Down
15 changes: 7 additions & 8 deletions ledger/src/ondisk/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ impl LockedFile {

#[cfg(unix)]
mod sys {
use std::fs::File;
use std::os::unix::io::AsRawFd;
use std::{fs::File, os::unix::io::AsRawFd};

fn flock(file: &File, flag: libc::c_int) -> std::io::Result<()> {
let ret = unsafe { libc::flock(file.as_raw_fd(), flag) };
Expand Down Expand Up @@ -99,13 +98,13 @@ mod sys {

#[cfg(windows)]
mod sys {
use std::fs::File;
use std::mem;
use std::os::windows::io::AsRawHandle;
use std::{fs::File, mem, os::windows::io::AsRawHandle};

use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::Storage::FileSystem::{
LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY,
use windows_sys::Win32::{
Foundation::HANDLE,
Storage::FileSystem::{
LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY,
},
};

pub(super) fn try_lock_exclusive(file: &File) -> std::io::Result<()> {
Expand Down
3 changes: 1 addition & 2 deletions ledger/src/proofs/accumulator_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use mina_hasher::Fp;
use mina_p2p_messages::{bigint::BigInt, v2::PicklesProofProofsVerified2ReprStableV2};
use poly_commitment::{commitment::CommitmentCurve, srs::SRS};

use super::public_input::scalar_challenge::ScalarChallenge;
use super::urs_utils;
use super::{public_input::scalar_challenge::ScalarChallenge, urs_utils};

pub fn accumulator_check(
urs: &SRS<Vesta>,
Expand Down
12 changes: 8 additions & 4 deletions ledger/src/proofs/group_map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::ops::Neg;

use crate::proofs::field::{field, FieldWitness};
use crate::proofs::witness::Witness;
use crate::proofs::{
field::{field, FieldWitness},
witness::Witness,
};

pub mod bw19 {
use super::*;
Expand Down Expand Up @@ -101,8 +103,10 @@ use mina_hasher::Fp;

use self::tock::Conic;

use super::field::{Boolean, GroupAffine, ToBoolean};
use super::transaction::make_group;
use super::{
field::{Boolean, GroupAffine, ToBoolean},
transaction::make_group,
};

fn sqrt_exn<F: FieldWitness>(x: F, w: &mut Witness<F>) -> F {
w.exists(x.sqrt().unwrap())
Expand Down
Loading