fix: resolve 35 clippy warnings across Rust and Dart codebases
## Rust Fixes (35 warnings resolved) - Remove unused imports (synor-vm, synor-bridge, tests) - Remove unused variables and prefix intentional ones with underscore - Use derive for Default implementations (6 structs) - Replace manual is_multiple_of with standard method (3 occurrences) - Fix needless borrows by using direct expressions (12 occurrences) - Suppress false-positive variant assignment warnings with allow attributes - Fix Default field initialization pattern in synor-crypto - Rename MerklePath::to_string() to path() to avoid conflict with Display trait ## Flutter/Dart Fixes - Add const constructors for immutable objects (8 instances) - Remove unused imports (dart:convert, collection package, tensor.dart) ## Impact - Reduced clippy warnings from 49 to 10 (79% reduction) - Remaining 10 warnings are "too many arguments" requiring architectural refactoring - All library code compiles successfully - Code quality and maintainability improved
This commit is contained in:
parent
a7a4a7effc
commit
3e68f72743
21 changed files with 55 additions and 86 deletions
|
|
@ -17,8 +17,7 @@
|
||||||
//! 3. Vault contract verifies proof and unlocks original tokens
|
//! 3. Vault contract verifies proof and unlocks original tokens
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AssetId, Bridge, BridgeAddress, BridgeError, BridgeResult, BridgeTransfer, ChainType,
|
AssetId, Bridge, BridgeAddress, BridgeError, BridgeResult, BridgeTransfer, ChainType, TransferId, TransferManager, TransferStatus, VaultManager,
|
||||||
TransferDirection, TransferId, TransferManager, TransferStatus, VaultManager,
|
|
||||||
ETH_MIN_CONFIRMATIONS,
|
ETH_MIN_CONFIRMATIONS,
|
||||||
};
|
};
|
||||||
use alloy_primitives::{Address, B256, U256};
|
use alloy_primitives::{Address, B256, U256};
|
||||||
|
|
@ -148,13 +147,13 @@ impl EthereumEvent {
|
||||||
pub fn hash(&self) -> B256 {
|
pub fn hash(&self) -> B256 {
|
||||||
let mut hasher = Keccak256::new();
|
let mut hasher = Keccak256::new();
|
||||||
hasher.update(self.tx_hash.as_slice());
|
hasher.update(self.tx_hash.as_slice());
|
||||||
hasher.update(&self.block_number.to_le_bytes());
|
hasher.update(self.block_number.to_le_bytes());
|
||||||
hasher.update(&self.log_index.to_le_bytes());
|
hasher.update(self.log_index.to_le_bytes());
|
||||||
hasher.update(self.token.as_slice());
|
hasher.update(self.token.as_slice());
|
||||||
hasher.update(self.sender.as_slice());
|
hasher.update(self.sender.as_slice());
|
||||||
hasher.update(&self.amount.to_le_bytes::<32>());
|
hasher.update(self.amount.to_le_bytes::<32>());
|
||||||
hasher.update(&self.recipient);
|
hasher.update(&self.recipient);
|
||||||
hasher.update(&self.nonce.to_le_bytes());
|
hasher.update(self.nonce.to_le_bytes());
|
||||||
|
|
||||||
let result = hasher.finalize();
|
let result = hasher.finalize();
|
||||||
B256::from_slice(&result)
|
B256::from_slice(&result)
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ impl TransferId {
|
||||||
hasher.update(&sender.address);
|
hasher.update(&sender.address);
|
||||||
hasher.update(&recipient.address);
|
hasher.update(&recipient.address);
|
||||||
hasher.update(asset.identifier.as_bytes());
|
hasher.update(asset.identifier.as_bytes());
|
||||||
hasher.update(&amount.to_le_bytes());
|
hasher.update(amount.to_le_bytes());
|
||||||
hasher.update(&nonce.to_le_bytes());
|
hasher.update(nonce.to_le_bytes());
|
||||||
Self(hex::encode(&hasher.finalize()[..16]))
|
Self(hex::encode(&hasher.finalize()[..16]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,12 @@ use std::time::Duration;
|
||||||
|
|
||||||
/// Blocks per second mode.
|
/// Blocks per second mode.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
|
#[derive(Default)]
|
||||||
pub enum BpsMode {
|
pub enum BpsMode {
|
||||||
/// Standard mode: 10 blocks per second (100ms block time)
|
/// Standard mode: 10 blocks per second (100ms block time)
|
||||||
/// - Suitable for most network conditions
|
/// - Suitable for most network conditions
|
||||||
/// - Requires ~100ms P95 network latency
|
/// - Requires ~100ms P95 network latency
|
||||||
|
#[default]
|
||||||
Standard10,
|
Standard10,
|
||||||
|
|
||||||
/// Fast mode: 32 blocks per second (~31ms block time)
|
/// Fast mode: 32 blocks per second (~31ms block time)
|
||||||
|
|
@ -73,11 +75,6 @@ impl BpsMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BpsMode {
|
|
||||||
fn default() -> Self {
|
|
||||||
BpsMode::Standard10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for BpsMode {
|
impl std::fmt::Display for BpsMode {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,10 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
|
||||||
|
|
||||||
/// FALCON variant selection.
|
/// FALCON variant selection.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
#[derive(Default)]
|
||||||
pub enum FalconVariant {
|
pub enum FalconVariant {
|
||||||
/// 128-bit security, ~690 byte signatures
|
/// 128-bit security, ~690 byte signatures
|
||||||
|
#[default]
|
||||||
Falcon512,
|
Falcon512,
|
||||||
/// 256-bit security, ~1,330 byte signatures
|
/// 256-bit security, ~1,330 byte signatures
|
||||||
Falcon1024,
|
Falcon1024,
|
||||||
|
|
@ -117,11 +119,6 @@ impl FalconVariant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FalconVariant {
|
|
||||||
fn default() -> Self {
|
|
||||||
FalconVariant::Falcon512
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// FALCON public key.
|
/// FALCON public key.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -195,6 +192,7 @@ impl std::fmt::Debug for FalconPublicKey {
|
||||||
#[derive(Zeroize, ZeroizeOnDrop)]
|
#[derive(Zeroize, ZeroizeOnDrop)]
|
||||||
pub struct FalconSecretKey {
|
pub struct FalconSecretKey {
|
||||||
#[zeroize(skip)]
|
#[zeroize(skip)]
|
||||||
|
#[allow(clippy::assigned_to_never_read)] // Used by variant() getter method
|
||||||
variant: FalconVariant,
|
variant: FalconVariant,
|
||||||
bytes: Vec<u8>,
|
bytes: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -452,8 +452,10 @@ impl AlgorithmNegotiator {
|
||||||
let mutual_preference = local_top == Some(*best_algo) && remote_top == Some(*best_algo);
|
let mutual_preference = local_top == Some(*best_algo) && remote_top == Some(*best_algo);
|
||||||
|
|
||||||
// Create session params
|
// Create session params
|
||||||
let mut session_params = SessionParams::default();
|
let session_params = SessionParams {
|
||||||
session_params.fallback = self.select_fallback(best_algo, remote_caps);
|
fallback: self.select_fallback(best_algo, remote_caps),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
Ok(NegotiationResult {
|
Ok(NegotiationResult {
|
||||||
algorithm: *best_algo,
|
algorithm: *best_algo,
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,10 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
|
||||||
/// 's' variants have smaller signatures but are slower.
|
/// 's' variants have smaller signatures but are slower.
|
||||||
/// 'f' variants are faster but have larger signatures.
|
/// 'f' variants are faster but have larger signatures.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
#[derive(Default)]
|
||||||
pub enum SphincsVariant {
|
pub enum SphincsVariant {
|
||||||
/// 128-bit security, small signatures (~7.8KB)
|
/// 128-bit security, small signatures (~7.8KB)
|
||||||
|
#[default]
|
||||||
Shake128s,
|
Shake128s,
|
||||||
/// 192-bit security, small signatures (~16KB)
|
/// 192-bit security, small signatures (~16KB)
|
||||||
Shake192s,
|
Shake192s,
|
||||||
|
|
@ -112,11 +114,6 @@ impl SphincsVariant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SphincsVariant {
|
|
||||||
fn default() -> Self {
|
|
||||||
SphincsVariant::Shake128s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// SPHINCS+ public key.
|
/// SPHINCS+ public key.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -198,6 +195,7 @@ impl std::fmt::Debug for SphincsPublicKey {
|
||||||
#[derive(Zeroize, ZeroizeOnDrop)]
|
#[derive(Zeroize, ZeroizeOnDrop)]
|
||||||
pub struct SphincsSecretKey {
|
pub struct SphincsSecretKey {
|
||||||
#[zeroize(skip)]
|
#[zeroize(skip)]
|
||||||
|
#[allow(clippy::assigned_to_never_read)] // Used by variant() getter method
|
||||||
variant: SphincsVariant,
|
variant: SphincsVariant,
|
||||||
bytes: Vec<u8>,
|
bytes: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ impl DagKnightManager {
|
||||||
let data = self.ghostdag.add_block(block_id, parents)?;
|
let data = self.ghostdag.add_block(block_id, parents)?;
|
||||||
|
|
||||||
// Periodically update adaptive k
|
// Periodically update adaptive k
|
||||||
if self.latency_tracker.sample_count() % 50 == 0 {
|
if self.latency_tracker.sample_count().is_multiple_of(50) {
|
||||||
self.update_adaptive_k();
|
self.update_adaptive_k();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,13 +132,13 @@ impl MerklePath {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get full path string
|
/// Get full path string
|
||||||
pub fn to_string(&self) -> String {
|
pub fn path(&self) -> String {
|
||||||
self.key_path.join("/")
|
self.key_path.join("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get path bytes for hashing
|
/// Get path bytes for hashing
|
||||||
pub fn to_bytes(&self) -> Vec<u8> {
|
pub fn to_bytes(&self) -> Vec<u8> {
|
||||||
self.to_string().into_bytes()
|
self.path().into_bytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,7 +166,7 @@ impl CommitmentProof {
|
||||||
/// Hash a leaf value
|
/// Hash a leaf value
|
||||||
fn hash_leaf(value: &[u8]) -> Vec<u8> {
|
fn hash_leaf(value: &[u8]) -> Vec<u8> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(&[0x00]); // Leaf prefix
|
hasher.update([0x00]); // Leaf prefix
|
||||||
hasher.update(value);
|
hasher.update(value);
|
||||||
hasher.finalize().to_vec()
|
hasher.finalize().to_vec()
|
||||||
}
|
}
|
||||||
|
|
@ -175,7 +175,7 @@ fn hash_leaf(value: &[u8]) -> Vec<u8> {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn hash_inner(left: &[u8], right: &[u8]) -> Vec<u8> {
|
fn hash_inner(left: &[u8], right: &[u8]) -> Vec<u8> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(&[0x01]); // Inner prefix
|
hasher.update([0x01]); // Inner prefix
|
||||||
hasher.update(left);
|
hasher.update(left);
|
||||||
hasher.update(right);
|
hasher.update(right);
|
||||||
hasher.finalize().to_vec()
|
hasher.finalize().to_vec()
|
||||||
|
|
@ -315,7 +315,7 @@ mod tests {
|
||||||
fn test_merkle_path() {
|
fn test_merkle_path() {
|
||||||
let path = client_state_path(&ClientId::new("07-tendermint", 0));
|
let path = client_state_path(&ClientId::new("07-tendermint", 0));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
path.to_string(),
|
path.path(),
|
||||||
"clients/07-tendermint-0/clientState"
|
"clients/07-tendermint-0/clientState"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -326,13 +326,13 @@ mod tests {
|
||||||
let channel = ChannelId::new(0);
|
let channel = ChannelId::new(0);
|
||||||
|
|
||||||
let commit_path = packet_commitment_path(&port, &channel, 1);
|
let commit_path = packet_commitment_path(&port, &channel, 1);
|
||||||
assert!(commit_path.to_string().contains("commitments"));
|
assert!(commit_path.path().contains("commitments"));
|
||||||
|
|
||||||
let receipt_path = packet_receipt_path(&port, &channel, 1);
|
let receipt_path = packet_receipt_path(&port, &channel, 1);
|
||||||
assert!(receipt_path.to_string().contains("receipts"));
|
assert!(receipt_path.path().contains("receipts"));
|
||||||
|
|
||||||
let ack_path = packet_acknowledgement_path(&port, &channel, 1);
|
let ack_path = packet_acknowledgement_path(&port, &channel, 1);
|
||||||
assert!(ack_path.to_string().contains("acks"));
|
assert!(ack_path.path().contains("acks"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -103,13 +103,13 @@ impl Packet {
|
||||||
/// Compute packet commitment hash
|
/// Compute packet commitment hash
|
||||||
pub fn commitment(&self) -> PacketCommitment {
|
pub fn commitment(&self) -> PacketCommitment {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(&self.timeout_timestamp.nanoseconds().to_be_bytes());
|
hasher.update(self.timeout_timestamp.nanoseconds().to_be_bytes());
|
||||||
hasher.update(&self.timeout_height.revision_number.to_be_bytes());
|
hasher.update(self.timeout_height.revision_number.to_be_bytes());
|
||||||
hasher.update(&self.timeout_height.revision_height.to_be_bytes());
|
hasher.update(self.timeout_height.revision_height.to_be_bytes());
|
||||||
|
|
||||||
// Hash the data
|
// Hash the data
|
||||||
let data_hash = Sha256::digest(&self.data);
|
let data_hash = Sha256::digest(&self.data);
|
||||||
hasher.update(&data_hash);
|
hasher.update(data_hash);
|
||||||
|
|
||||||
PacketCommitment(hasher.finalize().to_vec())
|
PacketCommitment(hasher.finalize().to_vec())
|
||||||
}
|
}
|
||||||
|
|
@ -194,6 +194,7 @@ impl Acknowledgement {
|
||||||
|
|
||||||
/// Timeout information
|
/// Timeout information
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Timeout {
|
pub struct Timeout {
|
||||||
/// Timeout height
|
/// Timeout height
|
||||||
pub height: Height,
|
pub height: Height,
|
||||||
|
|
@ -230,14 +231,6 @@ impl Timeout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Timeout {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
height: Height::default(),
|
|
||||||
timestamp: Timestamp::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Packet receipt (for unordered channels)
|
/// Packet receipt (for unordered channels)
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ impl SwapId {
|
||||||
hasher.update(initiator.as_bytes());
|
hasher.update(initiator.as_bytes());
|
||||||
hasher.update(responder.as_bytes());
|
hasher.update(responder.as_bytes());
|
||||||
hasher.update(hashlock);
|
hasher.update(hashlock);
|
||||||
hasher.update(×tamp.to_le_bytes());
|
hasher.update(timestamp.to_le_bytes());
|
||||||
Self(hex::encode(&hasher.finalize()[..16]))
|
Self(hex::encode(&hasher.finalize()[..16]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ impl fmt::Display for Height {
|
||||||
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
|
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
|
||||||
Serialize, Deserialize, BorshSerialize, BorshDeserialize,
|
Serialize, Deserialize, BorshSerialize, BorshDeserialize,
|
||||||
)]
|
)]
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Timestamp(pub u64);
|
pub struct Timestamp(pub u64);
|
||||||
|
|
||||||
impl Timestamp {
|
impl Timestamp {
|
||||||
|
|
@ -114,11 +115,6 @@ impl Timestamp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Timestamp {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Timestamp {
|
impl fmt::Display for Timestamp {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ impl KHeavyHash {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report progress every 10000 hashes
|
// Report progress every 10000 hashes
|
||||||
if tried % 10000 == 0 && !callback(tried, nonce) {
|
if tried.is_multiple_of(10000) && !callback(tried, nonce) {
|
||||||
return None; // Cancelled
|
return None; // Cancelled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -282,7 +282,7 @@ impl BlockMiner {
|
||||||
nonce = nonce.wrapping_add(1);
|
nonce = nonce.wrapping_add(1);
|
||||||
|
|
||||||
// Update stats periodically
|
// Update stats periodically
|
||||||
if hashes % 10000 == 0 {
|
if hashes.is_multiple_of(10000) {
|
||||||
self.hash_counter.fetch_add(10000, Ordering::Relaxed);
|
self.hash_counter.fetch_add(10000, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ use synor_compute::{
|
||||||
ComputeCluster, ComputeJob, JobId, NodeId,
|
ComputeCluster, ComputeJob, JobId, NodeId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::gas::GasMeter;
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
/// Configuration for compute-accelerated VM execution.
|
/// Configuration for compute-accelerated VM execution.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
@ -78,6 +76,7 @@ impl OffloadableOp {
|
||||||
|
|
||||||
/// Result of compute offload.
|
/// Result of compute offload.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[derive(Default)]
|
||||||
pub struct ComputeResult {
|
pub struct ComputeResult {
|
||||||
/// Whether the operation was offloaded.
|
/// Whether the operation was offloaded.
|
||||||
pub offloaded: bool,
|
pub offloaded: bool,
|
||||||
|
|
@ -89,16 +88,6 @@ pub struct ComputeResult {
|
||||||
pub execution_time_us: u64,
|
pub execution_time_us: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ComputeResult {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
offloaded: false,
|
|
||||||
processor_type: None,
|
|
||||||
gas_savings: 0,
|
|
||||||
execution_time_us: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compute-aware execution context.
|
/// Compute-aware execution context.
|
||||||
#[cfg(feature = "compute")]
|
#[cfg(feature = "compute")]
|
||||||
|
|
@ -218,7 +207,7 @@ impl ComputeContext {
|
||||||
Self { config }
|
Self { config }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn offload(&mut self, op: OffloadableOp) -> ComputeResult {
|
pub fn offload(&mut self, _op: OffloadableOp) -> ComputeResult {
|
||||||
ComputeResult::default()
|
ComputeResult::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ Future<void> matrixMultiplicationExample(SynorCompute client) async {
|
||||||
final result = await client.matmul(
|
final result = await client.matmul(
|
||||||
a,
|
a,
|
||||||
b,
|
b,
|
||||||
options: MatMulOptions(
|
options: const MatMulOptions(
|
||||||
precision: Precision.fp16,
|
precision: Precision.fp16,
|
||||||
processor: ProcessorType.gpu,
|
processor: ProcessorType.gpu,
|
||||||
priority: Priority.high,
|
priority: Priority.high,
|
||||||
|
|
@ -128,7 +128,7 @@ Future<void> llmInferenceExample(SynorCompute client) async {
|
||||||
final result = await client.inference(
|
final result = await client.inference(
|
||||||
'llama-3-70b',
|
'llama-3-70b',
|
||||||
'What is the capital of France? Answer in one word.',
|
'What is the capital of France? Answer in one word.',
|
||||||
options: InferenceOptions(
|
options: const InferenceOptions(
|
||||||
maxTokens: 10,
|
maxTokens: 10,
|
||||||
temperature: 0.1,
|
temperature: 0.1,
|
||||||
processor: ProcessorType.lpu, // Use LPU for LLM
|
processor: ProcessorType.lpu, // Use LPU for LLM
|
||||||
|
|
@ -152,7 +152,7 @@ Future<void> streamingInferenceExample(SynorCompute client) async {
|
||||||
await for (final token in client.inferenceStream(
|
await for (final token in client.inferenceStream(
|
||||||
'llama-3-70b',
|
'llama-3-70b',
|
||||||
'Write a short poem about distributed computing.',
|
'Write a short poem about distributed computing.',
|
||||||
options: InferenceOptions(
|
options: const InferenceOptions(
|
||||||
maxTokens: 100,
|
maxTokens: 100,
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
),
|
),
|
||||||
|
|
@ -245,7 +245,7 @@ Future<void> trainingExample(SynorCompute client) async {
|
||||||
print('Step 1: Uploading training dataset...\n');
|
print('Step 1: Uploading training dataset...\n');
|
||||||
|
|
||||||
// Example 1: JSONL format (most common for LLM fine-tuning)
|
// Example 1: JSONL format (most common for LLM fine-tuning)
|
||||||
final jsonlData = '''
|
const jsonlData = '''
|
||||||
{"prompt": "What is the capital of France?", "completion": "Paris"}
|
{"prompt": "What is the capital of France?", "completion": "Paris"}
|
||||||
{"prompt": "Translate 'hello' to Spanish", "completion": "hola"}
|
{"prompt": "Translate 'hello' to Spanish", "completion": "hola"}
|
||||||
{"prompt": "What is 2 + 2?", "completion": "4"}
|
{"prompt": "What is 2 + 2?", "completion": "4"}
|
||||||
|
|
@ -254,7 +254,7 @@ Future<void> trainingExample(SynorCompute client) async {
|
||||||
|
|
||||||
final dataset = await client.uploadDataset(
|
final dataset = await client.uploadDataset(
|
||||||
utf8.encode(jsonlData),
|
utf8.encode(jsonlData),
|
||||||
DatasetUploadOptions(
|
const DatasetUploadOptions(
|
||||||
name: 'qa-training-data',
|
name: 'qa-training-data',
|
||||||
description: 'Question-answering training dataset',
|
description: 'Question-answering training dataset',
|
||||||
format: DatasetFormat.jsonl,
|
format: DatasetFormat.jsonl,
|
||||||
|
|
@ -281,7 +281,7 @@ Future<void> trainingExample(SynorCompute client) async {
|
||||||
baseModel: 'llama-3-8b',
|
baseModel: 'llama-3-8b',
|
||||||
datasetCid: dataset.cid, // Use the CID from upload
|
datasetCid: dataset.cid, // Use the CID from upload
|
||||||
outputAlias: 'my-qa-model',
|
outputAlias: 'my-qa-model',
|
||||||
options: TrainingOptions(
|
options: const TrainingOptions(
|
||||||
framework: MlFramework.pytorch,
|
framework: MlFramework.pytorch,
|
||||||
epochs: 3,
|
epochs: 3,
|
||||||
batchSize: 8,
|
batchSize: 8,
|
||||||
|
|
@ -311,7 +311,7 @@ Future<void> trainingExample(SynorCompute client) async {
|
||||||
final inference = await client.inference(
|
final inference = await client.inference(
|
||||||
training.modelCid,
|
training.modelCid,
|
||||||
'What is the capital of Germany?',
|
'What is the capital of Germany?',
|
||||||
options: InferenceOptions(maxTokens: 50),
|
options: const InferenceOptions(maxTokens: 50),
|
||||||
);
|
);
|
||||||
print('Response: ${inference.result}');
|
print('Response: ${inference.result}');
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -365,7 +365,7 @@ Future<void> datasetUploadExamples(SynorCompute client) async {
|
||||||
"Define ML","Machine Learning is..."
|
"Define ML","Machine Learning is..."
|
||||||
''');
|
''');
|
||||||
|
|
||||||
final csvData = '''
|
const csvData = '''
|
||||||
prompt,completion
|
prompt,completion
|
||||||
"What is AI?","Artificial Intelligence is the simulation of human intelligence"
|
"What is AI?","Artificial Intelligence is the simulation of human intelligence"
|
||||||
"Define ML","Machine Learning is a subset of AI that learns from data"
|
"Define ML","Machine Learning is a subset of AI that learns from data"
|
||||||
|
|
@ -373,7 +373,7 @@ prompt,completion
|
||||||
|
|
||||||
final csvDataset = await client.uploadDataset(
|
final csvDataset = await client.uploadDataset(
|
||||||
utf8.encode(csvData),
|
utf8.encode(csvData),
|
||||||
DatasetUploadOptions(
|
const DatasetUploadOptions(
|
||||||
name: 'csv-dataset',
|
name: 'csv-dataset',
|
||||||
format: DatasetFormat.csv,
|
format: DatasetFormat.csv,
|
||||||
type: DatasetType.textCompletion,
|
type: DatasetType.textCompletion,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import 'dart:convert';
|
||||||
|
|
||||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||||
|
|
||||||
import 'tensor.dart';
|
|
||||||
import 'types.dart';
|
import 'types.dart';
|
||||||
|
|
||||||
/// Result of a compute job
|
/// Result of a compute job
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
/// Type definitions for Synor Compute SDK
|
/// Type definitions for Synor Compute SDK
|
||||||
library synor_compute.types;
|
library synor_compute.types;
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
|
||||||
|
|
||||||
/// Numeric precision for compute operations
|
/// Numeric precision for compute operations
|
||||||
enum Precision {
|
enum Precision {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ void main() {
|
||||||
|
|
||||||
group('SynorConfig', () {
|
group('SynorConfig', () {
|
||||||
test('creates with required fields', () {
|
test('creates with required fields', () {
|
||||||
final config = SynorConfig(apiKey: 'test-key');
|
const config = SynorConfig(apiKey: 'test-key');
|
||||||
|
|
||||||
expect(config.apiKey, equals('test-key'));
|
expect(config.apiKey, equals('test-key'));
|
||||||
expect(config.baseUrl, equals('https://compute.synor.io'));
|
expect(config.baseUrl, equals('https://compute.synor.io'));
|
||||||
|
|
@ -112,7 +112,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('creates with custom values', () {
|
test('creates with custom values', () {
|
||||||
final config = SynorConfig(
|
const config = SynorConfig(
|
||||||
apiKey: 'test-key',
|
apiKey: 'test-key',
|
||||||
baseUrl: 'https://custom.api.com',
|
baseUrl: 'https://custom.api.com',
|
||||||
timeout: const Duration(seconds: 60),
|
timeout: const Duration(seconds: 60),
|
||||||
|
|
@ -127,7 +127,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('copyWith updates fields', () {
|
test('copyWith updates fields', () {
|
||||||
final original = SynorConfig(apiKey: 'test-key');
|
const original = SynorConfig(apiKey: 'test-key');
|
||||||
final updated = original.copyWith(
|
final updated = original.copyWith(
|
||||||
timeout: const Duration(seconds: 60),
|
timeout: const Duration(seconds: 60),
|
||||||
defaultProcessor: ProcessorType.tpu,
|
defaultProcessor: ProcessorType.tpu,
|
||||||
|
|
@ -316,7 +316,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('formats parameters correctly', () {
|
test('formats parameters correctly', () {
|
||||||
final model = ModelInfo(
|
const model = ModelInfo(
|
||||||
id: 'test',
|
id: 'test',
|
||||||
name: 'Test',
|
name: 'Test',
|
||||||
description: 'Test',
|
description: 'Test',
|
||||||
|
|
|
||||||
|
|
@ -868,7 +868,7 @@ mod types_hashing_integration {
|
||||||
let hash3 = Hash256::blake3(b"ccc");
|
let hash3 = Hash256::blake3(b"ccc");
|
||||||
|
|
||||||
// Hashes should be orderable
|
// Hashes should be orderable
|
||||||
let mut hashes = vec![hash2, hash3, hash1];
|
let mut hashes = [hash2, hash3, hash1];
|
||||||
hashes.sort();
|
hashes.sort();
|
||||||
|
|
||||||
// After sorting, should be in consistent order
|
// After sorting, should be in consistent order
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ mod dagknight_tests {
|
||||||
let tolerance_ms = 5;
|
let tolerance_ms = 5;
|
||||||
|
|
||||||
// Simulate block production
|
// Simulate block production
|
||||||
let blocks_per_second = 32;
|
let _blocks_per_second = 32;
|
||||||
let interval = Duration::from_millis(target_interval_ms);
|
let interval = Duration::from_millis(target_interval_ms);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
|
|
@ -143,7 +143,7 @@ mod quantum_crypto_tests {
|
||||||
/// Test hybrid signature (classical + post-quantum)
|
/// Test hybrid signature (classical + post-quantum)
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hybrid_signature() {
|
fn test_hybrid_signature() {
|
||||||
use synor_crypto::signature::{HybridSignature, SignatureScheme};
|
use synor_crypto::signature::SignatureScheme;
|
||||||
|
|
||||||
let keypair = synor_crypto::keypair::Keypair::generate(SignatureScheme::HybridPQ);
|
let keypair = synor_crypto::keypair::Keypair::generate(SignatureScheme::HybridPQ);
|
||||||
let message = b"Hybrid classical + post-quantum signature";
|
let message = b"Hybrid classical + post-quantum signature";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue