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

feat(alerts): Display the number of proofs in a batch from the created task #1727

Open
wants to merge 5 commits into
base: testnet
Choose a base branch
from
Open
Changes from all commits
Commits
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
27 changes: 24 additions & 3 deletions alerts/sender_with_alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ 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 input)
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=$(echo $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() {
Expand Down Expand Up @@ -94,7 +110,7 @@ do
--rpc_url $RPC_URL \
--batcher_url $BATCHER_URL \
--network $NETWORK \
--max_fee 4000000000000000 \
--max_fee 0.004ether \
2>&1)

echo "$submit"
Expand All @@ -113,6 +129,7 @@ do
fi

total_fee_in_wei=0
total_number_proofs=0
batch_explorer_urls=()
for batch_merkle_root in $batch_merkle_roots
do
Expand All @@ -127,12 +144,16 @@ 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 $submission_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))

# Accumulate the fee
total_fee_in_wei=$(($total_fee_in_wei + $batch_fee_in_wei))

# Accumulate proofs in batch
total_number_proofs=$(($total_number_proofs + $number_proofs_in_batch))
done

# Calculate the spent amount by converting the fee to ETH
Expand Down Expand Up @@ -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="$total_number_proofs proofs submitted and verified. We sent $REPETITIONS proofs. 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="$total_number_proofs proofs submitted but not verified. We sent $REPETITIONS proofs. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]"
fi

## Send Update to Slack
Expand Down