Skip to content

Commit

Permalink
solana-ibc: upgrade to latest ibc away from fork (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 authored Oct 11, 2023
1 parent 4184314 commit 274b60b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ incremental = false
codegen-units = 1

[workspace.dependencies]
anchor-lang = {version = "0.28.0", features = ["init-if-needed"]}
base64 = { version = "0.21", default-features = false, features = ["alloc"] }
bincode = "1.3.3"
borsh = { version = "0.10.3", default-features = false }
derive_more = "0.99.17"
ibc = { version = "0.45.0", default-features = false, features = ["serde"] }
ibc-proto = { version = "0.35.0", default-features = false, features = ["serde"] }
pretty_assertions = "1.4.0"
rand = { version = "0.8.5" }
serde = "1"
serde_json = "1"
sha2 = { version = "0.10.7", default-features = false }
solana-client = "1.16.14"
solana-program = "1.16.14"
solana-sdk = "1.16.14"
strum = { version = "0.25.0", default-features = false, features = ["derive"] }
anchor-lang = {version = "0.28.0", features = ["init-if-needed"]}
bincode = "1.3.3"
ibc = { git = "https://github.com/dhruvja/ibc-rs", features = ["serde", "borsh", "mocks"] }
ibc-proto = { git = "https://github.com/dhruvja/ibc-proto-rs", default-features = false, features = ["serde", "borsh"] }
serde = "1"
serde_json = "1"

lib = { path = "common/lib" }
memory = { path = "common/memory" }
Expand All @@ -50,4 +50,4 @@ anyhow = "1.0.32"

[patch.crates-io]
curve25519-dalek = { git = "https://github.com/dhruvja/curve25519-dalek", branch = "master" }
aes-gcm-siv = { git = "https://github.com/dhruvja/AEADs", branch = "main-aes-gcm-siv-v0.10.3" }
aes-gcm-siv = { git = "https://github.com/dhruvja/AEADs", branch = "main-aes-gcm-siv-v0.10.3" }
4 changes: 1 addition & 3 deletions solana/solana-ibc/programs/solana-ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ serde_json.workspace = true
[dev-dependencies]
anchor-client.workspace = true
anyhow.workspace = true



ibc = { workspace = true, features = ["mocks", "std"] }
55 changes: 25 additions & 30 deletions solana/solana-ibc/programs/solana-ibc/src/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ibc::core::ics24_host::path::{
SeqRecvPath, SeqSendPath,
};
use ibc::core::timestamp::Timestamp;
use ibc::core::{ContextError, ExecutionContext, ValidationContext};
use ibc::core::{ExecutionContext, ValidationContext};
use ibc::Height;

use crate::client_state::AnyClientState;
Expand All @@ -29,6 +29,8 @@ use crate::{
InnerSequence, SolanaIbcStorage, SolanaTimestamp,
};

type Result<T = (), E = ibc::core::ContextError> = core::result::Result<T, E>;

impl ClientExecutionContext for SolanaIbcStorage {
type ClientValidationContext = Self;
type AnyClientState = AnyClientState;
Expand All @@ -38,7 +40,7 @@ impl ClientExecutionContext for SolanaIbcStorage {
&mut self,
client_state_path: ClientStatePath,
client_state: Self::AnyClientState,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_client_state - path: {}, client_state: {:?}",
client_state_path,
Expand All @@ -55,7 +57,7 @@ impl ClientExecutionContext for SolanaIbcStorage {
&mut self,
consensus_state_path: ClientConsensusStatePath,
consensus_state: Self::AnyConsensusState,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!("{}-{}", consensus_state_path.epoch, consensus_state_path.height);
let consensus_state_key = (
consensus_state_path.client_id.to_string(),
Expand All @@ -70,9 +72,7 @@ impl ClientExecutionContext for SolanaIbcStorage {
}

impl ExecutionContext for SolanaIbcStorage {
fn increase_client_counter(
&mut self,
) -> std::result::Result<(), ContextError> {
fn increase_client_counter(&mut self) -> Result {
self.client_counter.checked_add(1).unwrap();
msg!("client_counter has increased to: {}", self.client_counter);
Ok(())
Expand All @@ -83,7 +83,7 @@ impl ExecutionContext for SolanaIbcStorage {
client_id: ClientId,
height: Height,
timestamp: Timestamp,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_update_time - client_id: {}, height: {}, timestamp: {}",
client_id,
Expand Down Expand Up @@ -118,7 +118,7 @@ impl ExecutionContext for SolanaIbcStorage {
client_id: ClientId,
height: ibc::Height,
host_height: ibc::Height,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_update_height - client_id: {}, height: {:?}, host_height: \
{:?}",
Expand Down Expand Up @@ -155,7 +155,7 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
connection_path: &ConnectionPath,
connection_end: ConnectionEnd,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_connection: path: {}, connection_end: {:?}",
connection_path,
Expand All @@ -172,7 +172,7 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
client_connection_path: &ClientConnectionPath,
conn_id: ConnectionId,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_connection_to_client: path: {}, connection_id: {:?}",
client_connection_path,
Expand All @@ -183,9 +183,7 @@ impl ExecutionContext for SolanaIbcStorage {
Ok(())
}

fn increase_connection_counter(
&mut self,
) -> std::result::Result<(), ContextError> {
fn increase_connection_counter(&mut self) -> Result {
self.connection_counter.checked_add(1).unwrap();
msg!(
"connection_counter has increased to: {}",
Expand All @@ -198,7 +196,7 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
commitment_path: &CommitmentPath,
commitment: PacketCommitment,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_packet_commitment: path: {}, commitment: {:?}",
commitment_path,
Expand All @@ -216,7 +214,7 @@ impl ExecutionContext for SolanaIbcStorage {
fn delete_packet_commitment(
&mut self,
commitment_path: &CommitmentPath,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!("delete_packet_commitment: path: {}", commitment_path);
let sequences = self.packet_commitment_sequence_sets.get_mut(&(
commitment_path.port_id.clone().to_string(),
Expand All @@ -236,7 +234,7 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
receipt_path: &ReceiptPath,
receipt: Receipt,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_packet_receipt: path: {}, receipt: {:?}",
receipt_path,
Expand All @@ -255,7 +253,7 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
ack_path: &AckPath,
ack_commitment: AcknowledgementCommitment,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_packet_acknowledgement: path: {}, ack_commitment: {:?}",
ack_path,
Expand All @@ -270,10 +268,7 @@ impl ExecutionContext for SolanaIbcStorage {
Ok(())
}

fn delete_packet_acknowledgement(
&mut self,
ack_path: &AckPath,
) -> std::result::Result<(), ContextError> {
fn delete_packet_acknowledgement(&mut self, ack_path: &AckPath) -> Result {
msg!("delete_packet_acknowledgement: path: {}", ack_path,);
let sequences = self.packet_acknowledgement_sequence_sets.get_mut(&(
ack_path.port_id.clone().to_string(),
Expand All @@ -290,7 +285,7 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
channel_end_path: &ChannelEndPath,
channel_end: ChannelEnd,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_channel: path: {}, channel_end: {:?}",
channel_end_path,
Expand All @@ -311,7 +306,7 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
seq_send_path: &SeqSendPath,
seq: Sequence,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_next_sequence_send: path: {}, seq: {:?}",
seq_send_path,
Expand All @@ -327,7 +322,7 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
seq_recv_path: &SeqRecvPath,
seq: Sequence,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!(
"store_next_sequence_recv: path: {}, seq: {:?}",
seq_recv_path,
Expand All @@ -343,23 +338,21 @@ impl ExecutionContext for SolanaIbcStorage {
&mut self,
seq_ack_path: &SeqAckPath,
seq: Sequence,
) -> std::result::Result<(), ContextError> {
) -> Result {
msg!("store_next_sequence_ack: path: {}, seq: {:?}", seq_ack_path, seq);
let seq_ack_key =
(seq_ack_path.0.to_string(), seq_ack_path.1.to_string());
self.next_sequence_ack.insert(seq_ack_key, u64::from(seq));
Ok(())
}

fn increase_channel_counter(
&mut self,
) -> std::result::Result<(), ContextError> {
fn increase_channel_counter(&mut self) -> Result {
self.channel_counter += 1;
msg!("channel_counter has increased to: {}", self.channel_counter);
Ok(())
}

fn emit_ibc_event(&mut self, event: IbcEvent) {
fn emit_ibc_event(&mut self, event: IbcEvent) -> Result {
let host_height = self.host_height().unwrap();
let event_in_bytes: Vec<u8> = bincode::serialize(&event).unwrap();
let inner_host_height =
Expand All @@ -369,10 +362,12 @@ impl ExecutionContext for SolanaIbcStorage {
.or_default()
.push(event_in_bytes.clone());
emit!(EmitIBCEvent { ibc_event: event_in_bytes });
Ok(())
}

fn log_message(&mut self, message: String) {
fn log_message(&mut self, message: String) -> Result {
msg!("{}", message);
Ok(())
}

fn get_client_execution_context(&mut self) -> &mut Self::E { self }
Expand Down
11 changes: 8 additions & 3 deletions solana/solana-ibc/programs/solana-ibc/src/transfer/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,18 @@ impl SendPacketExecutionContext for ModuleHolder {
result
}

fn emit_ibc_event(&mut self, event: ibc::core::events::IbcEvent) {
fn emit_ibc_event(
&mut self,
event: ibc::core::events::IbcEvent,
) -> Result<(), ContextError> {
let mut store = Self::get_solana_ibc_store(self.account);
ExecutionContext::emit_ibc_event(&mut store, event);
let result = ExecutionContext::emit_ibc_event(&mut store, event);
Self::set_solana_ibc_store(&store);
result
}

fn log_message(&mut self, message: String) {
fn log_message(&mut self, message: String) -> Result<(), ContextError> {
msg!(&message);
Ok(())
}
}

0 comments on commit 274b60b

Please sign in to comment.