From 525e183014da65583c0f60ca0724d97b37b1bbaa Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Tue, 17 Dec 2024 17:54:30 -0500 Subject: [PATCH] refactor: add more tests, use blake3 --- Cargo.lock | 2 + crates/crypto/Cargo.toml | 3 +- crates/crypto/bls/src/w3f_bls.rs | 12 +++++ crates/crypto/bn254/Cargo.toml | 1 + crates/crypto/bn254/src/arkworks_bn254.rs | 9 +++- crates/crypto/core/src/lib.rs | 43 +++++++++--------- crates/crypto/ed25519/src/zebra_ed25519.rs | 1 - crates/crypto/k256/src/k256_ecdsa.rs | 8 ++-- crates/crypto/sp-core/src/sp_core_util.rs | 18 ++++++++ .../crypto/sr25519/src/schnorrkel_sr25519.rs | 8 +++- crates/crypto/src/hashing.rs | 7 +++ crates/networking/Cargo.toml | 6 ++- crates/networking/src/gossip.rs | 9 ++-- crates/networking/src/handlers/connections.rs | 21 ++++++--- crates/networking/src/handlers/gossip.rs | 2 +- crates/networking/src/handlers/p2p.rs | 45 ++++++++++--------- crates/networking/src/lib.rs | 3 +- crates/networking/src/networking.rs | 10 ++--- crates/networking/src/round_based_compat.rs | 4 +- crates/networking/src/setup.rs | 4 +- 20 files changed, 141 insertions(+), 75 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4bfbc2e..196760b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4728,6 +4728,7 @@ dependencies = [ name = "gadget-crypto" version = "0.1.0" dependencies = [ + "blake3", "gadget-crypto-bls", "gadget-crypto-bn254", "gadget-crypto-core", @@ -4765,6 +4766,7 @@ dependencies = [ "ark-serialize 0.5.0", "gadget-crypto-core", "gadget-std", + "hex", "num-bigint", "num-traits", "serde", diff --git a/crates/crypto/Cargo.toml b/crates/crypto/Cargo.toml index 5b4489e..cf1b027 100644 --- a/crates/crypto/Cargo.toml +++ b/crates/crypto/Cargo.toml @@ -13,6 +13,7 @@ gadget-crypto-bn254 = { path = "bn254", optional = true } gadget-crypto-sp-core = { path = "sp-core", optional = true } sha2 = { workspace = true, optional = true } sha3 = { workspace = true, optional = true } +blake3 = { workspace = true, optional = true } thiserror = { workspace = true } [features] @@ -34,4 +35,4 @@ bn254 = ["gadget-crypto-bn254", "gadget-crypto-core/bn254"] sp-core = ["gadget-crypto-sp-core", "gadget-crypto-core/tangle"] sp-core-bls = ["gadget-crypto-sp-core/bls", "gadget-crypto-core/tangle"] -hashing = ["sha2", "sha3"] \ No newline at end of file +hashing = ["sha2", "sha3", "blake3"] \ No newline at end of file diff --git a/crates/crypto/bls/src/w3f_bls.rs b/crates/crypto/bls/src/w3f_bls.rs index 3a514e7..cbe86e7 100644 --- a/crates/crypto/bls/src/w3f_bls.rs +++ b/crates/crypto/bls/src/w3f_bls.rs @@ -138,3 +138,15 @@ macro_rules! define_bls_key { } define_bls_key!(Bls377, Bls381); + +#[cfg(test)] +mod test_bls377 { + use super::bls377::{Secret, W3fBls377, W3fBls377Signature}; + gadget_crypto_core::impl_crypto_tests!(W3fBls377, Secret, W3fBls377Signature); +} + +#[cfg(test)] +mod test_bls381 { + use super::bls381::{Secret, W3fBls381, W3fBls381Signature}; + gadget_crypto_core::impl_crypto_tests!(W3fBls381, Secret, W3fBls381Signature); +} diff --git a/crates/crypto/bn254/Cargo.toml b/crates/crypto/bn254/Cargo.toml index c54ce33..de81d76 100644 --- a/crates/crypto/bn254/Cargo.toml +++ b/crates/crypto/bn254/Cargo.toml @@ -17,6 +17,7 @@ thiserror = { workspace = true } num-bigint = { workspace = true, features = ["serde"] } num-traits = { workspace = true } sha2 = { workspace = true } +hex = { workspace = true, features = ["alloc"] } [features] default = ["std"] diff --git a/crates/crypto/bn254/src/arkworks_bn254.rs b/crates/crypto/bn254/src/arkworks_bn254.rs index e539278..5a3ed4b 100644 --- a/crates/crypto/bn254/src/arkworks_bn254.rs +++ b/crates/crypto/bn254/src/arkworks_bn254.rs @@ -37,7 +37,8 @@ macro_rules! impl_ark_serde { &self, serializer: S, ) -> core::result::Result { - serializer.serialize_bytes(&to_bytes(self.0)) + let bytes = to_bytes(self.0); + Vec::serialize(&bytes, serializer) } } @@ -114,4 +115,8 @@ impl KeyType for ArkBlsBn254 { } } -// Continue with KeyType implementation... +#[cfg(test)] +mod tests { + use super::*; + gadget_crypto_core::impl_crypto_tests!(ArkBlsBn254, ArkBlsBn254Secret, ArkBlsBn254Signature); +} diff --git a/crates/crypto/core/src/lib.rs b/crates/crypto/core/src/lib.rs index 1cd432b..c1577a8 100644 --- a/crates/crypto/core/src/lib.rs +++ b/crates/crypto/core/src/lib.rs @@ -140,17 +140,6 @@ macro_rules! impl_crypto_tests { // Test random key generation let secret = <$ecdsa_type>::generate_with_seed(None).unwrap(); let _public = <$ecdsa_type>::public_from_secret(&secret); - - // Test deterministic key generation with seed - let seed = [1u8; 32]; - let secret1 = <$ecdsa_type>::generate_with_seed(Some(&seed)).unwrap(); - let secret2 = <$ecdsa_type>::generate_with_seed(Some(&seed)).unwrap(); - assert_eq!(secret1, secret2, "Deterministic key generation should produce same keys"); - - // Test key generation from string - let hex_string = hex::encode(&seed); - let secret3 = <$ecdsa_type>::generate_with_string(hex_string).unwrap(); - assert_eq!(secret1, secret3, "String-based key generation should match seed-based"); } #[test] @@ -161,17 +150,22 @@ macro_rules! impl_crypto_tests { // Test normal signing let message = b"Hello, world!"; let signature = <$ecdsa_type>::sign_with_secret(&mut secret, message).unwrap(); - assert!(<$ecdsa_type>::verify(&public, message, &signature), - "Signature verification failed"); + assert!( + <$ecdsa_type>::verify(&public, message, &signature), + "Signature verification failed" + ); // Test pre-hashed signing let hashed_msg = [42u8; 32]; - let signature = <$ecdsa_type>::sign_with_secret_pre_hashed(&mut secret, &hashed_msg).unwrap(); + let signature = + <$ecdsa_type>::sign_with_secret_pre_hashed(&mut secret, &hashed_msg).unwrap(); // Verify with wrong message should fail let wrong_message = b"Wrong message"; - assert!(!<$ecdsa_type>::verify(&public, wrong_message, &signature), - "Verification should fail with wrong message"); + assert!( + !<$ecdsa_type>::verify(&public, wrong_message, &signature), + "Verification should fail with wrong message" + ); } #[test] @@ -182,12 +176,18 @@ macro_rules! impl_crypto_tests { // Test signing key serialization let serialized = serde_json::to_string(&secret).unwrap(); let deserialized: $signing_key = serde_json::from_str(&serialized).unwrap(); - assert_eq!(secret, deserialized, "SigningKey serialization roundtrip failed"); + assert_eq!( + secret, deserialized, + "SigningKey serialization roundtrip failed" + ); // Test verifying key serialization let serialized = serde_json::to_string(&public).unwrap(); let deserialized = serde_json::from_str(&serialized).unwrap(); - assert_eq!(public, deserialized, "VerifyingKey serialization roundtrip failed"); + assert_eq!( + public, deserialized, + "VerifyingKey serialization roundtrip failed" + ); } #[test] @@ -199,7 +199,10 @@ macro_rules! impl_crypto_tests { // Test signature serialization let serialized = serde_json::to_string(&signature).unwrap(); let deserialized: $signature = serde_json::from_str(&serialized).unwrap(); - assert_eq!(signature, deserialized, "Signature serialization roundtrip failed"); + assert_eq!( + signature, deserialized, + "Signature serialization roundtrip failed" + ); } #[test] @@ -217,4 +220,4 @@ macro_rules! impl_crypto_tests { assert_eq!(public1.partial_cmp(&public2), Some(public1.cmp(&public2))); } }; -} \ No newline at end of file +} diff --git a/crates/crypto/ed25519/src/zebra_ed25519.rs b/crates/crypto/ed25519/src/zebra_ed25519.rs index d886884..753f61e 100644 --- a/crates/crypto/ed25519/src/zebra_ed25519.rs +++ b/crates/crypto/ed25519/src/zebra_ed25519.rs @@ -163,6 +163,5 @@ impl KeyType for Ed25519Zebra { #[cfg(test)] mod tests { use super::*; - // Generate tests for K256 ECDSA gadget_crypto_core::impl_crypto_tests!(Ed25519Zebra, Ed25519SigningKey, Ed25519Signature); } diff --git a/crates/crypto/k256/src/k256_ecdsa.rs b/crates/crypto/k256/src/k256_ecdsa.rs index cd915dc..d7e0ecc 100644 --- a/crates/crypto/k256/src/k256_ecdsa.rs +++ b/crates/crypto/k256/src/k256_ecdsa.rs @@ -1,11 +1,9 @@ +use crate::error::{K256Error, Result}; use gadget_crypto_core::{KeyType, KeyTypeId}; +use gadget_std::string::{String, ToString}; use gadget_std::UniformRand; -use gadget_std::{ - string::{String, ToString}, -}; use k256::ecdsa::signature::SignerMut; use serde::{Deserialize, Serialize}; -use crate::error::{K256Error, Result}; /// ECDSA key type pub struct K256Ecdsa; @@ -142,4 +140,4 @@ mod tests { use super::*; // Generate tests for K256 ECDSA gadget_crypto_core::impl_crypto_tests!(K256Ecdsa, K256SigningKey, K256Signature); -} \ No newline at end of file +} diff --git a/crates/crypto/sp-core/src/sp_core_util.rs b/crates/crypto/sp-core/src/sp_core_util.rs index e453525..ec454a0 100644 --- a/crates/crypto/sp-core/src/sp_core_util.rs +++ b/crates/crypto/sp-core/src/sp_core_util.rs @@ -238,3 +238,21 @@ impl_sp_core_crypto!(SpSr25519, sr25519); impl Copy for SpEcdsaPublic {} impl Copy for SpEd25519Public {} impl Copy for SpSr25519Public {} + +#[cfg(test)] +mod tests_ecdsa { + use super::*; + gadget_crypto_core::impl_crypto_tests!(SpEcdsa, SpEcdsaPair, SpEcdsaSignature); +} + +#[cfg(test)] +mod tests_ed25519 { + use super::*; + gadget_crypto_core::impl_crypto_tests!(SpEd25519, SpEd25519Pair, SpEd25519Signature); +} + +#[cfg(test)] +mod tests_sr25519 { + use super::*; + gadget_crypto_core::impl_crypto_tests!(SpSr25519, SpSr25519Pair, SpSr25519Signature); +} diff --git a/crates/crypto/sr25519/src/schnorrkel_sr25519.rs b/crates/crypto/sr25519/src/schnorrkel_sr25519.rs index 23a860d..ad9fd42 100644 --- a/crates/crypto/sr25519/src/schnorrkel_sr25519.rs +++ b/crates/crypto/sr25519/src/schnorrkel_sr25519.rs @@ -54,8 +54,8 @@ impl_schnorrkel_serde!(Secret, schnorrkel::SecretKey); impl_schnorrkel_serde!(SchnorrkelSignature, schnorrkel::Signature); impl KeyType for SchnorrkelSr25519 { - type Public = Public; type Secret = Secret; + type Public = Public; type Signature = SchnorrkelSignature; type Error = Sr25519Error; @@ -114,3 +114,9 @@ impl KeyType for SchnorrkelSr25519 { } } } + +#[cfg(test)] +mod tests { + use super::*; + gadget_crypto_core::impl_crypto_tests!(SchnorrkelSr25519, Secret, SchnorrkelSignature); +} diff --git a/crates/crypto/src/hashing.rs b/crates/crypto/src/hashing.rs index c4902a4..8d6f42c 100644 --- a/crates/crypto/src/hashing.rs +++ b/crates/crypto/src/hashing.rs @@ -24,3 +24,10 @@ pub fn keccak_256(data: &[u8]) -> [u8; 32] { let output = hasher.finalize(); output.into() } + +pub fn blake3_256(data: &[u8]) -> [u8; 32] { + let mut hasher = blake3::Hasher::new(); + hasher.update(data); + let output = hasher.finalize(); + output.into() +} diff --git a/crates/networking/Cargo.toml b/crates/networking/Cargo.toml index a850458..1ab65cd 100644 --- a/crates/networking/Cargo.toml +++ b/crates/networking/Cargo.toml @@ -35,7 +35,7 @@ gadget-crypto = { workspace = true, features = ["k256", "hashing"] } k256 = { workspace = true } # Round-based protocol support -round-based = { workspace = true } +round-based = { workspace = true, optional = true } [dev-dependencies] @@ -72,9 +72,11 @@ std = [ "tokio/full", "serde/std", "serde_json/std", - "round-based/std", + "round-based?/std", ] +round-based-compat = ["round-based"] + # Only one of these features should be enabled at a time. # If none are enabled, k256 ECDSA will be used by default. sp-core-ecdsa = ["gadget-crypto/sp-core"] diff --git a/crates/networking/src/gossip.rs b/crates/networking/src/gossip.rs index c0a94c2..c65d45d 100644 --- a/crates/networking/src/gossip.rs +++ b/crates/networking/src/gossip.rs @@ -5,11 +5,10 @@ clippy::exhaustive_enums )] -use std::sync::atomic::AtomicUsize; use crate::key_types::{CryptoKeyPair, CryptoPublicKey, CryptoSignature}; use crate::Error; use async_trait::async_trait; -use gadget_crypto::hashing::keccak_256; +use gadget_crypto::hashing::blake3_256; use gadget_std::collections::BTreeMap; use gadget_std::string::ToString; use gadget_std::sync::Arc; @@ -20,6 +19,7 @@ use libp2p::{ }; use lru_mem::LruCache; use serde::{Deserialize, Serialize}; +use std::sync::atomic::AtomicUsize; use tokio::sync::mpsc::UnboundedSender; use tokio::sync::{Mutex, RwLock}; @@ -362,7 +362,7 @@ impl Network for GossipHandle { drop(lock); match bincode::deserialize::(&message_bytes) { Ok(message) => { - let hash = keccak_256(&message_bytes); + let hash = blake3_256(&message_bytes); let mut map = self.recent_messages.lock(); if map .insert(hash, ()) @@ -402,7 +402,8 @@ impl Network for GossipHandle { MessageType::Broadcast }; - let raw_payload = bincode::serialize(&message).map_err(|err| Error::MessagingError(err.to_string()))?; + let raw_payload = + bincode::serialize(&message).map_err(|err| Error::MessagingError(err.to_string()))?; let payload_inner = match message_type { MessageType::Broadcast => GossipOrRequestResponse::Gossip(GossipMessage { topic: self.topic.to_string(), diff --git a/crates/networking/src/handlers/connections.rs b/crates/networking/src/handlers/connections.rs index 53a3238..a9c3ebe 100644 --- a/crates/networking/src/handlers/connections.rs +++ b/crates/networking/src/handlers/connections.rs @@ -2,7 +2,7 @@ use crate::gossip::{MyBehaviourRequest, NetworkService}; use crate::key_types::CryptoKeyCurve; -use gadget_crypto::{hashing::keccak_256, KeyType}; +use gadget_crypto::{hashing::blake3_256, KeyType}; use itertools::Itertools; use libp2p::PeerId; @@ -14,10 +14,16 @@ impl NetworkService<'_> { _num_established: u32, ) { gadget_logging::debug!("Connection established"); - if !self.crypto_peer_id_to_libp2p_id.read().await.iter().any(|(_, id)| id == &peer_id) { - let my_peer_id = self.swarm.local_peer_id().clone(); + if !self + .crypto_peer_id_to_libp2p_id + .read() + .await + .iter() + .any(|(_, id)| id == &peer_id) + { + let my_peer_id = *self.swarm.local_peer_id(); let msg = my_peer_id.to_bytes(); - let hash = keccak_256(&msg); + let hash = blake3_256(&msg); match ::sign_with_secret_pre_hashed( &mut self.crypto_secret_key.clone(), &hash, @@ -35,7 +41,7 @@ impl NetworkService<'_> { .behaviour_mut() .gossipsub .add_explicit_peer(&peer_id); - gadget_logging::info!("Sent handshake from {my_peer_id} to {peer_id}") + gadget_logging::info!("Sent handshake from {my_peer_id} to {peer_id}"); } Err(e) => { gadget_logging::error!("Failed to sign handshake: {e}"); @@ -59,9 +65,10 @@ impl NetworkService<'_> { .remove_explicit_peer(&peer_id); let mut pub_key_to_libp2p_id = self.crypto_peer_id_to_libp2p_id.write().await; let len_initial = 0; - pub_key_to_libp2p_id.retain(|_, id| &*id != &peer_id); + pub_key_to_libp2p_id.retain(|_, id| *id != peer_id); if pub_key_to_libp2p_id.len() == len_initial + 1 { - self.connected_peers.fetch_sub(1, std::sync::atomic::Ordering::Relaxed); + self.connected_peers + .fetch_sub(1, std::sync::atomic::Ordering::Relaxed); } } } diff --git a/crates/networking/src/handlers/gossip.rs b/crates/networking/src/handlers/gossip.rs index 1b39ee2..215effa 100644 --- a/crates/networking/src/handlers/gossip.rs +++ b/crates/networking/src/handlers/gossip.rs @@ -1,11 +1,11 @@ #![allow(unused_results)] -use std::sync::atomic::AtomicUsize; use crate::gossip::{GossipMessage, NetworkService}; use gadget_std::string::ToString; use gadget_std::sync::Arc; use libp2p::gossipsub::TopicHash; use libp2p::{gossipsub, PeerId}; +use std::sync::atomic::AtomicUsize; impl NetworkService<'_> { #[tracing::instrument(skip(self, event))] diff --git a/crates/networking/src/handlers/p2p.rs b/crates/networking/src/handlers/p2p.rs index 5c185c1..e1e2f33 100644 --- a/crates/networking/src/handlers/p2p.rs +++ b/crates/networking/src/handlers/p2p.rs @@ -1,13 +1,13 @@ #![allow(unused_results)] -use std::sync::atomic::Ordering; use crate::gossip::{MyBehaviourRequest, MyBehaviourResponse, NetworkService}; use crate::key_types::CryptoKeyCurve; -use gadget_crypto::hashing::keccak_256; +use gadget_crypto::hashing::blake3_256; use gadget_crypto::KeyType; use gadget_std::string::ToString; use libp2p::gossipsub::IdentTopic; use libp2p::{request_response, PeerId}; +use std::sync::atomic::Ordering; impl NetworkService<'_> { #[tracing::instrument(skip(self, event))] @@ -91,7 +91,7 @@ impl NetworkService<'_> { gadget_logging::trace!("Received handshake from peer: {peer}"); // Verify the signature let msg = peer.to_bytes(); - let hash = keccak_256(&msg); + let hash = blake3_256(&msg); let valid = ::verify(&crypto_public_key, &hash, &signature); if !valid { @@ -99,30 +99,30 @@ impl NetworkService<'_> { let _ = self.swarm.disconnect_peer_id(peer); return; } - if self.crypto_peer_id_to_libp2p_id + if self + .crypto_peer_id_to_libp2p_id .write() .await .insert(crypto_public_key, peer) - .is_none() { + .is_none() + { let _ = self.connected_peers.fetch_add(1, Ordering::Relaxed); } // Send response with our public key let my_peer_id = self.swarm.local_peer_id(); let msg = my_peer_id.to_bytes(); - let hash = keccak_256(&msg); + let hash = blake3_256(&msg); match ::sign_with_secret_pre_hashed( &mut self.crypto_secret_key.clone(), &hash, ) { - Ok(signature) => { - self.swarm.behaviour_mut().p2p.send_response( - channel, - MyBehaviourResponse::Handshaked { - crypto_public_key: self.crypto_secret_key.public(), - crypto_signature: signature, - }, - ) - }, + Ok(signature) => self.swarm.behaviour_mut().p2p.send_response( + channel, + MyBehaviourResponse::Handshaked { + crypto_public_key: self.crypto_secret_key.public(), + crypto_signature: signature, + }, + ), Err(e) => { gadget_logging::error!("Failed to sign message: {e}"); return; @@ -173,9 +173,12 @@ impl NetworkService<'_> { } => { gadget_logging::trace!("Received handshake-ack message from peer: {peer}"); let msg = peer.to_bytes(); - let hash = keccak_256(&msg); - let valid = - ::verify(&crypto_public_key, &hash, &crypto_signature); + let hash = blake3_256(&msg); + let valid = ::verify( + &crypto_public_key, + &hash, + &crypto_signature, + ); if !valid { gadget_logging::warn!("Invalid signature from peer: {peer}"); // TODO: report this peer. @@ -186,11 +189,13 @@ impl NetworkService<'_> { let _ = self.swarm.disconnect_peer_id(peer); return; } - if self.crypto_peer_id_to_libp2p_id + if self + .crypto_peer_id_to_libp2p_id .write() .await .insert(crypto_public_key, peer) - .is_none() { + .is_none() + { let _ = self.connected_peers.fetch_add(1, Ordering::Relaxed); } } diff --git a/crates/networking/src/lib.rs b/crates/networking/src/lib.rs index 69db29a..d292007 100644 --- a/crates/networking/src/lib.rs +++ b/crates/networking/src/lib.rs @@ -5,8 +5,9 @@ pub mod gossip; pub mod handlers; pub mod messaging; pub mod networking; +#[cfg(feature = "round-based-compat")] pub mod round_based_compat; - +#[cfg(feature = "round-based-compat")] pub use round_based; pub mod setup; diff --git a/crates/networking/src/networking.rs b/crates/networking/src/networking.rs index 4a98d3c..006c497 100644 --- a/crates/networking/src/networking.rs +++ b/crates/networking/src/networking.rs @@ -3,7 +3,7 @@ use crate::Error; use async_trait::async_trait; use dashmap::DashMap; use futures::{Stream, StreamExt}; -use gadget_crypto::hashing::keccak_256; +use gadget_crypto::hashing::blake3_256; use gadget_std::boxed::Box; use gadget_std::cmp::Reverse; use gadget_std::collections::{BinaryHeap, HashMap}; @@ -154,7 +154,7 @@ pub struct StreamKey { impl From for StreamKey { fn from(identifier_info: IdentifierInfo) -> Self { let str_repr = identifier_info.to_string(); - let task_hash = keccak_256(str_repr.as_bytes()); + let task_hash = blake3_256(str_repr.as_bytes()); Self { task_hash, round_id: -1, @@ -582,7 +582,7 @@ mod tests { use super::*; use crate::gossip::GossipHandle; use futures::{stream, StreamExt}; - use gadget_crypto::hashing::sha2_256; + use gadget_crypto::hashing::blake3_256; use gadget_crypto::KeyType; use gadget_logging::setup_log; use gadget_std::collections::BTreeMap; @@ -905,7 +905,7 @@ mod tests { let multiplexer1 = NetworkMultiplexer::new(network1); let stream_key = StreamKey { - task_hash: sha2_256(&[255u8]), + task_hash: blake3_256(&[255u8]), round_id: 100, }; @@ -1025,7 +1025,7 @@ mod tests { let stream_key = StreamKey { #[allow(clippy::cast_possible_truncation)] - task_hash: sha2_256(&[(cur_depth % 255) as u8]), + task_hash: blake3_256(&[(cur_depth % 255) as u8]), round_id: 0, }; diff --git a/crates/networking/src/round_based_compat.rs b/crates/networking/src/round_based_compat.rs index 61f8813..8ed0c11 100644 --- a/crates/networking/src/round_based_compat.rs +++ b/crates/networking/src/round_based_compat.rs @@ -117,7 +117,7 @@ where let id = res.identifier_info.message_id; - let msg = match bincode::deserialize(&res.payload) { + let msg = match serde_json::from_slice(&res.payload) { Ok(msg) => msg, Err(err) => { gadget_logging::error!(%err, "Failed to deserialize message (round_based_compat)"); @@ -196,7 +196,7 @@ where user_id, crypto_public_key: to_network_id, }), - payload: bincode::serialize(&out.msg).expect("Should be able to serialize message"), + payload: serde_json::to_vec(&out.msg).expect("Should be able to serialize message"), }; match substream.send(protocol_message) { diff --git a/crates/networking/src/setup.rs b/crates/networking/src/setup.rs index f0fb388..5d863ff 100644 --- a/crates/networking/src/setup.rs +++ b/crates/networking/src/setup.rs @@ -1,6 +1,5 @@ #![allow(unused_results, missing_docs)] -use std::sync::atomic::AtomicUsize; use crate::gossip::{ GossipHandle, IntraNodePayload, MyBehaviour, NetworkServiceWithoutSwarm, MAX_MESSAGE_SIZE, }; @@ -22,6 +21,7 @@ use libp2p::{ swarm::dial_opts::DialOpts, StreamProtocol, }; use lru_mem::LruCache; +use std::sync::atomic::AtomicUsize; use tokio::select; use tokio::sync::{Mutex, RwLock}; use tokio::task::{spawn, JoinHandle}; @@ -278,8 +278,6 @@ pub fn multiplexed_libp2p_network(config: NetworkConfig) -> NetworkResult { let ips_to_bind_to = [ IpAddr::from_str("::").unwrap(), // IN_ADDR_ANY_V6 IpAddr::from_str("0.0.0.0").unwrap(), // IN_ADDR_ANY_V4 - IpAddr::from_str("::1").unwrap(), - IpAddr::from_str("127.0.0.1").unwrap(), ]; for addr in ips_to_bind_to {