Skip to content

Commit

Permalink
chore: lints
Browse files Browse the repository at this point in the history
  • Loading branch information
dndll committed Apr 15, 2024
1 parent 0a6e72d commit ed8f056
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 45 deletions.
9 changes: 2 additions & 7 deletions bin/operator/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Engine {
succinct_client,
proving_queue: state
.as_ref()
.map(|s| Queue::from_iter(s.queue.clone().into_iter()))
.map(|s| Queue::from_iter(s.queue.clone()))
.unwrap_or(Queue::with_default_hasher()),
batches: state
.as_ref()
Expand Down Expand Up @@ -333,12 +333,7 @@ impl Handler<Persist> for Engine {
registry: self.registry.clone(),
batches: self.batches.clone(),
request_info: self.request_info.clone(),
queue: self
.proving_queue
.clone()
.into_sorted_iter()
.map(|(i, w)| (i, w))
.collect(),
queue: self.proving_queue.clone().into_sorted_iter().collect(),
};
std::fs::write("state.json", serde_json::to_string(&state)?)?;
Ok(())
Expand Down
22 changes: 9 additions & 13 deletions bin/operator/src/succinct/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Client {
.get_chain_id()
.await
.with_context(|| "failed to get chain id")?;
let contract = NearXInstance::new(config.contract_address, inner.into());
let contract = NearXInstance::new(config.contract_address, inner);
debug!("chain id: {}", chain_id);

Ok((contract, chain_id.to()))
Expand Down Expand Up @@ -351,14 +351,10 @@ impl Client {
proofs
.iter()
.find(|p| {
p.edges
.requests
.iter()
.find(|r| {
debug!("checking if {:?} matches {:?}", r.id, request_id);
r.id == request_id
})
.is_some()
p.edges.requests.iter().any(|r| {
debug!("checking if {:?} matches {:?}", r.id, request_id);
r.id == request_id
})
})
.inspect(|p| debug!("found proof {:?} matching request: {:?}", p.id, request_id))
}
Expand Down Expand Up @@ -522,7 +518,7 @@ pub mod tests {
.respond_with(
ResponseTemplate::new(200).set_body_json(json!({"proof_id": self.proof_id()})),
)
.mount(&server)
.mount(server)
.await;

Mock::given(method("POST"))
Expand All @@ -532,7 +528,7 @@ pub mod tests {
ResponseTemplate::new(200).set_body_json(json!({"request_id":
self.request_id()})),
)
.mount(&server)
.mount(server)
.await;

let proof_fixture = match self.0 {
Expand All @@ -546,7 +542,7 @@ pub mod tests {
ResponseTemplate::new(200)
.set_body_json(fixture::<ProofResponse>(proof_fixture)),
)
.mount(&server)
.mount(server)
.await;
}
}
Expand All @@ -573,7 +569,7 @@ pub mod tests {
config.succinct.eth_rpc_url = server.uri();
config.succinct.rpc_url = server.uri();

let releases = Client::extract_release_details(deployments.clone(), &CHAIN_ID, &VERSION);
let releases = Client::extract_release_details(deployments.clone(), &CHAIN_ID, VERSION);

// Mock for eth_chainId request
Mock::given(method("POST"))
Expand Down
2 changes: 1 addition & 1 deletion bin/operator/src/succinct/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Circuit {

/// Writes the input prepended with the selector
pub fn with_selector(&self, input: &[u8]) -> Vec<u8> {
vec![&self.selector()[..], input].concat()
[&self.selector()[..], input].concat()
}

/// Get the function id from the contract
Expand Down
2 changes: 1 addition & 1 deletion bin/operator/tests/succinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn client() -> Client {
async fn test_check_proof() {
let c = client().await;
let request_id = "76688871-5262-4384-9891-0a68fe7a2efb";
let p = c.wait_for_proof(&request_id).await.unwrap();
let p = c.wait_for_proof(request_id).await.unwrap();
println!("found proof: {:?}", p);
assert_eq!(
p.0,
Expand Down
3 changes: 2 additions & 1 deletion crates/primitives/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn default_host() -> String {
pub trait Configurable {}

pub trait BaseConfig<T> {
#[allow(clippy::new_ret_no_self)]
fn new(path_prefix: Option<&str>) -> Result<T, ConfigError>;
fn test_config() -> T;
fn default() -> T;
Expand All @@ -32,7 +33,7 @@ where
let env_prefix = "NEAR_LIGHT_CLIENT";

let required = env::var(format!("{env_prefix}_CONFIG_FILE"))
.unwrap_or_else(|_| format!("config.toml"));
.unwrap_or_else(|_| "config.toml".to_string());
log::debug!("required file: {required}");

let mode = env::var(format!("{env_prefix}_MODE"))
Expand Down
1 change: 1 addition & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use near_primitives_core::types::AccountId;
// https://github.com/near/nearcore/blob/master/nearcore/src/config.rs#L133C1-L134C1
// TODO: expose this from NP, currently this is a risk that the light client
// could be exploited if the max seats changes without knowing
// they already have, need to witness the var, TODO: create ticket
pub const NUM_BLOCK_PRODUCER_SEATS: usize = 50;

// Used by nearcore to determine the end of the account in the state trie.
Expand Down
2 changes: 0 additions & 2 deletions crates/protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use error::Error;
pub use merkle_util::*;
pub use near_crypto::{ED25519PublicKey, PublicKey, Signature};
use near_light_client_primitives::NUM_BLOCK_PRODUCER_SEATS;
pub use near_primitives::{
account::id as near_account_id,
block_header::{ApprovalInner, BlockHeaderInnerLite},
Expand Down Expand Up @@ -255,7 +254,6 @@ impl Protocol {
signatures
.iter()
.zip(epoch_bps.iter())
.take(NUM_BLOCK_PRODUCER_SEATS)
.fold((0, 0), |(total_stake, approved_stake), (sig, vs)| {
let pk = vs.public_key();
let stake = vs.stake();
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ impl From<Network> for Config {
mod tests {
use std::str::FromStr;

use futures::{stream::FusedStream, AsyncReadExt, StreamExt};
use near_primitives::{
types::{BlockId, BlockReference, TransactionOrReceiptId},
views::{BlockView, ChunkView},
Expand Down
2 changes: 1 addition & 1 deletion nearx/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<L: PlonkParameters<D>, const D: usize> Ensure<L, D> for CircuitBuilder<L, D
let is_active = self.select(is_dummy, inactive, sig_active);

pubkeys.push(vs.public_key.clone());
active.push(is_active.clone());
active.push(is_active);

let added_stake = self.add(approved_stake, vs.stake);
total_stake = self.add(total_stake, vs.stake);
Expand Down
19 changes: 10 additions & 9 deletions nearx/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ where
b.watch(&untrusted_header_hash, "untrusted_header_hash");
// Build trust in the header by hashing, ensuring equality
b.assert_is_equal(untrusted_header_hash, untrusted_header_hash);
let header = untrusted_header;
header

untrusted_header
}
}

Expand Down Expand Up @@ -307,13 +307,13 @@ mod tests {
let header = b.read::<HeaderVariable>();
let trusted_header_hash = header.hash(b);

let (header, bps, next_block) =
let (_header, _bps, next_block) =
InputFetcher::<Testnet>(Default::default()).fetch_sync(b, &trusted_header_hash);
b.write::<BlockVariable<{ Testnet::BPS }>>(next_block);

let header = b.read::<HeaderVariable>();
let trusted_header_hash = header.hash(b);
let (header, bps, next_block) =
let (_header, _bps, next_block) =
InputFetcher::<Mainnet>(Default::default()).fetch_sync(b, &trusted_header_hash);
b.write::<BlockVariable<{ Mainnet::BPS }>>(next_block);
};
Expand Down Expand Up @@ -359,15 +359,16 @@ mod tests {
};
let writer = |input: &mut PI| {
for hash in corner_cases {
input.write::<CryptoHashVariable>(hash.into());
input.write::<CryptoHashVariable>(hash);
}
};
let assertions = |mut output: PO| {
for hash in corner_cases {
let header = output.read::<HeaderVariable>();
let bps = output.read::<ValidatorsVariable<{ Testnet::BPS }>>();
let nb = output.read::<BlockVariable<{ Testnet::BPS }>>();
for _hash in corner_cases {
let _header = output.read::<HeaderVariable>();
let _bps = output.read::<ValidatorsVariable<{ Testnet::BPS }>>();
let _nb = output.read::<BlockVariable<{ Testnet::BPS }>>();
}
// TODO: assert on these
};
builder_suite(define, writer, assertions);
}
Expand Down
10 changes: 5 additions & 5 deletions nearx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use near_light_clientx::{

cfg_if::cfg_if! {
if #[cfg(feature = "testnet")] {
type CFG = Testnet;
type Cfg = Testnet;

Check failure on line 9 in nearx/src/main.rs

View workflow job for this annotation

GitHub Actions / Build test artifacts

type alias `Cfg` is never used
} else if #[cfg(feature = "mainnet")] {
type CFG = Mainnet;
type Cfg = Mainnet;
} else {
panic!("No network feature enabled")
}
Expand All @@ -18,11 +18,11 @@ fn main() {
cfg_if::cfg_if! {
if #[cfg(feature = "sync")] {
use near_light_clientx::SyncCircuit;
SyncCircuit::<CFG>::entrypoint();
SyncCircuit::<Cfg>::entrypoint();
} else if #[cfg(feature = "verify")] {

assert!(CFG::VERIFY_AMT % CFG::VERIFY_BATCH == 0);
assert!((CFG::VERIFY_AMT / CFG::VERIFY_BATCH).is_power_of_two());
assert!(Cfg::VERIFY_AMT % Cfg::VERIFY_BATCH == 0);
assert!((Cfg::VERIFY_AMT / Cfg::VERIFY_BATCH).is_power_of_two());

use near_light_clientx::VerifyCircuit;
VerifyCircuit::<CFG>::entrypoint();
Expand Down
8 changes: 4 additions & 4 deletions nearx/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ mod beefy_tests {
SyncCircuit::<FixturesConfig<config::Testnet, 52>>::define(b);
};
let writer = |input: &mut PI| {
input.evm_write::<CryptoHashVariable>(h.into());
input.evm_write::<CryptoHashVariable>(h);
};
let assertions = |mut output: PO| {};
let assertions = |_output: PO| {};
builder_suite(define, writer, assertions);
}

Expand All @@ -144,9 +144,9 @@ mod beefy_tests {
SyncCircuit::<FixturesConfig<config::Testnet, 52>>::define(b);
};
let writer = |input: &mut PI| {
input.evm_write::<CryptoHashVariable>(h.into());
input.evm_write::<CryptoHashVariable>(h);
};
let assertions = |mut output: PO| {};
let assertions = |_output: PO| {};
builder_suite(define, writer, assertions);
}

Expand Down

0 comments on commit ed8f056

Please sign in to comment.