Skip to content

Commit 39cbaf9

Browse files
mskrzypkowsCopilot
andauthored
Ms/second compression for better batch fulfilment (#568)
* Second level of compression for complete batch fulfilment * v1.2.0 additional log msg * Update node/src/node/batch_manager/batch_builder.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8226e12 commit 39cbaf9

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resolver = "2"
1010
default-members = ["node"]
1111

1212
[workspace.package]
13-
version = "1.1.0"
13+
version = "1.2.0"
1414
edition = "2024"
1515
repository = "https://github.com/NethermindEth/Catalyst"
1616
license = "MIT"

node/src/node/batch_manager/batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloy::primitives::Address;
44
use std::time::Instant;
55
use tracing::{debug, warn};
66

7-
#[derive(Default)]
7+
#[derive(Default, Clone)]
88
pub struct Batch {
99
pub l2_blocks: Vec<L2Block>,
1010
pub total_bytes: u64,

node/src/node/batch_manager/batch_builder.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,21 @@ impl BatchBuilder {
6464
let mut new_total_bytes = batch.total_bytes + l2_block.prebuilt_tx_list.bytes_length;
6565

6666
if !self.config.is_within_bytes_limit(new_total_bytes) {
67+
// first compression, compressing the batch without the new L2 block
6768
batch.compress();
6869
new_total_bytes = batch.total_bytes + l2_block.prebuilt_tx_list.bytes_length;
70+
if !self.config.is_within_bytes_limit(new_total_bytes) {
71+
// second compression, compressing the batch with the new L2 block
72+
// we can tolerate the processing overhead as it's a very rare case
73+
let mut batch_clone = batch.clone();
74+
batch_clone.l2_blocks.push(l2_block.clone());
75+
batch_clone.compress();
76+
new_total_bytes = batch_clone.total_bytes;
77+
debug!(
78+
"can_consume_l2_block: Second compression, new total bytes: {}",
79+
new_total_bytes
80+
);
81+
}
6982
}
7083

7184
self.config.is_within_bytes_limit(new_total_bytes)
@@ -541,18 +554,25 @@ mod tests {
541554

542555
#[test]
543556
fn test_can_not_consume_l2_block_with_compression() {
544-
let (res, total_bytes) = test_can_consume_l2_block(377);
557+
let (res, total_bytes) = test_can_consume_l2_block(366);
545558
assert!(!res);
546559
assert_eq!(total_bytes, 242);
547560
}
548561

549562
#[test]
550-
fn test_can_consume_l2_block_with_compression() {
563+
fn test_can_consume_l2_block_with_single_compression() {
551564
let (res, total_bytes) = test_can_consume_l2_block(378);
552565
assert!(res);
553566
assert_eq!(total_bytes, 242);
554567
}
555568

569+
#[test]
570+
fn test_can_consume_l2_block_with_double_compression() {
571+
let (res, total_bytes) = test_can_consume_l2_block(367);
572+
assert!(res);
573+
assert_eq!(total_bytes, 242);
574+
}
575+
556576
#[test]
557577
fn test_can_consume_l2_block_no_compression() {
558578
let (res, total_bytes) = test_can_consume_l2_block(1000);

0 commit comments

Comments
 (0)