Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/net/eth-wire-types/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,20 @@ impl FromIterator<(TxHash, Eth68TxMetadata)> for RequestTxHashes {
}
}

/// The earliest block, the latest block and hash of the latest block which can be provided.
/// See [BlockRangeUpdate](https://github.com/ethereum/devp2p/blob/master/caps/eth.md#blockrangeupdate-0x11).
#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct BlockRangeUpdate {
/// The earliest block which is available.
pub earliest: u64,
/// The latest block which is available.
pub latest: u64,
/// Latest available block's hash.
pub latest_hash: B256,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
26 changes: 24 additions & 2 deletions crates/net/eth-wire-types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
Transactions,
};
use crate::{
status::StatusMessage, EthNetworkPrimitives, EthVersion, NetworkPrimitives,
status::StatusMessage, BlockRangeUpdate, EthNetworkPrimitives, EthVersion, NetworkPrimitives,
RawCapabilityMessage, Receipts69, SharedTransactions,
};
use alloc::{boxed::Box, sync::Arc};
Expand Down Expand Up @@ -123,6 +123,12 @@ impl<N: NetworkPrimitives> ProtocolMessage<N> {
EthMessage::Receipts69(RequestPair::decode(buf)?)
}
}
EthMessageID::BlockRangeUpdate => {
if version < EthVersion::Eth69 {
return Err(MessageError::Invalid(version, EthMessageID::BlockRangeUpdate))
}
EthMessage::BlockRangeUpdate(BlockRangeUpdate::decode(buf)?)
}
EthMessageID::Other(_) => {
let raw_payload = Bytes::copy_from_slice(buf);
buf.advance(raw_payload.len());
Expand Down Expand Up @@ -201,7 +207,7 @@ impl<N: NetworkPrimitives> From<EthBroadcastMessage<N>> for ProtocolBroadcastMes
/// [`NewPooledTransactionHashes68`] is defined.
///
/// The `eth/69` announces the historical block range served by the node. Removes total difficulty
/// information. And removes the Bloom field from receipts transfered over the protocol.
/// information. And removes the Bloom field from receipts transferred over the protocol.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EthMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
Expand Down Expand Up @@ -268,6 +274,12 @@ pub enum EthMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
serde(bound = "N::Receipt: serde::Serialize + serde::de::DeserializeOwned")
)]
Receipts69(RequestPair<Receipts69<N::Receipt>>),
/// Represents a `BlockRangeUpdate` message broadcast to the network.
#[cfg_attr(
feature = "serde",
serde(bound = "N::BroadcastedTransaction: serde::Serialize + serde::de::DeserializeOwned")
)]
BlockRangeUpdate(BlockRangeUpdate),
/// Represents an encoded message that doesn't match any other variant
Other(RawCapabilityMessage),
}
Expand All @@ -293,6 +305,7 @@ impl<N: NetworkPrimitives> EthMessage<N> {
Self::NodeData(_) => EthMessageID::NodeData,
Self::GetReceipts(_) => EthMessageID::GetReceipts,
Self::Receipts(_) | Self::Receipts69(_) => EthMessageID::Receipts,
Self::BlockRangeUpdate(_) => EthMessageID::BlockRangeUpdate,
Self::Other(msg) => EthMessageID::Other(msg.id as u8),
}
}
Expand Down Expand Up @@ -342,6 +355,7 @@ impl<N: NetworkPrimitives> Encodable for EthMessage<N> {
Self::GetReceipts(request) => request.encode(out),
Self::Receipts(receipts) => receipts.encode(out),
Self::Receipts69(receipt69) => receipt69.encode(out),
Self::BlockRangeUpdate(block_range_update) => block_range_update.encode(out),
Self::Other(unknown) => out.put_slice(&unknown.payload),
}
}
Expand All @@ -364,6 +378,7 @@ impl<N: NetworkPrimitives> Encodable for EthMessage<N> {
Self::GetReceipts(request) => request.length(),
Self::Receipts(receipts) => receipts.length(),
Self::Receipts69(receipt69) => receipt69.length(),
Self::BlockRangeUpdate(block_range_update) => block_range_update.length(),
Self::Other(unknown) => unknown.length(),
}
}
Expand Down Expand Up @@ -447,6 +462,10 @@ pub enum EthMessageID {
GetReceipts = 0x0f,
/// Represents receipts.
Receipts = 0x10,
/// Block range update.
///
/// Introduced in Eth69
BlockRangeUpdate = 0x11,
/// Represents unknown message types.
Other(u8),
}
Expand All @@ -470,6 +489,7 @@ impl EthMessageID {
Self::NodeData => 0x0e,
Self::GetReceipts => 0x0f,
Self::Receipts => 0x10,
Self::BlockRangeUpdate => 0x11,
Self::Other(value) => *value, // Return the stored `u8`
}
}
Expand Down Expand Up @@ -507,6 +527,7 @@ impl Decodable for EthMessageID {
0x0e => Self::NodeData,
0x0f => Self::GetReceipts,
0x10 => Self::Receipts,
0x11 => Self::BlockRangeUpdate,
unknown => Self::Other(*unknown),
};
buf.advance(1);
Expand Down Expand Up @@ -534,6 +555,7 @@ impl TryFrom<usize> for EthMessageID {
0x0e => Ok(Self::NodeData),
0x0f => Ok(Self::GetReceipts),
0x10 => Ok(Self::Receipts),
0x11 => Ok(Self::BlockRangeUpdate),
_ => Err("Invalid message ID"),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ impl<N: NetworkPrimitives> NetworkManager<N> {
PeerMessage::SendTransactions(_) => {
unreachable!("Not emitted by session")
}
PeerMessage::BlockRangeUpdated(_) => {}
PeerMessage::Other(other) => {
debug!(target: "net", message_id=%other.id, "Ignoring unsupported message");
}
Expand Down
10 changes: 6 additions & 4 deletions crates/net/network/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use alloy_consensus::{BlockHeader, ReceiptWithBloom};
use alloy_primitives::{Bytes, B256};
use futures::FutureExt;
use reth_eth_wire::{
message::RequestPair, BlockBodies, BlockHeaders, EthMessage, EthNetworkPrimitives,
GetBlockBodies, GetBlockHeaders, NetworkPrimitives, NewBlock, NewBlockHashes,
NewPooledTransactionHashes, NodeData, PooledTransactions, Receipts, SharedTransactions,
Transactions,
message::RequestPair, BlockBodies, BlockHeaders, BlockRangeUpdate, EthMessage,
EthNetworkPrimitives, GetBlockBodies, GetBlockHeaders, NetworkPrimitives, NewBlock,
NewBlockHashes, NewPooledTransactionHashes, NodeData, PooledTransactions, Receipts,
SharedTransactions, Transactions,
};
use reth_eth_wire_types::RawCapabilityMessage;
use reth_network_api::PeerRequest;
Expand Down Expand Up @@ -56,6 +56,8 @@ pub enum PeerMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
PooledTransactions(NewPooledTransactionHashes),
/// All `eth` request variants.
EthRequest(PeerRequest<N>),
/// Announces when `BlockRange` is updated.
BlockRangeUpdated(BlockRangeUpdate),
/// Any other or manually crafted eth message.
///
/// Caution: It is expected that this is a valid `eth_` capability message.
Expand Down
4 changes: 4 additions & 0 deletions crates/net/network/src/session/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ impl<N: NetworkPrimitives> ActiveSession<N> {
let resp = resp.map(|receipts| receipts.into_with_bloom());
on_response!(resp, GetReceipts)
}
EthMessage::BlockRangeUpdate(msg) => {
self.try_emit_broadcast(PeerMessage::BlockRangeUpdated(msg)).into()
}
EthMessage::Other(bytes) => self.try_emit_broadcast(PeerMessage::Other(bytes)).into(),
}
}
Expand Down Expand Up @@ -297,6 +300,7 @@ impl<N: NetworkPrimitives> ActiveSession<N> {
PeerMessage::SendTransactions(msg) => {
self.queued_outgoing.push_back(EthBroadcastMessage::Transactions(msg).into());
}
PeerMessage::BlockRangeUpdated(_) => {}
PeerMessage::ReceivedTransaction(_) => {
unreachable!("Not emitted by network")
}
Expand Down
Loading