Skip to content

Commit

Permalink
sealing receipt in trie
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvja committed Oct 18, 2023
1 parent 6c2c742 commit b04dac9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
24 changes: 11 additions & 13 deletions solana/solana-ibc/programs/solana-ibc/src/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ type Result<T = (), E = ibc::core::ContextError> = core::result::Result<T, E>;
const CONNECTION_ID_PREFIX: &str = "connection-";
const CHANNEL_ID_PREFIX: &str = "channel-";

const DEFAULT_PORT_ID: &str = "defaultPort";
const TRANSFER_PORT_ID: &str = "transfer";

impl ClientExecutionContext for SolanaIbcStorage<'_, '_> {
type ClientValidationContext = Self;
type AnyClientState = AnyClientState;
Expand Down Expand Up @@ -65,7 +62,7 @@ impl ClientExecutionContext for SolanaIbcStorage<'_, '_> {
let client_state_hash =
borsh::to_vec(&serialized_client_state).unwrap();
trie.set(
&client_state_trie_key,
client_state_trie_key,
&lib::hash::CryptoHash::digest(&client_state_hash),
)
.unwrap();
Expand Down Expand Up @@ -101,7 +98,7 @@ impl ClientExecutionContext for SolanaIbcStorage<'_, '_> {
let consensus_state_hash =
borsh::to_vec(&serialized_consensus_state).unwrap();
trie.set(
&consensus_state_trie_key,
consensus_state_trie_key,
&lib::hash::CryptoHash::digest(&consensus_state_hash),
)
.unwrap();
Expand Down Expand Up @@ -219,7 +216,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
let consensus_state_hash =
borsh::to_vec(&serialized_connection_end).unwrap();
trie.set(
&consensus_state_trie_key,
consensus_state_trie_key,
&lib::hash::CryptoHash::digest(&consensus_state_hash),
)
.unwrap();
Expand Down Expand Up @@ -275,7 +272,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
.to_vec();
let trie = self.trie.as_mut().unwrap();
trie.set(
&commitment_trie_key,
commitment_trie_key,
&lib::hash::CryptoHash::digest(&commitment.into_vec()),
)
.unwrap();
Expand Down Expand Up @@ -329,7 +326,8 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
trie.set(&receipt_trie_key, &lib::hash::CryptoHash::DEFAULT).unwrap();
trie.set(receipt_trie_key, &lib::hash::CryptoHash::DEFAULT).unwrap();
trie.seal(receipt_trie_key).unwrap();
record_packet_sequence(
&mut self.packet_receipt_sequence_sets,
&receipt_path.port_id,
Expand Down Expand Up @@ -361,7 +359,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
.to_vec();
let trie = self.trie.as_mut().unwrap();
trie.set(
&ack_commitment_trie_key,
ack_commitment_trie_key,
&lib::hash::CryptoHash::digest(&ack_commitment.into_vec()),
)
.unwrap();
Expand Down Expand Up @@ -416,7 +414,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
let trie = self.trie.as_mut().unwrap();
let channel_end_hash = borsh::to_vec(&serialized_channel_end).unwrap();
trie.set(
&channel_end_trie_key,
channel_end_trie_key,
&lib::hash::CryptoHash::digest(&channel_end_hash),
)
.unwrap();
Expand Down Expand Up @@ -454,7 +452,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
let seq_in_bytes = seq_in_u64.to_be_bytes();

trie.set(
&next_seq_send_trie_key,
next_seq_send_trie_key,
&lib::hash::CryptoHash::digest(&seq_in_bytes),
)
.unwrap();
Expand Down Expand Up @@ -488,7 +486,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
let seq_in_bytes = seq_in_u64.to_be_bytes();

trie.set(
&next_seq_recv_trie_key,
next_seq_recv_trie_key,
&lib::hash::CryptoHash::digest(&seq_in_bytes),
)
.unwrap();
Expand Down Expand Up @@ -517,7 +515,7 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
let seq_in_bytes = seq_in_u64.to_be_bytes();

trie.set(
&next_seq_ack_trie_key,
next_seq_ack_trie_key,
&lib::hash::CryptoHash::digest(&seq_in_bytes),
)
.unwrap();
Expand Down
40 changes: 20 additions & 20 deletions solana/solana-ibc/programs/solana-ibc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub mod solana_ibc {
) -> Result<()> {
msg!("Called deliver method");
let _sender = ctx.accounts.sender.to_account_info();
let mut solana_ibc_store: &mut SolanaIbcStorageTemp =
let solana_ibc_store: &mut SolanaIbcStorageTemp =
&mut ctx.accounts.storage;
msg!("This is solana_ibc_store {:?}", solana_ibc_store);

Expand All @@ -68,7 +68,7 @@ pub mod solana_ibc {
module_holder: solana_ibc_store.module_holder.clone(),
clients: solana_ibc_store.clients.clone(),
client_id_set: solana_ibc_store.client_id_set.clone(),
client_counter: solana_ibc_store.client_counter.clone(),
client_counter: solana_ibc_store.client_counter,
client_processed_times: solana_ibc_store
.client_processed_times
.clone(),
Expand All @@ -80,12 +80,12 @@ pub mod solana_ibc {
.client_consensus_state_height_sets
.clone(),
connection_id_set: solana_ibc_store.connection_id_set.clone(),
connection_counter: solana_ibc_store.connection_counter.clone(),
connection_counter: solana_ibc_store.connection_counter,
connections: solana_ibc_store.connections.clone(),
channel_ends: solana_ibc_store.channel_ends.clone(),
connection_to_client: solana_ibc_store.connection_to_client.clone(),
port_channel_id_set: solana_ibc_store.port_channel_id_set.clone(),
channel_counter: solana_ibc_store.channel_counter.clone(),
channel_counter: solana_ibc_store.channel_counter,
next_sequence_send: solana_ibc_store.next_sequence_send.clone(),
next_sequence_recv: solana_ibc_store.next_sequence_recv.clone(),
next_sequence_ack: solana_ibc_store.next_sequence_ack.clone(),
Expand All @@ -107,7 +107,7 @@ pub mod solana_ibc {
module_holder: solana_ibc_store.module_holder.clone(),
clients: solana_ibc_store.clients.clone(),
client_id_set: solana_ibc_store.client_id_set.clone(),
client_counter: solana_ibc_store.client_counter.clone(),
client_counter: solana_ibc_store.client_counter,
client_processed_times: solana_ibc_store
.client_processed_times
.clone(),
Expand All @@ -119,12 +119,12 @@ pub mod solana_ibc {
.client_consensus_state_height_sets
.clone(),
connection_id_set: solana_ibc_store.connection_id_set.clone(),
connection_counter: solana_ibc_store.connection_counter.clone(),
connection_counter: solana_ibc_store.connection_counter,
connections: solana_ibc_store.connections.clone(),
channel_ends: solana_ibc_store.channel_ends.clone(),
connection_to_client: solana_ibc_store.connection_to_client.clone(),
port_channel_id_set: solana_ibc_store.port_channel_id_set.clone(),
channel_counter: solana_ibc_store.channel_counter.clone(),
channel_counter: solana_ibc_store.channel_counter,
next_sequence_send: solana_ibc_store.next_sequence_send.clone(),
next_sequence_recv: solana_ibc_store.next_sequence_recv.clone(),
next_sequence_ack: solana_ibc_store.next_sequence_ack.clone(),
Expand Down Expand Up @@ -168,7 +168,7 @@ pub mod solana_ibc {
solana_ibc_store.client_id_set =
solana_real_storage.client_id_set.clone();
solana_ibc_store.client_counter =
solana_real_storage.client_counter.clone();
solana_real_storage.client_counter;
solana_ibc_store.client_processed_times =
solana_real_storage.client_processed_times.clone();
solana_ibc_store.client_processed_heights =
Expand All @@ -180,7 +180,7 @@ pub mod solana_ibc {
solana_ibc_store.connection_id_set =
solana_real_storage.connection_id_set.clone();
solana_ibc_store.connection_counter =
solana_real_storage.connection_counter.clone();
solana_real_storage.connection_counter;
solana_ibc_store.connections = solana_real_storage.connections.clone();
solana_ibc_store.channel_ends =
solana_real_storage.channel_ends.clone();
Expand All @@ -189,7 +189,7 @@ pub mod solana_ibc {
solana_ibc_store.port_channel_id_set =
solana_real_storage.port_channel_id_set.clone();
solana_ibc_store.channel_counter =
solana_real_storage.channel_counter.clone();
solana_real_storage.channel_counter;
solana_ibc_store.next_sequence_send =
solana_real_storage.next_sequence_send.clone();
solana_ibc_store.next_sequence_recv =
Expand Down Expand Up @@ -257,33 +257,33 @@ pub enum TrieKeyWithoutFields {


impl TrieKey {
pub fn len(&self) -> usize {
fn len(&self) -> usize {
size_of::<u8>() +
match self {
TrieKey::ClientState { client_id } => client_id.len(),
TrieKey::ConsensusState { client_id, epoch: u64, height } => {
TrieKey::ConsensusState { client_id, epoch: _u64, height: _ } => {
client_id.len() + size_of::<u64>() + size_of::<u64>()
}
TrieKey::Connection { connection_id } => size_of::<u32>(),
TrieKey::ChannelEnd { port_id, channel_id } => {
TrieKey::Connection { connection_id: _ } => size_of::<u32>(),
TrieKey::ChannelEnd { port_id, channel_id: _ } => {
port_id.len() + size_of::<u32>()
}
TrieKey::NextSequenceSend { port_id, channel_id } => {
TrieKey::NextSequenceSend { port_id, channel_id: _ } => {
port_id.len() + size_of::<u32>()
}
TrieKey::NextSequenceRecv { port_id, channel_id } => {
TrieKey::NextSequenceRecv { port_id, channel_id: _ } => {
port_id.len() + size_of::<u32>()
}
TrieKey::NextSequenceAck { port_id, channel_id } => {
TrieKey::NextSequenceAck { port_id, channel_id: _ } => {
port_id.len() + size_of::<u32>()
}
TrieKey::Commitment { port_id, channel_id, sequence } => {
TrieKey::Commitment { port_id, channel_id: _, sequence: _ } => {
port_id.len() + size_of::<u32>() + size_of::<u64>()
}
TrieKey::Receipts { port_id, channel_id, sequence } => {
TrieKey::Receipts { port_id, channel_id: _, sequence: _ } => {
port_id.len() + size_of::<u32>() + size_of::<u64>()
}
TrieKey::Acks { port_id, channel_id, sequence } => {
TrieKey::Acks { port_id, channel_id: _, sequence: _ } => {
port_id.len() + size_of::<u32>() + size_of::<u64>()
}
}
Expand Down
3 changes: 1 addition & 2 deletions solana/solana-ibc/programs/solana-ibc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ use ibc::mock::header::MockHeader;
use ibc::Any;
use ibc_proto::protobuf::Protobuf;

use crate::trie::AccountTrie;
use crate::{
accounts, instruction, AnyCheck, SolanaIbcStorage, SolanaIbcStorageTemp,
accounts, instruction, AnyCheck, SolanaIbcStorageTemp,
ID, SOLANA_IBC_STORAGE_SEED, TEST_TRIE_SEED,
};

Expand Down
4 changes: 3 additions & 1 deletion solana/solana-ibc/programs/solana-ibc/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ use core::cell::RefMut;
use core::mem::ManuallyDrop;
use std::result::Result;

use anchor_lang::{prelude::*, solana_program};
use lib::hash::CryptoHash;
use memory::Ptr;

use crate::magic;

#[cfg(test)]
use anchor_lang::solana_program;

type DataRef<'a, 'b> = RefMut<'a, &'b mut [u8]>;

const SZ: usize = sealable_trie::nodes::RawNode::SIZE;
Expand Down

0 comments on commit b04dac9

Please sign in to comment.