Skip to content

Commit 422f6d4

Browse files
PatStilesJuArce
andauthored
feat(alerts): Display the number of proofs in a batch from the created task (#1727)
Co-authored-by: Julian Arce <[email protected]>
1 parent 9a4b37b commit 422f6d4

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

alerts/sender_with_alert.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ function fetch_tx_cost() {
5353
fi
5454
}
5555

56+
# Function to get the tx cost from the tx hash
57+
# @param tx_hash
58+
function get_number_proofs_in_batch_from_create_task_tx() {
59+
if [[ -z "$1" ]]; then
60+
echo 0
61+
else
62+
# Get the tx receipt from the blockchain
63+
calldata=$(cast tx $1 --rpc-url $RPC_URL input)
64+
decoded_calldata=$(cast --calldata-decode --json "createNewTask(bytes32 batchMerkleRoot, string batchDataPointer, address[] proofSubmitters, uint256 feeForAggregator, uint256 feePerProof, uint256 respondToTaskFeeLimit)" $calldata)
65+
# We count the number of proofSubmitters within the tx which corresponds to the number of proofs sent in the last batch
66+
number_proofs_in_batch=$(echo $decoded_calldata | jq '.[2] | [ match(","; "g")] | length + 1')
67+
68+
echo $number_proofs_in_batch
69+
fi
70+
}
71+
5672
# Function to send PagerDuty alert
5773
# @param message
5874
function send_pagerduty_alert() {
@@ -94,7 +110,7 @@ do
94110
--rpc_url $RPC_URL \
95111
--batcher_url $BATCHER_URL \
96112
--network $NETWORK \
97-
--max_fee 4000000000000000 \
113+
--max_fee 0.004ether \
98114
2>&1)
99115

100116
echo "$submit"
@@ -113,6 +129,7 @@ do
113129
fi
114130

115131
total_fee_in_wei=0
132+
total_number_proofs=0
116133
batch_explorer_urls=()
117134
for batch_merkle_root in $batch_merkle_roots
118135
do
@@ -127,12 +144,16 @@ do
127144
response_tx_hash=$(echo "$log" | grep -oE "transactionHash: 0x[[:alnum:]]{64}" | awk '{ print $2 }')
128145

129146
# Calculate fees for transactions
147+
number_proofs_in_batch=$(get_number_proofs_in_batch_from_create_task_tx $submission_tx_hash)
130148
submission_fee_in_wei=$(fetch_tx_cost $submission_tx_hash)
131149
response_fee_in_wei=$(fetch_tx_cost $response_tx_hash)
132150
batch_fee_in_wei=$((submission_fee_in_wei + response_fee_in_wei))
133151

134152
# Accumulate the fee
135153
total_fee_in_wei=$(($total_fee_in_wei + $batch_fee_in_wei))
154+
155+
# Accumulate proofs in batch
156+
total_number_proofs=$(($total_number_proofs + $number_proofs_in_batch))
136157
done
137158

138159
# Calculate the spent amount by converting the fee to ETH
@@ -168,9 +189,9 @@ do
168189
done
169190

170191
if [ $verified -eq 1 ]; then
171-
slack_message="$REPETITIONS Proofs submitted and verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]"
192+
slack_message="$total_number_proofs proofs submitted and verified. We sent $REPETITIONS proofs. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]"
172193
else
173-
slack_message="$REPETITIONS Proofs submitted but not verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]"
194+
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[@]} ]"
174195
fi
175196

176197
## Send Update to Slack

0 commit comments

Comments
 (0)