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 d63859d5..37943143 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -27,8 +27,7 @@ use crate::client_state::AnyClientState; use crate::consensus_state::AnyConsensusState; use crate::trie_key::TrieKey; use crate::{ - EmitIBCEvent, HostHeight, InnerChannelId, InnerHeight, InnerPortId, - InnerSequence, SolanaIbcStorage, SolanaTimestamp, + EmitIBCEvent, InnerChannelId, InnerPortId, InnerSequence, SolanaIbcStorage, }; type Result = core::result::Result; @@ -116,33 +115,19 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { height: Height, timestamp: Timestamp, ) -> Result { - msg!("I am here inside update time"); msg!( "store_update_time - client_id: {}, height: {}, timestamp: {}", client_id, height, timestamp ); - let mut new_map: BTreeMap = - BTreeMap::new(); - BTreeMap::insert( - &mut new_map, - (height.revision_number(), height.revision_height()), - timestamp.nanoseconds(), - ); - if !self.client_processed_times.contains_key(&client_id.to_string()) { - self.client_processed_times - .insert(client_id.to_string().clone(), new_map); - } - self.client_processed_times.get_mut(&client_id.to_string()).map( - |processed_times| { - BTreeMap::insert( - processed_times, - (height.revision_number(), height.revision_height()), - timestamp.nanoseconds(), - ) - }, - ); + self.client_processed_times + .entry(client_id.to_string()) + .or_default() + .insert( + (height.revision_number(), height.revision_height()), + timestamp.nanoseconds(), + ); Ok(()) } @@ -159,28 +144,13 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> { height, host_height ); - let mut new_map: BTreeMap = BTreeMap::new(); - BTreeMap::insert( - &mut new_map, - (height.revision_number(), height.revision_height()), - (host_height.revision_number(), host_height.revision_height()), - ); - if !self.client_processed_heights.contains_key(&client_id.to_string()) { - self.client_processed_heights - .insert(client_id.to_string().clone(), new_map); - } - self.client_processed_heights.get_mut(&client_id.to_string()).map( - |processed_heights| { - BTreeMap::insert( - processed_heights, - (height.revision_number(), height.revision_height()), - ( - host_height.revision_number(), - host_height.revision_height(), - ), - ) - }, - ); + self.client_processed_heights + .entry(client_id.to_string()) + .or_default() + .insert( + (height.revision_number(), height.revision_height()), + (host_height.revision_number(), host_height.revision_height()), + ); Ok(()) } 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 fdc0f4ed..e48a0f34 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs @@ -35,7 +35,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { &self, client_id: &ClientId, ) -> std::result::Result { - match self.clients.get(&client_id.to_string()) { + match self.clients.get(client_id.as_str()) { Some(data) => { let client: AnyClientState = serde_json::from_str(data).unwrap(); @@ -112,7 +112,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { &self, conn_id: &ConnectionId, ) -> std::result::Result { - match self.connections.get(&conn_id.to_string()) { + match self.connections.get(conn_id.as_str()) { Some(data) => { let connection: ConnectionEnd = serde_json::from_str(data).unwrap(); @@ -282,7 +282,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { height: &Height, ) -> std::result::Result { self.client_processed_times - .get(&client_id.to_string()) + .get(client_id.as_str()) .and_then(|processed_times| { processed_times .get(&(height.revision_number(), height.revision_height())) @@ -305,7 +305,7 @@ impl ValidationContext for SolanaIbcStorage<'_, '_> { height: &Height, ) -> std::result::Result { self.client_processed_heights - .get(&client_id.to_string()) + .get(client_id.as_str()) .and_then(|processed_heights| { processed_heights .get(&(height.revision_number(), height.revision_height()))