Skip to content

Commit

Permalink
feat(eth69): support for ETH69 (paradigmxyz#12158)
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishekkochar <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
Abhishekkochar and mattsse authored Oct 30, 2024
1 parent 93a9b8a commit ff9a42a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
10 changes: 9 additions & 1 deletion crates/net/eth-wire-types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 16 additions & 4 deletions crates/net/eth-wire-types/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}

Expand All @@ -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`.
Expand All @@ -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())),
}
}
Expand All @@ -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())),
}
}
Expand Down Expand Up @@ -126,6 +135,7 @@ impl From<EthVersion> for &'static str {
EthVersion::Eth66 => "66",
EthVersion::Eth67 => "67",
EthVersion::Eth68 => "68",
EthVersion::Eth69 => "69",
}
}
}
Expand Down Expand Up @@ -179,14 +189,16 @@ 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]
fn test_eth_version_from_str() {
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>());
}
}
2 changes: 1 addition & 1 deletion crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}

Expand Down

0 comments on commit ff9a42a

Please sign in to comment.