Skip to content

Commit 6e40a72

Browse files
authored
feat(l1): omit copying bytes when encoding transactions (#5137)
**Motivation** When encoding non-legacy transactions we need to encode the payload (txType || rlp(Transaction) as a bytes object. In order to do so we copy the payload to a `Bytes` object and then encode it in rlp, this is not needed as we can just encode the payload as bytes by invoking the implementation for [u8] directly **Description** * Avoid using `Bytes::copy_from_slice` when encoding transactions <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 -->
1 parent 05211ba commit 6e40a72

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/common/types/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl RLPEncode for P2PTransaction {
7070
fn encode(&self, buf: &mut dyn bytes::BufMut) {
7171
match self {
7272
P2PTransaction::LegacyTransaction(t) => t.encode(buf),
73-
tx => Bytes::copy_from_slice(&tx.encode_canonical_to_vec()).encode(buf),
73+
tx => <[u8] as RLPEncode>::encode(&tx.encode_canonical_to_vec(), buf),
7474
};
7575
}
7676
}
@@ -395,7 +395,7 @@ impl RLPEncode for Transaction {
395395
fn encode(&self, buf: &mut dyn bytes::BufMut) {
396396
match self {
397397
Transaction::LegacyTransaction(t) => t.encode(buf),
398-
tx => Bytes::copy_from_slice(&tx.encode_canonical_to_vec()).encode(buf),
398+
tx => <[u8] as RLPEncode>::encode(&tx.encode_canonical_to_vec(), buf),
399399
};
400400
}
401401
}

0 commit comments

Comments
 (0)