Skip to content

Commit ec2f42c

Browse files
committed
Merge branch 'staging' into 1422-docs-add-pause-process-with-multisig
2 parents 6711308 + c962068 commit ec2f42c

File tree

84 files changed

+1178
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1178
-336
lines changed

Makefile

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,21 @@ operator_mint_mock_tokens:
229229

230230
operator_whitelist_devnet:
231231
@echo "Whitelisting operator"
232-
$(eval OPERATOR_ADDRESS = $(shell yq -r '.operator.address' $(CONFIG_FILE)))
233232
@echo "Operator address: $(OPERATOR_ADDRESS)"
234-
RPC_URL="http://localhost:8545" PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" OUTPUT_PATH=./script/output/devnet/alignedlayer_deployment_output.json ./contracts/scripts/whitelist_operator.sh $(OPERATOR_ADDRESS)
233+
RPC_URL="http://localhost:8545" PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" OUTPUT_PATH=./script/output/devnet/alignedlayer_deployment_output.json ./contracts/scripts/operator_whitelist.sh $(OPERATOR_ADDRESS)
235234

236-
operator_remove_devnet:
235+
operator_remove_from_whitelist_devnet:
237236
@echo "Removing operator"
238-
$(eval OPERATOR_ADDRESS = $(shell yq -r '.operator.address' $(CONFIG_FILE)))
239237
@echo "Operator address: $(OPERATOR_ADDRESS)"
240-
RPC_URL="http://localhost:8545" PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" OUTPUT_PATH=./script/output/devnet/alignedlayer_deployment_output.json ./contracts/scripts/remove_operator.sh $(OPERATOR_ADDRESS)
238+
RPC_URL="http://localhost:8545" PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" OUTPUT_PATH=./script/output/devnet/alignedlayer_deployment_output.json ./contracts/scripts/operator_remove_from_whitelist.sh $(OPERATOR_ADDRESS)
241239

242240
operator_whitelist:
243241
@echo "Whitelisting operator $(OPERATOR_ADDRESS)"
244-
@. contracts/scripts/.env && . contracts/scripts/whitelist_operator.sh $(OPERATOR_ADDRESS)
242+
@. contracts/scripts/.env && . contracts/scripts/operator_whitelist.sh $(OPERATOR_ADDRESS)
243+
244+
operator_remove_from_whitelist:
245+
@echo "Removing operator $(OPERATOR_ADDRESS)"
246+
@. contracts/scripts/.env && . contracts/scripts/operator_remove_from_whitelist.sh $(OPERATOR_ADDRESS)
245247

246248
operator_deposit_into_mock_strategy:
247249
@echo "Depositing into mock strategy"
@@ -563,18 +565,18 @@ run_storage: ## Run storage using storage-docker-compose.yaml
563565
@echo "Running storage..."
564566
@docker compose -f storage-docker-compose.yaml up
565567

566-
__DEPLOYMENT__:
567-
deploy_aligned_contracts: ## Deploy Aligned Contracts
568-
@echo "Deploying Aligned Contracts..."
569-
@. contracts/scripts/.env && . contracts/scripts/deploy_aligned_contracts.sh
568+
__DEPLOYMENT__: ## ____
569+
deploy_aligned_contracts: ## Deploy Aligned Contracts. Parameters: NETWORK=<mainnet|holesky|sepolia>
570+
@echo "Deploying Aligned Contracts on $(NETWORK) network..."
571+
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/deploy_aligned_contracts.sh
570572

571573
deploy_pauser_registry: ## Deploy Pauser Registry
572574
@echo "Deploying Pauser Registry..."
573575
@. contracts/scripts/.env && . contracts/scripts/deploy_pauser_registry.sh
574576

575-
upgrade_aligned_contracts: ## Upgrade Aligned Contracts
576-
@echo "Upgrading Aligned Contracts..."
577-
@. contracts/scripts/.env && . contracts/scripts/upgrade_aligned_contracts.sh
577+
upgrade_aligned_contracts: ## Upgrade Aligned Contracts. Parameters: NETWORK=<mainnet|holesky|sepolia>
578+
@echo "Upgrading Aligned Contracts on $(NETWORK) network..."
579+
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/upgrade_aligned_contracts.sh
578580

579581
upgrade_pauser_aligned_contracts: ## Upgrade Aligned Contracts with Pauser initialization
580582
@echo "Upgrading Aligned Contracts with Pauser initialization..."
@@ -608,13 +610,13 @@ deploy_verify_batch_inclusion_caller:
608610
@echo "Deploying VerifyBatchInclusionCaller contract..."
609611
@. examples/verify/.env && . examples/verify/scripts/deploy_verify_batch_inclusion_caller.sh
610612

611-
deploy_batcher_payment_service:
612-
@echo "Deploying BatcherPayments contract..."
613-
@. contracts/scripts/.env && . contracts/scripts/deploy_batcher_payment_service.sh
613+
deploy_batcher_payment_service: ## Deploy BatcherPayments contract. Parameters: NETWORK=<mainnet|holesky|sepolia>
614+
@echo "Deploying BatcherPayments contract on $(NETWORK) network..."
615+
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/deploy_batcher_payment_service.sh
614616

615-
upgrade_batcher_payment_service:
616-
@echo "Upgrading BatcherPayments contract..."
617-
@. contracts/scripts/.env && . contracts/scripts/upgrade_batcher_payment_service.sh
617+
upgrade_batcher_payment_service: ## Upgrade BatcherPayments contract. Parameters: NETWORK=<mainnet|holesky|sepolia
618+
@echo "Upgrading BatcherPayments Contract on $(NETWORK) network..."
619+
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/upgrade_batcher_payment_service.sh
618620

619621
build_aligned_contracts:
620622
@cd contracts/src/core && forge build
@@ -1064,7 +1066,7 @@ docker_logs_batcher:
10641066

10651067
__TELEMETRY__:
10661068
# Collector, Jaeger and Elixir API
1067-
telemetry_full_start: open_telemetry_start telemetry_start
1069+
telemetry_full_start: telemetry_compile_bls_verifier open_telemetry_start telemetry_start
10681070

10691071
# Collector and Jaeger
10701072
open_telemetry_start: ## Run open telemetry services using telemetry-docker-compose.yaml
@@ -1108,6 +1110,10 @@ telemetry_create_env:
11081110
@cd telemetry_api && \
11091111
cp .env.dev .env
11101112

1113+
telemetry_compile_bls_verifier:
1114+
@cd telemetry_api/priv && \
1115+
go build ../bls_verifier/bls_verify.go
1116+
11111117
setup_local_aligned_all:
11121118
tmux kill-session -t aligned_layer || true
11131119
tmux new-session -d -s aligned_layer

aggregator/pkg/aggregator.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error
105105
// Telemetry
106106
aggregatorTelemetry := NewTelemetry(aggregatorConfig.Aggregator.TelemetryIpPortAddress, logger)
107107

108-
avsReader, err := chainio.NewAvsReaderFromConfig(aggregatorConfig.BaseConfig, aggregatorConfig.EcdsaConfig)
108+
avsReader, err := chainio.NewAvsReaderFromConfig(aggregatorConfig.BaseConfig)
109109
if err != nil {
110110
return nil, err
111111
}
@@ -134,9 +134,7 @@ func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error
134134
PromMetricsIpPortAddress: ":9090",
135135
}
136136

137-
aggregatorPrivateKey := aggregatorConfig.EcdsaConfig.PrivateKey
138-
139-
clients, err := sdkclients.BuildAll(chainioConfig, aggregatorPrivateKey, logger)
137+
clients, err := sdkclients.BuildReadClients(chainioConfig, logger)
140138
if err != nil {
141139
logger.Errorf("Cannot create sdk clients", "err", err)
142140
return nil, err
@@ -395,7 +393,7 @@ func (agg *Aggregator) AddNewTask(batchMerkleRoot [32]byte, senderAddress [20]by
395393
quorumNums := eigentypes.QuorumNums{eigentypes.QuorumNum(QUORUM_NUMBER)}
396394
quorumThresholdPercentages := eigentypes.QuorumThresholdPercentages{eigentypes.QuorumThresholdPercentage(QUORUM_THRESHOLD)}
397395

398-
err := agg.blsAggregationService.InitializeNewTask(batchIndex, taskCreatedBlock, quorumNums, quorumThresholdPercentages, agg.AggregatorConfig.Aggregator.BlsServiceTaskTimeout)
396+
err := agg.blsAggregationService.InitializeNewTaskWithWindow(batchIndex, taskCreatedBlock, quorumNums, quorumThresholdPercentages, agg.AggregatorConfig.Aggregator.BlsServiceTaskTimeout, 15*time.Second)
399397
if err != nil {
400398
agg.logger.Fatalf("BLS aggregation service error when initializing new task: %s", err)
401399
}

batcher/aligned-batcher/src/lib.rs

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ use retry::batcher_retryables::{
1111
get_user_nonce_from_ethereum_retryable, user_balance_is_unlocked_retryable,
1212
};
1313
use retry::{retry_function, RetryError};
14+
use tokio::time::timeout;
1415
use types::batch_state::BatchState;
1516
use types::user_state::UserState;
1617

1718
use std::collections::HashMap;
1819
use std::env;
1920
use std::net::SocketAddr;
2021
use std::sync::Arc;
22+
use std::time::Duration;
2123

2224
use aligned_sdk::core::constants::{
2325
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, AGGREGATOR_GAS_COST, BUMP_BACKOFF_FACTOR,
24-
BUMP_MAX_RETRIES, BUMP_MAX_RETRY_DELAY, BUMP_MIN_RETRY_DELAY, CONSTANT_GAS_COST,
25-
DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER, DEFAULT_MAX_FEE_PER_PROOF,
26+
BUMP_MAX_RETRIES, BUMP_MAX_RETRY_DELAY, BUMP_MIN_RETRY_DELAY, CONNECTION_TIMEOUT,
27+
CONSTANT_GAS_COST, DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER, DEFAULT_MAX_FEE_PER_PROOF,
2628
ETHEREUM_CALL_BACKOFF_FACTOR, ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY,
2729
ETHEREUM_CALL_MIN_RETRY_DELAY, GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER,
2830
RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER,
@@ -79,7 +81,7 @@ pub struct Batcher {
7981
service_manager: ServiceManager,
8082
service_manager_fallback: ServiceManager,
8183
batch_state: Mutex<BatchState>,
82-
max_block_interval: u64,
84+
min_block_interval: u64,
8385
transaction_wait_timeout: u64,
8486
max_proof_size: usize,
8587
max_batch_byte_size: usize,
@@ -242,7 +244,7 @@ impl Batcher {
242244
payment_service_fallback,
243245
service_manager,
244246
service_manager_fallback,
245-
max_block_interval: config.batcher.block_interval,
247+
min_block_interval: config.batcher.block_interval,
246248
transaction_wait_timeout: config.batcher.transaction_wait_timeout,
247249
max_proof_size: config.batcher.max_proof_size,
248250
max_batch_byte_size: config.batcher.max_batch_byte_size,
@@ -265,13 +267,19 @@ impl Batcher {
265267
.map_err(|e| BatcherError::TcpListenerError(e.to_string()))?;
266268
info!("Listening on: {}", address);
267269

268-
// Let's spawn the handling of each connection in a separate task.
269-
while let Ok((stream, addr)) = listener.accept().await {
270-
self.metrics.open_connections.inc();
271-
let batcher = self.clone();
272-
tokio::spawn(batcher.handle_connection(stream, addr));
270+
loop {
271+
match listener.accept().await {
272+
Ok((stream, addr)) => {
273+
let batcher = self.clone();
274+
// Let's spawn the handling of each connection in a separate task.
275+
tokio::spawn(batcher.handle_connection(stream, addr));
276+
}
277+
Err(e) => {
278+
self.metrics.user_error(&["connection_accept_error", ""]);
279+
error!("Couldn't accept new connection: {}", e);
280+
}
281+
}
273282
}
274-
Ok(())
275283
}
276284

277285
/// Listen for Ethereum new blocks.
@@ -360,7 +368,24 @@ impl Batcher {
360368
addr: SocketAddr,
361369
) -> Result<(), BatcherError> {
362370
info!("Incoming TCP connection from: {}", addr);
363-
let ws_stream = tokio_tungstenite::accept_async(raw_stream).await?;
371+
self.metrics.open_connections.inc();
372+
373+
let ws_stream_future = tokio_tungstenite::accept_async(raw_stream);
374+
let ws_stream =
375+
match timeout(Duration::from_secs(CONNECTION_TIMEOUT), ws_stream_future).await {
376+
Ok(Ok(stream)) => stream,
377+
Ok(Err(e)) => {
378+
warn!("Error while establishing websocket connection: {}", e);
379+
self.metrics.open_connections.dec();
380+
return Ok(());
381+
}
382+
Err(e) => {
383+
warn!("Error while establishing websocket connection: {}", e);
384+
self.metrics.open_connections.dec();
385+
self.metrics.user_error(&["user_timeout", ""]);
386+
return Ok(());
387+
}
388+
};
364389

365390
debug!("WebSocket connection established: {}", addr);
366391
let (outgoing, incoming) = ws_stream.split();
@@ -379,8 +404,33 @@ impl Batcher {
379404
.send(Message::binary(serialized_protocol_version_msg))
380405
.await?;
381406

382-
match incoming
383-
.try_filter(|msg| future::ready(msg.is_binary()))
407+
let mut incoming_filter = incoming.try_filter(|msg| future::ready(msg.is_binary()));
408+
let future_msg = incoming_filter.try_next();
409+
410+
// timeout to prevent a DOS attack
411+
match timeout(Duration::from_secs(CONNECTION_TIMEOUT), future_msg).await {
412+
Ok(Ok(Some(msg))) => {
413+
self.clone().handle_message(msg, outgoing.clone()).await?;
414+
}
415+
Err(elapsed) => {
416+
warn!("[{}] {}", &addr, elapsed);
417+
self.metrics.user_error(&["user_timeout", ""]);
418+
self.metrics.open_connections.dec();
419+
return Ok(());
420+
}
421+
Ok(Ok(None)) => {
422+
info!("[{}] Connection closed by the other side", &addr);
423+
self.metrics.open_connections.dec();
424+
return Ok(());
425+
}
426+
Ok(Err(e)) => {
427+
error!("Unexpected error: {}", e);
428+
self.metrics.open_connections.dec();
429+
return Ok(());
430+
}
431+
};
432+
433+
match incoming_filter
384434
.try_for_each(|msg| self.clone().handle_message(msg, outgoing.clone()))
385435
.await
386436
{
@@ -1082,9 +1132,9 @@ impl Batcher {
10821132
return None;
10831133
}
10841134

1085-
if block_number < *last_uploaded_batch_block_lock + self.max_block_interval {
1135+
if block_number < *last_uploaded_batch_block_lock + self.min_block_interval {
10861136
info!(
1087-
"Current batch not ready to be posted. Minimium amount of {} blocks have not passed. Block passed: {}", self.max_block_interval,
1137+
"Current batch not ready to be posted. Minimium amount of {} blocks have not passed. Block passed: {}", self.min_block_interval,
10881138
block_number - *last_uploaded_batch_block_lock,
10891139
);
10901140
return None;
@@ -1418,7 +1468,7 @@ impl Batcher {
14181468
}
14191469
}
14201470

1421-
/// Sends a `create_new_task` transaction to Ethereum and waits for a maximum of 3 blocks for the receipt.
1471+
/// Sends a `create_new_task` transaction to Ethereum and waits for a maximum of 8 blocks for the receipt.
14221472
/// Retries up to `ETHEREUM_CALL_MAX_RETRIES` times using exponential backoff on recoverable errors while trying to send the transaction:
14231473
/// (0,5 secs - 1 secs - 2 secs - 4 secs - 8 secs).
14241474
/// `ReceiptNotFoundError` is treated as non-recoverable, and the transaction will be canceled using `cancel_create_new_task_tx` in that case.
@@ -1469,7 +1519,7 @@ impl Batcher {
14691519

14701520
/// Sends a transaction to Ethereum with the same nonce as the previous one to override it.
14711521
/// Retries on recoverable errors with exponential backoff.
1472-
/// Bumps the fee if not included in 3 blocks, using `calculate_bumped_gas_price`.
1522+
/// Bumps the fee if not included in 6 blocks, using `calculate_bumped_gas_price`.
14731523
/// In the first 5 attemps, bumps the fee every 3 blocks. Then exponential backoff takes over.
14741524
/// After 2 hours (attempt 13), retries occur hourly for 1 day (33 retries).
14751525
pub async fn cancel_create_new_task_tx(&self, old_tx_gas_price: U256) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub const CONSTANT_GAS_COST: u128 =
88
+ BATCHER_SUBMISSION_BASE_GAS_COST;
99
pub const DEFAULT_MAX_FEE_PER_PROOF: u128 =
1010
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * 100_000_000_000; // gas_price = 100 Gwei = 0.0000001 ether (high gas price)
11+
pub const CONNECTION_TIMEOUT: u64 = 5; // 5 secs
1112

1213
// % modifiers: (100% is x1, 10% is x0.1, 1000% is x10)
1314
pub const RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER: u128 = 250; // fee_for_aggregator -> respondToTaskFeeLimit modifier

batcher/aligned-task-sender/src/commands.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use aligned_sdk::core::types::{Network, ProvingSystemId, VerificationData};
2-
use aligned_sdk::sdk::{deposit_to_aligned, get_nonce_from_ethereum, submit_multiple};
2+
use aligned_sdk::sdk::{deposit_to_aligned, get_nonce_from_batcher, submit_multiple};
33
use ethers::prelude::*;
44
use ethers::utils::parse_ether;
55
use futures_util::StreamExt;
@@ -317,15 +317,15 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
317317
info!("Starting senders!");
318318
for (i, sender) in senders.iter().enumerate() {
319319
// this is necessary because of the move
320-
let eth_rpc_url = args.eth_rpc_url.clone();
321320
let batcher_url = args.batcher_url.clone();
322321
let wallet = sender.wallet.clone();
323322
let verification_data = verification_data.clone();
324323

325324
// a thread to send tasks from each loaded wallet:
326325
let handle = tokio::spawn(async move {
327-
let mut nonce =
328-
get_nonce_from_ethereum(&eth_rpc_url, wallet.address(), args.network.into())
326+
loop {
327+
let mut result = Vec::with_capacity(args.burst_size);
328+
let nonce = get_nonce_from_batcher(&batcher_url, wallet.address())
329329
.await
330330
.inspect_err(|e| {
331331
error!(
@@ -335,9 +335,6 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
335335
)
336336
})
337337
.unwrap();
338-
339-
loop {
340-
let mut result = Vec::with_capacity(args.burst_size);
341338
while result.len() < args.burst_size {
342339
let samples = verification_data
343340
.choose_multiple(&mut thread_rng(), args.burst_size - result.len());
@@ -365,7 +362,6 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) {
365362
match aligned_verification_data {
366363
Ok(_) => {
367364
debug!("Response received for sender {}", i);
368-
nonce += U256::from(1);
369365
}
370366
Err(e) => {
371367
error!(

config-files/config-batcher-docker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ecdsa:
1818
batcher:
1919
block_interval: 3
2020
batch_size_interval: 10
21-
transaction_wait_timeout: 36000 # 3 blocks
21+
transaction_wait_timeout: 96000 # 8 blocks
2222
max_proof_size: 67108864 # 64 MiB
2323
max_batch_byte_size: 268435456 # 256 MiB
2424
max_batch_proof_qty: 3000 # 3000 proofs in a batch

config-files/config-batcher.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ecdsa:
1818
batcher:
1919
block_interval: 3
2020
batch_size_interval: 10
21-
transaction_wait_timeout: 36000 # 3 blocks
21+
transaction_wait_timeout: 96000 # 8 blocks
2222
max_proof_size: 67108864 # 64 MiB
2323
max_batch_byte_size: 268435456 # 256 MiB
2424
max_batch_proof_qty: 3000 # 3000 proofs in a batch

contracts/script/deploy/config/holesky/aligned.holesky.config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"chainId": 17000
44
},
55
"permissions" : {
6+
"aggregator": "<aggregator_address>",
7+
"deployer": "<deployer_address>",
68
"owner": "<owner_address>",
7-
"aggregator": "<aggregator_address>",
89
"upgrader": "<upgrader_address>",
910
"churner": "<churner_address>",
1011
"ejector": "<ejector_address>",
11-
"deployer": "<deployer_address>",
1212
"pauser": "<pauser_address>",
1313
"initalPausedStatus": 0
1414
},

0 commit comments

Comments
 (0)