Skip to content

Commit

Permalink
feat: address small lints
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Jun 13, 2024
1 parent 6567615 commit 2c4add1
Show file tree
Hide file tree
Showing 10 changed files with 891 additions and 1,030 deletions.
1,755 changes: 797 additions & 958 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [
"provers/sgx/setup",
"pipeline",
"core",
"task_manager"
"task_manager",
]

# Always optimize; building and running the guest takes much longer without optimization.
Expand Down Expand Up @@ -178,4 +178,3 @@ rand = "0.8.5"
rand_core = "0.6.4"
dirs = "5.0.1"
pathdiff = "0.2.1"

2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn merge(a: &mut Value, b: &Value) {
merge(a.entry(k).or_insert(Value::Null), v);
}
}
(a, b) if !b.is_null() => *a = b.to_owned(),
(a, b) if !b.is_null() => b.clone_into(a),
// If b is null, just keep a (which means do nothing).
_ => {}
}
Expand Down
13 changes: 7 additions & 6 deletions core/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ impl Prover for NativeProver {
output: &GuestOutput,
config: &ProverConfig,
) -> ProverResult<Proof> {
let param = config
.get("native")
.map(|v| NativeParam::deserialize(v))
.ok_or(ProverError::Param(serde_json::Error::custom(
"native param not provided",
)))??;
let param =
config
.get("native")
.map(NativeParam::deserialize)
.ok_or(ProverError::Param(serde_json::Error::custom(
"native param not provided",
)))??;

if let Some(path) = param.write_guest_input_path {
let path = Path::new(&path);
Expand Down
4 changes: 4 additions & 0 deletions harness/core/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ impl AssertionLog {
self.assertions.len()
}

pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn display_failures(&self, start: usize, end: usize) {
for i in start..end {
if let Some(assertion) = self.assertions.get(i) {
Expand Down
4 changes: 2 additions & 2 deletions host/src/server/api/v1/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn validate_cache_input(

// double check if cache is valid
if cached_block_hash == real_block_hash {
return Ok(cache_input);
Ok(cache_input)
} else {
Err(HostError::InvalidRequestConfig(
"Cached input is not valid".to_owned(),
Expand Down Expand Up @@ -251,7 +251,7 @@ mod test {
block_number: u64,
) -> (GuestInput, RpcBlockDataProvider) {
let l1_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(&l1_network)
.get_chain_spec(l1_network)
.unwrap();
let taiko_chain_spec = SupportedChainSpecs::default()
.get_chain_spec(network)
Expand Down
16 changes: 8 additions & 8 deletions lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ pub enum Network {
TaikoMainnet,
}

impl ToString for Network {
fn to_string(&self) -> String {
match self {
Network::Ethereum => "ethereum".to_string(),
Network::Holesky => "holesky".to_string(),
Network::TaikoA7 => "taiko_a7".to_string(),
Network::TaikoMainnet => "taiko_mainnet".to_string(),
}
impl std::fmt::Display for Network {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(match self {
Network::Ethereum => "ethereum",
Network::Holesky => "holesky",
Network::TaikoA7 => "taiko_a7",
Network::TaikoMainnet => "taiko_mainnet",
})
}
}

Expand Down
8 changes: 4 additions & 4 deletions task_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
name = "task_manager"
version = "0.1.0"
authors = ["Mamy Ratsimbazafy <mamy $at$ taiko.xyz>"]
edition = "2021" # { workspace = true }
edition = "2021" # { workspace = true }

[dependencies]
raiko-primitives = { workspace = true }
rusqlite = { workspace = true, features = ["chrono"] }
raiko-lib = { workspace = true }
rusqlite = { workspace = true, features = ["chrono"] }
num_enum = { workspace = true }
chrono = { workspace = true }

[dev-dependencies]
rand = "0.9.0-alpha.1" # This is an alpha version, that has rng.gen_iter::<T>()
rand = "0.9.0-alpha.1" # This is an alpha version, that has rng.gen_iter::<T>()
rand_chacha = "0.9.0-alpha.1"
tempfile = "3.10.1"
alloy-primitives = { workspace = true, features = ["getrandom"] }
Expand Down
54 changes: 36 additions & 18 deletions task_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ use std::io::{Error as IOError, ErrorKind as IOErrorKind};
use std::fs::File;
use std::path::Path;

use raiko_primitives::{BlockNumber, ChainId, B256};
use raiko_lib::primitives::{BlockNumber, ChainId, B256};

use rusqlite::{named_params, MappedRows, Statement};
use rusqlite::{named_params, Statement};
use rusqlite::{Connection, OpenFlags};

use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -198,6 +198,7 @@ pub struct TaskManager<'db> {
update_task_progress: Statement<'db>,
get_task_proof: Statement<'db>,
get_task_proving_status: Statement<'db>,
#[allow(dead_code)]
get_tasks_unfinished: Statement<'db>,
get_db_size: Statement<'db>,
}
Expand Down Expand Up @@ -457,7 +458,7 @@ impl TaskDb {
self.conn.trace(trace_fn);
}

pub fn manage<'db>(&'db self) -> Result<TaskManager<'db>, TaskManagerError> {
pub fn manage(&self) -> Result<TaskManager<'_>, TaskManagerError> {
// To update all the tables with the task_id assigned by Sqlite
// we require row IDs for the tasks table
// and we use last_insert_rowid() which is not reentrant and need a transaction lock
Expand Down Expand Up @@ -683,22 +684,39 @@ impl TaskDb {
}
}

pub struct EnqueTaskParams {

Check warning on line 687 in task_manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / check-for-typos

"Enque" should be "Enqueue".
pub chain_id: ChainId,
pub blockhash: B256,
pub proof_system: TaskProofsys,
pub submitter: String,
pub block_number: BlockNumber,
pub parent_hash: B256,
pub state_root: B256,
pub num_transactions: u64,
pub gas_used: u64,
pub payload: Vec<u8>,
}

type TaskProvingStatus = Vec<(Option<String>, TaskStatus, DateTime<Utc>)>;

impl<'db> TaskManager<'db> {
pub fn enqueue_task(
&mut self,
chain_id: ChainId,
blockhash: &B256,
proof_system: TaskProofsys,
submitter: &str,
block_number: BlockNumber,
parent_hash: &B256,
state_root: &B256,
num_transactions: u64,
gas_used: u64,
payload: &[u8],
EnqueTaskParams {

Check warning on line 705 in task_manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / check-for-typos

"Enque" should be "Enqueue".
chain_id,
blockhash,
proof_system,
submitter,
block_number,
parent_hash,
state_root,
num_transactions,
gas_used,
payload,
}: EnqueTaskParams,

Check warning on line 716 in task_manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / check-for-typos

"Enque" should be "Enqueue".
) -> Result<(), TaskManagerError> {
self.enqueue_task.execute(named_params! {
":chain_id": chain_id as u64,
":chain_id": chain_id,
":blockhash": blockhash.as_slice(),
":id_proofsys": proof_system as u8,
":submitter": submitter,
Expand All @@ -722,7 +740,7 @@ impl<'db> TaskManager<'db> {
proof: Option<&[u8]>,
) -> Result<(), TaskManagerError> {
self.update_task_progress.execute(named_params! {
":chain_id": chain_id as u64,
":chain_id": chain_id,
":blockhash": blockhash.as_slice(),
":id_proofsys": proof_system as u8,
":fulfiller": fulfiller,
Expand All @@ -738,10 +756,10 @@ impl<'db> TaskManager<'db> {
chain_id: ChainId,
blockhash: &B256,
proof_system: TaskProofsys,
) -> Result<Vec<(Option<String>, TaskStatus, DateTime<Utc>)>, TaskManagerError> {
) -> Result<TaskProvingStatus, TaskManagerError> {
let rows = self.get_task_proving_status.query_map(
named_params! {
":chain_id": chain_id as u64,
":chain_id": chain_id,
":blockhash": blockhash.as_slice(),
":id_proofsys": proof_system as u8,
},
Expand All @@ -766,7 +784,7 @@ impl<'db> TaskManager<'db> {
) -> Result<Vec<u8>, TaskManagerError> {
let proof = self.get_task_proof.query_row(
named_params! {
":chain_id": chain_id as u64,
":chain_id": chain_id,
":blockhash": blockhash.as_slice(),
":id_proofsys": proof_system as u8,
},
Expand Down
62 changes: 31 additions & 31 deletions task_manager/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mod tests {
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;

use raiko_primitives::B256;
use task_manager::{TaskDb, TaskProofsys, TaskStatus};
use raiko_lib::primitives::B256;
use task_manager::{EnqueTaskParams, TaskDb, TaskProofsys, TaskStatus};

Check warning on line 16 in task_manager/tests/main.rs

View workflow job for this annotation

GitHub Actions / check-for-typos

"Enque" should be "Enqueue".

#[test]
fn test_enqueue_task() {
Expand All @@ -38,8 +38,8 @@ mod tests {

let chain_id = 100;
let blockhash = B256::random();
let proofsys = TaskProofsys::Risc0;
let submitter = "test_enqueue_task";
let proof_system = TaskProofsys::Risc0;
let submitter = "test_enqueue_task".to_owned();
let block_number = rng.gen_range(1..4_000_000);
let parent_hash = B256::random();
let state_root = B256::random();
Expand All @@ -48,18 +48,18 @@ mod tests {
let payload_length = rng.gen_range(20..200);
let payload: Vec<u8> = (&mut rng).gen_iter::<u8>().take(payload_length).collect();

tama.enqueue_task(
tama.enqueue_task(EnqueTaskParams {

Check warning on line 51 in task_manager/tests/main.rs

View workflow job for this annotation

GitHub Actions / check-for-typos

"Enque" should be "Enqueue".
chain_id,
&blockhash,
proofsys,
blockhash,
proof_system,
submitter,
block_number,
&parent_hash,
&state_root,
parent_hash,
state_root,
num_transactions,
gas_used,
&payload,
)
payload,
})
.unwrap();
}

Expand Down Expand Up @@ -87,7 +87,7 @@ mod tests {
for _ in 0..42 {
let chain_id = 100;
let blockhash = B256::random();
let proofsys = TaskProofsys::Risc0;
let proof_system = TaskProofsys::Risc0;
let submitter = format!("test_get_db_size/{}", rng.gen_range(1..10));
let block_number = rng.gen_range(1..4_000_000);
let parent_hash = B256::random();
Expand All @@ -97,18 +97,18 @@ mod tests {
let payload_length = rng.gen_range(1_000_000..10_000_000);
let payload: Vec<u8> = (&mut rng).gen_iter::<u8>().take(payload_length).collect();

tama.enqueue_task(
tama.enqueue_task(EnqueTaskParams {

Check warning on line 100 in task_manager/tests/main.rs

View workflow job for this annotation

GitHub Actions / check-for-typos

"Enque" should be "Enqueue".
chain_id,
&blockhash,
proofsys,
&submitter,
blockhash,
proof_system,
submitter,
block_number,
&parent_hash,
&state_root,
parent_hash,
state_root,
num_transactions,
gas_used,
&payload,
)
payload,
})
.unwrap();
}

Expand Down Expand Up @@ -144,7 +144,7 @@ mod tests {
for _ in 0..5 {
let chain_id = 100;
let blockhash = B256::random();
let proofsys = TaskProofsys::Risc0;
let proof_system = TaskProofsys::Risc0;
let submitter = format!("test_get_db_size/{}", rng.gen_range(1..10));
let block_number = rng.gen_range(1..4_000_000);
let parent_hash = B256::random();
Expand All @@ -154,28 +154,28 @@ mod tests {
let payload_length = rng.gen_range(16..64);
let payload: Vec<u8> = (&mut rng).gen_iter::<u8>().take(payload_length).collect();

tama.enqueue_task(
tama.enqueue_task(EnqueTaskParams {

Check warning on line 157 in task_manager/tests/main.rs

View workflow job for this annotation

GitHub Actions / check-for-typos

"Enque" should be "Enqueue".
chain_id,
&blockhash,
proofsys,
&submitter,
blockhash,
proof_system,
submitter: submitter.clone(),
block_number,
&parent_hash,
&state_root,
parent_hash,
state_root,
num_transactions,
gas_used,
&payload,
)
payload,
})
.unwrap();

let task_status = tama
.get_task_proving_status(chain_id, &blockhash, proofsys)
.get_task_proving_status(chain_id, &blockhash, proof_system)
.unwrap();
assert_eq!(task_status.len(), 1);
assert_eq!(task_status[0].0, Some(submitter.clone()));
assert_eq!(task_status[0].1, TaskStatus::Registered);

tasks.push((chain_id, blockhash, proofsys, submitter));
tasks.push((chain_id, blockhash, proof_system, submitter));
}

std::thread::sleep(Duration::from_millis(1));
Expand Down

0 comments on commit 2c4add1

Please sign in to comment.