From 6c6e2f7183f01755365d8952ce2802ad7dc3b5b2 Mon Sep 17 00:00:00 2001 From: petarjuki7 Date: Tue, 26 Nov 2024 12:45:04 +0100 Subject: [PATCH] renaming --- crates/node/src/sync/blobs.rs | 30 ++++++++++++----------- crates/node/src/sync/key.rs | 26 ++++++++++---------- crates/node/src/sync/state.rs | 45 ++++++++++++++++------------------- 3 files changed, 49 insertions(+), 52 deletions(-) diff --git a/crates/node/src/sync/blobs.rs b/crates/node/src/sync/blobs.rs index ea2453240..1db874ccb 100644 --- a/crates/node/src/sync/blobs.rs +++ b/crates/node/src/sync/blobs.rs @@ -1,4 +1,4 @@ -use calimero_crypto::{Nonce, SharedKey}; +use calimero_crypto::{Nonce, SharedKey, NONCE_LEN}; use calimero_network::stream::Stream; use calimero_primitives::blobs::BlobId; use calimero_primitives::context::Context; @@ -30,7 +30,7 @@ impl Node { "Initiating blob share", ); - let nonce = thread_rng().gen::(); + let our_nonce = thread_rng().gen::(); send( stream, @@ -38,7 +38,7 @@ impl Node { context_id: context.id, party_id: our_identity, payload: InitPayload::BlobShare { blob_id }, - next_nonce: nonce, + next_nonce: our_nonce, }, None, ) @@ -48,7 +48,7 @@ impl Node { bail!("connection closed while awaiting blob share handshake"); }; - let (their_identity, mut nonce) = match ack { + let (their_identity, mut their_nonce) = match ack { StreamMessage::Init { party_id, payload: @@ -93,10 +93,14 @@ impl Node { let read_task = async { let mut sequencer = Sequencer::default(); - while let Some(msg) = - recv(stream, self.sync_config.timeout, Some((shared_key, nonce))).await? + while let Some(msg) = recv( + stream, + self.sync_config.timeout, + Some((shared_key, their_nonce)), + ) + .await? { - let (sequence_id, chunk, new_nonce) = match msg { + let (sequence_id, chunk, their_new_nonce) = match msg { StreamMessage::OpaqueError => bail!("other peer ran into an error"), StreamMessage::Message { sequence_id, @@ -116,7 +120,7 @@ impl Node { tx.send(Ok(chunk)).await?; - nonce = new_nonce; + their_nonce = their_new_nonce; } drop(tx); @@ -190,7 +194,7 @@ impl Node { let mut sequencer = Sequencer::default(); while let Some(chunk) = blob.try_next().await? { - let new_nonce = thread_rng().gen::(); + let next_nonce = thread_rng().gen::(); send( stream, &StreamMessage::Message { @@ -198,23 +202,21 @@ impl Node { payload: MessagePayload::BlobShare { chunk: chunk.into_vec().into(), }, - next_nonce: new_nonce, + next_nonce, }, Some((shared_key, nonce)), ) .await?; - nonce = new_nonce; + nonce = next_nonce; } - let new_nonce = thread_rng().gen::(); - send( stream, &StreamMessage::Message { sequence_id: sequencer.next(), payload: MessagePayload::BlobShare { chunk: b"".into() }, - next_nonce: new_nonce, + next_nonce: [0; NONCE_LEN], }, Some((shared_key, nonce)), ) diff --git a/crates/node/src/sync/key.rs b/crates/node/src/sync/key.rs index 6126d4a4d..0848bbe75 100644 --- a/crates/node/src/sync/key.rs +++ b/crates/node/src/sync/key.rs @@ -23,7 +23,7 @@ impl Node { "Initiating key share", ); - let nonce = thread_rng().gen::(); + let our_nonce = thread_rng().gen::(); send( stream, @@ -31,7 +31,7 @@ impl Node { context_id: context.id, party_id: our_identity, payload: InitPayload::KeyShare, - next_nonce: nonce, + next_nonce: our_nonce, }, None, ) @@ -60,7 +60,7 @@ impl Node { our_identity, their_identity, stream, - nonce, + our_nonce, their_nonce, ) .await @@ -72,7 +72,7 @@ impl Node { our_identity: PublicKey, their_identity: PublicKey, stream: &mut Stream, - nonce: Nonce, + their_nonce: Nonce, ) -> eyre::Result<()> { debug!( context_id=%context.id, @@ -80,9 +80,7 @@ impl Node { "Received key share request", ); - let their_nonce = nonce; - - let nonce = thread_rng().gen::(); + let our_nonce = thread_rng().gen::(); send( stream, @@ -90,7 +88,7 @@ impl Node { context_id: context.id, party_id: our_identity, payload: InitPayload::KeyShare, - next_nonce: nonce, + next_nonce: our_nonce, }, None, ) @@ -101,7 +99,7 @@ impl Node { our_identity, their_identity, stream, - nonce, + our_nonce, their_nonce, ) .await @@ -113,8 +111,8 @@ impl Node { our_identity: PublicKey, their_identity: PublicKey, stream: &mut Stream, - sending_nonce: Nonce, - receiving_nonce: Nonce, + our_nonce: Nonce, + their_nonce: Nonce, ) -> eyre::Result<()> { debug!( context_id=%context.id, @@ -142,16 +140,16 @@ impl Node { &StreamMessage::Message { sequence_id: sqx_out.next(), payload: MessagePayload::KeyShare { sender_key }, - next_nonce: sending_nonce, // the next nonce will not be used + next_nonce: our_nonce, }, - Some((shared_key, sending_nonce)), + Some((shared_key, our_nonce)), ) .await?; let Some(msg) = recv( stream, self.sync_config.timeout, - Some((shared_key, receiving_nonce)), + Some((shared_key, their_nonce)), ) .await? else { diff --git a/crates/node/src/sync/state.rs b/crates/node/src/sync/state.rs index d79f37f9c..64a78a0e1 100644 --- a/crates/node/src/sync/state.rs +++ b/crates/node/src/sync/state.rs @@ -29,7 +29,7 @@ impl Node { "Initiating state sync", ); - let nonce = thread_rng().gen::(); + let our_nonce = thread_rng().gen::(); send( stream, @@ -40,7 +40,7 @@ impl Node { root_hash: context.root_hash, application_id: context.application_id, }, - next_nonce: nonce, + next_nonce: our_nonce, }, None, ) @@ -118,7 +118,7 @@ impl Node { .ok_or_eyre("expected own identity to have private key")?; let shared_key = SharedKey::new(&private_key, &their_identity); - let new_nonce = thread_rng().gen::(); + let our_new_nonce = thread_rng().gen::(); send( stream, @@ -127,9 +127,9 @@ impl Node { payload: MessagePayload::StateSync { artifact: b"".into(), }, - next_nonce: new_nonce, + next_nonce: our_new_nonce, }, - Some((shared_key, nonce)), + Some((shared_key, our_nonce)), ) .await?; self.bidirectional_sync( @@ -139,7 +139,7 @@ impl Node { &mut sqx_out, stream, shared_key, - new_nonce, + our_new_nonce, their_nonce, ) .await?; @@ -155,7 +155,7 @@ impl Node { their_root_hash: Hash, their_application_id: ApplicationId, stream: &mut Stream, - nonce: Nonce, + their_nonce: Nonce, ) -> eyre::Result<()> { debug!( context_id=%context.id, @@ -200,9 +200,7 @@ impl Node { debug!(context_id=%context.id, "Resuming state sync"); } - let their_nonce = nonce; - - let nonce = thread_rng().gen::(); + let our_nonce = thread_rng().gen::(); send( stream, @@ -213,7 +211,7 @@ impl Node { root_hash: context.root_hash, application_id: context.application_id, }, - next_nonce: nonce, + next_nonce: our_nonce, }, None, ) @@ -229,7 +227,6 @@ impl Node { .ok_or_eyre("expected own identity to have private key")?; let shared_key = SharedKey::new(&private_key, &their_identity); - let nonce = thread_rng().gen::(); let mut sqx_out = Sequencer::default(); @@ -240,7 +237,7 @@ impl Node { &mut sqx_out, stream, shared_key, - nonce, + our_nonce, their_nonce, ) .await @@ -256,8 +253,8 @@ impl Node { sqx_out: &mut Sequencer, stream: &mut Stream, shared_key: SharedKey, - sending_nonce: Nonce, - receiving_nonce: Nonce, + our_nonce: Nonce, + their_nonce: Nonce, ) -> eyre::Result<()> { debug!( context_id=%context.id, @@ -268,17 +265,17 @@ impl Node { let mut sqx_in = Sequencer::default(); - let mut sending_nonce = sending_nonce; - let mut receiving_nonce = receiving_nonce; + let mut our_nonce = our_nonce; + let mut their_nonce = their_nonce; while let Some(msg) = recv( stream, self.sync_config.timeout, - Some((shared_key, receiving_nonce)), + Some((shared_key, their_nonce)), ) .await? { - let (sequence_id, artifact, new_receiving_nonce) = match msg { + let (sequence_id, artifact, new_their_nonce) = match msg { StreamMessage::OpaqueError => bail!("other peer ran into an error"), StreamMessage::Message { sequence_id, @@ -290,7 +287,7 @@ impl Node { } }; - receiving_nonce = new_receiving_nonce; + their_nonce = new_their_nonce; sqx_in.test(sequence_id)?; @@ -314,7 +311,7 @@ impl Node { "State sync outcome", ); - let new_sending_nonce = thread_rng().gen::(); + let new_our_nonce = thread_rng().gen::(); send( stream, @@ -323,13 +320,13 @@ impl Node { payload: MessagePayload::StateSync { artifact: Cow::from(&outcome.artifact), }, - next_nonce: new_sending_nonce, + next_nonce: new_our_nonce, }, - Some((shared_key, sending_nonce)), + Some((shared_key, our_nonce)), ) .await?; - sending_nonce = new_sending_nonce; + our_nonce = new_our_nonce; } debug!(