Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add documentation comments #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# ibc-grpc-server
# ibc-grpc-server
To work with IBC relayer, e.g Hermes, properly. We must implement some required grpc query services. By far, we have implemented services required by ics02_client、ics03_connection and ics04_channel.
This crate provides all these services by exposing the `run_ibc_grpc` function. To use `run_ibc_grpc`, you must implementation trait `IbcStore` first.
17 changes: 16 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! # ibc-grpc-server
//!
//! `ibc-grpc-server` exposes the grpc Query service required by cosmos IBC standards. At present,
//! the query requirements of ics02_client、ics03_connection and ics04_channel are nearly ready.

pub mod error;
mod service;
pub mod types;
Expand All @@ -18,45 +23,52 @@ use crate::types::{Path, StoreHeight};

pub type Result<T> = std::result::Result<T, ServerError>;

/// Run the gRPC server
pub async fn run_ibc_grpc<Store>(store: Store, addr: String)
where
Store: IbcStore + 'static,
{
log::info!("ibc start");
log::info!("Starting ibc grpc server.");
IbcGrpcService::new(store, addr).run().await;
}

pub trait IbcStore: Sync + Send {
/// Return an IBC light client state by height and path.
fn get_client_state(
&self,
height: StoreHeight,
path: &ClientStatePath,
) -> Result<Option<AnyClientState>>;

/// Return a consensus state associated with a client state by height and path.
fn get_consensus_state(
&self,
height: StoreHeight,
path: &ClientConsensusStatePath,
) -> Result<Option<AnyConsensusState>>;

/// Return an IBC connection end by height and path.
fn get_connection_end(
&self,
height: StoreHeight,
path: &ConnectionsPath,
) -> Result<Option<ConnectionEnd>>;

/// Return the connection ids associated with a client state by height and path.
fn get_connection_ids(
&self,
height: StoreHeight,
path: &ClientConnectionsPath,
) -> Result<Vec<ConnectionId>>;

/// Return the packet acknowledgement by height and path.
fn get_acknowledgement_commitment(
&self,
height: StoreHeight,
path: &AcksPath,
) -> Result<Option<AcknowledgementCommitment>>;

/// Return an IBC Channel by height and path.
fn get_channel_end(
&self,
height: StoreHeight,
Expand All @@ -65,13 +77,16 @@ pub trait IbcStore: Sync + Send {

fn get_opt(&self, height: StoreHeight, path: &ReceiptsPath) -> Result<Option<()>>;

/// Return the packet commitment associated with a channel by height and path.
fn get_packet_commitment(
&self,
height: StoreHeight,
path: &CommitmentsPath,
) -> Result<Option<PacketCommitment>>;

/// Return all paths with same prefix.
fn get_paths_by_prefix(&self, key_prefix: &Path) -> Result<Vec<Path>>;

/// Return the current height of the chain.
fn current_height(&self) -> u64;
}
43 changes: 28 additions & 15 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ impl<Store: IbcStore> IbcClientService<Store> {

#[tonic::async_trait]
impl<Store: IbcStore + 'static> ClientQuery for IbcClientService<Store> {
/// Queries an IBC light client.
async fn client_state(
&self,
_request: Request<QueryClientStateRequest>,
) -> Result<Response<QueryClientStateResponse>, Status> {
unimplemented!()
}

/// Queries all the IBC light clients of a chain.
async fn client_states(
&self,
request: Request<QueryClientStatesRequest>,
Expand Down Expand Up @@ -155,13 +157,17 @@ impl<Store: IbcStore + 'static> ClientQuery for IbcClientService<Store> {
}))
}

/// Queries a consensus state associated with a client state at
/// a given height.
async fn consensus_state(
&self,
_request: Request<QueryConsensusStateRequest>,
) -> Result<Response<QueryConsensusStateResponse>, Status> {
unimplemented!()
}

/// Queries all the consensus state associated with a given
/// client.
async fn consensus_states(
&self,
request: Request<QueryConsensusStatesRequest>,
Expand Down Expand Up @@ -202,34 +208,39 @@ impl<Store: IbcStore + 'static> ClientQuery for IbcClientService<Store> {
}))
}

/// Queries the height of every consensus states associated with a given client.
async fn consensus_state_heights(
&self,
_request: Request<QueryConsensusStateHeightsRequest>,
) -> Result<Response<QueryConsensusStateHeightsResponse>, Status> {
unimplemented!()
}

/// Queries the status of an IBC client.
async fn client_status(
&self,
_request: Request<QueryClientStatusRequest>,
) -> Result<Response<QueryClientStatusResponse>, Status> {
unimplemented!()
}

/// Queries all parameters of the ibc client.
async fn client_params(
&self,
_request: Request<QueryClientParamsRequest>,
) -> Result<Response<QueryClientParamsResponse>, Status> {
unimplemented!()
}

/// Queries an Upgraded IBC light client.
async fn upgraded_client_state(
&self,
_request: Request<QueryUpgradedClientStateRequest>,
) -> Result<Response<QueryUpgradedClientStateResponse>, Status> {
unimplemented!()
}

/// Queries an Upgraded IBC consensus state.
async fn upgraded_consensus_state(
&self,
_request: Request<QueryUpgradedConsensusStateRequest>,
Expand All @@ -254,6 +265,7 @@ impl<Store: IbcStore> IbcConnectionService<Store> {

#[tonic::async_trait]
impl<Store: IbcStore + 'static> ConnectionQuery for IbcConnectionService<Store> {
/// Queries an IBC connection end.
async fn connection(
&self,
request: Request<QueryConnectionRequest>,
Expand All @@ -271,6 +283,7 @@ impl<Store: IbcStore + 'static> ConnectionQuery for IbcConnectionService<Store>
}))
}

/// Queries all the IBC connections of a chain.
async fn connections(
&self,
_request: Request<QueryConnectionsRequest>,
Expand Down Expand Up @@ -310,6 +323,7 @@ impl<Store: IbcStore + 'static> ConnectionQuery for IbcConnectionService<Store>
}))
}

/// Queries the connection paths associated with a client state.
async fn client_connections(
&self,
request: Request<QueryClientConnectionsRequest>,
Expand All @@ -335,13 +349,15 @@ impl<Store: IbcStore + 'static> ConnectionQuery for IbcConnectionService<Store>
}))
}

/// Queries the client state associated with the connection.
async fn connection_client_state(
&self,
_request: Request<QueryConnectionClientStateRequest>,
) -> Result<Response<QueryConnectionClientStateResponse>, Status> {
todo!()
}

/// Queries the consensus state associated with the connection.
async fn connection_consensus_state(
&self,
_request: Request<QueryConnectionConsensusStateRequest>,
Expand Down Expand Up @@ -370,6 +386,7 @@ impl<Store: IbcStore> IbcChannelService<Store> {

#[tonic::async_trait]
impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
/// Queries an IBC Channel.
async fn channel(
&self,
request: Request<QueryChannelRequest>,
Expand All @@ -396,7 +413,7 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
}))
}

/// Channels queries all the IBC channels of a chain.
/// Queries all the IBC channels of a chain.
async fn channels(
&self,
_request: Request<QueryChannelsRequest>,
Expand Down Expand Up @@ -438,8 +455,7 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
}))
}

/// ConnectionChannels queries all the channels associated with a connection
/// end.
/// Queries all the channels associated with a connection end.
async fn connection_channels(
&self,
request: Request<QueryConnectionChannelsRequest>,
Expand Down Expand Up @@ -483,7 +499,7 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
}))
}

/// ChannelClientState queries for the client state for the channel
/// Queries for the client state for the channel
/// associated with the provided channel identifiers.
async fn channel_client_state(
&self,
Expand All @@ -492,7 +508,7 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
todo!()
}

/// ChannelConsensusState queries for the consensus state for the channel
/// Queries for the consensus state for the channel
/// associated with the provided channel identifiers.
async fn channel_consensus_state(
&self,
Expand All @@ -508,8 +524,7 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
todo!()
}

/// PacketCommitments returns all the packet commitments hashes associated
/// with a channel.
/// Returns all the packet commitments hashes associated with a channel.
async fn packet_commitments(
&self,
request: Request<QueryPacketCommitmentsRequest>,
Expand Down Expand Up @@ -572,24 +587,23 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
}))
}

/// PacketReceipt queries if a given packet sequence has been received on
/// the queried chain
/// Queries if a given packet sequence has been received on the queried chain
async fn packet_receipt(
&self,
_request: Request<QueryPacketReceiptRequest>,
) -> Result<Response<QueryPacketReceiptResponse>, Status> {
todo!()
}

/// Queries a stored packet acknowledgement hash.
async fn packet_acknowledgement(
&self,
_request: Request<QueryPacketAcknowledgementRequest>,
) -> Result<Response<QueryPacketAcknowledgementResponse>, Status> {
todo!()
}

/// PacketAcknowledgements returns all the packet acknowledgements
/// associated with a channel.
/// Returns all the packet acknowledgements associated with a channel.
async fn packet_acknowledgements(
&self,
request: Request<QueryPacketAcknowledgementsRequest>,
Expand Down Expand Up @@ -648,7 +662,7 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
}))
}

/// UnreceivedPackets returns all the unreceived IBC packets associated with
/// Returns all the unreceived IBC packets associated with
/// a channel and sequences.
///
/// QUESTION. Currently only works for unordered channels; ordered channels
Expand Down Expand Up @@ -691,7 +705,7 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
}))
}

/// UnreceivedAcks returns all the unreceived IBC acknowledgements
/// Returns all the unreceived IBC acknowledgements
/// associated with a channel and sequences.
async fn unreceived_acks(
&self,
Expand Down Expand Up @@ -733,8 +747,7 @@ impl<Store: IbcStore + 'static> ChannelQuery for IbcChannelService<Store> {
}))
}

/// NextSequenceReceive returns the next receive sequence for a given
/// channel.
/// Returns the next receive sequence for a given channel.
async fn next_sequence_receive(
&self,
_request: Request<QueryNextSequenceReceiveRequest>,
Expand Down