mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf: replace BytesMut with alloy_rlp::encode (#7432)
This commit is contained in:
committed by
GitHub
parent
f71d9c0003
commit
933317c62a
@ -1702,7 +1702,6 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use alloy_primitives::{address, b256, bytes};
|
use alloy_primitives::{address, b256, bytes};
|
||||||
use alloy_rlp::{Decodable, Encodable, Error as RlpError};
|
use alloy_rlp::{Decodable, Encodable, Error as RlpError};
|
||||||
use bytes::BytesMut;
|
|
||||||
use reth_codecs::Compact;
|
use reth_codecs::Compact;
|
||||||
use secp256k1::{KeyPair, Secp256k1};
|
use secp256k1::{KeyPair, Secp256k1};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -1963,10 +1962,8 @@ mod tests {
|
|||||||
let tx = TransactionSigned::decode(&mut &input[..]).unwrap();
|
let tx = TransactionSigned::decode(&mut &input[..]).unwrap();
|
||||||
let recovered = tx.into_ecrecovered().unwrap();
|
let recovered = tx.into_ecrecovered().unwrap();
|
||||||
|
|
||||||
let mut encoded = BytesMut::new();
|
let decoded =
|
||||||
recovered.encode(&mut encoded);
|
TransactionSignedEcRecovered::decode(&mut &alloy_rlp::encode(&recovered)[..]).unwrap();
|
||||||
|
|
||||||
let decoded = TransactionSignedEcRecovered::decode(&mut &encoded[..]).unwrap();
|
|
||||||
assert_eq!(recovered, decoded)
|
assert_eq!(recovered, decoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -352,10 +352,7 @@ pub struct UnauthedP2PStream<S> {
|
|||||||
impl<S> UnauthedP2PStream<S> {
|
impl<S> UnauthedP2PStream<S> {
|
||||||
// ...
|
// ...
|
||||||
pub async fn handshake(mut self, hello: HelloMessage) -> Result<(P2PStream<S>, HelloMessage), Error> {
|
pub async fn handshake(mut self, hello: HelloMessage) -> Result<(P2PStream<S>, HelloMessage), Error> {
|
||||||
let mut raw_hello_bytes = BytesMut::new();
|
self.inner.send(alloy_rlp::encode(P2PMessage::Hello(hello.clone())).into()).await?;
|
||||||
P2PMessage::Hello(hello.clone()).encode(&mut raw_hello_bytes);
|
|
||||||
|
|
||||||
self.inner.send(raw_hello_bytes.into()).await?;
|
|
||||||
let first_message_bytes = tokio::time::timeout(HANDSHAKE_TIMEOUT, self.inner.next()).await;
|
let first_message_bytes = tokio::time::timeout(HANDSHAKE_TIMEOUT, self.inner.next()).await;
|
||||||
|
|
||||||
let their_hello = match P2PMessage::decode(&mut &first_message_bytes[..]) {
|
let their_hello = match P2PMessage::decode(&mut &first_message_bytes[..]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user