Skip to content

Commit 75ae277

Browse files
authored
Pull fixes testnet 17 01 (#1750)
2 parents 6a1e129 + 731e250 commit 75ae277

File tree

32 files changed

+230
-139
lines changed

32 files changed

+230
-139
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,18 @@ docker_verify_proof_submission_success:
10641064
verification=$$(aligned verify-proof-onchain \
10651065
--aligned-verification-data $${proof} \
10661066
--rpc_url $$(echo $(DOCKER_RPC_URL)) 2>&1); \
1067+
cat $${proof%.cbor}.json; \
1068+
echo "$$verification"; \
10671069
if echo "$$verification" | grep -q not; then \
10681070
echo "ERROR: Proof verification failed for $${proof}"; \
10691071
exit 1; \
10701072
elif echo "$$verification" | grep -q verified; then \
10711073
echo "Proof verification succeeded for $${proof}"; \
1074+
else \
1075+
echo "WARNING: Unexpected verification result for $${proof}"; \
1076+
echo "Output:"; \
1077+
echo "$$verification"; \
1078+
exit 1; \
10721079
fi; \
10731080
echo "---------------------------------------------------------------------------------------------------"; \
10741081
done; \

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

batcher/aligned-batcher/src/config/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ impl NonPayingConfig {
3737

3838
#[derive(Debug, Deserialize)]
3939
pub struct BatcherConfigFromYaml {
40+
#[serde(default = "default_aggregator_fee_percentage_multiplier")]
41+
pub aggregator_fee_percentage_multiplier: u128,
42+
#[serde(default = "default_aggregator_gas_cost")]
43+
pub aggregator_gas_cost: u128,
4044
pub block_interval: u64,
4145
pub transaction_wait_timeout: u64,
4246
pub max_proof_size: usize,
@@ -86,3 +90,11 @@ impl ContractDeploymentOutput {
8690
serde_json::from_str(&deployment_output).expect("Failed to parse deployment output file")
8791
}
8892
}
93+
94+
fn default_aggregator_fee_percentage_multiplier() -> u128 {
95+
aligned_sdk::core::constants::DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER
96+
}
97+
98+
fn default_aggregator_gas_cost() -> u128 {
99+
aligned_sdk::core::constants::DEFAULT_AGGREGATOR_GAS_COST
100+
}

batcher/aligned-batcher/src/lib.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ use std::sync::Arc;
2424
use std::time::Duration;
2525

2626
use aligned_sdk::core::constants::{
27-
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, AGGREGATOR_GAS_COST, BUMP_BACKOFF_FACTOR,
28-
BUMP_MAX_RETRIES, BUMP_MAX_RETRY_DELAY, BUMP_MIN_RETRY_DELAY, CONNECTION_TIMEOUT,
29-
CONSTANT_GAS_COST, DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER, DEFAULT_MAX_FEE_PER_PROOF,
30-
ETHEREUM_CALL_BACKOFF_FACTOR, ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY,
31-
ETHEREUM_CALL_MIN_RETRY_DELAY, GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER,
27+
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, BATCHER_SUBMISSION_BASE_GAS_COST,
28+
BUMP_BACKOFF_FACTOR, BUMP_MAX_RETRIES, BUMP_MAX_RETRY_DELAY, BUMP_MIN_RETRY_DELAY,
29+
CONNECTION_TIMEOUT, DEFAULT_MAX_FEE_PER_PROOF, ETHEREUM_CALL_BACKOFF_FACTOR,
30+
ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY, ETHEREUM_CALL_MIN_RETRY_DELAY,
31+
GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER,
3232
RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER,
3333
};
3434
use aligned_sdk::core::types::{
@@ -93,6 +93,8 @@ pub struct Batcher {
9393
non_paying_config: Option<NonPayingConfig>,
9494
posting_batch: Mutex<bool>,
9595
disabled_verifiers: Mutex<U256>,
96+
aggregator_fee_percentage_multiplier: u128,
97+
aggregator_gas_cost: u128,
9698
pub metrics: metrics::BatcherMetrics,
9799
pub telemetry: TelemetrySender,
98100
}
@@ -254,6 +256,10 @@ impl Batcher {
254256
last_uploaded_batch_block: Mutex::new(last_uploaded_batch_block),
255257
pre_verification_is_enabled: config.batcher.pre_verification_is_enabled,
256258
non_paying_config,
259+
aggregator_fee_percentage_multiplier: config
260+
.batcher
261+
.aggregator_fee_percentage_multiplier,
262+
aggregator_gas_cost: config.batcher.aggregator_gas_cost,
257263
posting_batch: Mutex::new(false),
258264
batch_state: Mutex::new(batch_state),
259265
disabled_verifiers: Mutex::new(disabled_verifiers),
@@ -1163,6 +1169,7 @@ impl Batcher {
11631169
gas_price,
11641170
self.max_batch_byte_size,
11651171
self.max_batch_proof_qty,
1172+
self.constant_gas_cost(),
11661173
)
11671174
.inspect_err(|e| {
11681175
*batch_posting = false;
@@ -1444,13 +1451,13 @@ impl Batcher {
14441451
let batch_data_pointer: String = "".to_owned() + &self.download_endpoint + "/" + &file_name;
14451452

14461453
let num_proofs_in_batch = leaves.len();
1447-
let gas_per_proof = (CONSTANT_GAS_COST
1454+
let gas_per_proof = (self.constant_gas_cost()
14481455
+ ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * num_proofs_in_batch as u128)
14491456
/ num_proofs_in_batch as u128;
14501457
let fee_per_proof = U256::from(gas_per_proof) * gas_price;
1451-
let fee_for_aggregator = (U256::from(AGGREGATOR_GAS_COST)
1458+
let fee_for_aggregator = (U256::from(self.aggregator_gas_cost)
14521459
* gas_price
1453-
* U256::from(DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER))
1460+
* U256::from(self.aggregator_fee_percentage_multiplier))
14541461
/ U256::from(PERCENTAGE_DIVIDER);
14551462
let respond_to_task_fee_limit = (fee_for_aggregator
14561463
* U256::from(RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER))
@@ -1748,7 +1755,7 @@ impl Batcher {
17481755
let nonced_verification_data = NoncedVerificationData::new(
17491756
client_msg.verification_data.verification_data.clone(),
17501757
client_msg.verification_data.nonce,
1751-
DEFAULT_MAX_FEE_PER_PROOF.into(), // 13_000 gas per proof * 100 gwei gas price (upper bound)
1758+
DEFAULT_MAX_FEE_PER_PROOF.into(), // 2_000 gas per proof * 100 gwei gas price (upper bound)
17521759
self.chain_id,
17531760
self.payment_service.address(),
17541761
);
@@ -1875,4 +1882,9 @@ impl Batcher {
18751882
})?;
18761883
Ok(())
18771884
}
1885+
1886+
fn constant_gas_cost(&self) -> u128 {
1887+
(self.aggregator_fee_percentage_multiplier * self.aggregator_gas_cost) / PERCENTAGE_DIVIDER
1888+
+ BATCHER_SUBMISSION_BASE_GAS_COST
1889+
}
18781890
}

batcher/aligned-batcher/src/types/batch_queue.rs

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,14 @@ pub(crate) fn try_build_batch(
154154
gas_price: U256,
155155
max_batch_byte_size: usize,
156156
max_batch_proof_qty: usize,
157+
constant_gas_cost: u128,
157158
) -> Result<Vec<BatchQueueEntry>, BatcherError> {
158159
let mut finalized_batch = batch_queue;
159160
let mut batch_size = calculate_batch_size(&finalized_batch)?;
160161

161162
while let Some((entry, _)) = finalized_batch.peek() {
162163
let batch_len = finalized_batch.len();
163-
let fee_per_proof = calculate_fee_per_proof(batch_len, gas_price);
164+
let fee_per_proof = calculate_fee_per_proof(batch_len, gas_price, constant_gas_cost);
164165

165166
// if batch is not acceptable:
166167
if batch_size > max_batch_byte_size
@@ -197,8 +198,8 @@ pub(crate) fn try_build_batch(
197198
Ok(finalized_batch.clone().into_sorted_vec())
198199
}
199200

200-
fn calculate_fee_per_proof(batch_len: usize, gas_price: U256) -> U256 {
201-
let gas_per_proof = (crate::CONSTANT_GAS_COST
201+
fn calculate_fee_per_proof(batch_len: usize, gas_price: U256, constant_gas_cost: u128) -> U256 {
202+
let gas_per_proof = (constant_gas_cost
202203
+ crate::ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * batch_len as u128)
203204
/ batch_len as u128;
204205

@@ -207,6 +208,7 @@ fn calculate_fee_per_proof(batch_len: usize, gas_price: U256) -> U256 {
207208

208209
#[cfg(test)]
209210
mod test {
211+
use aligned_sdk::core::constants::DEFAULT_CONSTANT_GAS_COST;
210212
use aligned_sdk::core::types::ProvingSystemId;
211213
use aligned_sdk::core::types::VerificationData;
212214
use ethers::types::Address;
@@ -303,7 +305,14 @@ mod test {
303305
batch_queue.push(entry_3, batch_priority_3);
304306

305307
let gas_price = U256::from(1);
306-
let finalized_batch = try_build_batch(batch_queue, gas_price, 5000000, 50).unwrap();
308+
let finalized_batch = try_build_batch(
309+
batch_queue.clone(),
310+
gas_price,
311+
5000000,
312+
50,
313+
DEFAULT_CONSTANT_GAS_COST,
314+
)
315+
.unwrap();
307316

308317
assert_eq!(
309318
finalized_batch[0].nonced_verification_data.max_fee,
@@ -408,7 +417,14 @@ mod test {
408417
batch_queue.push(entry_3, batch_priority_3);
409418

410419
let gas_price = U256::from(1);
411-
let finalized_batch = try_build_batch(batch_queue.clone(), gas_price, 5000000, 50).unwrap();
420+
let finalized_batch = try_build_batch(
421+
batch_queue.clone(),
422+
gas_price,
423+
5000000,
424+
50,
425+
DEFAULT_CONSTANT_GAS_COST,
426+
)
427+
.unwrap();
412428

413429
// All entries from the batch queue should be in
414430
// the finalized batch.
@@ -511,7 +527,14 @@ mod test {
511527
batch_queue.push(entry_3.clone(), batch_priority_3.clone());
512528

513529
let gas_price = U256::from(1);
514-
let finalized_batch = try_build_batch(batch_queue.clone(), gas_price, 5000000, 2).unwrap();
530+
let finalized_batch = try_build_batch(
531+
batch_queue.clone(),
532+
gas_price,
533+
5000000,
534+
2,
535+
DEFAULT_CONSTANT_GAS_COST,
536+
)
537+
.unwrap();
515538

516539
// One Entry from the batch_queue should not be in the finalized batch
517540
// Particularly, nonce_3 is not in the finalized batch
@@ -614,7 +637,14 @@ mod test {
614637
batch_queue.push(entry_3, batch_priority_3);
615638

616639
let gas_price = U256::from(1);
617-
let finalized_batch = try_build_batch(batch_queue.clone(), gas_price, 5000000, 50).unwrap();
640+
let finalized_batch = try_build_batch(
641+
batch_queue.clone(),
642+
gas_price,
643+
5000000,
644+
50,
645+
DEFAULT_CONSTANT_GAS_COST,
646+
)
647+
.unwrap();
618648

619649
// All entries from the batch queue should be in
620650
// the finalized batch.
@@ -723,7 +753,14 @@ mod test {
723753
batch_queue.push(entry_3, batch_priority_3);
724754

725755
let gas_price = U256::from(1);
726-
let finalized_batch = try_build_batch(batch_queue.clone(), gas_price, 5000000, 50).unwrap();
756+
let finalized_batch = try_build_batch(
757+
batch_queue.clone(),
758+
gas_price,
759+
5000000,
760+
50,
761+
DEFAULT_CONSTANT_GAS_COST,
762+
)
763+
.unwrap();
727764

728765
// All but one entries from the batch queue should be in the finalized batch.
729766
assert_eq!(batch_queue.len(), 3);
@@ -832,8 +869,14 @@ mod test {
832869
// The max batch len is 2, so the algorithm should stop at the second entry.
833870
let max_batch_proof_qty = 2;
834871

835-
let finalized_batch =
836-
try_build_batch(batch_queue.clone(), gas_price, 5000000, max_batch_proof_qty).unwrap();
872+
let finalized_batch = try_build_batch(
873+
batch_queue.clone(),
874+
gas_price,
875+
5000000,
876+
max_batch_proof_qty,
877+
DEFAULT_CONSTANT_GAS_COST,
878+
)
879+
.unwrap();
837880

838881
assert_eq!(batch_queue.len(), 3);
839882
assert_eq!(finalized_batch.len(), 2);

batcher/aligned-sdk/src/core/constants.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/// Batcher ///
22
pub const GAS_PRICE_INCREMENT_PERCENTAGE_PER_ITERATION: usize = 5;
3-
pub const AGGREGATOR_GAS_COST: u128 = 400_000;
3+
pub const DEFAULT_AGGREGATOR_GAS_COST: u128 = 330_000;
44
pub const BATCHER_SUBMISSION_BASE_GAS_COST: u128 = 125_000;
5-
pub const ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF: u128 = 13_000;
6-
pub const CONSTANT_GAS_COST: u128 =
7-
((AGGREGATOR_GAS_COST * DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER) / PERCENTAGE_DIVIDER)
8-
+ BATCHER_SUBMISSION_BASE_GAS_COST;
5+
pub const ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF: u128 = 2_000;
6+
pub const DEFAULT_CONSTANT_GAS_COST: u128 = ((DEFAULT_AGGREGATOR_GAS_COST
7+
* DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER)
8+
/ PERCENTAGE_DIVIDER)
9+
+ BATCHER_SUBMISSION_BASE_GAS_COST;
910
pub const DEFAULT_MAX_FEE_PER_PROOF: u128 =
1011
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * 100_000_000_000; // gas_price = 100 Gwei = 0.0000001 ether (high gas price)
1112
pub const CONNECTION_TIMEOUT: u64 = 30; // 30 secs
1213

1314
// % modifiers: (100% is x1, 10% is x0.1, 1000% is x10)
1415
pub const RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER: u128 = 250; // fee_for_aggregator -> respondToTaskFeeLimit modifier
15-
pub const DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER: u128 = 150; // feeForAggregator modifier
16+
pub const DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER: u128 = 125; // feeForAggregator modifier
1617
pub const GAS_PRICE_PERCENTAGE_MULTIPLIER: u128 = 110; // gasPrice modifier
1718
pub const OVERRIDE_GAS_PRICE_PERCENTAGE_MULTIPLIER: u128 = 120; // gasPrice modifier to override previous transactions
1819
pub const PERCENTAGE_DIVIDER: u128 = 100;

batcher/aligned-sdk/src/sdk.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
},
88
core::{
99
constants::{
10-
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, CONSTANT_GAS_COST,
10+
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, DEFAULT_CONSTANT_GAS_COST,
1111
MAX_FEE_BATCH_PROOF_NUMBER, MAX_FEE_DEFAULT_PROOF_NUMBER,
1212
},
1313
errors::{self, GetNonceError},
@@ -191,7 +191,7 @@ pub async fn fee_per_proof(
191191
let gas_price = fetch_gas_price(&eth_rpc_provider).await?;
192192

193193
// Cost for estimate `num_proofs_per_batch` proofs
194-
let estimated_gas_per_proof = (CONSTANT_GAS_COST
194+
let estimated_gas_per_proof = (DEFAULT_CONSTANT_GAS_COST
195195
+ ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * num_proofs_per_batch as u128)
196196
/ num_proofs_per_batch as u128;
197197

@@ -284,7 +284,7 @@ pub fn get_payment_service_address(network: Network) -> ethers::types::H160 {
284284

285285
pub fn get_aligned_service_manager_address(network: Network) -> ethers::types::H160 {
286286
match network {
287-
Network::Devnet => H160::from_str("0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8").unwrap(),
287+
Network::Devnet => H160::from_str("0x851356ae760d987E095750cCeb3bC6014560891C").unwrap(),
288288
Network::Holesky => H160::from_str("0x58F280BeBE9B34c9939C3C39e0890C81f163B623").unwrap(),
289289
Network::HoleskyStage => {
290290
H160::from_str("0x9C5231FC88059C086Ea95712d105A2026048c39B").unwrap()

config-files/config-aggregator-docker.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ aggregator:
3131
garbage_collector_tasks_age: 20 #The age of tasks that will be removed by the GC, in blocks. Suggested value for prod: '216000' (30 days)
3232
garbage_collector_tasks_interval: 10 #The interval of queried blocks to get an old batch. Suggested value for prod: '900' (3 hours)
3333
bls_service_task_timeout: 168h # The timeout of bls aggregation service tasks. Suggested value for prod '168h' (7 days)
34+
gas_base_bump_percentage: 25 # Percentage to overestimate gas price when sending a task
35+
gas_bump_incremental_percentage: 20 # An extra percentage to overestimate in each bump of respond to task. This is additive between tries
36+
# Gas used formula = est_gas_by_node * (gas_base_bump_percentage + gas_bum_incremental_percentage * i) / 100, where i is the iteration number.
37+
gas_bump_percentage_limit: 150 # The max percentage to bump the gas price.
38+
# The Gas formula is percentage (gas_base_bump_percentage + gas_bump_incremental_percentage * i) / 100) is checked against this value
39+
# If it is higher, it will default to `gas_bump_percentage_limit`
40+
time_to_wait_before_bump: 72s # The time to wait for the receipt when responding to task. Suggested value 72 seconds (6 blocks)

0 commit comments

Comments
 (0)