feat: add rlp support for EthVersion (#12221)

This commit is contained in:
Léa Narzis
2024-10-31 15:33:33 +07:00
committed by GitHub
parent e5fc048139
commit c19af293a6
7 changed files with 89 additions and 22 deletions

View File

@ -5,6 +5,7 @@ use crate::{
};
use alloy_primitives::B256;
use reth_chainspec::Chain;
use reth_eth_wire_types::EthVersion;
use reth_primitives::{GotExpected, GotExpectedBoxed, ValidationError};
use std::io;
@ -88,7 +89,7 @@ pub enum EthHandshakeError {
MismatchedGenesis(GotExpectedBoxed<B256>),
#[error("mismatched protocol version in status message: {0}")]
/// Mismatched protocol versions in status messages.
MismatchedProtocolVersion(GotExpected<u8>),
MismatchedProtocolVersion(GotExpected<EthVersion>),
#[error("mismatched chain in status message: {0}")]
/// Mismatch in chain details in status messages.
MismatchedChain(GotExpected<Chain>),

View File

@ -102,7 +102,7 @@ where
return Err(EthStreamError::MessageTooBig(their_msg.len()))
}
let version = EthVersion::try_from(status.version)?;
let version = status.version;
let msg = match ProtocolMessage::decode_message(version, &mut their_msg.as_ref()) {
Ok(m) => m,
Err(err) => {
@ -368,7 +368,7 @@ mod tests {
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
let status = Status {
version: EthVersion::Eth67 as u8,
version: EthVersion::Eth67,
chain: NamedChain::Mainnet.into(),
total_difficulty: U256::ZERO,
blockhash: B256::random(),
@ -415,7 +415,7 @@ mod tests {
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
let status = Status {
version: EthVersion::Eth67 as u8,
version: EthVersion::Eth67,
chain: NamedChain::Mainnet.into(),
total_difficulty: U256::from(2).pow(U256::from(100)) - U256::from(1),
blockhash: B256::random(),
@ -462,7 +462,7 @@ mod tests {
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
let status = Status {
version: EthVersion::Eth67 as u8,
version: EthVersion::Eth67,
chain: NamedChain::Mainnet.into(),
total_difficulty: U256::from(2).pow(U256::from(100)),
blockhash: B256::random(),
@ -603,7 +603,7 @@ mod tests {
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
let status = Status {
version: EthVersion::Eth67 as u8,
version: EthVersion::Eth67,
chain: NamedChain::Mainnet.into(),
total_difficulty: U256::ZERO,
blockhash: B256::random(),
@ -674,7 +674,7 @@ mod tests {
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
let status = Status {
version: EthVersion::Eth67 as u8,
version: EthVersion::Eth67,
chain: NamedChain::Mainnet.into(),
total_difficulty: U256::ZERO,
blockhash: B256::random(),

View File

@ -37,7 +37,7 @@ pub fn eth_handshake() -> (Status, ForkFilter) {
let fork_filter = ForkFilter::new(Head::default(), genesis, 0, Vec::new());
let status = Status {
version: EthVersion::Eth67 as u8,
version: EthVersion::Eth67,
chain: Chain::mainnet(),
total_difficulty: U256::ZERO,
blockhash: B256::random(),