Skip to content

Commit a3eb4d2

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/testnet' into pull_fixes_testnet_17_01
# Conflicts: # explorer/.env.dev # explorer/.env.example # explorer/lib/explorer_web/live/utils.ex # explorer/start.sh
2 parents 6a1e129 + 422f6d4 commit a3eb4d2

File tree

27 files changed

+209
-114
lines changed

27 files changed

+209
-114
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

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: 2 additions & 2 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

config-files/config-batcher-docker.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ ecdsa:
1616

1717
## Batcher configurations
1818
batcher:
19+
aggregator_fee_percentage_multiplier: 125
20+
aggregator_gas_cost: 330000
1921
block_interval: 3
2022
batch_size_interval: 10
2123
transaction_wait_timeout: 96000 # 8 blocks

config-files/config-batcher.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ ecdsa:
1616

1717
## Batcher configurations
1818
batcher:
19+
aggregator_fee_percentage_multiplier: 125
20+
aggregator_gas_cost: 330000
1921
block_interval: 3
2022
batch_size_interval: 10
2123
transaction_wait_timeout: 96000 # 8 blocks

docs/1_introduction/1_try_aligned.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
In this tutorial, you will learn how to send your first SP1 proofs to get verified in Aligned in under 3 minutes.
44

5+
{% hint style="warning" %}
6+
This tutorial is for sending proofs on Holesky network.
7+
To send proofs on Mainnet, please refer to the [submitting proofs](../3_guides/0_submitting_proofs.md) guide.
8+
{% endhint %}
9+
510
## Quickstart
611

712
We will download a previously generated SP1 proof, send it to Aligned for verification, and retrieve the results from Ethereum Holesky testnet.

explorer/.env.dev

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ BATCH_TTL_MINUTES=5
2828

2929
# Scheduled minutes between batch submissions. This is shown in the next batch progress bar component.
3030
SCHEDULED_BATCH_INTERVAL_MINUTES=10
31+
32+
# Latest aligned release that operators should be running
33+
LATEST_RELEASE=v0.13.0

0 commit comments

Comments
 (0)