From 63144bc909d86f05af4a16440f10b8be4f4e67b2 Mon Sep 17 00:00:00 2001 From: Sebastian Angel Date: Thu, 18 Dec 2025 11:31:05 -0500 Subject: [PATCH 1/6] changing version to 2024, and dealing with most of clippy --- Cargo.toml | 2 + coordinator/Cargo.toml | 6 +- coordinator/src/coordinator_state.rs | 69 ++++++++---------- coordinator/src/main.rs | 24 +++---- coordinator_ctrl/Cargo.toml | 2 +- endorser/Cargo.toml | 4 +- endorser/src/endorser_state.rs | 14 ++-- endpoint/Cargo.toml | 4 +- endpoint/src/lib.rs | 103 +++++++++++++-------------- ledger/Cargo.toml | 6 +- ledger/src/lib.rs | 27 ++++--- light_client_rest/Cargo.toml | 4 +- light_client_rest/src/main.rs | 8 +-- store/Cargo.toml | 4 +- store/src/ledger/filestore.rs | 2 +- store/src/ledger/mongodb_cosmos.rs | 12 ++-- 16 files changed, 137 insertions(+), 154 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 729ee61..2e4421d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,6 @@ members = [ "coordinator_ctrl", ] +resolver = "3" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/coordinator/Cargo.toml b/coordinator/Cargo.toml index 148d29b..a6c09a7 100644 --- a/coordinator/Cargo.toml +++ b/coordinator/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "coordinator" version = "0.1.0" -edition = "2018" -authors = ["Srinath Setty ", "Sudheesh Singanamalla "] +edition = "2024" +authors = ["Srinath Setty ", "Weidong Cui "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -29,4 +29,4 @@ rand = "0.8.4" [build-dependencies] tonic-build = "0.8.2" -prost-build = "0.11.1" \ No newline at end of file +prost-build = "0.11.1" diff --git a/coordinator/src/coordinator_state.rs b/coordinator/src/coordinator_state.rs index fa10db1..499d2fc 100644 --- a/coordinator/src/coordinator_state.rs +++ b/coordinator/src/coordinator_state.rs @@ -666,9 +666,7 @@ impl CoordinatorState { pub fn get_endorser_pks(&self) -> Vec> { if let Ok(conn_map_rd) = self.conn_map.read() { - conn_map_rd - .iter() - .map(|(pk, _endorser)| pk.clone()) + conn_map_rd.keys().cloned() .collect::>>() } else { eprintln!("Failed to acquire read lock"); @@ -678,9 +676,7 @@ impl CoordinatorState { pub fn get_endorser_uris(&self) -> Vec { if let Ok(conn_map_rd) = self.conn_map.read() { - conn_map_rd - .iter() - .map(|(_pk, endorser)| endorser.uri.clone()) + conn_map_rd.values().map(|endorser| endorser.uri.clone()) .collect::>() } else { eprintln!("Failed to acquire read lock"); @@ -984,11 +980,10 @@ impl CoordinatorState { match res { Ok(receipt_rs) => { receipts.add(&receipt_rs); - if let Ok(vs) = self.verifier_state.read() { - if receipts.check_quorum(&vs).is_ok() { + if let Ok(vs) = self.verifier_state.read() + && receipts.check_quorum(&vs).is_ok() { return Ok(receipts); } - } }, Err(error) => eprintln!("Failed to parse a receipt ({:?})", error), } @@ -1144,11 +1139,10 @@ impl CoordinatorState { Ok(receipt) => match Receipt::from_bytes(&receipt) { Ok(receipt_rs) => { receipts.add(&receipt_rs); - if let Ok(vs) = self.verifier_state.read() { - if receipts.check_quorum(&vs).is_ok() { + if let Ok(vs) = self.verifier_state.read() + && receipts.check_quorum(&vs).is_ok() { return Ok(receipts); } - } }, Err(error) => { eprintln!("Failed to parse a receipt (err={:?}", error); @@ -1307,15 +1301,12 @@ impl CoordinatorState { max_height = height; } receipts.add(&receipt_rs); - if let Ok(vs) = self.verifier_state.read() { - if let Ok(_h) = receipts.check_quorum(&vs) { - if let Ok(block_rs) = Block::from_bytes(&block) { - if let Ok(nonces_rs) = Nonces::from_bytes(&nonces) { + if let Ok(vs) = self.verifier_state.read() + && let Ok(_h) = receipts.check_quorum(&vs) + && let Ok(block_rs) = Block::from_bytes(&block) + && let Ok(nonces_rs) = Nonces::from_bytes(&nonces) { return Ok(LedgerEntry::new(block_rs, receipts, Some(nonces_rs))); } - } - } - } }, Err(error) => { eprintln!("Failed to parse a receipt (err={:?}", error); @@ -1503,10 +1494,10 @@ impl CoordinatorState { // Read the current ledger tail let res = self.ledger_store.read_view_ledger_tail().await; - if res.is_err() { + if let Err(e) = res { eprintln!( "Failed to read from the view ledger in the ledger store ({:?})", - res.unwrap_err() + e ); return Err(CoordinatorError::FailedToCallLedgerStore); } @@ -1622,10 +1613,10 @@ impl CoordinatorState { .ledger_store .attach_view_ledger_receipts(view_ledger_height, &receipts) .await; - if res.is_err() { + if let Err(e) = res { eprintln!( "Failed to attach view ledger receipt in the ledger store ({:?})", - res.unwrap_err() + e ); return Err(CoordinatorError::FailedToCallLedgerStore); } @@ -1638,12 +1629,12 @@ impl CoordinatorState { continue; } let mut block_hashes: Vec> = - Vec::with_capacity((cut_diff.high - cut_diff.low) as usize); + Vec::with_capacity(cut_diff.high - cut_diff.low ); let h = NimbleDigest::from_bytes(&cut_diff.handle).unwrap(); for index in (cut_diff.low + 1)..=cut_diff.high { let res = self .ledger_store - .read_ledger_by_index(&h, index as usize) + .read_ledger_by_index(&h, index) .await; if let Err(e) = res { eprintln!("Failed to read the ledger store {:?}", e); @@ -1723,10 +1714,10 @@ impl CoordinatorState { .ledger_store .create_ledger(&handle, genesis_block.clone()) .await; - if res.is_err() { + if let Err(e) = res { eprintln!( "Failed to create ledger in the ledger store ({:?})", - res.unwrap_err() + e ); return Err(CoordinatorError::FailedToCreateLedger); } @@ -1740,9 +1731,9 @@ impl CoordinatorState { let res = self .endorser_create_ledger(&endorsers, &handle, &block_hash, genesis_block) .await; - if res.is_err() { - eprintln!("Failed to create ledger in endorsers ({:?})", res); - return Err(res.unwrap_err()); + if let Err(e) = res { + eprintln!("Failed to create ledger in endorsers ({:?})", e); + return Err(e); } res.unwrap() }; @@ -1781,10 +1772,10 @@ impl CoordinatorState { .ledger_store .append_ledger(&handle, &data_block, expected_height) .await; - if res.is_err() { + if let Err(e) = res { eprintln!( "Failed to append to the ledger in the ledger store {:?}", - res.unwrap_err() + e ); return Err(CoordinatorError::FailedToAppendLedger); } @@ -1811,9 +1802,9 @@ impl CoordinatorState { nonces, ) .await; - if res.is_err() { - eprintln!("Failed to append to the ledger in endorsers {:?}", res); - return Err(res.unwrap_err()); + if let Err(e) = res { + eprintln!("Failed to append to the ledger in endorsers {:?}", e); + return Err(e); } res.unwrap() }; @@ -1822,10 +1813,10 @@ impl CoordinatorState { .ledger_store .attach_ledger_receipts(&handle, expected_height, &receipts) .await; - if res.is_err() { + if let Err(e) = res { eprintln!( "Failed to attach ledger receipt to the ledger store ({:?})", - res.unwrap_err() + e ); return Err(CoordinatorError::FailedToAttachReceipt); } @@ -1887,10 +1878,10 @@ impl CoordinatorState { CoordinatorError::FailedToObtainQuorum => { if !nonce_attached { let res = self.ledger_store.attach_ledger_nonce(&handle, &nonce).await; - if res.is_err() { + if let Err(e) = res { eprintln!( "Failed to attach the nonce for reading ledger tail {:?}", - res.unwrap_err() + e ); return Err(CoordinatorError::FailedToAttachNonce); } diff --git a/coordinator/src/main.rs b/coordinator/src/main.rs index c82b07b..d7b202e 100644 --- a/coordinator/src/main.rs +++ b/coordinator/src/main.rs @@ -649,7 +649,7 @@ mod tests { let block_bytes: Vec = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; // Step 1: NewLedger Request (With Application Data Embedded) - let handle_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let handle_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let request = tonic::Request::new(NewLedgerReq { handle: handle_bytes.to_vec(), block: block_bytes.to_vec(), @@ -678,7 +678,7 @@ mod tests { assert!(res.is_ok()); // Step 3: Read Latest with the Nonce generated - let nonce = rand::thread_rng().gen::<[u8; 16]>(); + let nonce = rand::thread_rng().r#gen::<[u8; 16]>(); let req = tonic::Request::new(ReadLatestReq { handle: handle.clone(), nonce: nonce.to_vec(), @@ -698,7 +698,7 @@ mod tests { let b1: Vec = "data_block_example_1".as_bytes().to_vec(); let b2: Vec = "data_block_example_2".as_bytes().to_vec(); let b3: Vec = "data_block_example_3".as_bytes().to_vec(); - let blocks = vec![&b1, &b2, &b3].to_vec(); + let blocks = [&b1, &b2, &b3].to_vec(); let mut expected_height = 0; for block_to_append in blocks { @@ -726,7 +726,7 @@ mod tests { } // Step 4: Read Latest with the Nonce generated and check for new data - let nonce = rand::thread_rng().gen::<[u8; 16]>(); + let nonce = rand::thread_rng().r#gen::<[u8; 16]>(); let latest_state_query = tonic::Request::new(ReadLatestReq { handle: handle.clone(), nonce: nonce.to_vec(), @@ -818,7 +818,7 @@ mod tests { assert!(res.is_ok()); // Step 8: Read Latest with the Nonce generated and check for new data appended without condition - let nonce = rand::thread_rng().gen::<[u8; 16]>(); + let nonce = rand::thread_rng().r#gen::<[u8; 16]>(); let latest_state_query = tonic::Request::new(ReadLatestReq { handle: handle.clone(), nonce: nonce.to_vec(), @@ -847,7 +847,7 @@ mod tests { let mut endorsers = server.get_state().get_endorser_pks(); endorsers.remove(1); - let handle_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let handle_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let res = server .get_state() .create_ledger(Some(endorsers.clone()), handle_bytes.as_ref(), &[]) @@ -870,7 +870,7 @@ mod tests { println!("append_ledger with first endorser: {:?}", res); assert!(res.is_ok()); - let handle2_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let handle2_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let res = server .get_state() .create_ledger(None, handle2_bytes.as_ref(), &[]) @@ -893,7 +893,7 @@ mod tests { println!("append_ledger with first endorser: {:?}", res); assert!(res.is_ok()); - let nonce1 = rand::thread_rng().gen::<[u8; 16]>(); + let nonce1 = rand::thread_rng().r#gen::<[u8; 16]>(); let res = server .get_state() .read_ledger_tail(&new_handle2, &nonce1) @@ -919,7 +919,7 @@ mod tests { .await; assert!(res.is_ok()); - let nonce2 = rand::thread_rng().gen::<[u8; 16]>(); + let nonce2 = rand::thread_rng().r#gen::<[u8; 16]>(); let res = server .get_state() .read_ledger_tail(&new_handle2, &nonce2) @@ -990,7 +990,7 @@ mod tests { assert!(res.is_ok()); // Step 11: read the latest of the new ledger - let nonce = rand::thread_rng().gen::<[u8; 16]>(); + let nonce = rand::thread_rng().r#gen::<[u8; 16]>(); let latest_state_query = tonic::Request::new(ReadLatestReq { handle: new_handle.clone(), nonce: nonce.to_vec(), @@ -1034,7 +1034,7 @@ mod tests { let mut endorsers = server.get_state().get_endorser_pks(); endorsers.remove(1); - let handle_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let handle_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let res = server .get_state() .create_ledger(Some(endorsers.clone()), handle_bytes.as_ref(), &[]) @@ -1060,7 +1060,7 @@ mod tests { ); assert!(res.is_ok()); - let handle2_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let handle2_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let res = server .get_state() .create_ledger(None, handle2_bytes.as_ref(), &[]) diff --git a/coordinator_ctrl/Cargo.toml b/coordinator_ctrl/Cargo.toml index c29592f..31c57e8 100644 --- a/coordinator_ctrl/Cargo.toml +++ b/coordinator_ctrl/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "coordinator_ctrl" version = "0.1.0" -edition = "2018" +edition = "2024" authors = ["Weidong Cui "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/endorser/Cargo.toml b/endorser/Cargo.toml index e98028d..f37b5d3 100644 --- a/endorser/Cargo.toml +++ b/endorser/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "endorser" version = "0.1.0" -edition = "2018" -authors = ["Srinath Setty ", "Sudheesh Singanamalla "] +edition = "2024" +authors = ["Srinath Setty ", "Weidong Cui ", "Sudheesh Singanamalla "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/endorser/src/endorser_state.rs b/endorser/src/endorser_state.rs index 00c0fcd..3fbc42c 100644 --- a/endorser/src/endorser_state.rs +++ b/endorser/src/endorser_state.rs @@ -499,7 +499,7 @@ mod tests { // The coordinator sends the hashed contents of the configuration to the endorsers // We will pick a dummy view value for testing purposes let view_block_hash = { - let t = rand::thread_rng().gen::<[u8; 32]>(); + let t = rand::thread_rng().r#gen::<[u8; 32]>(); let n = NimbleDigest::from_bytes(&t); assert!(n.is_ok(), "This should not have occured"); n.unwrap() @@ -537,13 +537,13 @@ mod tests { // The coordinator sends the hashed contents of the block to the endorsers let handle = { - let t = rand::thread_rng().gen::<[u8; 32]>(); + let t = rand::thread_rng().r#gen::<[u8; 32]>(); let n = NimbleDigest::from_bytes(&t); assert!(n.is_ok(), "This should not have occured"); n.unwrap() }; - let t = rand::thread_rng().gen::<[u8; 32]>(); + let t = rand::thread_rng().r#gen::<[u8; 32]>(); let block = Block::new(&t); let block_hash = block.hash(); @@ -598,7 +598,7 @@ mod tests { // The coordinator sends the hashed contents of the configuration to the endorsers // We will pick a dummy view value for testing purposes let view_block_hash = { - let t = rand::thread_rng().gen::<[u8; 32]>(); + let t = rand::thread_rng().r#gen::<[u8; 32]>(); let n = NimbleDigest::from_bytes(&t); assert!(n.is_ok(), "This should not have occured"); n.unwrap() @@ -635,8 +635,8 @@ mod tests { .endorser_mode = ledger::endorser_proto::EndorserMode::Active; // The coordinator sends the hashed contents of the block to the endorsers - let block = Block::new(&rand::thread_rng().gen::<[u8; 32]>()); - let handle = NimbleDigest::from_bytes(&rand::thread_rng().gen::<[u8; 32]>()).unwrap(); + let block = Block::new(&rand::thread_rng().r#gen::<[u8; 32]>()); + let handle = NimbleDigest::from_bytes(&rand::thread_rng().r#gen::<[u8; 32]>()).unwrap(); let block_hash = block.hash(); // this need not be the case, but it does not matter for testing let res = endorser_state.new_ledger(&handle, &block_hash, &block); assert!(res.is_ok()); @@ -652,7 +652,7 @@ mod tests { .expect("failed") .0 .hash(); - let block_hash_to_append_data = Block::new(&rand::thread_rng().gen::<[u8; 32]>()); + let block_hash_to_append_data = Block::new(&rand::thread_rng().r#gen::<[u8; 32]>()); let block_hash_to_append = block_hash_to_append_data.hash(); let height_plus_one = { diff --git a/endpoint/Cargo.toml b/endpoint/Cargo.toml index 568b5e6..8968225 100644 --- a/endpoint/Cargo.toml +++ b/endpoint/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "endpoint" version = "0.1.0" -edition = "2018" -authors = ["Srinath Setty ", "Sudheesh Singanamalla "] +edition = "2024" +authors = ["Srinath Setty ", "Weidong Cui "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/endpoint/src/lib.rs b/endpoint/src/lib.rs index 114e6f9..bf441c7 100644 --- a/endpoint/src/lib.rs +++ b/endpoint/src/lib.rs @@ -346,25 +346,24 @@ impl EndpointState { } }; - if res.is_err() { - if res.unwrap_err() != VerificationError::ViewNotFound { + if let Err(e) = res { + if e != VerificationError::ViewNotFound { return Err(EndpointError::FailedToVerifyNewCounter); - } else { - let res = self.update_view().await; - if res.is_err() { - return Err(EndpointError::FailedToVerifyNewCounter); - } - let res = { - if let Ok(vs_rd) = self.vs.read() { - vs_rd.verify_new_ledger(handle, &block, &receipts) - } else { - return Err(EndpointError::FailedToAcquireReadLock); - } - }; - if res.is_err() { - eprintln!("failed to create a new counter {:?}", res); - return Err(EndpointError::FailedToVerifyNewCounter); + } + let res = self.update_view().await; + if res.is_err() { + return Err(EndpointError::FailedToVerifyNewCounter); + } + let res = { + if let Ok(vs_rd) = self.vs.read() { + vs_rd.verify_new_ledger(handle, &block, &receipts) + } else { + return Err(EndpointError::FailedToAcquireReadLock); } + }; + if let Err(e) = res { + eprintln!("failed to create a new counter {:?}", e); + return Err(EndpointError::FailedToVerifyNewCounter); } } @@ -442,25 +441,24 @@ impl EndpointState { return Err(EndpointError::FailedToAcquireReadLock); } }; - if res.is_err() { - if res.unwrap_err() != VerificationError::ViewNotFound { + if let Err(e) = res { + if e != VerificationError::ViewNotFound { return Err(EndpointError::FailedToVerifyIncrementedCounter); - } else { - let res = self.update_view().await; - if res.is_err() { - return Err(EndpointError::FailedToVerifyIncrementedCounter); - } - let res = { - if let Ok(vs_rd) = self.vs.read() { - vs_rd.verify_append(handle, &block, &hash_nonces, expected_height, &receipts) - } else { - return Err(EndpointError::FailedToAcquireReadLock); - } - }; - if res.is_err() { - eprintln!("failed to increment a counter {:?}", res); - return Err(EndpointError::FailedToVerifyIncrementedCounter); + } + let res = self.update_view().await; + if res.is_err() { + return Err(EndpointError::FailedToVerifyIncrementedCounter); + } + let res = { + if let Ok(vs_rd) = self.vs.read() { + vs_rd.verify_append(handle, &block, &hash_nonces, expected_height, &receipts) + } else { + return Err(EndpointError::FailedToAcquireReadLock); } + }; + if let Err(e) = res { + eprintln!("failed to increment a counter {:?}", e); + return Err(EndpointError::FailedToVerifyIncrementedCounter); } } @@ -509,31 +507,26 @@ impl EndpointState { return Err(EndpointError::FailedToAcquireReadLock); } }; - let counter = { - if res.is_err() { - if res.unwrap_err() != VerificationError::ViewNotFound { + let counter = match res { + Err(VerificationError::ViewNotFound) => { + let res = self.update_view().await; + if res.is_err() { return Err(EndpointError::FaieldToVerifyReadCounter); - } else { - let res = self.update_view().await; - if res.is_err() { - return Err(EndpointError::FaieldToVerifyReadCounter); - } - let res = { - if let Ok(vs_rd) = self.vs.read() { - vs_rd.verify_read_latest(handle, &block, &nonces, nonce, &receipts) - } else { - return Err(EndpointError::FailedToAcquireReadLock); - } - }; - if res.is_err() { - return Err(EndpointError::FaieldToVerifyReadCounter); + } + let res = { + if let Ok(vs_rd) = self.vs.read() { + vs_rd.verify_read_latest(handle, &block, &nonces, nonce, &receipts) } else { - res.unwrap() + return Err(EndpointError::FailedToAcquireReadLock); } + }; + match res { + Ok(c) => c, + Err(_) => return Err(EndpointError::FaieldToVerifyReadCounter), } - } else { - res.unwrap() - } + }, + Err(_) => return Err(EndpointError::FaieldToVerifyReadCounter), + Ok(c) => c, }; // verify the integrity of the coordinator's response by checking the signature diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index eeb25bb..ec78f3c 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "ledger" version = "0.1.0" -edition = "2018" -authors = ["Srinath Setty ", "Sudheesh Singanamalla "] +edition = "2024" +authors = ["Srinath Setty ", "Weidong Cui "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -24,4 +24,4 @@ hex = "0.4.3" [build-dependencies] tonic-build = "0.8.2" -prost-build = "0.11.1" \ No newline at end of file +prost-build = "0.11.1" diff --git a/ledger/src/lib.rs b/ledger/src/lib.rs index 8428324..af75e69 100644 --- a/ledger/src/lib.rs +++ b/ledger/src/lib.rs @@ -90,7 +90,6 @@ pub fn produce_hash_of_state(ledger_tail_map: &Vec) -> Nimbl // we ceil the slice size so the last slice contains fewer entries. let slice_size = (ledger_tail_map.len() as f64 / num_leaves as f64).ceil() as usize; let leaf_hashes = (0..num_leaves) - .into_iter() .collect::>() .par_iter() .map(|&i| { @@ -110,7 +109,7 @@ pub fn produce_hash_of_state(ledger_tail_map: &Vec) -> Nimbl let mut sha256 = Sha256::new(); for entry in leaf_hashes { - sha256.update(&entry.to_bytes()); + sha256.update(entry.to_bytes()); } NimbleDigest::new(sha256.finalize()) } @@ -161,7 +160,7 @@ impl Nonces { } pub fn contains(&self, nonce: &Nonce) -> bool { - self.nonces.iter().any(|nonce_iter| *nonce_iter == *nonce) + self.nonces.contains(nonce) } pub fn len(&self) -> usize { @@ -537,11 +536,10 @@ impl Receipts { return Err(VerificationError::InvalidBlockHash); } // check the height matches with the expected height - if let Some(h) = expected_height { - if h != ex_meta_block.get_metablock().get_height() { + if let Some(h) = expected_height + && h != ex_meta_block.get_metablock().get_height() { return Err(VerificationError::InvalidHeight); } - } // update the message let tail_hash = match nonce_bytes { Some(n) => ex_meta_block.get_metablock().hash().digest_with_bytes(n), @@ -704,13 +702,12 @@ impl Receipts { for ledger_tail_map in ledger_tail_maps { for entry in &ledger_tail_map.entries { let res = ledger_entries.get(&(entry.handle.clone(), entry.height)); - if let Some(metablock) = res { - if entry.metablock.cmp(metablock) != Ordering::Equal { + if let Some(metablock) = res + && entry.metablock.cmp(metablock) != Ordering::Equal { eprintln!("metablock1={:?}", entry.metablock); eprintln!("metablock2={:?}", metablock); return Err(VerificationError::InconsistentLedgerTailMaps); } - } } } @@ -1134,7 +1131,7 @@ impl CustomSerde for Nonces { } fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() % Nonce::num_bytes() != 0 { + if !bytes.len().is_multiple_of(Nonce::num_bytes()) { Err(CustomSerdeError::IncorrectLength) } else { let mut nonces = Nonces::new(); @@ -1289,7 +1286,7 @@ impl CustomSerde for Receipts { } fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() % Receipt::num_bytes() != 0 { + if !bytes.len().is_multiple_of(Receipt::num_bytes()) { return Err(CustomSerdeError::IncorrectLength); } let mut pos = 0; @@ -1335,8 +1332,8 @@ mod tests { #[test] pub fn test_nimble_digest_equality() { - let hash_bytes_1 = rand::thread_rng().gen::<[u8; 32]>(); - let hash_bytes_2 = rand::thread_rng().gen::<[u8; 32]>(); + let hash_bytes_1 = rand::thread_rng().r#gen::<[u8; 32]>(); + let hash_bytes_2 = rand::thread_rng().r#gen::<[u8; 32]>(); let duplicate_hash_bytes_1 = hash_bytes_1; let nimble_digest_1 = NimbleDigest::from_bytes(&hash_bytes_1); let nimble_digest_2 = NimbleDigest::from_bytes(&hash_bytes_2); @@ -1393,8 +1390,8 @@ mod tests { pub fn test_hash_of_state() { let map = (0..1024 * 1023) .map(|i: usize| { - let handle = NimbleDigest::digest(&rand::thread_rng().gen::<[u8; 32]>()); - let metablock = NimbleDigest::digest(&rand::thread_rng().gen::<[u8; 32]>()); + let handle = NimbleDigest::digest(&rand::thread_rng().r#gen::<[u8; 32]>()); + let metablock = NimbleDigest::digest(&rand::thread_rng().r#gen::<[u8; 32]>()); LedgerTailMapEntry { handle: handle.to_bytes(), metablock: metablock.to_bytes(), diff --git a/light_client_rest/Cargo.toml b/light_client_rest/Cargo.toml index d0d8ab8..2f9bc46 100644 --- a/light_client_rest/Cargo.toml +++ b/light_client_rest/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "light_client_rest" version = "0.1.0" -edition = "2018" -authors = ["Srinath Setty ", "Sudheesh Singanamalla "] +edition = "2024" +authors = ["Srinath Setty ", "Weidong Cui "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/light_client_rest/src/main.rs b/light_client_rest/src/main.rs index 5840d14..8fcacb8 100644 --- a/light_client_rest/src/main.rs +++ b/light_client_rest/src/main.rs @@ -122,7 +122,7 @@ async fn main() { // Step 1: NewCounter Request let tag_bytes: Vec = NimbleDigest::digest(&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]).to_bytes(); - let handle_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let handle_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let handle = base64_url::encode(&handle_bytes); let new_counter_req = NewCounterRequest { tag: base64_url::encode(&tag_bytes), @@ -163,7 +163,7 @@ async fn main() { assert!(res.is_ok()); // Step 2: Read Latest with the Nonce generated - let nonce_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let nonce_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let nonce = base64_url::encode(&nonce_bytes); let read_counter_url = reqwest::Url::parse_with_params( &format!("{}/counters/{}", endpoint_addr, handle), @@ -252,7 +252,7 @@ async fn main() { } // Step 4: ReadCounter with the Nonce generated and check for new data - let nonce_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let nonce_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let nonce = base64_url::encode(&nonce_bytes); let read_counter_url = reqwest::Url::parse_with_params( &format!("{}/counters/{}", endpoint_addr, handle), @@ -302,7 +302,7 @@ async fn main() { tag: base64_url::encode(&tag_bytes), }; for _idx in 0..num_ledgers { - let handle_bytes = rand::thread_rng().gen::<[u8; 16]>(); + let handle_bytes = rand::thread_rng().r#gen::<[u8; 16]>(); let handle = base64_url::encode(&handle_bytes); let new_counter_url = reqwest::Url::parse(&format!("{}/counters/{}", endpoint_addr, handle)).unwrap(); diff --git a/store/Cargo.toml b/store/Cargo.toml index a058023..dad4b75 100644 --- a/store/Cargo.toml +++ b/store/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "store" version = "0.1.0" -edition = "2018" -authors = ["Srinath Setty ", "Sudheesh Singanamalla "] +edition = "2024" +authors = ["Sebastian Angel , Srinath Setty ", "Weidong Cui "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/store/src/ledger/filestore.rs b/store/src/ledger/filestore.rs index 0a80fc9..6fec60a 100644 --- a/store/src/ledger/filestore.rs +++ b/store/src/ledger/filestore.rs @@ -211,7 +211,7 @@ fn open_and_lock( // Check if the ledger exists. let mut options = OpenOptions::new(); - let file_name = dir_path.join(&hex::encode(&handle.to_bytes())); + let file_name = dir_path.join(hex::encode(handle.to_bytes())); let ledger = match options .read(true) .write(true) diff --git a/store/src/ledger/mongodb_cosmos.rs b/store/src/ledger/mongodb_cosmos.rs index bce2f74..5cec1af 100644 --- a/store/src/ledger/mongodb_cosmos.rs +++ b/store/src/ledger/mongodb_cosmos.rs @@ -196,7 +196,7 @@ impl MongoCosmosLedgerStore { ledger_store .client .database(&nimble_db_name) - .collection::(&hex::encode(&view_handle.to_bytes())) + .collection::(&hex::encode(view_handle.to_bytes())) .insert_one(tail_entry, None) .await?; @@ -211,7 +211,7 @@ impl MongoCosmosLedgerStore { let ledger = ledger_store .client .database(&nimble_db_name) - .collection::(&hex::encode(&view_handle.to_bytes())); + .collection::(&hex::encode(view_handle.to_bytes())); fix_cached_height(&ledger_store.view_handle, &ledger_store.cache, &ledger).await?; } @@ -531,7 +531,7 @@ impl LedgerStore for MongoCosmosLedgerStore { let client = self.client.clone(); let ledger = client .database(&self.dbname) - .collection::(&hex::encode(&handle.to_bytes())); + .collection::(&hex::encode(handle.to_bytes())); loop { with_retry!( @@ -573,7 +573,7 @@ impl LedgerStore for MongoCosmosLedgerStore { let client = self.client.clone(); let ledger = client .database(&self.dbname) - .collection::(&hex::encode(&handle.to_bytes())); + .collection::(&hex::encode(handle.to_bytes())); loop { with_retry!( @@ -601,7 +601,7 @@ impl LedgerStore for MongoCosmosLedgerStore { let client = self.client.clone(); let ledger = client .database(&self.dbname) - .collection::(&hex::encode(&handle.to_bytes())); + .collection::(&hex::encode(handle.to_bytes())); loop_and_read(handle, None, &ledger, &self.cache).await } @@ -614,7 +614,7 @@ impl LedgerStore for MongoCosmosLedgerStore { let client = self.client.clone(); let ledger = client .database(&self.dbname) - .collection::(&hex::encode(&handle.to_bytes())); + .collection::(&hex::encode(handle.to_bytes())); let (entry, _height) = loop_and_read(handle, Some(index), &ledger, &self.cache).await?; Ok(entry) From 6b590c29543dc8dcd4f958abd00bd48b710d895b Mon Sep 17 00:00:00 2001 From: Sebastian Angel Date: Thu, 18 Dec 2025 11:52:20 -0500 Subject: [PATCH 2/6] Additional changes to address clippy feedback --- coordinator/src/coordinator_state.rs | 6 +++--- endorser/src/endorser_state.rs | 8 ++++---- ledger/src/lib.rs | 10 +++++----- store/src/ledger/azure_table.rs | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/coordinator/src/coordinator_state.rs b/coordinator/src/coordinator_state.rs index 499d2fc..ed44491 100644 --- a/coordinator/src/coordinator_state.rs +++ b/coordinator/src/coordinator_state.rs @@ -333,8 +333,7 @@ async fn update_endorser( }; let res = Receipt::from_bytes(&receipt); - if res.is_ok() { - let receipt_rs = res.unwrap(); + if let Ok(receipt_rs) = res { let mut receipts = Receipts::new(); receipts.add(&receipt_rs); let res = ledger_store @@ -630,7 +629,8 @@ impl CoordinatorState { let mut endorsers = EndorserHostnames::new(); for (pk, uri) in &endorser_hostnames { - let pks = self.connect_endorsers(&[uri.clone()]).await; + let pks = self.connect_endorsers(std::slice::from_ref(uri)).await; + if pks.len() == 1 && pks[0].0 == *pk { endorsers.push((pk.clone(), uri.clone())); } diff --git a/endorser/src/endorser_state.rs b/endorser/src/endorser_state.rs index 3fbc42c..b50576f 100644 --- a/endorser/src/endorser_state.rs +++ b/endorser/src/endorser_state.rs @@ -314,7 +314,7 @@ impl EndorserState { fn append_view_ledger( &self, view_ledger_state: &mut ViewLedgerState, - ledger_tail_map: &Vec, + ledger_tail_map: &[LedgerTailMapEntry], block_hash: &NimbleDigest, expected_height: usize, ) -> Result { @@ -354,7 +354,7 @@ impl EndorserState { fn sign_view_ledger( &self, view_ledger_state: &ViewLedgerState, - ledger_tail_map: &Vec, + ledger_tail_map: &[LedgerTailMapEntry], ) -> Receipt { // the view embedded in the view ledger is the hash of the current state of the endorser let view = produce_hash_of_state(ledger_tail_map); @@ -446,8 +446,8 @@ impl EndorserState { &self, old_config: &[u8], new_config: &[u8], - ledger_tail_maps: &Vec, - ledger_chunks: &Vec, + ledger_tail_maps: &[LedgerTailMap], + ledger_chunks: &[LedgerChunkEntry], receipts: &Receipts, ) -> Result<(), EndorserError> { if let Ok(mut view_ledger_state) = self.view_ledger_state.write() { diff --git a/ledger/src/lib.rs b/ledger/src/lib.rs index af75e69..a9d87e6 100644 --- a/ledger/src/lib.rs +++ b/ledger/src/lib.rs @@ -72,7 +72,7 @@ impl NimbleDigest { pub type Handle = NimbleDigest; // this function assumes the provided vector is sorted by handles -pub fn produce_hash_of_state(ledger_tail_map: &Vec) -> NimbleDigest { +pub fn produce_hash_of_state(ledger_tail_map: &[LedgerTailMapEntry]) -> NimbleDigest { // for empty state, hash is a vector of zeros if ledger_tail_map.is_empty() { NimbleDigest::default() @@ -579,8 +579,8 @@ impl Receipts { group_identity: &NimbleDigest, old_metablock: &MetaBlock, new_metablock: &MetaBlock, - ledger_tail_maps: &Vec, - ledger_chunks: &Vec, + ledger_tail_maps: &[LedgerTailMap], + ledger_chunks: &[LedgerChunkEntry], ) -> Result<(), VerificationError> { // check the conditions when this is the first view change if old_metablock.get_height() == 0 { @@ -985,7 +985,7 @@ impl VerifierState { } } -pub fn compute_max_cut(ledger_tail_maps: &Vec) -> Vec { +pub fn compute_max_cut(ledger_tail_maps: &[LedgerTailMap]) -> Vec { if ledger_tail_maps.is_empty() { Vec::new() } else { @@ -1033,7 +1033,7 @@ pub struct CutDiff { pub high: usize, } -pub fn compute_cut_diffs(ledger_tail_maps: &Vec) -> Vec { +pub fn compute_cut_diffs(ledger_tail_maps: &[LedgerTailMap]) -> Vec { if ledger_tail_maps.len() <= 1 { Vec::new() } else { diff --git a/store/src/ledger/azure_table.rs b/store/src/ledger/azure_table.rs index c1c8935..e374ddb 100644 --- a/store/src/ledger/azure_table.rs +++ b/store/src/ledger/azure_table.rs @@ -663,8 +663,8 @@ async fn read_ledger_internal( req_idx: Option, ledger: Arc, ) -> Result<(LedgerEntry, usize), LedgerStoreError> { - let actual_idx = if req_idx.is_some() { - req_idx.unwrap() + let actual_idx = if let Some(idx) = req_idx { + idx } else { let (entry, _etag) = find_db_entry(ledger.clone(), handle, TAIL).await?; entry.height as usize From ba281e95822d5f333c88c962211dcd2c5f242b2e Mon Sep 17 00:00:00 2001 From: Sebastian Angel Date: Thu, 18 Dec 2025 15:08:55 -0500 Subject: [PATCH 3/6] typos --- coordinator/Cargo.toml | 2 +- ledger/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/coordinator/Cargo.toml b/coordinator/Cargo.toml index a6c09a7..77a4b3b 100644 --- a/coordinator/Cargo.toml +++ b/coordinator/Cargo.toml @@ -2,7 +2,7 @@ name = "coordinator" version = "0.1.0" edition = "2024" -authors = ["Srinath Setty ", "Weidong Cui "] +authors = ["Srinath Setty ", "Weidong Cui ", "Sebastian Angel ", "Sudheesh Singanamalla "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index ec78f3c..0804f9e 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -2,7 +2,7 @@ name = "ledger" version = "0.1.0" edition = "2024" -authors = ["Srinath Setty ", "Weidong Cui "] +authors = ["Srinath Setty ", "Weidong Cui ", "Sebastian Angel ", "Sudheesh Singanamalla "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From f6274e8f50d63f1064b7273bf4a3c9b748cdf818 Mon Sep 17 00:00:00 2001 From: Sebastian Angel Date: Thu, 18 Dec 2025 15:59:36 -0500 Subject: [PATCH 4/6] use resolver 2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2e4421d..c495e5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,6 @@ members = [ "coordinator_ctrl", ] -resolver = "3" +resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From aadcd83e42e874e00ce21cefb08bec6f20945927 Mon Sep 17 00:00:00 2001 From: Sebastian Angel Date: Fri, 19 Dec 2025 21:00:24 -0500 Subject: [PATCH 5/6] rust version for CI --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9f72c2b..334652c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -9,7 +9,7 @@ on: jobs: build: env: - RUST_VERSION: 1.65.0 + RUST_VERSION: 1.92.0 runs-on: ubuntu-latest steps: - name: Install protoc From 49d7da92effd50e94c3c5e30d227918656969ac2 Mon Sep 17 00:00:00 2001 From: Sebastian Angel Date: Sat, 20 Dec 2025 09:00:02 -0500 Subject: [PATCH 6/6] cargo fmt --- coordinator/src/coordinator_state.rs | 65 ++++++++++++---------------- coordinator/src/main.rs | 12 ++--- endorser/src/endorser_state.rs | 35 +++++++-------- endorser/src/main.rs | 6 +-- endpoint/src/lib.rs | 9 ++-- ledger/src/lib.rs | 22 +++++----- light_client_rest/src/main.rs | 2 +- store/src/ledger/azure_table.rs | 2 +- store/src/ledger/filestore.rs | 2 +- store/src/ledger/in_memory.rs | 2 +- store/src/ledger/mod.rs | 4 +- store/src/ledger/mongodb_cosmos.rs | 4 +- 12 files changed, 80 insertions(+), 85 deletions(-) diff --git a/coordinator/src/coordinator_state.rs b/coordinator/src/coordinator_state.rs index ed44491..526d0eb 100644 --- a/coordinator/src/coordinator_state.rs +++ b/coordinator/src/coordinator_state.rs @@ -1,10 +1,10 @@ use crate::errors::CoordinatorError; use ledger::{ - compute_aggregated_block_hash, compute_cut_diffs, compute_max_cut, + Block, CustomSerde, EndorserHostnames, Handle, MetaBlock, NimbleDigest, NimbleHashTrait, Nonce, + Nonces, Receipt, Receipts, VerifierState, compute_aggregated_block_hash, compute_cut_diffs, + compute_max_cut, errors::VerificationError, signature::{PublicKey, PublicKeyTrait}, - Block, CustomSerde, EndorserHostnames, Handle, MetaBlock, NimbleDigest, NimbleHashTrait, Nonce, - Nonces, Receipt, Receipts, VerifierState, }; use rand::random; use std::{ @@ -14,14 +14,14 @@ use std::{ sync::{Arc, RwLock}, }; use store::ledger::{ - azure_table::TableLedgerStore, filestore::FileStore, in_memory::InMemoryLedgerStore, - mongodb_cosmos::MongoCosmosLedgerStore, LedgerEntry, LedgerStore, + LedgerEntry, LedgerStore, azure_table::TableLedgerStore, filestore::FileStore, + in_memory::InMemoryLedgerStore, mongodb_cosmos::MongoCosmosLedgerStore, }; use store::{errors::LedgerStoreError, errors::StorageError}; use tokio::sync::mpsc; use tonic::{ - transport::{Channel, Endpoint}, Code, Status, + transport::{Channel, Endpoint}, }; use ledger::endorser_proto; @@ -666,8 +666,7 @@ impl CoordinatorState { pub fn get_endorser_pks(&self) -> Vec> { if let Ok(conn_map_rd) = self.conn_map.read() { - conn_map_rd.keys().cloned() - .collect::>>() + conn_map_rd.keys().cloned().collect::>>() } else { eprintln!("Failed to acquire read lock"); Vec::new() @@ -676,7 +675,9 @@ impl CoordinatorState { pub fn get_endorser_uris(&self) -> Vec { if let Ok(conn_map_rd) = self.conn_map.read() { - conn_map_rd.values().map(|endorser| endorser.uri.clone()) + conn_map_rd + .values() + .map(|endorser| endorser.uri.clone()) .collect::>() } else { eprintln!("Failed to acquire read lock"); @@ -981,9 +982,10 @@ impl CoordinatorState { Ok(receipt_rs) => { receipts.add(&receipt_rs); if let Ok(vs) = self.verifier_state.read() - && receipts.check_quorum(&vs).is_ok() { - return Ok(receipts); - } + && receipts.check_quorum(&vs).is_ok() + { + return Ok(receipts); + } }, Err(error) => eprintln!("Failed to parse a receipt ({:?})", error), } @@ -1140,9 +1142,10 @@ impl CoordinatorState { Ok(receipt_rs) => { receipts.add(&receipt_rs); if let Ok(vs) = self.verifier_state.read() - && receipts.check_quorum(&vs).is_ok() { - return Ok(receipts); - } + && receipts.check_quorum(&vs).is_ok() + { + return Ok(receipts); + } }, Err(error) => { eprintln!("Failed to parse a receipt (err={:?}", error); @@ -1303,10 +1306,11 @@ impl CoordinatorState { receipts.add(&receipt_rs); if let Ok(vs) = self.verifier_state.read() && let Ok(_h) = receipts.check_quorum(&vs) - && let Ok(block_rs) = Block::from_bytes(&block) - && let Ok(nonces_rs) = Nonces::from_bytes(&nonces) { - return Ok(LedgerEntry::new(block_rs, receipts, Some(nonces_rs))); - } + && let Ok(block_rs) = Block::from_bytes(&block) + && let Ok(nonces_rs) = Nonces::from_bytes(&nonces) + { + return Ok(LedgerEntry::new(block_rs, receipts, Some(nonces_rs))); + } }, Err(error) => { eprintln!("Failed to parse a receipt (err={:?}", error); @@ -1628,14 +1632,10 @@ impl CoordinatorState { if cut_diff.low == cut_diff.high { continue; } - let mut block_hashes: Vec> = - Vec::with_capacity(cut_diff.high - cut_diff.low ); + let mut block_hashes: Vec> = Vec::with_capacity(cut_diff.high - cut_diff.low); let h = NimbleDigest::from_bytes(&cut_diff.handle).unwrap(); for index in (cut_diff.low + 1)..=cut_diff.high { - let res = self - .ledger_store - .read_ledger_by_index(&h, index) - .await; + let res = self.ledger_store.read_ledger_by_index(&h, index).await; if let Err(e) = res { eprintln!("Failed to read the ledger store {:?}", e); return Err(CoordinatorError::FailedToCallLedgerStore); @@ -1715,10 +1715,7 @@ impl CoordinatorState { .create_ledger(&handle, genesis_block.clone()) .await; if let Err(e) = res { - eprintln!( - "Failed to create ledger in the ledger store ({:?})", - e - ); + eprintln!("Failed to create ledger in the ledger store ({:?})", e); return Err(CoordinatorError::FailedToCreateLedger); } @@ -1773,10 +1770,7 @@ impl CoordinatorState { .append_ledger(&handle, &data_block, expected_height) .await; if let Err(e) = res { - eprintln!( - "Failed to append to the ledger in the ledger store {:?}", - e - ); + eprintln!("Failed to append to the ledger in the ledger store {:?}", e); return Err(CoordinatorError::FailedToAppendLedger); } @@ -1879,10 +1873,7 @@ impl CoordinatorState { if !nonce_attached { let res = self.ledger_store.attach_ledger_nonce(&handle, &nonce).await; if let Err(e) = res { - eprintln!( - "Failed to attach the nonce for reading ledger tail {:?}", - e - ); + eprintln!("Failed to attach the nonce for reading ledger tail {:?}", e); return Err(CoordinatorError::FailedToAttachNonce); } nonce_attached = true; diff --git a/coordinator/src/main.rs b/coordinator/src/main.rs index d7b202e..6ba3875 100644 --- a/coordinator/src/main.rs +++ b/coordinator/src/main.rs @@ -4,7 +4,7 @@ mod errors; use crate::coordinator_state::CoordinatorState; use ledger::CustomSerde; use std::{collections::HashMap, sync::Arc}; -use tonic::{transport::Server, Request, Response, Status}; +use tonic::{Request, Response, Status, transport::Server}; #[allow(clippy::derive_partial_eq_without_eq)] pub mod coordinator_proto { @@ -13,18 +13,18 @@ pub mod coordinator_proto { use clap::{App, Arg}; use coordinator_proto::{ - call_server::{Call, CallServer}, AppendReq, AppendResp, NewLedgerReq, NewLedgerResp, ReadByIndexReq, ReadByIndexResp, ReadLatestReq, ReadLatestResp, ReadViewByIndexReq, ReadViewByIndexResp, ReadViewTailReq, ReadViewTailResp, + call_server::{Call, CallServer}, }; use axum::{ + Json, Router, extract::{Extension, Path}, http::StatusCode, response::IntoResponse, routing::get, - Json, Router, }; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -482,11 +482,11 @@ async fn main() -> Result<(), Box> { #[cfg(test)] mod tests { use crate::{ + CoordinatorServiceState, CoordinatorState, coordinator_proto::{ - call_server::Call, AppendReq, AppendResp, NewLedgerReq, NewLedgerResp, ReadByIndexReq, - ReadByIndexResp, ReadLatestReq, ReadLatestResp, ReadViewTailReq, ReadViewTailResp, + AppendReq, AppendResp, NewLedgerReq, NewLedgerResp, ReadByIndexReq, ReadByIndexResp, + ReadLatestReq, ReadLatestResp, ReadViewTailReq, ReadViewTailResp, call_server::Call, }, - CoordinatorServiceState, CoordinatorState, }; use ledger::{Block, CustomSerde, NimbleDigest, VerifierState}; use rand::Rng; diff --git a/endorser/src/endorser_state.rs b/endorser/src/endorser_state.rs index b50576f..1d096b1 100644 --- a/endorser/src/endorser_state.rs +++ b/endorser/src/endorser_state.rs @@ -5,13 +5,12 @@ use itertools::Itertools; use ledger::endorser_proto::{EndorserMode, LedgerChunkEntry, LedgerTailMap, LedgerTailMapEntry}; use ledger::{ - produce_hash_of_state, - signature::{PrivateKey, PrivateKeyTrait, PublicKey}, Block, CustomSerde, Handle, IdSig, MetaBlock, NimbleDigest, NimbleHashTrait, Nonces, Receipt, - Receipts, + Receipts, produce_hash_of_state, + signature::{PrivateKey, PrivateKeyTrait, PublicKey}, }; use std::{ - collections::{hash_map, HashMap}, + collections::{HashMap, hash_map}, ops::{Deref, DerefMut}, sync::{Arc, RwLock}, }; @@ -561,19 +560,21 @@ mod tests { .expect("failed") .view_ledger_tail_hash, ); - assert!(receipt - .get_id_sig() - .verify_with_id( - &endorser_state.public_key, - &view_block_hash - .digest_with( - &receipt - .get_view() - .digest_with(&handle.digest_with(&genesis_tail_hash)) - ) - .to_bytes(), - ) - .is_ok()); + assert!( + receipt + .get_id_sig() + .verify_with_id( + &endorser_state.public_key, + &view_block_hash + .digest_with( + &receipt + .get_view() + .digest_with(&handle.digest_with(&genesis_tail_hash)) + ) + .to_bytes(), + ) + .is_ok() + ); // Fetch the value currently in the tail. let tail_result = endorser_state.read_latest(&handle, &[0]); diff --git a/endorser/src/main.rs b/endorser/src/main.rs index 56071d2..ab4c38b 100644 --- a/endorser/src/main.rs +++ b/endorser/src/main.rs @@ -1,18 +1,18 @@ use crate::{endorser_state::EndorserState, errors::EndorserError}; use clap::{App, Arg}; use ledger::{ - signature::PublicKeyTrait, Block, CustomSerde, MetaBlock, NimbleDigest, Nonces, Receipts, + Block, CustomSerde, MetaBlock, NimbleDigest, Nonces, Receipts, signature::PublicKeyTrait, }; -use tonic::{transport::Server, Code, Request, Response, Status}; +use tonic::{Code, Request, Response, Status, transport::Server}; mod endorser_state; mod errors; use ledger::endorser_proto::{ - endorser_call_server::{EndorserCall, EndorserCallServer}, ActivateReq, ActivateResp, AppendReq, AppendResp, FinalizeStateReq, FinalizeStateResp, GetPublicKeyReq, GetPublicKeyResp, InitializeStateReq, InitializeStateResp, NewLedgerReq, NewLedgerResp, ReadLatestReq, ReadLatestResp, ReadStateReq, ReadStateResp, + endorser_call_server::{EndorserCall, EndorserCallServer}, }; pub struct EndorserServiceState { diff --git a/endpoint/src/lib.rs b/endpoint/src/lib.rs index bf441c7..8518bf0 100644 --- a/endpoint/src/lib.rs +++ b/endpoint/src/lib.rs @@ -1,8 +1,8 @@ mod errors; use tonic::{ - transport::{Channel, Endpoint}, Request, + transport::{Channel, Endpoint}, }; #[allow(clippy::derive_partial_eq_without_eq)] @@ -12,13 +12,14 @@ pub mod coordinator_proto { use crate::errors::EndpointError; use coordinator_proto::{ - call_client::CallClient, AppendReq, AppendResp, NewLedgerReq, NewLedgerResp, ReadLatestReq, - ReadLatestResp, ReadViewByIndexReq, ReadViewByIndexResp, ReadViewTailReq, ReadViewTailResp, + AppendReq, AppendResp, NewLedgerReq, NewLedgerResp, ReadLatestReq, ReadLatestResp, + ReadViewByIndexReq, ReadViewByIndexResp, ReadViewTailReq, ReadViewTailResp, + call_client::CallClient, }; use ledger::{ + Block, CustomSerde, NimbleDigest, NimbleHashTrait, VerifierState, errors::VerificationError, signature::{PrivateKey, PrivateKeyTrait, PublicKey, PublicKeyTrait, Signature, SignatureTrait}, - Block, CustomSerde, NimbleDigest, NimbleHashTrait, VerifierState, }; use rand::random; use std::{ diff --git a/ledger/src/lib.rs b/ledger/src/lib.rs index a9d87e6..a115346 100644 --- a/ledger/src/lib.rs +++ b/ledger/src/lib.rs @@ -3,12 +3,12 @@ pub mod signature; use crate::signature::{PublicKey, PublicKeyTrait, Signature, SignatureTrait}; use digest::Output; use errors::VerificationError; -use generic_array::{typenum::U32, GenericArray}; +use generic_array::{GenericArray, typenum::U32}; use rayon::prelude::*; use sha2::{Digest, Sha256}; use std::{ cmp::Ordering, - collections::{hash_map, HashMap, HashSet}, + collections::{HashMap, HashSet, hash_map}, convert::TryInto, }; @@ -537,9 +537,10 @@ impl Receipts { } // check the height matches with the expected height if let Some(h) = expected_height - && h != ex_meta_block.get_metablock().get_height() { - return Err(VerificationError::InvalidHeight); - } + && h != ex_meta_block.get_metablock().get_height() + { + return Err(VerificationError::InvalidHeight); + } // update the message let tail_hash = match nonce_bytes { Some(n) => ex_meta_block.get_metablock().hash().digest_with_bytes(n), @@ -703,11 +704,12 @@ impl Receipts { for entry in &ledger_tail_map.entries { let res = ledger_entries.get(&(entry.handle.clone(), entry.height)); if let Some(metablock) = res - && entry.metablock.cmp(metablock) != Ordering::Equal { - eprintln!("metablock1={:?}", entry.metablock); - eprintln!("metablock2={:?}", metablock); - return Err(VerificationError::InconsistentLedgerTailMaps); - } + && entry.metablock.cmp(metablock) != Ordering::Equal + { + eprintln!("metablock1={:?}", entry.metablock); + eprintln!("metablock2={:?}", metablock); + return Err(VerificationError::InconsistentLedgerTailMaps); + } } } diff --git a/light_client_rest/src/main.rs b/light_client_rest/src/main.rs index 8fcacb8..76228d5 100644 --- a/light_client_rest/src/main.rs +++ b/light_client_rest/src/main.rs @@ -5,8 +5,8 @@ use serde::{Deserialize, Serialize}; use rand::Rng; use ledger::{ - signature::{PublicKey, PublicKeyTrait, Signature, SignatureTrait}, NimbleDigest, + signature::{PublicKey, PublicKeyTrait, Signature, SignatureTrait}, }; #[derive(Debug, Serialize, Deserialize)] diff --git a/store/src/ledger/azure_table.rs b/store/src/ledger/azure_table.rs index e374ddb..74ffac2 100644 --- a/store/src/ledger/azure_table.rs +++ b/store/src/ledger/azure_table.rs @@ -856,7 +856,7 @@ impl LedgerStore for TableLedgerStore { LedgerStoreError::LedgerError(StorageError::IncorrectConditionalData) => { return Err(LedgerStoreError::LedgerError( StorageError::IncorrectConditionalData, - )) + )); }, _ => return Err(e), }, diff --git a/store/src/ledger/filestore.rs b/store/src/ledger/filestore.rs index 6fec60a..dd5de81 100644 --- a/store/src/ledger/filestore.rs +++ b/store/src/ledger/filestore.rs @@ -14,7 +14,7 @@ use std::{ fmt::Debug, fs, fs::{File, OpenOptions}, - io::{prelude::*, SeekFrom}, + io::{SeekFrom, prelude::*}, path::{Path, PathBuf}, sync::{Arc, RwLock}, }; diff --git a/store/src/ledger/in_memory.rs b/store/src/ledger/in_memory.rs index 6d258f0..38afa07 100644 --- a/store/src/ledger/in_memory.rs +++ b/store/src/ledger/in_memory.rs @@ -5,7 +5,7 @@ use crate::{ }; use async_trait::async_trait; use std::{ - collections::{hash_map, HashMap}, + collections::{HashMap, hash_map}, sync::{Arc, RwLock}, }; diff --git a/store/src/ledger/mod.rs b/store/src/ledger/mod.rs index b7fa89e..ed0df2c 100644 --- a/store/src/ledger/mod.rs +++ b/store/src/ledger/mod.rs @@ -97,8 +97,8 @@ pub trait LedgerStore { #[cfg(test)] mod tests { use crate::ledger::{ - azure_table::TableLedgerStore, filestore::FileStore, in_memory::InMemoryLedgerStore, - mongodb_cosmos::MongoCosmosLedgerStore, LedgerStore, + LedgerStore, azure_table::TableLedgerStore, filestore::FileStore, + in_memory::InMemoryLedgerStore, mongodb_cosmos::MongoCosmosLedgerStore, }; use ledger::{Block, CustomSerde, NimbleHashTrait}; use std::collections::HashMap; diff --git a/store/src/ledger/mongodb_cosmos.rs b/store/src/ledger/mongodb_cosmos.rs index 5cec1af..8b0e3c6 100644 --- a/store/src/ledger/mongodb_cosmos.rs +++ b/store/src/ledger/mongodb_cosmos.rs @@ -7,9 +7,9 @@ use bincode; use hex; use ledger::{Block, CustomSerde, Handle, NimbleDigest, Nonce, Nonces, Receipts}; use mongodb::{ - bson::{doc, spec::BinarySubtype, Binary}, - error::WriteFailure::WriteError, Client, Collection, + bson::{Binary, doc, spec::BinarySubtype}, + error::WriteFailure::WriteError, }; use serde::{Deserialize, Serialize}; use std::{