Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvja committed Nov 18, 2023
2 parents 7c7eb00 + a91c4f2 commit d66029e
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 128 deletions.
19 changes: 9 additions & 10 deletions solana/solana-ibc/programs/solana-ibc/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,15 @@ impl ibc::clients::ics07_tendermint::CommonContext for IbcStorage<'_, '_, '_> {
&self,
client_id: &ClientId,
) -> Result<Vec<Height>, ContextError> {
let low = (client_id.to_string(), Height::min(0));
let high =
(client_id.to_string(), Height::new(u64::MAX, u64::MAX).unwrap());
let heights = self
Ok(self
.borrow()
.private
.client(client_id)?
.1
.consensus_states
.range(low..=high)
.map(|((_client, height), _value)| *height)
.collect();
Ok(heights)
.keys()
.copied()
.collect())
}

fn host_timestamp(&self) -> Result<Timestamp, ContextError> {
Expand Down Expand Up @@ -536,15 +534,16 @@ impl IbcStorage<'_, '_, '_> {
) -> Result<Option<AnyConsensusState>, ContextError> {
use core::ops::Bound;

let pivot = Bound::Excluded((client_id.to_string(), *height));
let pivot = Bound::Excluded(*height);
let range = if dir == Direction::Next {
(pivot, Bound::Unbounded)
} else {
(Bound::Unbounded, pivot)
};

let store = self.borrow();
let mut range = store.private.consensus_states.range(range);
let (_index, client) = store.private.client(client_id)?;
let mut range = client.consensus_states.range(range);
if dir == Direction::Next { range.next() } else { range.next_back() }
.map(|(_, data)| data.get())
.transpose()
Expand Down
98 changes: 45 additions & 53 deletions solana/solana-ibc/programs/solana-ibc/src/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ impl ClientExecutionContext for IbcStorage<'_, '_, '_> {
state: Self::AnyClientState,
) -> Result {
msg!("store_client_state({}, {:?})", path, state);
self.borrow_mut().store_serialised_proof(
|private| &mut private.clients,
path.0.to_string(),
&TrieKey::from(&path),
&state,
)
let mut store = self.borrow_mut();
let (client_idx, client) = store.private.client_mut(&path.0, true)?;
let hash = client.client_state.set(&state)?.digest();
let key = TrieKey::for_client_state(client_idx);
store.provable.set(&key, &hash).map_err(error)
}

fn store_consensus_state(
Expand All @@ -55,12 +54,15 @@ impl ClientExecutionContext for IbcStorage<'_, '_, '_> {
) -> Result {
msg!("store_consensus_state({}, {:?})", path, state);
let height = Height::new(path.epoch, path.height)?;
self.borrow_mut().store_serialised_proof(
|private| &mut private.consensus_states,
(path.client_id.to_string(), height),
&TrieKey::from(&path),
&state,
)
let mut store = self.borrow_mut();
let (client_idx, client) =
store.private.client_mut(&path.client_id, false)?;
let serialised = storage::Serialised::new(&state)?;
let hash = serialised.digest();
client.consensus_states.insert(height, serialised);
let trie_key = TrieKey::for_consensus_state(client_idx, height);
store.provable.set(&trie_key, &hash).map_err(error)?;
Ok(())
}

fn delete_consensus_state(
Expand All @@ -69,10 +71,12 @@ impl ClientExecutionContext for IbcStorage<'_, '_, '_> {
) -> Result<(), ContextError> {
msg!("delete_consensus_state({})", path);
let height = Height::new(path.epoch, path.height)?;
let key = (path.client_id.to_string(), height);
let mut store = self.borrow_mut();
store.private.consensus_states.remove(&key);
store.provable.del(&TrieKey::from(&path)).unwrap();
let (client_idx, client) =
store.private.client_mut(&path.client_id, false)?;
client.consensus_states.remove(&height);
let key = TrieKey::for_consensus_state(client_idx, height);
store.provable.del(&key).map_err(error)?;
Ok(())
}

Expand All @@ -84,9 +88,10 @@ impl ClientExecutionContext for IbcStorage<'_, '_, '_> {
) -> Result<(), ContextError> {
self.borrow_mut()
.private
.client_processed_heights
.get_mut(client_id.as_str())
.and_then(|processed_times| processed_times.remove(&height));
.client_mut(&client_id, false)?
.1
.processed_heights
.remove(&height);
Ok(())
}

Expand All @@ -97,9 +102,10 @@ impl ClientExecutionContext for IbcStorage<'_, '_, '_> {
) -> Result<(), ContextError> {
self.borrow_mut()
.private
.client_processed_times
.get_mut(client_id.as_str())
.and_then(|processed_times| processed_times.remove(&height));
.client_mut(&client_id, false)?
.1
.processed_times
.remove(&height);
Ok(())
}

Expand All @@ -113,9 +119,9 @@ impl ClientExecutionContext for IbcStorage<'_, '_, '_> {
let mut store = self.borrow_mut();
store
.private
.client_processed_times
.entry(client_id.to_string())
.or_default()
.client_mut(&client_id, false)?
.1
.processed_times
.insert(height, timestamp.nanoseconds());
Ok(())
}
Expand All @@ -130,25 +136,17 @@ impl ClientExecutionContext for IbcStorage<'_, '_, '_> {
let mut store = self.borrow_mut();
store
.private
.client_processed_heights
.entry(client_id.to_string())
.or_default()
.client_mut(&client_id, false)?
.1
.processed_heights
.insert(height, host_height);
Ok(())
}
}

impl ExecutionContext for IbcStorage<'_, '_, '_> {
fn increase_client_counter(&mut self) -> Result {
let mut store = self.borrow_mut();
store.private.client_counter =
store.private.client_counter.checked_add(1).unwrap();
msg!(
"client_counter has increased to: {}",
store.private.client_counter
);
Ok(())
}
/// The clients are stored in the vector so we can easily find how many clients were created. So thats why this method doesnt do anything.
fn increase_client_counter(&mut self) -> Result { Ok(()) }

fn store_connection(
&mut self,
Expand All @@ -166,19 +164,12 @@ impl ExecutionContext for IbcStorage<'_, '_, '_> {

fn store_connection_to_client(
&mut self,
client_connection_path: &ClientConnectionPath,
path: &ClientConnectionPath,
conn_id: ConnectionId,
) -> Result {
msg!(
"store_connection_to_client: path: {}, connection_id: {:?}",
client_connection_path,
conn_id
);
let mut store = self.borrow_mut();
store
.private
.client_to_connection
.insert(client_connection_path.0.to_string(), conn_id.to_string());
msg!("store_connection_to_client({}, {:?})", path, conn_id);
self.borrow_mut().private.client_mut(&path.0, false)?.1.connection_id =
Some(conn_id);
Ok(())
}

Expand Down Expand Up @@ -337,8 +328,7 @@ impl ExecutionContext for IbcStorage<'_, '_, '_> {
}

fn emit_ibc_event(&mut self, event: IbcEvent) -> Result {
crate::events::emit(event)
.map_err(|description| ClientError::Other { description }.into())
crate::events::emit(event).map_err(error)
}

fn log_message(&mut self, message: String) -> Result {
Expand Down Expand Up @@ -385,9 +375,7 @@ impl IbcStorageInner<'_, '_, '_> {
value: &V,
) -> Result {
let serialised = storage::Serialised::new(value)?;
self.provable
.set(trie_key, &serialised.digest())
.map_err(|e| ClientError::Other { description: e.to_string() })?;
self.provable.set(trie_key, &serialised.digest()).map_err(error)?;
get_map(self.private).insert(key, serialised);
Ok(())
}
Expand Down Expand Up @@ -427,3 +415,7 @@ fn delete_packet_sequence(
}
}
}

fn error(description: impl ToString) -> ContextError {
ClientError::Other { description: description.to_string() }.into()
}
Loading

0 comments on commit d66029e

Please sign in to comment.