Skip to content

Commit aabf944

Browse files
committed
fix(eigen_bundler): add tests and fix edge case during bundling
1 parent 28248fd commit aabf944

File tree

12 files changed

+486
-41
lines changed

12 files changed

+486
-41
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ base64 = { version = "0.22.1", default-features = false }
5454
bitvec = { version = "1.0", default-features = false }
5555
bytesize = { version = "1.3", default-features = false }
5656
alloy = { version = "0.3.6", default-features = false }
57+
derive_more = { version = "2.0.1", default-features = false }
5758
xdg = { version = "2.5", default-features = false }
5859
proptest = { version = "1.0", default-features = false }
5960
rayon = { version = "1.10", default-features = false }

committer/src/errors.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub enum Error {
1111
Network(String),
1212
#[error("Storage error: {0}")]
1313
Storage(String),
14+
#[error("Block validation error: {0}")]
15+
BlockValidation(String),
16+
#[error("Bundler error: {0}")]
17+
Bundler(String),
1418
}
1519

1620
pub trait WithContext<T> {
@@ -43,7 +47,9 @@ impl From<services::Error> for Error {
4347
match error {
4448
services::Error::Network(e) => Self::Network(e),
4549
services::Error::Storage(e) => Self::Storage(e),
46-
services::Error::BlockValidation(e) | services::Error::Other(e) => Self::Other(e),
50+
services::Error::BlockValidation(e) => Self::BlockValidation(e),
51+
services::Error::Bundler(e) => Self::Bundler(e),
52+
services::Error::Other(e) => Self::Other(e.to_string()),
4753
}
4854
}
4955
}
@@ -69,6 +75,10 @@ impl<T> WithContext<T> for Result<T> {
6975
Error::Other(e) => Error::Other(format!("{}: {}", context(), e)),
7076
Error::Network(e) => Error::Network(format!("{}: {}", context(), e)),
7177
Error::Storage(e) => Error::Storage(format!("{}: {}", context(), e)),
78+
Error::BlockValidation(e) => {
79+
Error::BlockValidation(format!("{}: {}", context(), e))
80+
}
81+
Error::Bundler(e) => Error::Bundler(format!("{}: {}", context(), e)),
7282
};
7383
Err(new_err)
7484
} else {

packages/encoding/src/bundle/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Decoder {
4141

4242
#[cfg(test)]
4343
mod tests {
44-
use crate::bundle::{Bundle, BundleV1, Encoder};
44+
use crate::bundle::{Bundle, BundleEncoder, BundleV1, Encoder};
4545

4646
#[test]
4747
fn complains_about_unsupported_version() {

packages/encoding/src/bundle/encoder.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ impl Default for Encoder {
1616
}
1717
}
1818

19+
/// Trait for encoding a bundle into a compressed byte vector.
20+
pub trait BundleEncoder {
21+
type Error: ToString + Send + Sync + 'static;
22+
23+
/// Encodes the given bundle into a compressed byte vector.
24+
fn encode(&self, bundle: Bundle) -> Result<Vec<u8>, Self::Error>;
25+
/// Compresses the given data using the configured compression level.
26+
fn compress(&self, data: &[u8]) -> Result<Vec<u8>, Self::Error>;
27+
}
28+
1929
impl Encoder {
2030
pub fn new(level: CompressionLevel) -> Self {
2131
let level = match level {
@@ -36,8 +46,12 @@ impl Encoder {
3646
compression_level: level.map(Compression::new),
3747
}
3848
}
49+
}
50+
51+
impl BundleEncoder for Encoder {
52+
type Error = anyhow::Error;
3953

40-
pub fn encode(&self, bundle: Bundle) -> anyhow::Result<Vec<u8>> {
54+
fn encode(&self, bundle: Bundle) -> anyhow::Result<Vec<u8>> {
4155
const VERSION_SIZE: usize = std::mem::size_of::<u16>();
4256

4357
let Bundle::V1(v1) = bundle;
@@ -150,7 +164,7 @@ impl CompressionLevel {
150164

151165
#[cfg(test)]
152166
mod tests {
153-
use crate::bundle::{CompressionLevel, Encoder};
167+
use crate::bundle::{BundleEncoder, CompressionLevel, Encoder};
154168

155169
#[test]
156170
fn can_disable_compression() {

packages/encoding/tests/public_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod tests {
44
use bitvec::{order::Msb0, vec::BitVec};
55
use fuel_block_committer_encoding::{
66
blob::{self, generate_sidecar},
7-
bundle::{self, BundleV1},
7+
bundle::{self, BundleEncoder, BundleV1},
88
};
99
use itertools::Itertools;
1010
use proptest::prelude::*;

packages/services/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ tracing = { workspace = true }
3333
trait-variant = { workspace = true }
3434

3535
[dev-dependencies]
36+
derive_more = { workspace = true, features = ["error", "display"] }
3637
test-case = { workspace = true }
3738
clock = { workspace = true, features = ["test-helpers"] }
3839
eth = { workspace = true, features = ["test-helpers"] }

packages/services/src/block_bundler/bundler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{cmp::min, collections::VecDeque, num::NonZeroUsize};
22

3-
use fuel_block_committer_encoding::bundle::{self, BundleV1};
3+
use fuel_block_committer_encoding::bundle::{self, BundleEncoder, BundleV1};
44
use itertools::Itertools;
55
use rayon::prelude::*;
66

0 commit comments

Comments
 (0)