Skip to content

Commit

Permalink
solana-ibc: improve naming of storage types
Browse files Browse the repository at this point in the history
`Temp` and `Test` suffixes don’t really reflect purpose of the storage
types.  Rename types to be more informative:
- Drop `Solana` from the names.  This is a Solana program so obviously
  it’s Solana.
- Call outer and inner types `IbcStorage` and `IbcStorageInner`
  respectively.  This follows typical Rust style where wrapped types
  have `Inner` suffix.
- Use `PrivateStorage` for data stored in Solana outside of the
  provable trie.  This reflect how the two storage types are named in
  IBC.
  • Loading branch information
mina86 authored Oct 20, 2023
1 parent 583708d commit 9cdf1ae
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 159 deletions.
42 changes: 21 additions & 21 deletions solana/solana-ibc/programs/solana-ibc/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -82,10 +82,10 @@ impl From<AnyClientState> for Any {
}
}

impl ClientStateValidation<SolanaIbcStorage<'_, '_>> for AnyClientState {
impl ClientStateValidation<IbcStorage<'_, '_>> for AnyClientState {
fn verify_client_message(
&self,
ctx: &SolanaIbcStorage,
ctx: &IbcStorage,
client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
Expand All @@ -111,7 +111,7 @@ impl ClientStateValidation<SolanaIbcStorage<'_, '_>> for AnyClientState {

fn check_for_misbehaviour(
&self,
ctx: &SolanaIbcStorage,
ctx: &IbcStorage,
client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
Expand All @@ -137,7 +137,7 @@ impl ClientStateValidation<SolanaIbcStorage<'_, '_>> for AnyClientState {

fn status(
&self,
_ctx: &SolanaIbcStorage,
_ctx: &IbcStorage,
_client_id: &ClientId,
) -> Result<ibc::core::ics02_client::client_state::Status, ClientError>
{
Expand Down Expand Up @@ -283,10 +283,10 @@ impl From<MockClientState> for AnyClientState {
fn from(value: MockClientState) -> Self { AnyClientState::Mock(value) }
}

impl ClientStateExecution<SolanaIbcStorage<'_, '_>> for AnyClientState {
impl ClientStateExecution<IbcStorage<'_, '_>> for AnyClientState {
fn initialise(
&self,
ctx: &mut SolanaIbcStorage,
ctx: &mut IbcStorage,
client_id: &ClientId,
consensus_state: Any,
) -> Result<(), ClientError> {
Expand All @@ -303,7 +303,7 @@ impl ClientStateExecution<SolanaIbcStorage<'_, '_>> for AnyClientState {

fn update_state(
&self,
ctx: &mut SolanaIbcStorage,
ctx: &mut IbcStorage,
client_id: &ClientId,
header: Any,
) -> Result<Vec<Height>, ClientError> {
Expand All @@ -320,7 +320,7 @@ impl ClientStateExecution<SolanaIbcStorage<'_, '_>> for AnyClientState {

fn update_state_on_misbehaviour(
&self,
ctx: &mut SolanaIbcStorage,
ctx: &mut IbcStorage,
client_id: &ClientId,
client_message: Any,
update_kind: &UpdateKind,
Expand All @@ -346,7 +346,7 @@ impl ClientStateExecution<SolanaIbcStorage<'_, '_>> 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,
Expand All @@ -371,9 +371,7 @@ impl ClientStateExecution<SolanaIbcStorage<'_, '_>> for AnyClientState {
}
}

impl ibc::clients::ics07_tendermint::CommonContext
for SolanaIbcStorage<'_, '_>
{
impl ibc::clients::ics07_tendermint::CommonContext for IbcStorage<'_, '_> {
type ConversionError = ClientError;

type AnyConsensusState = AnyConsensusState;
Expand All @@ -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;

Expand All @@ -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<Timestamp, ContextError> {
ValidationContext::host_timestamp(self)
}
Expand All @@ -416,8 +412,10 @@ impl ibc::clients::ics07_tendermint::ValidationContext
height: &Height,
) -> Result<Option<Self::AnyConsensusState>, 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))
{
Expand All @@ -438,8 +436,10 @@ impl ibc::clients::ics07_tendermint::ValidationContext
height: &Height,
) -> Result<Option<Self::AnyConsensusState>, 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))
{
Expand Down
Loading

0 comments on commit 9cdf1ae

Please sign in to comment.