From 60b16544ae9ab82d62a8ec4f2929afcad8dff074 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sat, 11 May 2024 09:16:26 +0800 Subject: [PATCH] Re-execute `make gen-rpc-doc` --- tx-pool/src/chunk_process.rs | 2 +- tx-pool/src/process.rs | 31 ++++++++-------- .../src/contextual_block_verifier.rs | 37 ++++++++++--------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/tx-pool/src/chunk_process.rs b/tx-pool/src/chunk_process.rs index 0d9b03f2f3..d5837cf1cc 100644 --- a/tx-pool/src/chunk_process.rs +++ b/tx-pool/src/chunk_process.rs @@ -220,7 +220,7 @@ impl ChunkProcess { let (ret, snapshot) = self.service.pre_check(&tx).await; let (tip_hash, rtx, status, fee, tx_size) = try_or_return_with_snapshot!(ret, snapshot); - let cached = self.service.fetch_tx_verify_cache(&tx_hash).await; + let cached = self.service.fetch_tx_verify_cache(&tx).await; let tip_header = snapshot.tip_header(); let consensus = snapshot.cloned_consensus(); diff --git a/tx-pool/src/process.rs b/tx-pool/src/process.rs index 39627ccf9a..4738f5132e 100644 --- a/tx-pool/src/process.rs +++ b/tx-pool/src/process.rs @@ -80,9 +80,9 @@ impl TxPoolService { } } - pub(crate) async fn fetch_tx_verify_cache(&self, hash: &Byte32) -> Option { + pub(crate) async fn fetch_tx_verify_cache(&self, tx: &TransactionView) -> Option { let guard = self.txs_verify_cache.read().await; - guard.peek(hash).cloned() + guard.peek(&tx.witness_hash()).cloned() } async fn fetch_txs_verify_cache( @@ -91,8 +91,11 @@ impl TxPoolService { ) -> HashMap { let guard = self.txs_verify_cache.read().await; txs.filter_map(|tx| { - let hash = tx.hash(); - guard.peek(&hash).cloned().map(|value| (hash, value)) + let wtx_hash = tx.witness_hash(); + guard + .peek(&wtx_hash) + .cloned() + .map(|value| (wtx_hash, value)) }) .collect() } @@ -678,7 +681,7 @@ impl TxPoolService { remote: Option<(Cycle, PeerIndex)>, ) -> Option<(Result, Arc)> { let limit_cycles = self.tx_pool_config.max_tx_verify_cycles; - let tx_hash = tx.hash(); + let wtx_hash = tx.witness_hash(); let (ret, snapshot) = self.pre_check(&tx).await; let (tip_hash, rtx, status, fee, tx_size) = try_or_return_with_snapshot!(ret, snapshot); @@ -691,7 +694,7 @@ impl TxPoolService { return None; } - let cached = self.fetch_tx_verify_cache(&tx_hash).await; + let cached = self.fetch_tx_verify_cache(&tx).await; let tip_header = snapshot.tip_header(); let tx_env = Arc::new(status.with_env(tip_header)); @@ -783,7 +786,7 @@ impl TxPoolService { let txs_verify_cache = Arc::clone(&self.txs_verify_cache); tokio::spawn(async move { let mut guard = txs_verify_cache.write().await; - guard.put(tx_hash, CacheEntry::Completed(completed)); + guard.put(wtx_hash, CacheEntry::Completed(completed)); }); } @@ -800,11 +803,11 @@ impl TxPoolService { cached: CacheEntry, remote: Option<(Cycle, PeerIndex)>, ) -> Result<(), Reject> { - let tx_hash = tx.hash(); + let wtx_hash = tx.witness_hash(); let mut chunk = self.chunk.write().await; if chunk.add_tx(tx, remote) { let mut guard = self.txs_verify_cache.write().await; - guard.put(tx_hash, cached); + guard.put(wtx_hash, cached); } Ok(()) @@ -815,7 +818,7 @@ impl TxPoolService { tx: TransactionView, declared_cycles: Option, ) -> Option<(Result, Arc)> { - let tx_hash = tx.hash(); + let wtx_hash = tx.witness_hash(); let (ret, snapshot) = self.pre_check(&tx).await; @@ -829,7 +832,7 @@ impl TxPoolService { return None; } - let verify_cache = self.fetch_tx_verify_cache(&tx_hash).await; + let verify_cache = self.fetch_tx_verify_cache(&tx).await; let max_cycles = declared_cycles.unwrap_or_else(|| self.consensus.max_block_cycles()); let tip_header = snapshot.tip_header(); let tx_env = Arc::new(status.with_env(tip_header)); @@ -865,7 +868,7 @@ impl TxPoolService { let txs_verify_cache = Arc::clone(&self.txs_verify_cache); tokio::spawn(async move { let mut guard = txs_verify_cache.write().await; - guard.put(tx_hash, CacheEntry::Completed(verified)); + guard.put(wtx_hash, CacheEntry::Completed(verified)); }); } @@ -873,15 +876,13 @@ impl TxPoolService { } pub(crate) async fn _test_accept_tx(&self, tx: TransactionView) -> Result { - let tx_hash = tx.hash(); - let (pre_check_ret, snapshot) = self.pre_check(&tx).await; let (_tip_hash, rtx, status, _fee, _tx_size) = pre_check_ret?; // skip check the delay window - let verify_cache = self.fetch_tx_verify_cache(&tx_hash).await; + let verify_cache = self.fetch_tx_verify_cache(&tx).await; let max_cycles = self.consensus.max_block_cycles(); let tip_header = snapshot.tip_header(); let tx_env = Arc::new(status.with_env(tip_header)); diff --git a/verification/contextual/src/contextual_block_verifier.rs b/verification/contextual/src/contextual_block_verifier.rs index 28fec9b09e..af0c32a873 100644 --- a/verification/contextual/src/contextual_block_verifier.rs +++ b/verification/contextual/src/contextual_block_verifier.rs @@ -345,17 +345,24 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, } } - fn fetched_cache + Send + 'static>( - &self, - keys: K, - ) -> HashMap { + fn fetched_cache(&self, rtxs: &'a [Arc]) -> HashMap { let (sender, receiver) = oneshot::channel(); let txs_verify_cache = Arc::clone(self.txs_verify_cache); + let wtx_hashes: Vec = rtxs + .iter() + .skip(1) + .map(|rtx| rtx.transaction.witness_hash()) + .collect(); self.handle.spawn(async move { let guard = txs_verify_cache.read().await; - let ret = keys + let ret = wtx_hashes .into_iter() - .filter_map(|hash| guard.peek(&hash).cloned().map(|value| (hash, value))) + .filter_map(|wtx_hash| { + guard + .peek(&wtx_hash) + .cloned() + .map(|value| (wtx_hash, value)) + }) .collect(); if let Err(e) = sender.send(ret) { @@ -385,13 +392,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, // We should skip updating tx_verify_cache about the cellbase tx, // putting it in cache that will never be used until lru cache expires. let fetched_cache = if resolved.len() > 1 { - let keys: Vec = resolved - .iter() - .skip(1) - .map(|rtx| rtx.transaction.hash()) - .collect(); - - self.fetched_cache(keys) + self.fetched_cache(resolved) } else { HashMap::new() }; @@ -403,9 +404,9 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, .par_iter() .enumerate() .map(|(index, tx)| { - let tx_hash = tx.transaction.hash(); + let wtx_hash = tx.transaction.witness_hash(); - if let Some(cache_entry) = fetched_cache.get(&tx_hash) { + if let Some(cache_entry) = fetched_cache.get(&wtx_hash) { match cache_entry { CacheEntry::Completed(completed) => TimeRelativeTransactionVerifier::new( Arc::clone(tx), @@ -421,7 +422,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, } .into() }) - .map(|_| (tx_hash, *completed)), + .map(|_| (wtx_hash, *completed)), CacheEntry::Suspended(suspended) => ContextualTransactionVerifier::new( Arc::clone(tx), Arc::clone(&self.context.consensus), @@ -440,7 +441,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, } .into() }) - .map(|completed| (tx_hash, completed)), + .map(|completed| (wtx_hash, completed)), } } else { ContextualTransactionVerifier::new( @@ -460,7 +461,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, } .into() }) - .map(|completed| (tx_hash, completed)) + .map(|completed| (wtx_hash, completed)) }.and_then(|result| { if self.context.consensus.rfc0044_active(self.parent.epoch().number()) { DaoScriptSizeVerifier::new(