Skip to content

Commit

Permalink
feat(verkle): create verkle ProtocolId and endpoint definition
Browse files Browse the repository at this point in the history
  • Loading branch information
morph-dev committed May 11, 2024
1 parent 4186743 commit 4f17904
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ethportal-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ pub mod state;
mod test_utils;
pub mod types;
pub mod utils;
pub mod verkle;
mod web3;

pub use crate::discv5::{Discv5ApiClient, Discv5ApiServer};
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::{
Expand All @@ -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::*},
};
Expand Down
1 change: 1 addition & 0 deletions ethportal-api/src/types/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions ethportal-api/src/types/content_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod error;
pub mod history;
pub mod overlay;
pub mod state;
pub mod verkle;
1 change: 1 addition & 0 deletions ethportal-api/src/types/content_key/verkle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub type VerkleContentKey = Vec<u8>;
1 change: 1 addition & 0 deletions ethportal-api/src/types/content_value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions ethportal-api/src/types/content_value/verkle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub type VerkleContentValue = Vec<u8>;
41 changes: 40 additions & 1 deletion ethportal-api/src/types/jsonrpc/endpoints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
types::enr::Enr, BeaconContentKey, BeaconContentValue, HistoryContentKey, HistoryContentValue,
StateContentKey, StateContentValue,
StateContentKey, StateContentValue, VerkleContentKey, VerkleContentValue,
};
use discv5::enr::NodeId;

Expand Down Expand Up @@ -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<u16>),
/// 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<VerkleContentValue>),
/// params: [content_key, content_value]
Gossip(VerkleContentKey, VerkleContentValue),
/// params: [content_key, content_value]
TraceGossip(VerkleContentKey, VerkleContentValue),
}
1 change: 1 addition & 0 deletions ethportal-api/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ pub mod portal_wire;
pub mod query_trace;
pub mod state;
pub mod state_trie;
pub mod verkle;
6 changes: 6 additions & 0 deletions ethportal-api/src/types/portal_wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub enum ProtocolId {
History,
TransactionGossip,
CanonicalIndices,
Verkle,
Beacon,
Utp,
}
Expand Down Expand Up @@ -211,6 +212,7 @@ pub static MAINNET: Lazy<Arc<NetworkSpec>> = 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 {
Expand All @@ -226,6 +228,7 @@ pub static TESTNET: Lazy<Arc<NetworkSpec>> = 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 {
Expand All @@ -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",
};
Expand All @@ -259,6 +263,7 @@ impl TryFrom<ProtocolId> for Vec<u8> {
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"),
};
Expand All @@ -273,6 +278,7 @@ impl From<ProtocolId> for u8 {
ProtocolId::History => 0,
ProtocolId::TransactionGossip => 3,
ProtocolId::CanonicalIndices => 4,
ProtocolId::Verkle => 5,
ProtocolId::Beacon => 1,
ProtocolId::Utp => 99,
}
Expand Down
32 changes: 32 additions & 0 deletions ethportal-api/src/types/verkle.rs
Original file line number Diff line number Diff line change
@@ -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<Enr> },
}

/// 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,
}
109 changes: 109 additions & 0 deletions ethportal-api/src/verkle.rs
Original file line number Diff line number Diff line change
@@ -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<RoutingTableInfo>;

/// Returns the node data radios
#[method(name = "verkleRadius")]
async fn radius(&self) -> RpcResult<DataRadius>;

/// Write an Ethereum Node Record to the overlay routing table.
#[method(name = "verkleAddEnr")]
async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;

/// Fetch the latest ENR associated with the given node ID.
#[method(name = "verkleGetEnr")]
async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;

/// Delete Node ID from the overlay routing table.
#[method(name = "verkleDeleteEnr")]
async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;

/// Fetch the ENR representation associated with the given Node ID.
#[method(name = "verkleLookupEnr")]
async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;

/// Send a PING message to the designated node and wait for a PONG response
#[method(name = "verklePing")]
async fn ping(&self, enr: Enr) -> RpcResult<PongInfo>;

/// 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<u16>) -> RpcResult<FindNodesInfo>;

/// Lookup a target node within in the network
#[method(name = "verkleRecursiveFindNodes")]
async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;

/// 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<ContentInfo>;

/// Lookup a target content key in the network
#[method(name = "verkleRecursiveFindContent")]
async fn recursive_find_content(&self, content_key: VerkleContentKey)
-> RpcResult<ContentInfo>;

/// 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<TraceContentInfo>;

/// 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<u32>;

/// 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<TraceGossipInfo>;

/// 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<VerkleContentValue>,
) -> RpcResult<AcceptInfo>;

/// 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<bool>;

/// Get a content from the local database
#[method(name = "verkleLocalContent")]
async fn local_content(&self, content_key: VerkleContentKey) -> RpcResult<VerkleContentValue>;
}
3 changes: 3 additions & 0 deletions trin-metrics/src/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ impl From<ProtocolLabel> for MetricLabel {
ProtocolLabel::History => "history",
ProtocolLabel::TransactionGossip => "transaction_gossip",
ProtocolLabel::CanonicalIndices => "canonical_indices",
ProtocolLabel::Verkle => "verkle",
ProtocolLabel::Beacon => "beacon",
ProtocolLabel::Utp => "utp",
}
Expand Down Expand Up @@ -91,6 +92,7 @@ pub enum ProtocolLabel {
History,
TransactionGossip,
CanonicalIndices,
Verkle,
Beacon,
Utp,
}
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 4f17904

Please sign in to comment.