Skip to content

Commit 935ec37

Browse files
authored
Merge branch 'testnet' into hotfix/reply_channel
2 parents a49bfe5 + 986b8ed commit 935ec37

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

batcher/aligned-batcher/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use std::time::Duration;
2525
use aligned_sdk::core::constants::{
2626
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, BATCHER_SUBMISSION_BASE_GAS_COST,
2727
BUMP_BACKOFF_FACTOR, BUMP_MAX_RETRIES, BUMP_MAX_RETRY_DELAY, BUMP_MIN_RETRY_DELAY,
28-
CONNECTION_TIMEOUT, DEFAULT_MAX_FEE_PER_PROOF, ETHEREUM_CALL_BACKOFF_FACTOR,
29-
ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY, ETHEREUM_CALL_MIN_RETRY_DELAY,
30-
GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER,
28+
CBOR_ARRAY_MAX_OVERHEAD, CONNECTION_TIMEOUT, DEFAULT_MAX_FEE_PER_PROOF,
29+
ETHEREUM_CALL_BACKOFF_FACTOR, ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY,
30+
ETHEREUM_CALL_MIN_RETRY_DELAY, GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER,
3131
RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER,
3232
};
3333
use aligned_sdk::core::types::{
@@ -114,6 +114,16 @@ impl Batcher {
114114
let s3_client = s3::create_client(upload_endpoint).await;
115115

116116
let config = ConfigFromYaml::new(config_file);
117+
// Ensure max_batch_bytes_size can at least hold one proof of max_proof_size,
118+
// including the overhead introduced by serialization
119+
assert!(
120+
config.batcher.max_proof_size + CBOR_ARRAY_MAX_OVERHEAD
121+
<= config.batcher.max_batch_byte_size,
122+
"max_batch_bytes_size ({}) not big enough for one max_proof_size ({}) proof",
123+
config.batcher.max_batch_byte_size,
124+
config.batcher.max_proof_size
125+
);
126+
117127
let deployment_output =
118128
ContractDeploymentOutput::new(config.aligned_layer_deployment_config_file_path);
119129

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use aligned_sdk::{
22
communication::serialization::cbor_serialize,
3-
core::types::{NoncedVerificationData, VerificationDataCommitment},
3+
core::{
4+
constants::CBOR_ARRAY_MAX_OVERHEAD,
5+
types::{NoncedVerificationData, VerificationDataCommitment},
6+
},
47
};
58
use ethers::types::{Address, Signature, U256};
69
use priority_queue::PriorityQueue;
@@ -132,7 +135,10 @@ pub(crate) fn calculate_batch_size(batch_queue: &BatchQueue) -> Result<usize, Ba
132135
});
133136

134137
if let ControlFlow::Continue(batch_size) = folded_result {
135-
Ok(batch_size)
138+
// We over-estimate the size of the batch by at most 8 bytes.
139+
// This saves us from a scenario where we actually try to send more
140+
// than the maximum allowed bytes and get rejected by operators.
141+
Ok(CBOR_ARRAY_MAX_OVERHEAD + batch_size)
136142
} else {
137143
Err(BatcherError::SerializationError(String::from(
138144
"Could not calculate size of batch",

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ pub const DEFAULT_MAX_FEE_PER_PROOF: u128 =
1111
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * 100_000_000_000; // gas_price = 100 Gwei = 0.0000001 ether (high gas price)
1212
pub const CONNECTION_TIMEOUT: u64 = 30; // 30 secs
1313

14+
// According to:
15+
// - https://www.rfc-editor.org/rfc/rfc8949.html#section-3.1-2.10
16+
// - https://www.rfc-editor.org/rfc/rfc8949.html#section-3-3.2
17+
// - https://www.rfc-editor.org/rfc/rfc8949.html#section-3-3.4
18+
// 9 bytes are the maximum overhead from aggregating data into an array in CBOR
19+
// (it may be as little as just 1 byte, but it depends on the number of elements
20+
// and serialization parameters).
21+
pub const CBOR_ARRAY_MAX_OVERHEAD: usize = 9;
22+
1423
// % modifiers: (100% is x1, 10% is x0.1, 1000% is x10)
1524
pub const RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER: u128 = 250; // fee_for_aggregator -> respondToTaskFeeLimit modifier
1625
pub const DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER: u128 = 125; // feeForAggregator modifier

0 commit comments

Comments
 (0)