Skip to content

Commit 688b017

Browse files
committed
Merge branch 'staging' into 1314-fix-sender-receive-batchinclusiondata-or-createnewtaskerror-in-validityresponsemessage
2 parents 5a43143 + d589ea5 commit 688b017

File tree

74 files changed

+4053
-2267
lines changed

Some content is hidden

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

74 files changed

+4053
-2267
lines changed

.github/workflows/build-and-test-go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/checkout@v4
2323
- uses: actions/setup-go@v5
2424
with:
25-
go-version: "1.22"
25+
go-version: "1.23"
2626
cache: false
2727
- name: Build SP1 bindings
2828
run: make build_sp1_linux

.github/workflows/test-risc-zero-old.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v4
2626
- uses: actions/setup-go@v5
2727
with:
28-
go-version: "1.22"
28+
go-version: "1.23"
2929
cache: false
3030
- uses: actions-rs/toolchain@v1
3131
with:

.github/workflows/test-risc-zero.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v4
2626
- uses: actions/setup-go@v5
2727
with:
28-
go-version: "1.22"
28+
go-version: "1.23"
2929
cache: false
3030
- uses: actions-rs/toolchain@v1
3131
with:

Makefile

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,29 @@ anvil_upgrade_add_aggregator:
9494
@echo "Adding Aggregator to Aligned Contracts..."
9595
. contracts/scripts/anvil/upgrade_add_aggregator_to_service_manager.sh
9696

97+
pause_all_aligned_service_manager:
98+
@echo "Pausing all contracts..."
99+
. contracts/scripts/pause_aligned_service_manager.sh all
100+
101+
unpause_all_aligned_service_manager:
102+
@echo "Pausing all contracts..."
103+
. contracts/scripts/unpause_aligned_service_manager.sh all
104+
105+
get_paused_state_aligned_service_manager:
106+
@echo "Getting paused state of Aligned Service Manager contract..."
107+
. contracts/scripts/get_paused_state_aligned_service_manager.sh
108+
109+
pause_batcher_payment_service:
110+
@echo "Pausing BatcherPayments contract..."
111+
. contracts/scripts/pause_batcher_payment_service.sh
112+
113+
unpause_batcher_payment_service:
114+
@echo "Unpausing BatcherPayments contract..."
115+
. contracts/scripts/unpause_batcher_payment_service.sh
116+
117+
get_paused_state_batcher_payments_service:
118+
@echo "Getting paused state of Batcher Payments Service contract..."
119+
. contracts/scripts/get_paused_state_batcher_payments_service.sh
97120
anvil_upgrade_initialize_disable_verifiers:
98121
@echo "Initializing disabled verifiers..."
99122
. contracts/scripts/anvil/upgrade_disabled_verifiers_in_service_manager.sh
@@ -453,10 +476,18 @@ deploy_aligned_contracts: ## Deploy Aligned Contracts
453476
@echo "Deploying Aligned Contracts..."
454477
@. contracts/scripts/.env && . contracts/scripts/deploy_aligned_contracts.sh
455478

479+
deploy_pauser_registry: ## Deploy Pauser Registry
480+
@echo "Deploying Pauser Registry..."
481+
@. contracts/scripts/.env && . contracts/scripts/deploy_pauser_registry.sh
482+
456483
upgrade_aligned_contracts: ## Upgrade Aligned Contracts
457484
@echo "Upgrading Aligned Contracts..."
458485
@. contracts/scripts/.env && . contracts/scripts/upgrade_aligned_contracts.sh
459486

487+
upgrade_pauser_aligned_contracts: ## Upgrade Aligned Contracts with Pauser initialization
488+
@echo "Upgrading Aligned Contracts with Pauser initialization..."
489+
@. contracts/scripts/.env && . contracts/scripts/upgrade_add_pausable_to_service_manager.sh
490+
460491
upgrade_registry_coordinator: ## Upgrade Registry Coordinator
461492
@echo "Upgrading Registry Coordinator..."
462493
@. contracts/scripts/.env && . contracts/scripts/upgrade_registry_coordinator.sh
@@ -663,6 +694,13 @@ build_all_ffi_linux: ## Build all FFIs for Linux
663694
@echo "All Linux FFIs built successfully."
664695

665696
__EXPLORER__:
697+
698+
run_explorer_without_docker_db: explorer_ecto_setup_db
699+
@cd explorer/ && \
700+
pnpm install --prefix assets && \
701+
mix setup && \
702+
./start.sh
703+
666704
run_explorer: explorer_run_db explorer_ecto_setup_db
667705
@cd explorer/ && \
668706
pnpm install --prefix assets && \
@@ -977,11 +1015,11 @@ open_telemetry_prod_start: ## Run open telemetry services with Cassandra using t
9771015
# Elixir API
9781016
telemetry_start: telemetry_run_db telemetry_ecto_migrate ## Run Telemetry API
9791017
@cd telemetry_api && \
980-
./start.sh
1018+
./start.sh
9811019

9821020
telemetry_ecto_migrate: ##
9831021
@cd telemetry_api && \
984-
./ecto_setup_db.sh
1022+
./ecto_setup_db.sh
9851023

9861024
telemetry_build_db:
9871025
@cd telemetry_api && \

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl NonPayingConfig {
3838
#[derive(Debug, Deserialize)]
3939
pub struct BatcherConfigFromYaml {
4040
pub block_interval: u64,
41+
pub transaction_wait_timeout: u64,
4142
pub max_proof_size: usize,
4243
pub max_batch_size: usize,
4344
pub pre_verification_is_enabled: bool,

batcher/aligned-batcher/src/eth/payment_service.rs

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@ use std::sync::Arc;
44
use aligned_sdk::eth::batcher_payment_service::BatcherPaymentServiceContract;
55
use ethers::prelude::k256::ecdsa::SigningKey;
66
use ethers::prelude::*;
7-
use gas_escalator::{Frequency, GeometricGasPrice};
8-
use log::info;
9-
10-
use crate::{config::ECDSAConfig, types::errors::BatcherSendError};
11-
12-
use super::utils::{GAS_ESCALATOR_INTERVAL, GAS_MULTIPLIER};
137

148
#[derive(Debug, Clone, EthEvent)]
159
pub struct BatchVerified {
1610
pub batch_merkle_root: [u8; 32],
1711
}
1812

19-
pub type SignerMiddlewareT =
20-
SignerMiddleware<GasEscalatorMiddleware<Provider<Http>>, Wallet<SigningKey>>;
13+
pub type SignerMiddlewareT = SignerMiddleware<Provider<Http>, Wallet<SigningKey>>;
2114

2215
pub type BatcherPaymentService = BatcherPaymentServiceContract<SignerMiddlewareT>;
2316

@@ -46,58 +39,10 @@ impl CreateNewTaskFeeParams {
4639
}
4740

4841
pub async fn get_batcher_payment_service(
49-
provider: Provider<Http>,
50-
ecdsa_config: ECDSAConfig,
42+
signer: Arc<SignerMiddlewareT>,
5143
contract_address: String,
5244
) -> Result<BatcherPaymentService, anyhow::Error> {
53-
let chain_id = provider.get_chainid().await?;
54-
55-
let escalator = GeometricGasPrice::new(GAS_MULTIPLIER, GAS_ESCALATOR_INTERVAL, None::<u64>);
56-
57-
let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);
58-
59-
// get private key from keystore
60-
let wallet = Wallet::decrypt_keystore(
61-
&ecdsa_config.private_key_store_path,
62-
&ecdsa_config.private_key_store_password,
63-
)?
64-
.with_chain_id(chain_id.as_u64());
65-
66-
let signer = Arc::new(SignerMiddleware::new(provider, wallet));
67-
6845
let payment_service =
6946
BatcherPaymentService::new(H160::from_str(contract_address.as_str())?, signer);
70-
7147
Ok(payment_service)
7248
}
73-
74-
pub async fn try_create_new_task(
75-
batch_merkle_root: [u8; 32],
76-
batch_data_pointer: String,
77-
proofs_submitters: Vec<Address>,
78-
fee_params: CreateNewTaskFeeParams,
79-
payment_service: &BatcherPaymentService,
80-
) -> Result<TransactionReceipt, BatcherSendError> {
81-
let call = payment_service
82-
.create_new_task(
83-
batch_merkle_root,
84-
batch_data_pointer,
85-
proofs_submitters,
86-
fee_params.fee_for_aggregator,
87-
fee_params.fee_per_proof,
88-
fee_params.respond_to_task_fee_limit,
89-
)
90-
.gas_price(fee_params.gas_price);
91-
92-
info!("Creating task for: {}", hex::encode(batch_merkle_root));
93-
94-
let pending_tx = call.send().await.map_err(|err| match err {
95-
ContractError::Revert(err) => BatcherSendError::TransactionReverted(err.to_string()),
96-
_ => BatcherSendError::UnknownError(err.to_string()),
97-
})?;
98-
99-
pending_tx
100-
.await
101-
.map_err(|err| BatcherSendError::UnknownError(err.to_string()))?
102-
.ok_or(BatcherSendError::ReceiptNotFound)
103-
}

batcher/aligned-batcher/src/eth/service_manager.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@ use std::{str::FromStr, sync::Arc};
33
use aligned_sdk::eth::aligned_service_manager::AlignedLayerServiceManagerContract;
44
use ethers::{
55
core::k256::ecdsa::SigningKey,
6-
middleware::{
7-
gas_escalator::{Frequency, GeometricGasPrice},
8-
GasEscalatorMiddleware, SignerMiddleware,
9-
},
6+
middleware::SignerMiddleware,
107
providers::{Http, Middleware, Provider},
118
signers::{Signer, Wallet},
129
types::H160,
1310
};
1411

1512
use crate::config::ECDSAConfig;
1613

17-
use super::utils::{GAS_ESCALATOR_INTERVAL, GAS_MULTIPLIER};
18-
19-
pub type SignerMiddlewareT =
20-
SignerMiddleware<GasEscalatorMiddleware<Provider<Http>>, Wallet<SigningKey>>;
14+
pub type SignerMiddlewareT = SignerMiddleware<Provider<Http>, Wallet<SigningKey>>;
2115

2216
pub type ServiceManager = AlignedLayerServiceManagerContract<SignerMiddlewareT>;
2317

@@ -28,10 +22,6 @@ pub async fn get_service_manager(
2822
) -> Result<ServiceManager, anyhow::Error> {
2923
let chain_id = provider.get_chainid().await?;
3024

31-
let escalator = GeometricGasPrice::new(GAS_MULTIPLIER, GAS_ESCALATOR_INTERVAL, None::<u64>);
32-
33-
let provider = GasEscalatorMiddleware::new(provider, escalator, Frequency::PerBlock);
34-
3525
// get private key from keystore
3626
let wallet = Wallet::decrypt_keystore(
3727
&ecdsa_config.private_key_store_path,
Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,144 @@
11
use std::str::FromStr;
2+
use std::sync::Arc;
23

4+
use crate::{
5+
config::ECDSAConfig,
6+
retry::{
7+
batcher_retryables::{get_current_nonce_retryable, get_gas_price_retryable},
8+
retry_function,
9+
},
10+
};
11+
use aligned_sdk::core::constants::{
12+
DEFAULT_BACKOFF_FACTOR, DEFAULT_MAX_RETRIES, DEFAULT_MIN_RETRY_DELAY,
13+
GAS_PRICE_INCREMENT_PERCENTAGE_PER_ITERATION, OVERRIDE_GAS_PRICE_PERCENTAGE_MULTIPLIER,
14+
PERCENTAGE_DIVIDER,
15+
};
16+
use ethers::prelude::*;
317
use ethers::providers::{Http, Provider};
18+
use log::error;
419

5-
pub(crate) const GAS_MULTIPLIER: f64 = 1.125; // Multiplier for the gas price for gas escalator
6-
pub(crate) const GAS_ESCALATOR_INTERVAL: u64 = 12; // Time in seconds between gas escalations
20+
use super::payment_service::SignerMiddlewareT;
721

822
pub fn get_provider(eth_rpc_url: String) -> Result<Provider<Http>, anyhow::Error> {
923
let provider = Http::from_str(eth_rpc_url.as_str())
1024
.map_err(|e| anyhow::Error::msg(format!("Failed to create provider: {}", e)))?;
1125
Ok(Provider::new(provider))
1226
}
27+
28+
pub async fn get_batcher_signer(
29+
provider: Provider<Http>,
30+
ecdsa_config: ECDSAConfig,
31+
) -> anyhow::Result<Arc<SignerMiddlewareT>> {
32+
let chain_id = provider.get_chainid().await?;
33+
34+
// get private key from keystore
35+
let wallet = Wallet::decrypt_keystore(
36+
&ecdsa_config.private_key_store_path,
37+
&ecdsa_config.private_key_store_password,
38+
)?
39+
.with_chain_id(chain_id.as_u64());
40+
41+
let signer = Arc::new(SignerMiddleware::new(provider, wallet));
42+
Ok(signer)
43+
}
44+
45+
/// Calculates an increased gas price for retrying a transaction override.
46+
/// The gas price rises with each retry by applying a multiplier based on the iteration count.
47+
pub fn calculate_bumped_gas_price(
48+
previous_gas_price: U256,
49+
current_gas_price: U256,
50+
iteration: usize,
51+
) -> U256 {
52+
let override_gas_multiplier = U256::from(OVERRIDE_GAS_PRICE_PERCENTAGE_MULTIPLIER)
53+
+ (GAS_PRICE_INCREMENT_PERCENTAGE_PER_ITERATION * iteration);
54+
let bumped_previous_gas_price =
55+
previous_gas_price * override_gas_multiplier / U256::from(PERCENTAGE_DIVIDER);
56+
57+
let bumped_current_gas_price =
58+
current_gas_price * override_gas_multiplier / U256::from(PERCENTAGE_DIVIDER);
59+
// Return the maximum of the previous and current gas prices
60+
// to avoid sending a transaction with a gas price lower than the previous one.
61+
bumped_current_gas_price.max(bumped_previous_gas_price)
62+
}
63+
64+
pub async fn get_current_nonce(
65+
eth_http_provider: &Provider<Http>,
66+
eth_http_provider_fallback: &Provider<Http>,
67+
addr: H160,
68+
) -> Result<U256, ProviderError> {
69+
retry_function(
70+
|| get_current_nonce_retryable(eth_http_provider, eth_http_provider_fallback, addr),
71+
DEFAULT_MIN_RETRY_DELAY,
72+
DEFAULT_BACKOFF_FACTOR,
73+
DEFAULT_MAX_RETRIES,
74+
)
75+
.await
76+
.map_err(|e| {
77+
error!("Could't get nonce: {:?}", e);
78+
e.inner()
79+
})
80+
}
81+
82+
/// Gets the current gas price from Ethereum using exponential backoff.
83+
pub async fn get_gas_price(
84+
eth_http_provider: &Provider<Http>,
85+
eth_http_provider_fallback: &Provider<Http>,
86+
) -> Result<U256, ProviderError> {
87+
retry_function(
88+
|| get_gas_price_retryable(eth_http_provider, eth_http_provider_fallback),
89+
DEFAULT_MIN_RETRY_DELAY,
90+
DEFAULT_BACKOFF_FACTOR,
91+
DEFAULT_MAX_RETRIES,
92+
)
93+
.await
94+
.map_err(|e| {
95+
error!("Could't get gas price: {e}");
96+
e.inner()
97+
})
98+
}
99+
#[cfg(test)]
100+
mod tests {
101+
use super::*;
102+
103+
#[test]
104+
fn test_get_bumped_gas_price_initial_iteration() {
105+
let previous_gas_price = U256::from(1000);
106+
let current_gas_price = U256::from(1200);
107+
let iteration = 0;
108+
109+
let expected = U256::from(1440); // (1200 * (120 + 0)) / 100
110+
111+
assert_eq!(
112+
calculate_bumped_gas_price(previous_gas_price, current_gas_price, iteration),
113+
expected
114+
);
115+
}
116+
117+
#[test]
118+
fn test_get_bumped_gas_price_with_iteration() {
119+
let previous_gas_price = U256::from(1000);
120+
let current_gas_price = U256::from(1200);
121+
let iteration = 2;
122+
123+
let expected = U256::from(1560); // (1200 * (120 + 10) / 100
124+
125+
assert_eq!(
126+
calculate_bumped_gas_price(previous_gas_price, current_gas_price, iteration),
127+
expected
128+
);
129+
}
130+
131+
#[test]
132+
fn test_get_bumped_gas_price_previous_higher() {
133+
let previous_gas_price = U256::from(1500);
134+
let current_gas_price = U256::from(1200);
135+
let iteration = 1;
136+
137+
let expected = U256::from(1875); // (1500 * (120 + 5) / 100
138+
139+
assert_eq!(
140+
calculate_bumped_gas_price(previous_gas_price, current_gas_price, iteration),
141+
expected
142+
);
143+
}
144+
}

0 commit comments

Comments
 (0)