From 274b60bd4c5091a0d720824dae4ccba5c22f872a Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Thu, 12 Oct 2023 00:00:15 +0200 Subject: [PATCH] solana-ibc: upgrade to latest ibc away from fork (#21) --- Cargo.toml | 14 ++--- .../solana-ibc/programs/solana-ibc/Cargo.toml | 4 +- .../solana-ibc/src/execution_context.rs | 55 +++++++++---------- .../programs/solana-ibc/src/transfer/impls.rs | 11 +++- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d48839c..8689dbfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } @@ -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" } \ No newline at end of file +aes-gcm-siv = { git = "https://github.com/dhruvja/AEADs", branch = "main-aes-gcm-siv-v0.10.3" } diff --git a/solana/solana-ibc/programs/solana-ibc/Cargo.toml b/solana/solana-ibc/programs/solana-ibc/Cargo.toml index c0c9ba2f..6714b97d 100644 --- a/solana/solana-ibc/programs/solana-ibc/Cargo.toml +++ b/solana/solana-ibc/programs/solana-ibc/Cargo.toml @@ -25,6 +25,4 @@ serde_json.workspace = true [dev-dependencies] anchor-client.workspace = true anyhow.workspace = true - - - +ibc = { workspace = true, features = ["mocks", "std"] } diff --git a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs index fd3218f1..cfb56b9c 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -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; @@ -29,6 +29,8 @@ use crate::{ InnerSequence, SolanaIbcStorage, SolanaTimestamp, }; +type Result = core::result::Result; + impl ClientExecutionContext for SolanaIbcStorage { type ClientValidationContext = Self; type AnyClientState = AnyClientState; @@ -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, @@ -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(), @@ -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(()) @@ -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, @@ -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: \ {:?}", @@ -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, @@ -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, @@ -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: {}", @@ -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, @@ -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(), @@ -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, @@ -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, @@ -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(), @@ -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, @@ -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, @@ -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, @@ -343,7 +338,7 @@ 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()); @@ -351,15 +346,13 @@ impl ExecutionContext for SolanaIbcStorage { 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 = bincode::serialize(&event).unwrap(); let inner_host_height = @@ -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 } diff --git a/solana/solana-ibc/programs/solana-ibc/src/transfer/impls.rs b/solana/solana-ibc/programs/solana-ibc/src/transfer/impls.rs index 8ae07e18..1c8176ee 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/transfer/impls.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/transfer/impls.rs @@ -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(()) } }