Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b54f280
improve rlp encoding
edg-l Nov 14, 2025
1c34ded
improve
edg-l Nov 14, 2025
65b23a1
lint
edg-l Nov 14, 2025
cf4fe74
remove another arrayvec
edg-l Nov 14, 2025
42fb6a7
docs2
edg-l Nov 14, 2025
ac21442
changelog
edg-l Nov 14, 2025
3c1fa78
more
edg-l Nov 14, 2025
0550e12
length for vec
edg-l Nov 14, 2025
4607070
improve tuples too
edg-l Nov 14, 2025
d3707c0
add specialized length for most types
edg-l Nov 14, 2025
0937315
lint
edg-l Nov 14, 2025
749655e
Merge branch 'main' into rlp_improve_encode
edg-l Nov 14, 2025
af50dc9
more tests
edg-l Nov 17, 2025
4c7de59
comment
edg-l Nov 17, 2025
1801cae
fix optionals
edg-l Nov 17, 2025
8136522
Merge remote-tracking branch 'origin/main' into rlp_improve_encode
edg-l Nov 17, 2025
c55f236
0
edg-l Nov 17, 2025
af6f7f2
replace encode_to_vec().len() calls with length(), add some tests
edg-l Nov 17, 2025
fc39cd1
length
edg-l Nov 17, 2025
89c2832
Merge branch 'main' into rlp_improve_encode
edg-l Nov 17, 2025
10a7c46
fix changelog
edg-l Nov 17, 2025
832e926
Merge branch 'main' into rlp_improve_encode
edg-l Nov 18, 2025
c2d05cc
Merge branch 'main' into rlp_improve_encode
edg-l Nov 19, 2025
d73b157
comment and fix
edg-l Nov 19, 2025
ac6d15a
comment
edg-l Nov 19, 2025
e9cdff4
Merge remote-tracking branch 'origin/rlp_improve_encode' into rlp_imp…
edg-l Nov 19, 2025
dd6368b
changelog
edg-l Nov 19, 2025
8973c25
comments2
edg-l Nov 19, 2025
2d6a390
more readable
edg-l Nov 19, 2025
d4aa7a2
fix
edg-l Nov 19, 2025
145c6aa
use ByteCounter fake BytesMut
edg-l Nov 19, 2025
f27a573
avoid division
edg-l Nov 19, 2025
f91c3c1
remove unneeded check
edg-l Nov 19, 2025
67acb70
changelog
edg-l Nov 19, 2025
b033860
Merge remote-tracking branch 'origin/main' into rlp_improve_encode
edg-l Nov 19, 2025
594a785
lint
edg-l Nov 19, 2025
83c9d45
Update crates/common/rlp/encode.rs
edg-l Nov 20, 2025
7360d8d
Update crates/common/rlp/encode.rs
edg-l Nov 20, 2025
07a6ef5
simplify and fix test
edg-l Nov 20, 2025
1d8df0a
Merge remote-tracking branch 'origin/main' into rlp_improve_encode
edg-l Nov 20, 2025
7917a07
lint
edg-l Nov 20, 2025
09c4561
Merge branch 'main' into rlp_improve_encode
edg-l Nov 21, 2025
7cec850
Merge branch 'rlp_improve_encode' into rlp_improve_encode_part2
edg-l Nov 24, 2025
4ec0d49
Merge branch 'main' into rlp_improve_encode
edg-l Nov 26, 2025
351b4e2
Merge branch 'main' into rlp_improve_encode
edg-l Nov 27, 2025
b92c79e
Merge branch 'rlp_improve_encode' into rlp_improve_encode_part2
edg-l Nov 27, 2025
8d9e63c
Merge remote-tracking branch 'origin/main' into rlp_improve_encode_part2
edg-l Nov 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Perf

### 2025-11-28

- Change some calls from `encode_to_vec().len()` to `.length()` when wanting to get the rlp encoded length [#5374](https://github.com/lambdaclass/ethrex/pull/5374)

### 2025-11-20

- Improve rlp encoding by avoiding extra loops and remove unneeded array vec, also adding a alloc-less length method the default trait impl [#5350](https://github.com/lambdaclass/ethrex/pull/5350)
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ pub fn validate_block(
.map_err(InvalidBlockError::from)?;

if chain_config.is_fork_activated(Osaka, block.header.timestamp) {
let block_rlp_size = block.encode_to_vec().len();
let block_rlp_size = block.length();
if block_rlp_size > MAX_RLP_BLOCK_SIZE as usize {
return Err(error::ChainError::InvalidBlock(
InvalidBlockError::MaximumRlpSizeExceeded(
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl PayloadBuildContext {
let vm_db = StoreVmDatabase::new(storage.clone(), parent_header);
let vm = new_evm(blockchain_type, vm_db)?;

let payload_size = payload.encode_to_vec().len() as u64;
let payload_size = payload.length() as u64;
Ok(PayloadBuildContext {
remaining_gas: payload.header.gas_limit,
receipts: vec![],
Expand Down
4 changes: 3 additions & 1 deletion crates/common/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,9 @@ mod test {
requests_hash: Some(*EMPTY_KECCACK_HASH),
..Default::default()
};
assert!(validate_block_header(&block, &parent_block, ELASTICITY_MULTIPLIER).is_ok())
assert!(validate_block_header(&block, &parent_block, ELASTICITY_MULTIPLIER).is_ok());
assert_eq!(parent_block.encode_to_vec().len(), parent_block.length());
assert_eq!(block.encode_to_vec().len(), block.length());
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions crates/common/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3445,10 +3445,12 @@ mod tests {

let encoded = PrivilegedL2Transaction::encode_to_vec(&privileged_l2);
println!("encoded length: {}", encoded.len());
assert_eq!(encoded.len(), privileged_l2.length());

let deserialized_tx = PrivilegedL2Transaction::decode(&encoded)?;

assert_eq!(deserialized_tx, privileged_l2);

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/l2/monitor/widget/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl BlocksTable {
block.header.coinbase,
block.header.gas_used,
block.header.blob_gas_used,
block.encode_to_vec().len(),
block.length(),
)
})
.collect::<Vec<_>>();
Expand Down
4 changes: 2 additions & 2 deletions crates/l2/sequencer/block_producer/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub async fn fill_transactions(
let VMType::L2(fee_config) = context.vm.vm_type else {
return Err(BlockProducerError::Custom("invalid VM type".to_string()));
};
let mut acc_encoded_size = context.payload.encode_to_vec().len();
let mut acc_encoded_size = context.payload.length();
let fee_config_len = fee_config.to_vec().len();

debug!("Fetching transactions from mempool");
Expand Down Expand Up @@ -152,7 +152,7 @@ pub async fn fill_transactions(

// Check if we have enough blob space to add this transaction
let tx: Transaction = head_tx.clone().into();
let tx_size = tx.encode_to_vec().len();
let tx_size = tx.length();
if acc_encoded_size + fee_config_len + tx_size > SAFE_BYTES_PER_BLOB {
debug!("No more blob space to run transactions");
break;
Expand Down
4 changes: 1 addition & 3 deletions crates/networking/rpc/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ impl RpcBlock {
hash: H256,
full_transactions: bool,
) -> Result<RpcBlock, RpcErr> {
let size = Block::new(header.clone(), body.clone())
.encode_to_vec()
.len();
let size = Block::new(header.clone(), body.clone()).length();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this can be done without cloning header and body. Not for this PR.

Maybe something like:

let tmp_block = Block::new(header, body);
let size = tmp_block.length();
let (header, body) = (tmp_block.header, tmp_block.body);

Ugly but I think should work.

let body_wrapper = if full_transactions {
BlockBodyWrapper::Full(FullBlockBody::from_body(body, header.number, hash)?)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/levm/src/hooks/l2_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ fn calculate_l1_fee_gas(
return Ok(0);
};

let tx_size = vm.tx.encode_to_vec().len();
let tx_size = vm.tx.length();

let l1_fee = calculate_l1_fee(fee_config, tx_size)?;
let mut l1_fee_gas = l1_fee
Expand Down