diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index fbcd8aa5..cbd44062 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -24,7 +24,7 @@ use ibc_proto::protobuf::Protobuf; use serde::{Deserialize, Serialize}; use super::consensus_state::AnyConsensusState; -use crate::SolanaIbcStorage; +use crate::IbcStorage; const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState"; @@ -82,10 +82,10 @@ impl From for Any { } } -impl ClientStateValidation> for AnyClientState { +impl ClientStateValidation> for AnyClientState { fn verify_client_message( &self, - ctx: &SolanaIbcStorage, + ctx: &IbcStorage, client_id: &ClientId, client_message: Any, update_kind: &UpdateKind, @@ -111,7 +111,7 @@ impl ClientStateValidation> for AnyClientState { fn check_for_misbehaviour( &self, - ctx: &SolanaIbcStorage, + ctx: &IbcStorage, client_id: &ClientId, client_message: Any, update_kind: &UpdateKind, @@ -137,7 +137,7 @@ impl ClientStateValidation> for AnyClientState { fn status( &self, - _ctx: &SolanaIbcStorage, + _ctx: &IbcStorage, _client_id: &ClientId, ) -> Result { @@ -283,10 +283,10 @@ impl From for AnyClientState { fn from(value: MockClientState) -> Self { AnyClientState::Mock(value) } } -impl ClientStateExecution> for AnyClientState { +impl ClientStateExecution> for AnyClientState { fn initialise( &self, - ctx: &mut SolanaIbcStorage, + ctx: &mut IbcStorage, client_id: &ClientId, consensus_state: Any, ) -> Result<(), ClientError> { @@ -303,7 +303,7 @@ impl ClientStateExecution> for AnyClientState { fn update_state( &self, - ctx: &mut SolanaIbcStorage, + ctx: &mut IbcStorage, client_id: &ClientId, header: Any, ) -> Result, ClientError> { @@ -320,7 +320,7 @@ impl ClientStateExecution> for AnyClientState { fn update_state_on_misbehaviour( &self, - ctx: &mut SolanaIbcStorage, + ctx: &mut IbcStorage, client_id: &ClientId, client_message: Any, update_kind: &UpdateKind, @@ -346,7 +346,7 @@ impl ClientStateExecution> for AnyClientState { fn update_state_on_upgrade( &self, - ctx: &mut SolanaIbcStorage, + ctx: &mut IbcStorage, client_id: &ClientId, upgraded_client_state: Any, upgraded_consensus_state: Any, @@ -371,9 +371,7 @@ impl ClientStateExecution> for AnyClientState { } } -impl ibc::clients::ics07_tendermint::CommonContext - for SolanaIbcStorage<'_, '_> -{ +impl ibc::clients::ics07_tendermint::CommonContext for IbcStorage<'_, '_> { type ConversionError = ClientError; type AnyConsensusState = AnyConsensusState; @@ -387,7 +385,7 @@ impl ibc::clients::ics07_tendermint::CommonContext } #[cfg(any(test, feature = "mocks"))] -impl MockClientContext for SolanaIbcStorage<'_, '_> { +impl MockClientContext for IbcStorage<'_, '_> { type ConversionError = ClientError; type AnyConsensusState = AnyConsensusState; @@ -403,9 +401,7 @@ impl MockClientContext for SolanaIbcStorage<'_, '_> { } } -impl ibc::clients::ics07_tendermint::ValidationContext - for SolanaIbcStorage<'_, '_> -{ +impl ibc::clients::ics07_tendermint::ValidationContext for IbcStorage<'_, '_> { fn host_timestamp(&self) -> Result { ValidationContext::host_timestamp(self) } @@ -416,8 +412,10 @@ impl ibc::clients::ics07_tendermint::ValidationContext height: &Height, ) -> Result, ContextError> { let end_height = (height.revision_number() + 1, 1); - let solana_ibc_store = &self.0.borrow().solana_ibc_store; - match solana_ibc_store + match self + .0 + .borrow() + .private .consensus_states .get(&(client_id.to_string(), end_height)) { @@ -438,8 +436,10 @@ impl ibc::clients::ics07_tendermint::ValidationContext height: &Height, ) -> Result, ContextError> { let end_height = (height.revision_number(), 1); - let solana_ibc_store = &self.0.borrow().solana_ibc_store; - match solana_ibc_store + match self + .0 + .borrow() + .private .consensus_states .get(&(client_id.to_string(), end_height)) { 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 30ca38e7..7b855c2c 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -27,13 +27,13 @@ use crate::client_state::AnyClientState; use crate::consensus_state::AnyConsensusState; use crate::trie_key::TrieKey; use crate::{ - EmitIBCEvent, InnerChannelId, InnerPortId, InnerSequence, SolanaIbcStorage, - SolanaIbcStorageTest, + EmitIBCEvent, IbcStorage, IbcStorageInner, InnerChannelId, InnerPortId, + InnerSequence, }; type Result = core::result::Result; -impl ClientExecutionContext for SolanaIbcStorage<'_, '_> { +impl ClientExecutionContext for IbcStorage<'_, '_> { type ClientValidationContext = Self; type AnyClientState = AnyClientState; type AnyConsensusState = AnyConsensusState; @@ -52,9 +52,8 @@ impl ClientExecutionContext for SolanaIbcStorage<'_, '_> { let serialized_client_state = serde_json::to_string(&client_state).unwrap(); let mut store = self.0.borrow_mut(); - // let mut solana_ibc_store = &store.solana_ibc_store; let client_state_trie_key = TrieKey::from(&client_state_path); - let trie = &mut store.trie; + let trie = &mut store.provable; msg!( "THis is serialized client state {}", &lib::hash::CryptoHash::digest(serialized_client_state.as_bytes()) @@ -64,14 +63,8 @@ impl ClientExecutionContext for SolanaIbcStorage<'_, '_> { &lib::hash::CryptoHash::digest(serialized_client_state.as_bytes()), ) .unwrap(); - store - .solana_ibc_store - .clients - .insert(client_state_key, serialized_client_state); - store - .solana_ibc_store - .client_id_set - .push(client_state_path.0.to_string()); + store.private.clients.insert(client_state_key, serialized_client_state); + store.private.client_id_set.push(client_state_path.0.to_string()); Ok(()) } @@ -94,7 +87,7 @@ impl ClientExecutionContext for SolanaIbcStorage<'_, '_> { serde_json::to_string(&consensus_state).unwrap(); let consensus_state_trie_key = TrieKey::from(&consensus_state_path); - let trie = &mut store.trie; + let trie = &mut store.provable; trie.set( &consensus_state_trie_key, &lib::hash::CryptoHash::digest( @@ -104,23 +97,23 @@ impl ClientExecutionContext for SolanaIbcStorage<'_, '_> { .unwrap(); store - .solana_ibc_store + .private .consensus_states .insert(consensus_state_key, serialized_consensus_state); - store.solana_ibc_store.height.0 = consensus_state_path.epoch; - store.solana_ibc_store.height.1 = consensus_state_path.height; + store.private.height.0 = consensus_state_path.epoch; + store.private.height.1 = consensus_state_path.height; Ok(()) } } -impl ExecutionContext for SolanaIbcStorage<'_, '_> { +impl ExecutionContext for IbcStorage<'_, '_> { fn increase_client_counter(&mut self) -> Result { let mut store = self.0.borrow_mut(); - store.solana_ibc_store.client_counter = - store.solana_ibc_store.client_counter.checked_add(1).unwrap(); + store.private.client_counter = + store.private.client_counter.checked_add(1).unwrap(); msg!( "client_counter has increased to: {}", - store.solana_ibc_store.client_counter + store.private.client_counter ); Ok(()) } @@ -139,7 +132,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { ); let mut store = self.0.borrow_mut(); store - .solana_ibc_store + .private .client_processed_times .entry(client_id.to_string()) .or_default() @@ -165,7 +158,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { ); let mut store = self.0.borrow_mut(); store - .solana_ibc_store + .private .client_processed_heights .entry(client_id.to_string()) .or_default() @@ -191,7 +184,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { let serialized_connection_end = serde_json::to_string(&connection_end).unwrap(); let connection_trie_key = TrieKey::from(connection_path); - let trie = &mut store.trie; + let trie = &mut store.provable; trie.set( &connection_trie_key, &lib::hash::CryptoHash::digest( @@ -201,7 +194,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { .unwrap(); store - .solana_ibc_store + .private .connections .insert(connection_path.0.to_string(), serialized_connection_end); Ok(()) @@ -219,7 +212,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { ); let mut store = self.0.borrow_mut(); store - .solana_ibc_store + .private .connection_to_client .insert(conn_id.to_string(), client_connection_path.0.to_string()); Ok(()) @@ -227,11 +220,11 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { fn increase_connection_counter(&mut self) -> Result { let mut store = self.0.borrow_mut(); - store.solana_ibc_store.connection_counter = - store.solana_ibc_store.connection_counter.checked_add(1).unwrap(); + store.private.connection_counter = + store.private.connection_counter.checked_add(1).unwrap(); msg!( "connection_counter has increased to: {}", - store.solana_ibc_store.connection_counter + store.private.connection_counter ); Ok(()) } @@ -248,7 +241,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { ); let mut store = self.0.borrow_mut(); let commitment_trie_key = TrieKey::from(commitment_path); - let trie = &mut store.trie; + let trie = &mut store.provable; trie.set( &commitment_trie_key, &lib::hash::CryptoHash::digest(&commitment.into_vec()), @@ -256,7 +249,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { .unwrap(); record_packet_sequence( - &mut store.solana_ibc_store.packet_commitment_sequence_sets, + &mut store.private.packet_commitment_sequence_sets, &commitment_path.port_id, &commitment_path.channel_id, &commitment_path.sequence, @@ -271,7 +264,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { msg!("delete_packet_commitment: path: {}", commitment_path); let mut store = self.0.borrow_mut(); let sequences = - store.solana_ibc_store.packet_commitment_sequence_sets.get_mut(&( + store.private.packet_commitment_sequence_sets.get_mut(&( commitment_path.port_id.clone().to_string(), commitment_path.channel_id.clone().to_string(), )); @@ -297,11 +290,11 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { ); let mut store = self.0.borrow_mut(); let receipt_trie_key = TrieKey::from(receipt_path); - let trie = &mut store.trie; + let trie = &mut store.provable; trie.set(&receipt_trie_key, &lib::hash::CryptoHash::DEFAULT).unwrap(); trie.seal(&receipt_trie_key).unwrap(); record_packet_sequence( - &mut store.solana_ibc_store.packet_receipt_sequence_sets, + &mut store.private.packet_receipt_sequence_sets, &receipt_path.port_id, &receipt_path.channel_id, &receipt_path.sequence, @@ -321,14 +314,14 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { ); let mut store = self.0.borrow_mut(); let ack_commitment_trie_key = TrieKey::from(ack_path); - let trie = &mut store.trie; + let trie = &mut store.provable; trie.set( &ack_commitment_trie_key, &lib::hash::CryptoHash::digest(&ack_commitment.into_vec()), ) .unwrap(); record_packet_sequence( - &mut store.solana_ibc_store.packet_acknowledgement_sequence_sets, + &mut store.private.packet_acknowledgement_sequence_sets, &ack_path.port_id, &ack_path.channel_id, &ack_path.sequence, @@ -339,10 +332,8 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { fn delete_packet_acknowledgement(&mut self, ack_path: &AckPath) -> Result { msg!("delete_packet_acknowledgement: path: {}", ack_path,); let mut store = self.0.borrow_mut(); - let sequences = store - .solana_ibc_store - .packet_acknowledgement_sequence_sets - .get_mut(&( + let sequences = + store.private.packet_acknowledgement_sequence_sets.get_mut(&( ack_path.port_id.clone().to_string(), ack_path.channel_id.clone().to_string(), )); @@ -364,21 +355,21 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { channel_end ); let mut store = self.0.borrow_mut(); - store.solana_ibc_store.port_channel_id_set.push(( + store.private.port_channel_id_set.push(( channel_end_path.0.clone().to_string(), channel_end_path.1.clone().to_string(), )); let serialized_channel_end = borsh::to_vec(&channel_end).unwrap(); let channel_end_trie_key = TrieKey::from(channel_end_path); - let trie = &mut &mut store.trie; + let trie = &mut &mut store.provable; trie.set( &channel_end_trie_key, &lib::hash::CryptoHash::digest(&serialized_channel_end), ) .unwrap(); - store.solana_ibc_store.channel_ends.insert( + store.private.channel_ends.insert( (channel_end_path.0.to_string(), channel_end_path.1.to_string()), serde_json::to_string(&channel_end).unwrap(), ); @@ -391,7 +382,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { seq: Sequence, ) -> Result { msg!("store_next_sequence_send: path: {path}, seq: {seq}"); - let store: &mut SolanaIbcStorageTest<'_, '_> = &mut self.0.borrow_mut(); + let store: &mut IbcStorageInner<'_, '_> = &mut self.0.borrow_mut(); store.store_next_sequence( path.into(), super::SequenceTripleIdx::Send, @@ -405,7 +396,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { seq: Sequence, ) -> Result { msg!("store_next_sequence_recv: path: {path}, seq: {seq}"); - let store: &mut SolanaIbcStorageTest<'_, '_> = &mut self.0.borrow_mut(); + let store: &mut IbcStorageInner<'_, '_> = &mut self.0.borrow_mut(); store.store_next_sequence( path.into(), super::SequenceTripleIdx::Recv, @@ -419,7 +410,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { seq: Sequence, ) -> Result { msg!("store_next_sequence_ack: path: {path}, seq: {seq}"); - let store: &mut SolanaIbcStorageTest<'_, '_> = &mut self.0.borrow_mut(); + let store: &mut IbcStorageInner<'_, '_> = &mut self.0.borrow_mut(); store.store_next_sequence( path.into(), super::SequenceTripleIdx::Ack, @@ -429,27 +420,25 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { fn increase_channel_counter(&mut self) -> Result { let mut store = self.0.borrow_mut(); - store.solana_ibc_store.channel_counter += 1; + store.private.channel_counter += 1; msg!( "channel_counter has increased to: {}", - store.solana_ibc_store.channel_counter + store.private.channel_counter ); Ok(()) } fn emit_ibc_event(&mut self, event: IbcEvent) -> Result { let mut store = self.0.borrow_mut(); - let host_height = ibc::Height::new( - store.solana_ibc_store.height.0, - store.solana_ibc_store.height.1, - ) - .map_err(ContextError::ClientError) - .unwrap(); + let host_height = + ibc::Height::new(store.private.height.0, store.private.height.1) + .map_err(ContextError::ClientError) + .unwrap(); let event_in_bytes: Vec = bincode::serialize(&event).unwrap(); let inner_host_height = (host_height.revision_height(), host_height.revision_number()); store - .solana_ibc_store + .private .ibc_events_history .entry(inner_host_height) .or_default() @@ -466,15 +455,15 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { fn get_client_execution_context(&mut self) -> &mut Self::E { self } } -impl SolanaIbcStorageTest<'_, '_> { +impl IbcStorageInner<'_, '_> { fn store_next_sequence( &mut self, path: crate::trie_key::SequencePath<'_>, index: super::SequenceTripleIdx, seq: Sequence, ) -> Result { - let trie = &mut self.trie; - let next_seq = &mut self.solana_ibc_store.next_sequence; + let trie = &mut self.provable; + let next_seq = &mut self.private.next_sequence; let map_key = (path.port_id.to_string(), path.channel_id.to_string()); let triple = next_seq.entry(map_key).or_default(); triple.set(index, seq); diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 4c70d724..905484fc 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -14,7 +14,7 @@ use ibc::core::ics24_host::identifier::PortId; use ibc::core::router::{Module, ModuleId, Router}; const SOLANA_IBC_STORAGE_SEED: &[u8] = b"solana_ibc_storage"; -const TEST_TRIE_SEED: &[u8] = b"test_trie"; +const TRIE_SEED: &[u8] = b"trie"; const CONNECTION_ID_PREFIX: &str = "connection-"; const CHANNEL_ID_PREFIX: &str = "channel-"; @@ -49,9 +49,8 @@ pub mod solana_ibc { ) -> Result<()> { msg!("Called deliver method"); let _sender = ctx.accounts.sender.to_account_info(); - let solana_ibc_store: &mut SolanaIbcStorageTemp = - &mut ctx.accounts.storage; - msg!("This is solana_ibc_store {:?}", solana_ibc_store); + let private_store: &mut PrivateStorage = &mut ctx.accounts.storage; + msg!("This is private_store {:?}", private_store); let all_messages = messages .into_iter() @@ -67,15 +66,12 @@ pub mod solana_ibc { let trie = trie::AccountTrie::new(account.try_borrow_mut_data()?) .ok_or(ProgramError::InvalidAccountData)?; - let solana_real_storage = SolanaIbcStorageTest { - solana_ibc_store: solana_ibc_store.clone(), - trie, - }; + let solana_real_storage = + IbcStorageInner { private: private_store.clone(), provable: trie }; - let mut store = - SolanaIbcStorage(Rc::>::new( - solana_real_storage.into(), - )); + let mut store = IbcStorage(Rc::>::new( + solana_real_storage.into(), + )); let mut router = store.clone(); let errors = @@ -93,40 +89,38 @@ pub mod solana_ibc { errors }); - let sol_store = &store.0.borrow_mut().solana_ibc_store; - solana_ibc_store.height = sol_store.height; - solana_ibc_store.clients = sol_store.clients.clone(); - solana_ibc_store.client_id_set = sol_store.client_id_set.clone(); - solana_ibc_store.client_counter = sol_store.client_counter; - solana_ibc_store.client_processed_times = + let sol_store = &store.0.borrow_mut().private; + private_store.height = sol_store.height; + private_store.clients = sol_store.clients.clone(); + private_store.client_id_set = sol_store.client_id_set.clone(); + private_store.client_counter = sol_store.client_counter; + private_store.client_processed_times = sol_store.client_processed_times.clone(); - solana_ibc_store.client_processed_heights = + private_store.client_processed_heights = sol_store.client_processed_heights.clone(); - solana_ibc_store.consensus_states = sol_store.consensus_states.clone(); - solana_ibc_store.client_consensus_state_height_sets = + private_store.consensus_states = sol_store.consensus_states.clone(); + private_store.client_consensus_state_height_sets = sol_store.client_consensus_state_height_sets.clone(); - solana_ibc_store.connection_id_set = - sol_store.connection_id_set.clone(); - solana_ibc_store.connection_counter = sol_store.connection_counter; - solana_ibc_store.connections = sol_store.connections.clone(); - solana_ibc_store.channel_ends = sol_store.channel_ends.clone(); - solana_ibc_store.connection_to_client = + private_store.connection_id_set = sol_store.connection_id_set.clone(); + private_store.connection_counter = sol_store.connection_counter; + private_store.connections = sol_store.connections.clone(); + private_store.channel_ends = sol_store.channel_ends.clone(); + private_store.connection_to_client = sol_store.connection_to_client.clone(); - solana_ibc_store.port_channel_id_set = + private_store.port_channel_id_set = sol_store.port_channel_id_set.clone(); - solana_ibc_store.channel_counter = sol_store.channel_counter; - solana_ibc_store.next_sequence = sol_store.next_sequence.clone(); - solana_ibc_store.packet_commitment_sequence_sets = + private_store.channel_counter = sol_store.channel_counter; + private_store.next_sequence = sol_store.next_sequence.clone(); + private_store.packet_commitment_sequence_sets = sol_store.packet_commitment_sequence_sets.clone(); - solana_ibc_store.packet_receipt_sequence_sets = + private_store.packet_receipt_sequence_sets = sol_store.packet_receipt_sequence_sets.clone(); - solana_ibc_store.packet_acknowledgement_sequence_sets = + private_store.packet_acknowledgement_sequence_sets = sol_store.packet_acknowledgement_sequence_sets.clone(); - solana_ibc_store.ibc_events_history = - sol_store.ibc_events_history.clone(); + private_store.ibc_events_history = sol_store.ibc_events_history.clone(); msg!("These are errors {:?}", errors); - msg!("This is final structure {:?}", solana_ibc_store); + msg!("This is final structure {:?}", private_store); // msg!("this is length {}", TrieKey::ClientState{ client_id: String::from("hello")}.into()); @@ -138,8 +132,8 @@ pub struct Deliver<'info> { #[account(mut)] pub sender: Signer<'info>, #[account(init_if_needed, payer = sender, seeds = [SOLANA_IBC_STORAGE_SEED],bump, space = 10000)] - pub storage: Account<'info, SolanaIbcStorageTemp>, - #[account(init_if_needed, payer = sender, seeds = [TEST_TRIE_SEED], bump, space = 1000)] + pub storage: Account<'info, PrivateStorage>, + #[account(init_if_needed, payer = sender, seeds = [TRIE_SEED], bump, space = 1000)] /// CHECK: pub trie: AccountInfo<'info>, pub system_program: Program<'info, System>, @@ -226,7 +220,7 @@ impl InnerSequenceTriple { #[account] #[derive(Debug)] /// All the structs from IBC are stored as String since they dont implement AnchorSerialize and AnchorDeserialize -pub struct SolanaIbcStorageTemp { +pub struct PrivateStorage { pub height: InnerHeight, pub clients: BTreeMap, /// The client ids of the clients. @@ -276,15 +270,15 @@ pub struct SolanaIbcStorageTemp { /// All the structs from IBC are stored as String since they dont implement AnchorSerialize and AnchorDeserialize #[derive(Debug)] -pub struct SolanaIbcStorageTest<'a, 'b> { - pub solana_ibc_store: SolanaIbcStorageTemp, - pub trie: trie::AccountTrie<'a, 'b>, +pub struct IbcStorageInner<'a, 'b> { + pub private: PrivateStorage, + pub provable: trie::AccountTrie<'a, 'b>, } #[derive(Debug, Clone)] -struct SolanaIbcStorage<'a, 'b>(Rc>>); +struct IbcStorage<'a, 'b>(Rc>>); -impl Router for SolanaIbcStorage<'_, '_> { +impl Router for IbcStorage<'_, '_> { // fn get_route(&self, module_id: &ModuleId) -> Option<&dyn Module> { let module_id = core::borrow::Borrow::borrow(module_id); diff --git a/solana/solana-ibc/programs/solana-ibc/src/tests.rs b/solana/solana-ibc/programs/solana-ibc/src/tests.rs index 0386585d..58e5d9b0 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/tests.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/tests.rs @@ -20,8 +20,8 @@ use ibc::Any; use ibc_proto::protobuf::Protobuf; use crate::{ - accounts, instruction, AnyCheck, SolanaIbcStorageTemp, ID, - SOLANA_IBC_STORAGE_SEED, TEST_TRIE_SEED, + accounts, instruction, AnyCheck, PrivateStorage, ID, + SOLANA_IBC_STORAGE_SEED, TRIE_SEED, }; const TYPE_URL: &str = "/ibc.core.client.v1.MsgCreateClient"; @@ -66,7 +66,7 @@ fn anchor_test_deliver() -> Result<()> { // Build, sign, and send program instruction let seeds = &[SOLANA_IBC_STORAGE_SEED]; let solana_ibc_storage = Pubkey::find_program_address(seeds, &crate::ID).0; - let trie_seeds = &[TEST_TRIE_SEED]; + let trie_seeds = &[TRIE_SEED]; let trie = Pubkey::find_program_address(trie_seeds, &crate::ID).0; let (mock_client_state, mock_cs_state) = create_mock_client_and_cs_state(); @@ -100,7 +100,7 @@ fn anchor_test_deliver() -> Result<()> { println!("demo sig: {sig}"); // Retrieve and validate state - let solana_ibc_storage_account: SolanaIbcStorageTemp = + let solana_ibc_storage_account: PrivateStorage = program.account(solana_ibc_storage).unwrap(); println!("This is solana storage account {:?}", solana_ibc_storage_account); @@ -111,7 +111,7 @@ fn anchor_test_deliver() -> Result<()> { // #[test] // fn internal_test() { // let authority = Keypair::new(); -// let mut solana_ibc_store = SolanaIbcStorage::new(authority.pubkey()); +// let mut solana_ibc_store = IbcStorage::new(authority.pubkey()); // let mock_client_state = MockClientState::new(MockHeader::default()); // let mock_cs_state = MockConsensusState::new(MockHeader::default()); // let client_id = ClientId::new(mock_client_state.client_type(), 0).unwrap(); 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 70ab4ffe..4c4e13ab 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/transfer/impls.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/transfer/impls.rs @@ -7,10 +7,10 @@ use ibc::applications::transfer::PrefixedCoin; use ibc::core::ics24_host::identifier::{ChannelId, PortId}; use ibc::Signer; -// use crate::module_holder::SolanaIbcStorage<'_,'_>; -use crate::SolanaIbcStorage; +// use crate::module_holder::IbcStorage<'_,'_>; +use crate::IbcStorage; -impl TokenTransferExecutionContext for SolanaIbcStorage<'_, '_> { +impl TokenTransferExecutionContext for IbcStorage<'_, '_> { fn send_coins_execute( &mut self, _from: &Self::AccountId, @@ -56,7 +56,7 @@ impl TokenTransferExecutionContext for SolanaIbcStorage<'_, '_> { } } -impl TokenTransferValidationContext for SolanaIbcStorage<'_, '_> { +impl TokenTransferValidationContext for IbcStorage<'_, '_> { type AccountId = Signer; fn get_port(&self) -> Result { diff --git a/solana/solana-ibc/programs/solana-ibc/src/transfer/mod.rs b/solana/solana-ibc/programs/solana-ibc/src/transfer/mod.rs index c4ed0dce..0306825e 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/transfer/mod.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/transfer/mod.rs @@ -13,11 +13,11 @@ use ibc::Signer; use ibc_proto::ibc::apps::transfer::v2::FungibleTokenPacketData; use serde::{Deserialize, Serialize}; -use crate::SolanaIbcStorage; +use crate::IbcStorage; mod impls; -impl Module for SolanaIbcStorage<'_, '_> { +impl Module for IbcStorage<'_, '_> { fn on_chan_open_init_validate( &self, order: Order, diff --git a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs index 4de0cec9..dfc2b977 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs @@ -23,9 +23,9 @@ use ibc::Height; use crate::client_state::AnyClientState; use crate::consensus_state::AnyConsensusState; -use crate::SolanaIbcStorage; +use crate::IbcStorage; -impl ValidationContext for SolanaIbcStorage<'_, '_> { +impl ValidationContext for IbcStorage<'_, '_> { type AnyConsensusState = AnyConsensusState; type AnyClientState = AnyClientState; type E = Self; @@ -36,7 +36,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { client_id: &ClientId, ) -> std::result::Result { let store = self.0.borrow(); - match store.solana_ibc_store.clients.get(client_id.as_str()) { + match store.private.clients.get(client_id.as_str()) { Some(data) => { let client: AnyClientState = serde_json::from_str(data).unwrap(); @@ -66,7 +66,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { (client_cons_state_path.epoch, client_cons_state_path.height), ); let store = self.0.borrow(); - match store.solana_ibc_store.consensus_states.get(consensus_state_key) { + match store.private.consensus_states.get(consensus_state_key) { Some(data) => { let result: Self::AnyConsensusState = serde_json::from_str(data).unwrap(); @@ -86,11 +86,8 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { fn host_height(&self) -> std::result::Result { let store = self.0.borrow(); - ibc::Height::new( - store.solana_ibc_store.height.0, - store.solana_ibc_store.height.1, - ) - .map_err(ContextError::ClientError) + ibc::Height::new(store.private.height.0, store.private.height.1) + .map_err(ContextError::ClientError) } fn host_timestamp(&self) -> std::result::Result { @@ -112,7 +109,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { fn client_counter(&self) -> std::result::Result { let store = self.0.borrow(); - Ok(store.solana_ibc_store.client_counter) + Ok(store.private.client_counter) } fn connection_end( @@ -120,7 +117,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { conn_id: &ConnectionId, ) -> std::result::Result { let store = self.0.borrow(); - match store.solana_ibc_store.connections.get(conn_id.as_str()) { + match store.private.connections.get(conn_id.as_str()) { Some(data) => { let connection: ConnectionEnd = serde_json::from_str(data).unwrap(); @@ -153,7 +150,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { fn connection_counter(&self) -> std::result::Result { let store = self.0.borrow(); - Ok(store.solana_ibc_store.connection_counter) + Ok(store.private.connection_counter) } fn channel_end( @@ -163,7 +160,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { let channel_end_key = &(channel_end_path.0.to_string(), channel_end_path.1.to_string()); let store = self.0.borrow(); - match store.solana_ibc_store.channel_ends.get(channel_end_key) { + match store.private.channel_ends.get(channel_end_key) { Some(data) => { let channel_end: ChannelEnd = serde_json::from_str(data).unwrap(); @@ -227,7 +224,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { ); let store = self.0.borrow(); match store - .solana_ibc_store + .private .packet_acknowledgement_sequence_sets .get(&commitment_key) { @@ -254,7 +251,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { ); let store = self.0.borrow(); match store - .solana_ibc_store + .private .packet_acknowledgement_sequence_sets .get(&receipt_key) { @@ -283,11 +280,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { let ack_key = (ack_path.port_id.to_string(), ack_path.channel_id.to_string()); let store = self.0.borrow(); - match store - .solana_ibc_store - .packet_acknowledgement_sequence_sets - .get(&ack_key) - { + match store.private.packet_acknowledgement_sequence_sets.get(&ack_key) { Some(data) => { let data_in_u8: Vec = data.iter().map(|x| *x as u8).collect(); @@ -308,7 +301,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { ) -> std::result::Result { let store = self.0.borrow(); store - .solana_ibc_store + .private .client_processed_times .get(client_id.as_str()) .and_then(|processed_times| { @@ -334,7 +327,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { ) -> std::result::Result { let store = self.0.borrow(); store - .solana_ibc_store + .private .client_processed_heights .get(client_id.as_str()) .and_then(|processed_heights| { @@ -357,7 +350,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { fn channel_counter(&self) -> std::result::Result { let store = self.0.borrow(); - Ok(store.solana_ibc_store.channel_counter) + Ok(store.private.channel_counter) } fn max_expected_time_per_block(&self) -> Duration { @@ -409,7 +402,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { } } -impl SolanaIbcStorage<'_, '_> { +impl IbcStorage<'_, '_> { fn get_next_sequence( &self, path: crate::trie_key::SequencePath<'_>, @@ -423,7 +416,7 @@ impl SolanaIbcStorage<'_, '_> { > { let store = self.0.borrow(); store - .solana_ibc_store + .private .next_sequence .get(&(path.port_id.to_string(), path.channel_id.to_string())) .and_then(|triple| triple.get(index))