From 4f179043be7b8110eed3181084689ad0c5b7b30f Mon Sep 17 00:00:00 2001 From: morph <82043364+morph-dev@users.noreply.github.com> Date: Sat, 11 May 2024 19:13:43 +0300 Subject: [PATCH] feat(verkle): create verkle ProtocolId and endpoint definition --- ethportal-api/src/lib.rs | 5 +- ethportal-api/src/types/cli.rs | 1 + ethportal-api/src/types/content_key/mod.rs | 1 + ethportal-api/src/types/content_key/verkle.rs | 1 + ethportal-api/src/types/content_value/mod.rs | 1 + .../src/types/content_value/verkle.rs | 1 + ethportal-api/src/types/jsonrpc/endpoints.rs | 41 ++++++- ethportal-api/src/types/mod.rs | 1 + ethportal-api/src/types/portal_wire.rs | 6 + ethportal-api/src/types/verkle.rs | 32 +++++ ethportal-api/src/verkle.rs | 109 ++++++++++++++++++ trin-metrics/src/labels.rs | 3 + 12 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 ethportal-api/src/types/content_key/verkle.rs create mode 100644 ethportal-api/src/types/content_value/verkle.rs create mode 100644 ethportal-api/src/types/verkle.rs create mode 100644 ethportal-api/src/verkle.rs diff --git a/ethportal-api/src/lib.rs b/ethportal-api/src/lib.rs index 827a02ee9..563ee20db 100644 --- a/ethportal-api/src/lib.rs +++ b/ethportal-api/src/lib.rs @@ -17,6 +17,7 @@ pub mod state; mod test_utils; pub mod types; pub mod utils; +pub mod verkle; mod web3; pub use crate::discv5::{Discv5ApiClient, Discv5ApiServer}; @@ -24,6 +25,7 @@ pub use beacon::{BeaconNetworkApiClient, BeaconNetworkApiServer}; pub use eth::{EthApiClient, EthApiServer}; pub use history::{HistoryNetworkApiClient, HistoryNetworkApiServer}; pub use state::{StateNetworkApiClient, StateNetworkApiServer}; +pub use verkle::{VerkleNetworkApiClient, VerkleNetworkApiServer}; pub use web3::{Web3ApiClient, Web3ApiServer}; pub use types::content_key::{ @@ -40,9 +42,10 @@ pub use types::content_key::{ pub use types::{ consensus, consensus::light_client, + content_key::verkle::VerkleContentKey, content_value::{ beacon::BeaconContentValue, error::ContentValueError, history::HistoryContentValue, - state::StateContentValue, + state::StateContentValue, verkle::VerkleContentValue, }, execution::{block_body::*, header::*, receipts::*}, }; diff --git a/ethportal-api/src/types/cli.rs b/ethportal-api/src/types/cli.rs index 431b150cf..e43a449d2 100644 --- a/ethportal-api/src/types/cli.rs +++ b/ethportal-api/src/types/cli.rs @@ -19,6 +19,7 @@ pub const DEFAULT_UTP_TRANSFER_LIMIT: usize = 50; pub const BEACON_NETWORK: &str = "beacon"; pub const HISTORY_NETWORK: &str = "history"; pub const STATE_NETWORK: &str = "state"; +pub const VERKLE_NETWORK: &str = "verkle"; const DEFAULT_SUBNETWORKS: &str = "history"; pub const DEFAULT_NETWORK: &str = "mainnet"; pub const DEFAULT_STORAGE_CAPACITY_MB: &str = "100"; diff --git a/ethportal-api/src/types/content_key/mod.rs b/ethportal-api/src/types/content_key/mod.rs index aae42488a..6a391e21c 100644 --- a/ethportal-api/src/types/content_key/mod.rs +++ b/ethportal-api/src/types/content_key/mod.rs @@ -3,3 +3,4 @@ pub mod error; pub mod history; pub mod overlay; pub mod state; +pub mod verkle; diff --git a/ethportal-api/src/types/content_key/verkle.rs b/ethportal-api/src/types/content_key/verkle.rs new file mode 100644 index 000000000..576518436 --- /dev/null +++ b/ethportal-api/src/types/content_key/verkle.rs @@ -0,0 +1 @@ +pub type VerkleContentKey = Vec; diff --git a/ethportal-api/src/types/content_value/mod.rs b/ethportal-api/src/types/content_value/mod.rs index 7785340b2..e5f08cb2b 100644 --- a/ethportal-api/src/types/content_value/mod.rs +++ b/ethportal-api/src/types/content_value/mod.rs @@ -8,6 +8,7 @@ pub mod constants; pub mod error; pub mod history; pub mod state; +pub mod verkle; /// An encodable portal network content value. pub trait ContentValue: Sized { diff --git a/ethportal-api/src/types/content_value/verkle.rs b/ethportal-api/src/types/content_value/verkle.rs new file mode 100644 index 000000000..bf00b7201 --- /dev/null +++ b/ethportal-api/src/types/content_value/verkle.rs @@ -0,0 +1 @@ +pub type VerkleContentValue = Vec; diff --git a/ethportal-api/src/types/jsonrpc/endpoints.rs b/ethportal-api/src/types/jsonrpc/endpoints.rs index 6cdf5d030..777e106ec 100644 --- a/ethportal-api/src/types/jsonrpc/endpoints.rs +++ b/ethportal-api/src/types/jsonrpc/endpoints.rs @@ -1,6 +1,6 @@ use crate::{ types::enr::Enr, BeaconContentKey, BeaconContentValue, HistoryContentKey, HistoryContentValue, - StateContentKey, StateContentValue, + StateContentKey, StateContentValue, VerkleContentKey, VerkleContentValue, }; use discv5::enr::NodeId; @@ -134,3 +134,42 @@ pub enum BeaconEndpoint { /// params: [node_id] RecursiveFindNodes(NodeId), } + +/// Verkle network JSON-RPC endpoints. Start with "portal_verkle" prefix +#[derive(Debug, PartialEq, Eq, Clone)] +pub enum VerkleEndpoint { + /// params: None + RoutingTableInfo, + /// params: [enr] + Ping(Enr), + /// params: [enr] + AddEnr(Enr), + /// params: [node_id] + DeleteEnr(NodeId), + /// params: [node_id] + GetEnr(NodeId), + /// params: [node_id] + LookupEnr(NodeId), + /// params: [enr, distances] + FindNodes(Enr, Vec), + /// params: [node_id] + RecursiveFindNodes(NodeId), + /// params: None + DataRadius, + /// params: content_key + LocalContent(VerkleContentKey), + /// params: [enr, content_key] + FindContent(Enr, VerkleContentKey), + /// params: content_key + RecursiveFindContent(VerkleContentKey), + /// params: content_key + TraceRecursiveFindContent(VerkleContentKey), + /// params: [content_key, content_value] + Store(VerkleContentKey, VerkleContentValue), + /// params: [enr, content_key] + Offer(Enr, VerkleContentKey, Option), + /// params: [content_key, content_value] + Gossip(VerkleContentKey, VerkleContentValue), + /// params: [content_key, content_value] + TraceGossip(VerkleContentKey, VerkleContentValue), +} diff --git a/ethportal-api/src/types/mod.rs b/ethportal-api/src/types/mod.rs index 88885db2d..2230d77d6 100644 --- a/ethportal-api/src/types/mod.rs +++ b/ethportal-api/src/types/mod.rs @@ -17,3 +17,4 @@ pub mod portal_wire; pub mod query_trace; pub mod state; pub mod state_trie; +pub mod verkle; diff --git a/ethportal-api/src/types/portal_wire.rs b/ethportal-api/src/types/portal_wire.rs index d593c3b31..cea831353 100644 --- a/ethportal-api/src/types/portal_wire.rs +++ b/ethportal-api/src/types/portal_wire.rs @@ -172,6 +172,7 @@ pub enum ProtocolId { History, TransactionGossip, CanonicalIndices, + Verkle, Beacon, Utp, } @@ -211,6 +212,7 @@ pub static MAINNET: Lazy> = Lazy::new(|| { portal_networks.insert(ProtocolId::History, "0x500B".to_string()); portal_networks.insert(ProtocolId::TransactionGossip, "0x500C".to_string()); portal_networks.insert(ProtocolId::CanonicalIndices, "0x500D".to_string()); + portal_networks.insert(ProtocolId::Verkle, "0x0x500E".to_string()); portal_networks.insert(ProtocolId::Beacon, "0x501A".to_string()); portal_networks.insert(ProtocolId::Utp, "0x757470".to_string()); NetworkSpec { @@ -226,6 +228,7 @@ pub static TESTNET: Lazy> = Lazy::new(|| { portal_networks.insert(ProtocolId::History, "0x501B".to_string()); portal_networks.insert(ProtocolId::TransactionGossip, "0x501C".to_string()); portal_networks.insert(ProtocolId::CanonicalIndices, "0x501D".to_string()); + portal_networks.insert(ProtocolId::Verkle, "0x0x501E".to_string()); portal_networks.insert(ProtocolId::Beacon, "0x502A".to_string()); portal_networks.insert(ProtocolId::Utp, "0x757470".to_string()); NetworkSpec { @@ -242,6 +245,7 @@ impl fmt::Display for ProtocolId { ProtocolId::History => "History", ProtocolId::TransactionGossip => "Transaction Gossip", ProtocolId::CanonicalIndices => "Canonical Indices", + ProtocolId::Verkle => "Verkle", ProtocolId::Beacon => "Beacon", ProtocolId::Utp => "uTP", }; @@ -259,6 +263,7 @@ impl TryFrom for Vec { ProtocolId::History => hex_decode("0x500B"), ProtocolId::TransactionGossip => hex_decode("0x500C"), ProtocolId::CanonicalIndices => hex_decode("0x500D"), + ProtocolId::Verkle => hex_decode("0x500E"), ProtocolId::Beacon => hex_decode("0x501A"), ProtocolId::Utp => hex_decode("0x757470"), }; @@ -273,6 +278,7 @@ impl From for u8 { ProtocolId::History => 0, ProtocolId::TransactionGossip => 3, ProtocolId::CanonicalIndices => 4, + ProtocolId::Verkle => 5, ProtocolId::Beacon => 1, ProtocolId::Utp => 99, } diff --git a/ethportal-api/src/types/verkle.rs b/ethportal-api/src/types/verkle.rs new file mode 100644 index 000000000..97f095c17 --- /dev/null +++ b/ethportal-api/src/types/verkle.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; + +use crate::{types::enr::Enr, VerkleContentValue}; + +use super::query_trace::QueryTrace; + +/// Response for FindContent & RecursiveFindContent endpoints. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ContentInfo { + #[serde(rename_all = "camelCase")] + ConnectionId { connection_id: u16 }, + #[serde(rename_all = "camelCase")] + Content { + content: VerkleContentValue, + utp_transfer: bool, + }, + #[serde(rename_all = "camelCase")] + Enrs { enrs: Vec }, +} + +/// Response for TraceRecursiveFindContent endpoint. +/// +/// This struct represents the content info, and is only used when the content is found locally or +/// on the network. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct TraceContentInfo { + pub content: VerkleContentValue, + pub utp_transfer: bool, + pub trace: QueryTrace, +} diff --git a/ethportal-api/src/verkle.rs b/ethportal-api/src/verkle.rs new file mode 100644 index 000000000..a45a7b102 --- /dev/null +++ b/ethportal-api/src/verkle.rs @@ -0,0 +1,109 @@ +use crate::{ + types::{ + enr::Enr, + portal::{AcceptInfo, DataRadius, FindNodesInfo, PongInfo, TraceGossipInfo}, + verkle::{ContentInfo, TraceContentInfo}, + }, + RoutingTableInfo, VerkleContentKey, VerkleContentValue, +}; +use discv5::enr::NodeId; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; + +/// Portal Verkle JSON-RPC endpoints +#[rpc(client, server, namespace = "portal")] +pub trait VerkleNetworkApi { + /// Returns meta information about overlay routing table. + #[method(name = "verkleRoutingTableInfo")] + async fn routing_table_info(&self) -> RpcResult; + + /// Returns the node data radios + #[method(name = "verkleRadius")] + async fn radius(&self) -> RpcResult; + + /// Write an Ethereum Node Record to the overlay routing table. + #[method(name = "verkleAddEnr")] + async fn add_enr(&self, enr: Enr) -> RpcResult; + + /// Fetch the latest ENR associated with the given node ID. + #[method(name = "verkleGetEnr")] + async fn get_enr(&self, node_id: NodeId) -> RpcResult; + + /// Delete Node ID from the overlay routing table. + #[method(name = "verkleDeleteEnr")] + async fn delete_enr(&self, node_id: NodeId) -> RpcResult; + + /// Fetch the ENR representation associated with the given Node ID. + #[method(name = "verkleLookupEnr")] + async fn lookup_enr(&self, node_id: NodeId) -> RpcResult; + + /// Send a PING message to the designated node and wait for a PONG response + #[method(name = "verklePing")] + async fn ping(&self, enr: Enr) -> RpcResult; + + /// Send a FINDNODES request for nodes that fall within the given set of distances, to the + /// designated peer and wait for a response + #[method(name = "verkleFindNodes")] + async fn find_nodes(&self, enr: Enr, distances: Vec) -> RpcResult; + + /// Lookup a target node within in the network + #[method(name = "verkleRecursiveFindNodes")] + async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult>; + + /// Send FINDCONTENT message to get the content with a content key. + #[method(name = "verkleFindContent")] + async fn find_content(&self, enr: Enr, content_key: VerkleContentKey) + -> RpcResult; + + /// Lookup a target content key in the network + #[method(name = "verkleRecursiveFindContent")] + async fn recursive_find_content(&self, content_key: VerkleContentKey) + -> RpcResult; + + /// Lookup a target content key in the network. Return tracing info. + #[method(name = "verkleTraceRecursiveFindContent")] + async fn trace_recursive_find_content( + &self, + content_key: VerkleContentKey, + ) -> RpcResult; + + /// Send the provided content value to interested peers. Clients may choose to send to some or + /// all peers. Return the number of peers that the content was gossiped to. + #[method(name = "verkleGossip")] + async fn gossip( + &self, + content_key: VerkleContentKey, + content_value: VerkleContentValue, + ) -> RpcResult; + + /// Send the provided content value to interested peers. Clients may choose to send to some or + /// all peers. Return tracing info detailing the gossip propagation. + #[method(name = "verkleTraceGossip")] + async fn trace_gossip( + &self, + content_key: VerkleContentKey, + content_value: VerkleContentValue, + ) -> RpcResult; + + /// Send an OFFER request with given ContentKey, to the designated peer and wait for a response. + /// Returns the content keys bitlist upon successful content transmission or empty bitlist + /// receive. + #[method(name = "verkleOffer")] + async fn offer( + &self, + enr: Enr, + content_key: VerkleContentKey, + content_value: Option, + ) -> RpcResult; + + /// Store content key with a content data to the local database. + #[method(name = "verkleStore")] + async fn store( + &self, + content_key: VerkleContentKey, + content_value: VerkleContentValue, + ) -> RpcResult; + + /// Get a content from the local database + #[method(name = "verkleLocalContent")] + async fn local_content(&self, content_key: VerkleContentKey) -> RpcResult; +} diff --git a/trin-metrics/src/labels.rs b/trin-metrics/src/labels.rs index 3428f09cf..e3d6dec59 100644 --- a/trin-metrics/src/labels.rs +++ b/trin-metrics/src/labels.rs @@ -9,6 +9,7 @@ impl From for MetricLabel { ProtocolLabel::History => "history", ProtocolLabel::TransactionGossip => "transaction_gossip", ProtocolLabel::CanonicalIndices => "canonical_indices", + ProtocolLabel::Verkle => "verkle", ProtocolLabel::Beacon => "beacon", ProtocolLabel::Utp => "utp", } @@ -91,6 +92,7 @@ pub enum ProtocolLabel { History, TransactionGossip, CanonicalIndices, + Verkle, Beacon, Utp, } @@ -123,6 +125,7 @@ impl From<&ProtocolId> for ProtocolLabel { ProtocolId::History => Self::History, ProtocolId::TransactionGossip => Self::TransactionGossip, ProtocolId::CanonicalIndices => Self::CanonicalIndices, + ProtocolId::Verkle => Self::Verkle, ProtocolId::Beacon => Self::Beacon, ProtocolId::Utp => Self::Utp, }