Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
fix(cache-opt): fix typo introduced by #1197 (#1208)
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-mathieu authored Oct 20, 2023
1 parent 7210c6d commit 2a4edbe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
method being used)
- refactor(sealing): how the sealing mode is passed into runtime
- feat(sealing): finalization for instant sealing
- feat(cache-option): add an option to enable aggressive caching in the
command-line parameters
- feat(cache-option): add an option to enable aggressive caching in command-line
parameters

## v0.4.0

Expand Down
30 changes: 22 additions & 8 deletions crates/client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ where
.map(|tx_hashes| h256_to_felt(*tx_hashes.get(index as usize).ok_or(StarknetRpcApiError::InvalidTxnIndex)?))
.unwrap_or_else(|| Ok(transaction.compute_hash::<H>(chain_id.0.into(), false).0))?;

Ok(to_starknet_core_tx::<H>(transaction.clone(), transaction_hash))
Ok(to_starknet_core_tx(transaction.clone(), transaction_hash))
}

/// Get block information with full transactions given the block id
Expand All @@ -681,7 +681,7 @@ where
.as_ref()
.map(|tx_hashes| h256_to_felt(*tx_hashes.get(index).ok_or(StarknetRpcApiError::InternalServerError)?))
.unwrap_or_else(|| Ok(tx.compute_hash::<H>(chain_id.0.into(), false).0))?;
transactions.push(to_starknet_core_tx::<H>(tx.clone(), hash));
transactions.push(to_starknet_core_tx(tx.clone(), hash));
}

let block_with_txs = BlockWithTxs {
Expand Down Expand Up @@ -761,8 +761,14 @@ where
})?;

let chain_id = self.chain_id()?;
let transactions = transactions.into_iter().map(|tx| to_starknet_core_tx::<H>(tx, chain_id.0)).collect();

let transactions = transactions
.into_iter()
.map(|tx| {
let hash = tx.compute_hash::<H>(chain_id.0.into(), false).into();
to_starknet_core_tx(tx, hash)
})
.collect();
Ok(transactions)
}

Expand Down Expand Up @@ -845,11 +851,19 @@ where
let block = get_block_by_block_hash(self.client.as_ref(), substrate_block_hash).unwrap_or_default();
let chain_id = self.chain_id()?.0.into();

let find_tx = block
.transactions()
.iter()
.find(|tx| tx.compute_hash::<H>(chain_id, false).0 == transaction_hash)
.map(|tx| to_starknet_core_tx::<H>(tx.clone(), transaction_hash));
let find_tx = if let Some(tx_hashes) = self.get_cached_transaction_hashes(block.header().hash::<H>().into()) {
tx_hashes
.into_iter()
.zip(block.transactions())
.find(|(tx_hash, _)| *tx_hash == Felt252Wrapper(transaction_hash).into())
.map(|(_, tx)| to_starknet_core_tx(tx.clone(), transaction_hash))
} else {
block
.transactions()
.iter()
.find(|tx| tx.compute_hash::<H>(chain_id, false).0 == transaction_hash)
.map(|tx| to_starknet_core_tx(tx.clone(), transaction_hash))
};

find_tx.ok_or(StarknetRpcApiError::TxnHashNotFound.into())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::vec::Vec;

use mp_felt::Felt252Wrapper;
use mp_hashers::HasherT;
use starknet_crypto::FieldElement;

fn cast_vec_of_felt_252_wrappers(data: Vec<Felt252Wrapper>) -> Vec<FieldElement> {
Expand All @@ -11,7 +10,7 @@ fn cast_vec_of_felt_252_wrappers(data: Vec<Felt252Wrapper>) -> Vec<FieldElement>
unsafe { alloc::vec::Vec::from_raw_parts(data.as_mut_ptr() as *mut FieldElement, data.len(), data.capacity()) }
}

pub fn to_starknet_core_tx<H: HasherT>(
pub fn to_starknet_core_tx(
tx: super::Transaction,
transaction_hash: FieldElement,
) -> starknet_core::types::Transaction {
Expand Down

0 comments on commit 2a4edbe

Please sign in to comment.