forked from ethereum/trin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(verkle): create verkle ProtocolId and endpoint definition
- Loading branch information
Showing
12 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod error; | |
pub mod history; | ||
pub mod overlay; | ||
pub mod state; | ||
pub mod verkle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub type VerkleContentKey = Vec<u8>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub type VerkleContentValue = Vec<u8>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ pub mod portal_wire; | |
pub mod query_trace; | ||
pub mod state; | ||
pub mod state_trie; | ||
pub mod verkle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters