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

Track ibc-rs PR 774 #122

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cosmrs = "0.14.0"
displaydoc = { version = "0.2", default-features = false }
derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] }
ed25519 = { version = "2.1.0", default-features = false }
ibc = { git = "https://github.com/cosmos/ibc-rs.git", rev= "12317a0" }
ibc = { git = "https://github.com/cosmos/ibc-rs.git", rev= "41e052a" }
ibc-proto = { version = "0.32.1", default-features = false, features = ["server", "proto-descriptor"] }
ics23 = { version = "0.10.1", default-features = false, features = ["host-functions"] }
primitive-types = { version = "0.12.0", default-features = false, features = ["serde_no_std"] }
Expand Down
176 changes: 89 additions & 87 deletions src/modules/ibc/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ where
S: 'static + ProvableStore + Default + Debug,
{
pub fn new(store: SharedStore<S>, bank_keeper: BankBalanceKeeper<S>) -> Self {
let transfer_module = IbcTransferModule::new(store.clone(), bank_keeper);
let transfer_module = IbcTransferModule::new(bank_keeper);
let router = IbcRouter::new(transfer_module);

Self {
Expand All @@ -120,90 +120,6 @@ where
}
}

/// The IBC module
///
/// Implements all IBC-rs validation and execution contexts and gRPC endpoints
/// required by `hermes` as well.
#[derive(Clone)]
pub struct IbcContext<S>
where
S: Store + Send + Sync + Debug,
{
/// Handle to store instance.
/// The module is guaranteed exclusive access to all paths in the store key-space.
pub store: SharedStore<S>,
/// Counter for clients
client_counter: u64,
/// Counter for connections
conn_counter: u64,
/// Counter for channels
channel_counter: u64,
/// Tracks the processed time for client updates
client_processed_times: HashMap<(ClientId, IbcHeight), Timestamp>,
/// Tracks the processed height for client updates
client_processed_heights: HashMap<(ClientId, IbcHeight), IbcHeight>,
/// Map of host consensus states
consensus_states: HashMap<u64, TmConsensusState>,
/// A typed-store for AnyClientState
pub client_state_store: ProtobufStore<SharedStore<S>, ClientStatePath, TmClientState, Any>,
/// A typed-store for AnyConsensusState
pub consensus_state_store:
ProtobufStore<SharedStore<S>, ClientConsensusStatePath, TmConsensusState, Any>,
/// A typed-store for ConnectionEnd
connection_end_store:
ProtobufStore<SharedStore<S>, ConnectionPath, ConnectionEnd, RawConnectionEnd>,
/// A typed-store for ConnectionIds
connection_ids_store: JsonStore<SharedStore<S>, ClientConnectionPath, Vec<ConnectionId>>,
/// A typed-store for ChannelEnd
channel_end_store: ProtobufStore<SharedStore<S>, ChannelEndPath, ChannelEnd, RawChannelEnd>,
/// A typed-store for send sequences
send_sequence_store: JsonStore<SharedStore<S>, SeqSendPath, Sequence>,
/// A typed-store for receive sequences
recv_sequence_store: JsonStore<SharedStore<S>, SeqRecvPath, Sequence>,
/// A typed-store for ack sequences
ack_sequence_store: JsonStore<SharedStore<S>, SeqAckPath, Sequence>,
/// A typed-store for packet commitments
packet_commitment_store: BinStore<SharedStore<S>, CommitmentPath, PacketCommitment>,
/// A typed-store for packet receipts
packet_receipt_store: TypedSet<SharedStore<S>, ReceiptPath>,
/// A typed-store for packet ack
packet_ack_store: BinStore<SharedStore<S>, AckPath, AcknowledgementCommitment>,
/// IBC Events
pub(crate) events: Vec<IbcEvent>,
/// message logs
logs: Vec<String>,
}

impl<S> IbcContext<S>
where
S: 'static + ProvableStore + Default + Debug,
{
pub fn new(store: SharedStore<S>) -> Self {
Self {
client_counter: 0,
conn_counter: 0,
channel_counter: 0,
client_processed_times: Default::default(),
client_processed_heights: Default::default(),
consensus_states: Default::default(),
client_state_store: TypedStore::new(store.clone()),
consensus_state_store: TypedStore::new(store.clone()),
connection_end_store: TypedStore::new(store.clone()),
connection_ids_store: TypedStore::new(store.clone()),
channel_end_store: TypedStore::new(store.clone()),
send_sequence_store: TypedStore::new(store.clone()),
recv_sequence_store: TypedStore::new(store.clone()),
ack_sequence_store: TypedStore::new(store.clone()),
packet_commitment_store: TypedStore::new(store.clone()),
packet_receipt_store: TypedStore::new(store.clone()),
packet_ack_store: TypedStore::new(store.clone()),
store,
events: Vec::new(),
logs: Vec::new(),
}
}
}

impl<S> Ibc<S>
where
S: ProvableStore + Debug,
Expand Down Expand Up @@ -246,8 +162,10 @@ where
.get_transfer_module_mut()
.expect("Failed to get the transfer module");

send_transfer(transfer_module, transfer_msg).map_err(|e| AppError::Custom {
reason: e.to_string(),
send_transfer(&mut self.ctx, transfer_module, transfer_msg).map_err(|e| {
AppError::Custom {
reason: e.to_string(),
}
})?;

Ok(transfer_module
Expand Down Expand Up @@ -328,6 +246,90 @@ where
}
}

/// The IBC module
///
/// Implements all IBC-rs validation and execution contexts and gRPC endpoints
/// required by `hermes` as well.
#[derive(Clone)]
pub struct IbcContext<S>
where
S: Store + Send + Sync + Debug,
{
/// Handle to store instance.
/// The module is guaranteed exclusive access to all paths in the store key-space.
pub store: SharedStore<S>,
/// Counter for clients
client_counter: u64,
/// Counter for connections
conn_counter: u64,
/// Counter for channels
channel_counter: u64,
/// Tracks the processed time for client updates
client_processed_times: HashMap<(ClientId, IbcHeight), Timestamp>,
/// Tracks the processed height for client updates
client_processed_heights: HashMap<(ClientId, IbcHeight), IbcHeight>,
/// Map of host consensus states
consensus_states: HashMap<u64, TmConsensusState>,
/// A typed-store for AnyClientState
pub client_state_store: ProtobufStore<SharedStore<S>, ClientStatePath, TmClientState, Any>,
/// A typed-store for AnyConsensusState
pub consensus_state_store:
ProtobufStore<SharedStore<S>, ClientConsensusStatePath, TmConsensusState, Any>,
/// A typed-store for ConnectionEnd
connection_end_store:
ProtobufStore<SharedStore<S>, ConnectionPath, ConnectionEnd, RawConnectionEnd>,
/// A typed-store for ConnectionIds
connection_ids_store: JsonStore<SharedStore<S>, ClientConnectionPath, Vec<ConnectionId>>,
/// A typed-store for ChannelEnd
channel_end_store: ProtobufStore<SharedStore<S>, ChannelEndPath, ChannelEnd, RawChannelEnd>,
/// A typed-store for send sequences
send_sequence_store: JsonStore<SharedStore<S>, SeqSendPath, Sequence>,
/// A typed-store for receive sequences
recv_sequence_store: JsonStore<SharedStore<S>, SeqRecvPath, Sequence>,
/// A typed-store for ack sequences
ack_sequence_store: JsonStore<SharedStore<S>, SeqAckPath, Sequence>,
/// A typed-store for packet commitments
packet_commitment_store: BinStore<SharedStore<S>, CommitmentPath, PacketCommitment>,
/// A typed-store for packet receipts
packet_receipt_store: TypedSet<SharedStore<S>, ReceiptPath>,
/// A typed-store for packet ack
packet_ack_store: BinStore<SharedStore<S>, AckPath, AcknowledgementCommitment>,
/// IBC Events
pub(crate) events: Vec<IbcEvent>,
/// message logs
logs: Vec<String>,
}

impl<S> IbcContext<S>
where
S: 'static + ProvableStore + Default + Debug,
{
pub fn new(store: SharedStore<S>) -> Self {
Self {
client_counter: 0,
conn_counter: 0,
channel_counter: 0,
client_processed_times: Default::default(),
client_processed_heights: Default::default(),
consensus_states: Default::default(),
client_state_store: TypedStore::new(store.clone()),
consensus_state_store: TypedStore::new(store.clone()),
connection_end_store: TypedStore::new(store.clone()),
connection_ids_store: TypedStore::new(store.clone()),
channel_end_store: TypedStore::new(store.clone()),
send_sequence_store: TypedStore::new(store.clone()),
recv_sequence_store: TypedStore::new(store.clone()),
ack_sequence_store: TypedStore::new(store.clone()),
packet_commitment_store: TypedStore::new(store.clone()),
packet_receipt_store: TypedStore::new(store.clone()),
packet_ack_store: TypedStore::new(store.clone()),
store,
events: Vec::new(),
logs: Vec::new(),
}
}
}

pub(crate) struct TmEvent(pub TendermintEvent);

impl From<TmEvent> for Event {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/ibc/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct IbcRouter<S>
where
S: Store + Send + Sync + Debug,
{
transfer: Arc<IbcTransferModule<S, BankBalanceKeeper<S>>>,
transfer: Arc<IbcTransferModule<BankBalanceKeeper<S>>>,

/// Mapping of which IBC modules own which port
port_to_module_map: BTreeMap<PortId, ModuleId>,
Expand All @@ -29,7 +29,7 @@ impl<S> IbcRouter<S>
where
S: 'static + Store + Send + Sync + Debug,
{
pub fn new(transfer: IbcTransferModule<S, BankBalanceKeeper<S>>) -> Self {
pub fn new(transfer: IbcTransferModule<BankBalanceKeeper<S>>) -> Self {
let mut port_to_module_map = BTreeMap::default();
let transfer_module_id: ModuleId = ModuleId::new(IBC_TRANSFER_MODULE_ID.to_string());
port_to_module_map.insert(PortId::transfer(), transfer_module_id);
Expand All @@ -42,7 +42,7 @@ where

pub fn get_transfer_module_mut(
&mut self,
) -> Option<&mut IbcTransferModule<S, BankBalanceKeeper<S>>> {
) -> Option<&mut IbcTransferModule<BankBalanceKeeper<S>>> {
match Arc::get_mut(&mut self.transfer) {
Some(m) => Some(m),
None => None,
Expand Down
Loading