feat(eth69): support for ETH69 (#12158)

Signed-off-by: Abhishekkochar <abhishekkochar2@gmail.com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Abhishek kochar
2024-10-30 22:13:03 +08:00
committed by GitHub
parent 93a9b8a218
commit ff9a42ae8f
3 changed files with 26 additions and 6 deletions

View File

@ -50,9 +50,17 @@ impl ProtocolMessage {
let message = match message_type {
EthMessageID::Status => EthMessage::Status(Status::decode(buf)?),
EthMessageID::NewBlockHashes => {
if version.is_eth69() {
return Err(MessageError::Invalid(version, EthMessageID::NewBlockHashes));
}
EthMessage::NewBlockHashes(NewBlockHashes::decode(buf)?)
}
EthMessageID::NewBlock => EthMessage::NewBlock(Box::new(NewBlock::decode(buf)?)),
EthMessageID::NewBlock => {
if version.is_eth69() {
return Err(MessageError::Invalid(version, EthMessageID::NewBlock));
}
EthMessage::NewBlock(Box::new(NewBlock::decode(buf)?))
}
EthMessageID::Transactions => EthMessage::Transactions(Transactions::decode(buf)?),
EthMessageID::NewPooledTransactionHashes => {
if version >= EthVersion::Eth68 {

View File

@ -18,12 +18,12 @@ pub struct ParseVersionError(String);
pub enum EthVersion {
/// The `eth` protocol version 66.
Eth66 = 66,
/// The `eth` protocol version 67.
Eth67 = 67,
/// The `eth` protocol version 68.
Eth68 = 68,
/// The `eth` protocol version 69.
Eth69 = 69,
}
impl EthVersion {
@ -38,6 +38,8 @@ impl EthVersion {
// eth/67,68 are eth/66 minus GetNodeData and NodeData messages
13
}
// eth69 is both eth67 and eth68 minus NewBlockHashes and NewBlock
Self::Eth69 => 11,
}
}
@ -55,6 +57,11 @@ impl EthVersion {
pub const fn is_eth68(&self) -> bool {
matches!(self, Self::Eth68)
}
/// Returns true if the version is eth/69
pub const fn is_eth69(&self) -> bool {
matches!(self, Self::Eth69)
}
}
/// Allow for converting from a `&str` to an `EthVersion`.
@ -75,6 +82,7 @@ impl TryFrom<&str> for EthVersion {
"66" => Ok(Self::Eth66),
"67" => Ok(Self::Eth67),
"68" => Ok(Self::Eth68),
"69" => Ok(Self::Eth69),
_ => Err(ParseVersionError(s.to_string())),
}
}
@ -98,6 +106,7 @@ impl TryFrom<u8> for EthVersion {
66 => Ok(Self::Eth66),
67 => Ok(Self::Eth67),
68 => Ok(Self::Eth68),
69 => Ok(Self::Eth69),
_ => Err(ParseVersionError(u.to_string())),
}
}
@ -126,6 +135,7 @@ impl From<EthVersion> for &'static str {
EthVersion::Eth66 => "66",
EthVersion::Eth67 => "67",
EthVersion::Eth68 => "68",
EthVersion::Eth69 => "69",
}
}
}
@ -179,7 +189,8 @@ mod tests {
assert_eq!(EthVersion::Eth66, EthVersion::try_from("66").unwrap());
assert_eq!(EthVersion::Eth67, EthVersion::try_from("67").unwrap());
assert_eq!(EthVersion::Eth68, EthVersion::try_from("68").unwrap());
assert_eq!(Err(ParseVersionError("69".to_string())), EthVersion::try_from("69"));
assert_eq!(EthVersion::Eth69, EthVersion::try_from("69").unwrap());
assert_eq!(Err(ParseVersionError("70".to_string())), EthVersion::try_from("70"));
}
#[test]
@ -187,6 +198,7 @@ mod tests {
assert_eq!(EthVersion::Eth66, "66".parse().unwrap());
assert_eq!(EthVersion::Eth67, "67".parse().unwrap());
assert_eq!(EthVersion::Eth68, "68".parse().unwrap());
assert_eq!(Err(ParseVersionError("69".to_string())), "69".parse::<EthVersion>());
assert_eq!(EthVersion::Eth69, "69".parse().unwrap());
assert_eq!(Err(ParseVersionError("70".to_string())), "70".parse::<EthVersion>());
}
}

View File

@ -1668,7 +1668,7 @@ impl PooledTransactionsHashesBuilder {
fn new(version: EthVersion) -> Self {
match version {
EthVersion::Eth66 | EthVersion::Eth67 => Self::Eth66(Default::default()),
EthVersion::Eth68 => Self::Eth68(Default::default()),
EthVersion::Eth68 | EthVersion::Eth69 => Self::Eth68(Default::default()),
}
}