Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solana-ibc: fix build warnings #17

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions solana/solana-ibc/programs/solana-ibc/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ impl ClientStateValidation<SolanaIbcStorage> for AnyClientState {

fn status(
&self,
ctx: &SolanaIbcStorage,
client_id: &ClientId,
_ctx: &SolanaIbcStorage,
_client_id: &ClientId,
) -> Result<ibc::core::ics02_client::client_state::Status, ClientError>
{
todo!()
Expand Down Expand Up @@ -286,7 +286,7 @@ impl ibc::clients::ics07_tendermint::ValidationContext for SolanaIbcStorage {
client_id: &ClientId,
height: &Height,
) -> Result<Option<Self::AnyConsensusState>, ContextError> {
let end_height = (height.revision_number() + 1, 1 as u64);
let end_height = (height.revision_number() + 1, 1);
match self.consensus_states.get(&(client_id.to_string(), end_height)) {
Some(data) => {
let result: Self::AnyConsensusState =
Expand All @@ -304,7 +304,7 @@ impl ibc::clients::ics07_tendermint::ValidationContext for SolanaIbcStorage {
client_id: &ClientId,
height: &Height,
) -> Result<Option<Self::AnyConsensusState>, ContextError> {
let end_height = (height.revision_number(), 1 as u64);
let end_height = (height.revision_number(), 1);
match self.consensus_states.get(&(client_id.to_string(), end_height)) {
Some(data) => {
let result: Self::AnyConsensusState =
Expand Down
75 changes: 32 additions & 43 deletions solana/solana-ibc/programs/solana-ibc/src/execution_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;

use anchor_lang::prelude::*;
use anchor_lang::emit;
use anchor_lang::solana_program::msg;
use ibc::core::events::IbcEvent;
use ibc::core::ics02_client::ClientExecutionContext;
use ibc::core::ics03_connection::connection::ConnectionEnd;
Expand Down Expand Up @@ -100,13 +101,13 @@ impl ExecutionContext for SolanaIbcStorage {
self.client_processed_times
.insert(client_id.to_string().clone(), new_map);
}
self.client_processed_times.get_mut(&client_id.to_string()).and_then(
self.client_processed_times.get_mut(&client_id.to_string()).map(
|processed_times| {
Some(BTreeMap::insert(
BTreeMap::insert(
processed_times,
(height.revision_number(), height.revision_height()),
timestamp.nanoseconds(),
))
)
},
);
Ok(())
Expand Down Expand Up @@ -135,16 +136,16 @@ impl ExecutionContext for SolanaIbcStorage {
self.client_processed_heights
.insert(client_id.to_string().clone(), new_map);
}
self.client_processed_heights.get_mut(&client_id.to_string()).and_then(
self.client_processed_heights.get_mut(&client_id.to_string()).map(
|processed_heights| {
Some(BTreeMap::insert(
BTreeMap::insert(
processed_heights,
(height.revision_number(), height.revision_height()),
(
host_height.revision_number(),
host_height.revision_height(),
),
))
)
},
);
Ok(())
Expand Down Expand Up @@ -217,19 +218,17 @@ impl ExecutionContext for SolanaIbcStorage {
commitment_path: &CommitmentPath,
) -> std::result::Result<(), ContextError> {
msg!("delete_packet_commitment: path: {}", commitment_path);
//
self.packet_commitment_sequence_sets
.get_mut(&(
commitment_path.port_id.clone().to_string(),
commitment_path.channel_id.clone().to_string(),
))
.map(|sequences| {
let index = sequences
.iter()
.position(|x| *x == u64::from(commitment_path.sequence))
.unwrap();
sequences.remove(index);
});
let sequences = self.packet_commitment_sequence_sets.get_mut(&(
commitment_path.port_id.clone().to_string(),
commitment_path.channel_id.clone().to_string(),
));
if let Some(sequences) = sequences {
let index = sequences
.iter()
.position(|x| *x == u64::from(commitment_path.sequence))
.unwrap();
sequences.remove(index);
};
Ok(())
}

Expand Down Expand Up @@ -276,15 +275,14 @@ impl ExecutionContext for SolanaIbcStorage {
ack_path: &AckPath,
) -> std::result::Result<(), ContextError> {
msg!("delete_packet_acknowledgement: path: {}", ack_path,);
self.packet_acknowledgement_sequence_sets
.get_mut(&(
ack_path.port_id.clone().to_string(),
ack_path.channel_id.clone().to_string(),
))
.map(|sequences| {
let sequence_as_u64: u64 = ack_path.sequence.into();
sequences.remove(sequence_as_u64 as usize);
});
let sequences = self.packet_acknowledgement_sequence_sets.get_mut(&(
ack_path.port_id.clone().to_string(),
ack_path.channel_id.clone().to_string(),
));
if let Some(sequences) = sequences {
let sequence_as_u64: u64 = ack_path.sequence.into();
sequences.remove(sequence_as_u64 as usize);
}
Ok(())
}

Expand Down Expand Up @@ -366,14 +364,10 @@ impl ExecutionContext for SolanaIbcStorage {
let event_in_bytes: Vec<u8> = bincode::serialize(&event).unwrap();
let inner_host_height =
(host_height.revision_height(), host_height.revision_number());
if self.ibc_events_history.contains_key(&inner_host_height) {
self.ibc_events_history
.get_mut(&inner_host_height)
.map(|events| events.push(event_in_bytes.clone()));
} else {
self.ibc_events_history
.insert(inner_host_height, vec![event_in_bytes.clone()]);
}
self.ibc_events_history
.entry(inner_host_height)
.or_default()
.push(event_in_bytes.clone());
emit!(EmitIBCEvent { ibc_event: event_in_bytes });
}

Expand All @@ -391,10 +385,5 @@ fn record_packet_sequence(
sequence: &Sequence,
) {
let key = (port_id.clone().to_string(), channel_id.clone().to_string());
if hash_map.contains_key(&key) {
hash_map.insert(key.clone(), Vec::new());
}
hash_map.get_mut(&key).map(|sequences| {
sequences.push(u64::from(*sequence));
});
hash_map.entry(key).or_default().push(u64::from(*sequence));
}
14 changes: 9 additions & 5 deletions solana/solana-ibc/programs/solana-ibc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// anchor_lang::error::Error and anchor_lang::Result is ≥ 160 bytes and there’s
// not much we can do about it.
#![allow(clippy::result_large_err)]

use std::collections::BTreeMap;

use anchor_lang::prelude::*;
Expand All @@ -6,7 +10,7 @@ use ibc::core::ics24_host::identifier::PortId;
use ibc::core::router::{Module, ModuleId, Router};
use module_holder::ModuleHolder;

const SOLANA_IBC_STORAGE_SEED: &'static [u8] = b"solana_ibc_storage";
const SOLANA_IBC_STORAGE_SEED: &[u8] = b"solana_ibc_storage";

declare_id!("7MEuaEwNMsjVCJy9N31ZgvQf1dFkRNXYFREaAjMsoE5g");

Expand All @@ -20,7 +24,7 @@ mod transfer;
mod validation_context;
// mod client_context;

#[program]
#[anchor_lang::program]
pub mod solana_ibc {
use super::*;

Expand Down Expand Up @@ -157,7 +161,7 @@ pub struct SolanaIbcStorage {
}

impl SolanaIbcStorage {
fn new(account: Pubkey) -> Self {
pub fn new(account: Pubkey) -> Self {
SolanaIbcStorage {
height: (0, 0),
module_holder: ModuleHolder::new(account),
Expand Down Expand Up @@ -188,12 +192,12 @@ impl SolanaIbcStorage {

pub trait SolanaIbcStorageHost {
///
fn get_solana_ibc_store(account: Pubkey) -> SolanaIbcStorage {
fn get_solana_ibc_store(_account: Pubkey) -> SolanaIbcStorage {
// Unpack the account
todo!()
}
///
fn set_solana_ibc_store(store: &SolanaIbcStorage) { todo!() }
fn set_solana_ibc_store(_store: &SolanaIbcStorage) { todo!() }
}

impl Router for SolanaIbcStorage {
Expand Down
19 changes: 7 additions & 12 deletions solana/solana-ibc/programs/solana-ibc/src/transfer/impls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use anchor_lang::prelude::{Error, Pubkey};
use anchor_lang::solana_program::account_info::AccountInfo;
use anchor_lang::solana_program::msg;
use anchor_lang::ToAccountInfo;
use ibc::applications::transfer::context::{
TokenTransferExecutionContext, TokenTransferValidationContext,
};
Expand Down Expand Up @@ -31,16 +28,14 @@ use crate::{SolanaIbcStorage, SolanaIbcStorageHost};
impl TokenTransferExecutionContext for ModuleHolder {
fn send_coins_execute(
&mut self,
from: &Self::AccountId,
to: &Self::AccountId,
amt: &PrefixedCoin,
_from: &Self::AccountId,
_to: &Self::AccountId,
_amt: &PrefixedCoin,
) -> Result<(), TokenTransferError> {
let sender_id = from.to_string();
let receiver_id = to.to_string();
let base_denom = amt.denom.base_denom.to_string();

// Todo!
Ok(())
//let sender_id = from.to_string();
//let receiver_id = to.to_string();
//let base_denom = amt.denom.base_denom.to_string();
todo!()
}

fn mint_coins_execute(
Expand Down
17 changes: 8 additions & 9 deletions solana/solana-ibc/programs/solana-ibc/src/validation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl ValidationContext for SolanaIbcStorage {
}

fn host_height(&self) -> std::result::Result<ibc::Height, ContextError> {
Ok(ibc::Height::new(self.height.0, self.height.1)
.map_err(|e| ContextError::ClientError(e))?)
ibc::Height::new(self.height.0, self.height.1)
.map_err(ContextError::ClientError)
}

fn host_timestamp(&self) -> std::result::Result<Timestamp, ContextError> {
Expand All @@ -101,10 +101,9 @@ impl ValidationContext for SolanaIbcStorage {
_height: &ibc::Height,
) -> std::result::Result<Self::AnyConsensusState, ContextError> {
Err(ContextError::ClientError(ClientError::ClientSpecific {
description: format!(
"The `host_consensus_state` is not supported on Solana \
protocol."
),
description: "The `host_consensus_state` is not supported on \
Solana protocol."
.into(),
}))
}

Expand Down Expand Up @@ -355,16 +354,16 @@ impl ValidationContext for SolanaIbcStorage {
&self,
signer: &ibc::Signer,
) -> std::result::Result<(), ContextError> {
match Pubkey::from_str(&signer.to_string()) {
match Pubkey::from_str(signer.as_ref()) {
Ok(_) => Ok(()),
Err(e) => Err(ContextError::ClientError(ClientError::Other {
description: format!("Invalid signer: {:?}", e).to_string(),
description: format!("Invalid signer: {e:?}"),
})),
}
}

fn get_client_validation_context(&self) -> &Self::ClientValidationContext {
&self
self
}

fn get_compatible_versions(
Expand Down
Loading