Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(batcher): add user state & other code quality refactors #1106

Merged
merged 49 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f9e2ac0
Save work in progress
entropidelic Sep 25, 2024
0faa5b4
Save work in progress - Adding user state validations
entropidelic Sep 25, 2024
304e862
Save work in progress - Refactoring message handlers
entropidelic Sep 25, 2024
4010b80
Save work in progress - More refactoring message handlers
entropidelic Sep 26, 2024
02582e8
Save work in progress - More refactoring replacement message function
entropidelic Sep 26, 2024
02316a4
Save work in progress - Batcher compiling
entropidelic Sep 26, 2024
da389d1
Full flow working, fix non-paying message handling bug
entropidelic Sep 26, 2024
2fac2b0
Polish code, remove commented legacy code
entropidelic Sep 27, 2024
e82fc66
Some more code polishing
entropidelic Sep 27, 2024
f7c0606
Add new entities files
entropidelic Sep 27, 2024
26d66cc
Remoe legacy code
entropidelic Sep 27, 2024
9996df5
Save work in progress - Refactor user states into batch state
entropidelic Sep 27, 2024
85de7d5
Save work in progress - Fixed concurrency bugs and refactored batch s…
entropidelic Sep 27, 2024
5a30e47
Remove legacy commented code
entropidelic Sep 27, 2024
c230382
Refactor with Pablo
entropidelic Sep 27, 2024
0c8d6ff
Some more refactors and code polishing
entropidelic Sep 28, 2024
4379034
Polish code, handle errors better
entropidelic Sep 28, 2024
f2f363d
Fix nonpaying address bug when user states are flushed
entropidelic Sep 28, 2024
bc12587
Remove commented code
entropidelic Sep 30, 2024
331def9
removed mutex from user state
entropidelic Sep 30, 2024
d2ce540
Revert burst size changes in Makefile
entropidelic Sep 30, 2024
5955cb2
Apply clippy suggestions
entropidelic Sep 30, 2024
0a82306
Revert more changes in Makefile
entropidelic Sep 30, 2024
770acd1
Revert more changes in Makefile
entropidelic Sep 30, 2024
ca4939e
Revert changes in send_burst_tasks.sh script
entropidelic Sep 30, 2024
0a55b8f
Apply clippy code docs suggestions
entropidelic Sep 30, 2024
db0a15f
Minor docs fix
entropidelic Sep 30, 2024
03ce156
Add drop on batch state lock when sending error messages
entropidelic Sep 30, 2024
f4dd5ce
Add some more drops when sending error messages and returnig
entropidelic Sep 30, 2024
84c8e67
simplify UserState struct
entropidelic Oct 1, 2024
d77eeac
Some more refactors on the ordering of validations
entropidelic Oct 1, 2024
9f7e695
Small refactor on check_min_balance
entropidelic Oct 1, 2024
68bb54e
Small refactor on handle_replacement_message
entropidelic Oct 1, 2024
ddb9fd1
Small refactor on add_to_batch
entropidelic Oct 1, 2024
a1745f6
Small refactor on update_user_state
entropidelic Oct 1, 2024
37a9a0b
Revert changes in Makefile
entropidelic Oct 1, 2024
c7e0ae1
Revert changes in Makefile
entropidelic Oct 1, 2024
815751b
Revert changes in Makefile
entropidelic Oct 1, 2024
3f0e362
Small changes in logs and removal of verification data cloning before…
entropidelic Oct 1, 2024
2cbf62a
Merge branch 'staging' into refactor-user-states
entropidelic Oct 1, 2024
e30044f
Apply clippy suggestions
entropidelic Oct 1, 2024
bfccf27
Fix code comment
entropidelic Oct 1, 2024
15be4a4
Remove unneded return statement
entropidelic Oct 1, 2024
e850304
feat: observability log of handling paying vs nonpaying
uri-99 Oct 1, 2024
95897f1
Add drop of batch state lock inside handle_nonpaying_message
entropidelic Oct 2, 2024
ccfdacb
Refactor querying of user states to hold the batch state lock the les…
entropidelic Oct 2, 2024
f6febd9
Remove unused import
entropidelic Oct 2, 2024
fc5e488
Merge branch 'staging' into refactor-user-states
entropidelic Oct 2, 2024
166509b
Add some code comments
entropidelic Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ batcher_send_risc0_burst:
--proof ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.proof \
--vm_program ../../scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id.bin \
--public_input ../../scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci.pub \
--repetitions $(BURST_SIZE) \
--repetitions 500 \
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
Expand Down Expand Up @@ -361,7 +361,8 @@ batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
--proof ../../scripts/test_files/halo2_ipa/proof.bin \
--public_input ../../scripts/test_files/halo2_ipa/pub_input.bin \
--vk ../../scripts/test_files/halo2_ipa/params.bin \
--repetitions 5 \
--repetitions 1000 \
--private_key 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97 \
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
--rpc_url $(RPC_URL) \
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)

Expand Down
68 changes: 68 additions & 0 deletions batcher/aligned-batcher/src/connection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::sync::Arc;

use aligned_sdk::{
communication::serialization::cbor_serialize,
core::types::{BatchInclusionData, ResponseMessage, VerificationCommitmentBatch},
};
use futures_util::{stream::SplitSink, SinkExt};
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
use log::{error, info};
use serde::Serialize;
use tokio::{net::TcpStream, sync::RwLock};
use tokio_tungstenite::{
tungstenite::{Error, Message},
WebSocketStream,
};

use crate::types::{batch_queue::BatchQueueEntry, errors::BatcherError};

pub(crate) type WsMessageSink = Arc<RwLock<SplitSink<WebSocketStream<TcpStream>, Message>>>;

pub(crate) async fn send_batch_inclusion_data_responses(
finalized_batch: Vec<BatchQueueEntry>,
batch_merkle_tree: &MerkleTree<VerificationCommitmentBatch>,
) -> Result<(), BatcherError> {
for (vd_batch_idx, entry) in finalized_batch.iter().enumerate() {
let batch_inclusion_data = BatchInclusionData::new(vd_batch_idx, batch_merkle_tree);
let response = ResponseMessage::BatchInclusionData(batch_inclusion_data);

let serialized_response = cbor_serialize(&response)
.map_err(|e| BatcherError::SerializationError(e.to_string()))?;

let Some(ws_sink) = entry.messaging_sink.as_ref() else {
return Err(BatcherError::WsSinkEmpty);
};

let sending_result = ws_sink
.write()
.await
.send(Message::binary(serialized_response))
.await;

match sending_result {
Err(Error::AlreadyClosed) => (),
Err(e) => error!("Error while sending batch inclusion data response: {}", e),
Ok(_) => (),
}

info!("Response sent");
}

Ok(())
}

pub(crate) async fn send_message<T: Serialize>(ws_conn_sink: WsMessageSink, message: T) {
match cbor_serialize(&message) {
Ok(serialized_response) => {
if let Err(err) = ws_conn_sink
.write()
.await
.send(Message::binary(serialized_response))
.await
{
error!("Error while sending message: {}", err)
}
}
Err(e) => error!("Error while serializing message: {}", e),
}
}
Loading