From e2d382f77486b0dfc3912d41c317e62a3d46f99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Mon, 6 Jan 2025 12:08:25 -0300 Subject: [PATCH 1/4] feat: add `--addr` flag to batcher (#1708) --- batcher/aligned-batcher/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/batcher/aligned-batcher/src/main.rs b/batcher/aligned-batcher/src/main.rs index bc13885052..089d5c0abf 100644 --- a/batcher/aligned-batcher/src/main.rs +++ b/batcher/aligned-batcher/src/main.rs @@ -24,12 +24,15 @@ struct Cli { env_file: Option, #[arg(short, long)] port: Option, + #[arg(short, long)] + addr: Option, } #[tokio::main] async fn main() -> Result<(), BatcherError> { let cli = Cli::parse(); let port = cli.port.unwrap_or(8080); + let addr = cli.addr.unwrap_or("localhost".to_string()); match cli.env_file { Some(env_file) => dotenvy::from_filename(env_file).ok(), @@ -40,7 +43,7 @@ async fn main() -> Result<(), BatcherError> { let batcher = Batcher::new(cli.config).await; let batcher = Arc::new(batcher); - let addr = format!("localhost:{}", port); + let address = format!("{addr}:{port}"); // spawn task to listening for incoming blocks tokio::spawn({ @@ -54,7 +57,7 @@ async fn main() -> Result<(), BatcherError> { batcher.metrics.inc_batcher_restart(); - batcher.listen_connections(&addr).await?; + batcher.listen_connections(&address).await?; Ok(()) } From 70b685e33010f582d0cb119c5e089d8c8f9cd01f Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 8 Jan 2025 12:15:36 -0300 Subject: [PATCH 2/4] add number of proofs --- alerts/sender_with_alert.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/alerts/sender_with_alert.sh b/alerts/sender_with_alert.sh index 3b70d57d7c..71b5f22e8d 100755 --- a/alerts/sender_with_alert.sh +++ b/alerts/sender_with_alert.sh @@ -53,6 +53,23 @@ function fetch_tx_cost() { fi } +# Function to get the tx cost from the tx hash +# @param tx_hash +function get_number_proofs_in_batch_from_create_task_tx() { + if [[ -z "$1" ]]; then + echo 0 + else + # Get the tx receipt from the blockchain + calldata=$(cast tx $1 --rpc-url $RPC_URL | grep -i input | cut -d' ' -f2-) + decoded_calldata=$(cast --calldata-decode "createNewTask(bytes32 batchMerkleRoot, string batchDataPointer, address[] proofSubmitters, uint256 feeF +orAggregator, uint256 feePerProof, uint256 respondToTaskFeeLimit)" $calldata) + # We count the number of proofSubmitters within the tx which corresponds to the number of proofs sent in the last batch + number_proofs_in_batch=$($decoded_calldata | jq '.[2] | [ match(","; "g")] | length + 1') + + echo $number_proofs_in_batch + fi +} + # Function to send PagerDuty alert # @param message function send_pagerduty_alert() { @@ -94,7 +111,7 @@ do --rpc_url $RPC_URL \ --batcher_url $BATCHER_URL \ --network $NETWORK \ - --max_fee 4000000000000000 \ + --max_fee 0.004ether \ 2>&1) echo "$submit" @@ -120,6 +137,9 @@ do batch_explorer_url="$EXPLORER_URL/batches/$batch_merkle_root" batch_explorer_urls+=($batch_explorer_url) + log=$(cast logs --rpc-url $RPC_URL --from-block $from_block_number --to-block latest 'TaskCreated(bytes32 indexed batchMerkleRoot, uint256 feePerProof)' --address $SENDER_ADDRESS) + task_creation_tx_hash=$(echo "$log" | grep -oE "transactionHash: 0x[[:alnum:]]{64}" | awk '{ print $2 }') + log=$(cast logs --rpc-url $RPC_URL --from-block $from_block_number --to-block latest 'NewBatchV3 (bytes32 indexed batchMerkleRoot, address senderAddress, uint32 taskCreatedBlock, string batchDataPointer, uint256 respondToTaskFeeLimit)' $batch_merkle_root) submission_tx_hash=$(echo "$log" | grep -oE "transactionHash: 0x[[:alnum:]]{64}" | awk '{ print $2 }') @@ -127,6 +147,7 @@ do response_tx_hash=$(echo "$log" | grep -oE "transactionHash: 0x[[:alnum:]]{64}" | awk '{ print $2 }') # Calculate fees for transactions + number_proofs_in_batch=$(get_number_proofs_in_batch_from_create_task_tx $task_creation_tx_hash) submission_fee_in_wei=$(fetch_tx_cost $submission_tx_hash) response_fee_in_wei=$(fetch_tx_cost $response_tx_hash) batch_fee_in_wei=$((submission_fee_in_wei + response_fee_in_wei)) @@ -168,9 +189,9 @@ do done if [ $verified -eq 1 ]; then - slack_message="$REPETITIONS Proofs submitted and verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" + slack_message="$number_proofs_in_batch Proofs submitted and verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" else - slack_message="$REPETITIONS Proofs submitted but not verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" + slack_message="$number_proofs_in_batch Proofs submitted but not verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" fi ## Send Update to Slack From 98eef581f95c31980b04bd6b3cd02cc4521811bb Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 9 Jan 2025 11:11:14 -0300 Subject: [PATCH 3/4] nit --- alerts/sender_with_alert.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/alerts/sender_with_alert.sh b/alerts/sender_with_alert.sh index 71b5f22e8d..5100103256 100755 --- a/alerts/sender_with_alert.sh +++ b/alerts/sender_with_alert.sh @@ -137,7 +137,7 @@ do batch_explorer_url="$EXPLORER_URL/batches/$batch_merkle_root" batch_explorer_urls+=($batch_explorer_url) - log=$(cast logs --rpc-url $RPC_URL --from-block $from_block_number --to-block latest 'TaskCreated(bytes32 indexed batchMerkleRoot, uint256 feePerProof)' --address $SENDER_ADDRESS) + log=$(cast logs --rpc-url $RPC_URL --from-block $from_block_number --to-block latest 'TaskCreated (bytes32 indexed batchMerkleRoot, uint256 feePerProof)' --address $SENDER_ADDRESS) task_creation_tx_hash=$(echo "$log" | grep -oE "transactionHash: 0x[[:alnum:]]{64}" | awk '{ print $2 }') log=$(cast logs --rpc-url $RPC_URL --from-block $from_block_number --to-block latest 'NewBatchV3 (bytes32 indexed batchMerkleRoot, address senderAddress, uint32 taskCreatedBlock, string batchDataPointer, uint256 respondToTaskFeeLimit)' $batch_merkle_root) @@ -148,6 +148,7 @@ do # Calculate fees for transactions number_proofs_in_batch=$(get_number_proofs_in_batch_from_create_task_tx $task_creation_tx_hash) + echo "here 2" submission_fee_in_wei=$(fetch_tx_cost $submission_tx_hash) response_fee_in_wei=$(fetch_tx_cost $response_tx_hash) batch_fee_in_wei=$((submission_fee_in_wei + response_fee_in_wei)) From 1d8846a8e9d47ed15c5df1fc535d386e6d493625 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 9 Jan 2025 13:53:47 -0300 Subject: [PATCH 4/4] fix json command --- alerts/sender_with_alert.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/alerts/sender_with_alert.sh b/alerts/sender_with_alert.sh index 5100103256..f6e66b403f 100755 --- a/alerts/sender_with_alert.sh +++ b/alerts/sender_with_alert.sh @@ -61,10 +61,9 @@ function get_number_proofs_in_batch_from_create_task_tx() { else # Get the tx receipt from the blockchain calldata=$(cast tx $1 --rpc-url $RPC_URL | grep -i input | cut -d' ' -f2-) - decoded_calldata=$(cast --calldata-decode "createNewTask(bytes32 batchMerkleRoot, string batchDataPointer, address[] proofSubmitters, uint256 feeF -orAggregator, uint256 feePerProof, uint256 respondToTaskFeeLimit)" $calldata) + decoded_calldata=$(cast --calldata-decode --json "createNewTask(bytes32 batchMerkleRoot, string batchDataPointer, address[] proofSubmitters, uint256 feeForAggregator, uint256 feePerProof, uint256 respondToTaskFeeLimit)" $calldata) # We count the number of proofSubmitters within the tx which corresponds to the number of proofs sent in the last batch - number_proofs_in_batch=$($decoded_calldata | jq '.[2] | [ match(","; "g")] | length + 1') + number_proofs_in_batch=$(echo $decoded_calldata | jq '.[2] | [ match(","; "g")] | length + 1') echo $number_proofs_in_batch fi @@ -148,7 +147,6 @@ do # Calculate fees for transactions number_proofs_in_batch=$(get_number_proofs_in_batch_from_create_task_tx $task_creation_tx_hash) - echo "here 2" submission_fee_in_wei=$(fetch_tx_cost $submission_tx_hash) response_fee_in_wei=$(fetch_tx_cost $response_tx_hash) batch_fee_in_wei=$((submission_fee_in_wei + response_fee_in_wei)) @@ -190,9 +188,9 @@ do done if [ $verified -eq 1 ]; then - slack_message="$number_proofs_in_batch Proofs submitted and verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" + slack_message="$REPETITIONS Proofs in batch of size $number_proofs_in_batch submitted and verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" else - slack_message="$number_proofs_in_batch Proofs submitted but not verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" + slack_message="$REPETITIONS Proofs in batch of size $number_proofs_in_batch submitted but not verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]" fi ## Send Update to Slack