Skip to content

Commit

Permalink
storing data in trie in execution context
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvja committed Oct 18, 2023
1 parent e9e18ae commit df1ce21
Showing 1 changed file with 58 additions and 50 deletions.
108 changes: 58 additions & 50 deletions solana/solana-ibc/programs/solana-ibc/src/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,17 @@ impl ClientExecutionContext for SolanaIbcStorage<'_, '_> {
client_id: consensus_state_path.client_id.to_string(),
height: consensus_state_path.height,
epoch: consensus_state_path.epoch,
}.to_vec();
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
let consensus_state_hash =
borsh::to_vec(&serialized_consensus_state).unwrap();
trie.set(
&consensus_state_trie_key,

Check failure on line 104 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:104:13 | 104 | &consensus_state_trie_key, | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `consensus_state_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
&lib::hash::CryptoHash::digest(&consensus_state_hash),
)
.unwrap();
.unwrap();

self.consensus_states
.insert(consensus_state_key, serialized_consensus_state);
self.height.0 = consensus_state_path.epoch;
Expand Down Expand Up @@ -205,26 +206,26 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
connection_end
);

let serialized_connection_end =
let serialized_connection_end =
serde_json::to_string(&connection_end).unwrap();
let connection_prefix_length = CONNECTION_ID_PREFIX.len();
let connection_id = &connection_path.0.to_string()[connection_prefix_length..];
let connection_prefix_length = CONNECTION_ID_PREFIX.len();
let connection_id =
&connection_path.0.to_string()[connection_prefix_length..];
let consensus_state_trie_key = &TrieKey::Connection {
connection_id: connection_id.parse().unwrap(),
}.to_vec();
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
let consensus_state_hash =
borsh::to_vec(&serialized_connection_end).unwrap();
trie.set(
&consensus_state_trie_key,

Check failure on line 222 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:222:13 | 222 | &consensus_state_trie_key, | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `consensus_state_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
&lib::hash::CryptoHash::digest(&consensus_state_hash),
)
.unwrap();
.unwrap();

self.connections.insert(
connection_path.0.to_string(),
serialized_connection_end
);
self.connections
.insert(connection_path.0.to_string(), serialized_connection_end);
Ok(())
}

Expand Down Expand Up @@ -262,14 +263,16 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
commitment_path,
commitment
);
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id = &commitment_path.channel_id.to_string()[channel_prefix_length..];
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id =
&commitment_path.channel_id.to_string()[channel_prefix_length..];

let commitment_trie_key = &TrieKey::Commitment {
port_id: commitment_path.port_id.clone().to_string(),
channel_id: channel_id.parse().unwrap(),
sequence: u64::from(commitment_path.sequence)
}.to_vec();
sequence: u64::from(commitment_path.sequence),
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
trie.set(
&commitment_trie_key,

Check failure on line 278 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:278:13 | 278 | &commitment_trie_key, | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `commitment_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Expand Down Expand Up @@ -315,19 +318,18 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
receipt_path,
receipt
);
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id = &receipt_path.channel_id.to_string()[channel_prefix_length..];
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id =
&receipt_path.channel_id.to_string()[channel_prefix_length..];

let receipt_trie_key = &TrieKey::Receipts {
port_id: receipt_path.port_id.clone().to_string(),
channel_id: channel_id.parse().unwrap(),
sequence: u64::from(receipt_path.sequence)
}.to_vec();
sequence: u64::from(receipt_path.sequence),
}
.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();

Check failure on line 332 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:332:18 | 332 | trie.set(&receipt_trie_key, &lib::hash::CryptoHash::DEFAULT).unwrap(); | ^^^^^^^^^^^^^^^^^ help: change this to: `receipt_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
record_packet_sequence(
&mut self.packet_receipt_sequence_sets,
&receipt_path.port_id,
Expand All @@ -347,20 +349,22 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
ack_path,
ack_commitment
);
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id = &ack_path.channel_id.to_string()[channel_prefix_length..];
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id =
&ack_path.channel_id.to_string()[channel_prefix_length..];

let ack_commitment_trie_key = &TrieKey::Acks {
port_id: ack_path.port_id.clone().to_string(),
channel_id: channel_id.parse().unwrap(),
sequence: u64::from(ack_path.sequence)
}.to_vec();
sequence: u64::from(ack_path.sequence),
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
trie.set(
&ack_commitment_trie_key,

Check failure on line 364 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:364:13 | 364 | &ack_commitment_trie_key, | ^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `ack_commitment_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
&lib::hash::CryptoHash::digest(&ack_commitment.into_vec()),
)
.unwrap();
.unwrap();
record_packet_sequence(
&mut self.packet_acknowledgement_sequence_sets,
&ack_path.port_id,
Expand Down Expand Up @@ -398,23 +402,24 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
channel_end_path.1.clone().to_string(),
));

let serialized_channel_end =
let serialized_channel_end =
serde_json::to_string(&channel_end).unwrap();
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id = &channel_end_path.1.to_string()[channel_prefix_length..];
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id =
&channel_end_path.1.to_string()[channel_prefix_length..];

let channel_end_trie_key = &TrieKey::ChannelEnd {
port_id: channel_end_path.0.clone().to_string(),
channel_id: channel_id.parse().unwrap(),
}.to_vec();
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
let channel_end_hash =
borsh::to_vec(&serialized_channel_end).unwrap();
let channel_end_hash = borsh::to_vec(&serialized_channel_end).unwrap();
trie.set(
&channel_end_trie_key,

Check failure on line 419 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:419:13 | 419 | &channel_end_trie_key, | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `channel_end_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
&lib::hash::CryptoHash::digest(&channel_end_hash),
)
.unwrap();
.unwrap();

self.channel_ends.insert(
(channel_end_path.0.to_string(), channel_end_path.1.to_string()),
Expand All @@ -436,23 +441,24 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
let seq_send_key =
(seq_send_path.0.to_string(), seq_send_path.1.to_string());

let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id = &seq_send_path.1.to_string()[channel_prefix_length..];

let next_seq_send_trie_key = &TrieKey::NextSequenceSend {
port_id: seq_send_path.0.clone().to_string(),
channel_id: channel_id.parse().unwrap(),
}.to_vec();
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
let seq_in_u64: u64 = seq.into();
let seq_in_bytes = seq_in_u64.to_be_bytes();

trie.set(
&next_seq_send_trie_key,

Check failure on line 457 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:457:13 | 457 | &next_seq_send_trie_key, | ^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `next_seq_send_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
&lib::hash::CryptoHash::digest(&seq_in_bytes),
)
.unwrap();
.unwrap();

self.next_sequence_send.insert(seq_send_key, u64::from(seq));
Ok(())
}
Expand All @@ -468,23 +474,24 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
seq
);
let seq_recv_key =
(seq_recv_path.0.to_string(), seq_recv_path.1.to_string());
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
(seq_recv_path.0.to_string(), seq_recv_path.1.to_string());
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id = &seq_recv_path.1.to_string()[channel_prefix_length..];

let next_seq_recv_trie_key = &TrieKey::NextSequenceRecv {
port_id: seq_recv_path.0.clone().to_string(),
channel_id: channel_id.parse().unwrap(),
}.to_vec();
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
let seq_in_u64: u64 = seq.into();
let seq_in_bytes = seq_in_u64.to_be_bytes();

trie.set(
&next_seq_recv_trie_key,

Check failure on line 491 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:491:13 | 491 | &next_seq_recv_trie_key, | ^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `next_seq_recv_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
&lib::hash::CryptoHash::digest(&seq_in_bytes),
)
.unwrap();
.unwrap();
self.next_sequence_recv.insert(seq_recv_key, u64::from(seq));
Ok(())
}
Expand All @@ -497,22 +504,23 @@ impl ExecutionContext for SolanaIbcStorage<'_, '_> {
msg!("store_next_sequence_ack: path: {}, seq: {:?}", seq_ack_path, seq);
let seq_ack_key =
(seq_ack_path.0.to_string(), seq_ack_path.1.to_string());
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_prefix_length = CHANNEL_ID_PREFIX.len();
let channel_id = &seq_ack_path.1.to_string()[channel_prefix_length..];

let next_seq_ack_trie_key = &TrieKey::NextSequenceAck {
port_id: seq_ack_path.0.clone().to_string(),
channel_id: channel_id.parse().unwrap(),
}.to_vec();
}
.to_vec();
let trie = self.trie.as_mut().unwrap();
let seq_in_u64: u64 = seq.into();
let seq_in_bytes = seq_in_u64.to_be_bytes();

trie.set(
&next_seq_ack_trie_key,

Check failure on line 520 in solana/solana-ibc/programs/solana-ibc/src/execution_context.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> solana/solana-ibc/programs/solana-ibc/src/execution_context.rs:520:13 | 520 | &next_seq_ack_trie_key, | ^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `next_seq_ack_trie_key` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
&lib::hash::CryptoHash::digest(&seq_in_bytes),
)
.unwrap();
.unwrap();
self.next_sequence_ack.insert(seq_ack_key, u64::from(seq));
Ok(())
}
Expand Down

0 comments on commit df1ce21

Please sign in to comment.