Skip to content

Commit

Permalink
Exclude txs (#2357)
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Mar 23, 2023
1 parent 718ff20 commit b31a15c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/lib/storage/src/chain/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ impl<'a, 'c> MempoolSchema<'a, 'c> {
) -> QueryResult<VecDeque<SignedTxVariant>> {
let start = Instant::now();
// Load the transactions from mempool along with corresponding batch IDs.
let excluded_txs: Vec<String> = executed_txs.iter().map(|tx| tx.to_string()).collect();
let excluded_txs: Vec<String> = executed_txs
.iter()
.map(|tx| tx.to_string_without_prefix())
.collect();
let txs: Vec<MempoolTx> = sqlx::query_as!(
MempoolTx,
"SELECT * FROM mempool_txs WHERE reverted = false AND tx_hash NOT IN (
Expand Down
12 changes: 12 additions & 0 deletions core/lib/storage/src/tests/chain/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ async fn store_load(mut storage: StorageProcessor<'_>) -> QueryResult<()> {
);
}

let hashes: Vec<_> = txs
.iter()
.take(txs.len() / 2)
.map(|tx| tx.tx.hash())
.collect();

let txs_from_db = MempoolSchema(&mut storage)
.load_txs(&hashes)
.await
.expect("Can't load txs");
assert_eq!(txs_from_db.len(), txs.len() / 2);

Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions core/lib/types/src/tx/primitives/tx_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl TxHash {
let bytes: Vec<u8> = tx_hashes.iter().flat_map(AsRef::as_ref).cloned().collect();
TxHash::from_slice(&sha256(&bytes)).unwrap()
}

pub fn to_string_without_prefix(&self) -> String {
hex::encode(self.data)
}
}

impl AsRef<[u8]> for TxHash {
Expand Down

0 comments on commit b31a15c

Please sign in to comment.