Skip to content

Commit

Permalink
Re-execute make gen-rpc-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec authored and doitian committed Jun 20, 2024
1 parent 7db9023 commit 60b1654
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion tx-pool/src/chunk_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 16 additions & 15 deletions tx-pool/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ impl TxPoolService {
}
}

pub(crate) async fn fetch_tx_verify_cache(&self, hash: &Byte32) -> Option<CacheEntry> {
pub(crate) async fn fetch_tx_verify_cache(&self, tx: &TransactionView) -> Option<CacheEntry> {
let guard = self.txs_verify_cache.read().await;
guard.peek(hash).cloned()
guard.peek(&tx.witness_hash()).cloned()
}

async fn fetch_txs_verify_cache(
Expand All @@ -91,8 +91,11 @@ impl TxPoolService {
) -> HashMap<Byte32, CacheEntry> {
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()
}
Expand Down Expand Up @@ -678,7 +681,7 @@ impl TxPoolService {
remote: Option<(Cycle, PeerIndex)>,
) -> Option<(Result<ProcessResult, Reject>, Arc<Snapshot>)> {
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);
Expand All @@ -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));

Expand Down Expand Up @@ -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));
});
}

Expand All @@ -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(())
Expand All @@ -815,7 +818,7 @@ impl TxPoolService {
tx: TransactionView,
declared_cycles: Option<Cycle>,
) -> Option<(Result<Completed, Reject>, Arc<Snapshot>)> {
let tx_hash = tx.hash();
let wtx_hash = tx.witness_hash();

let (ret, snapshot) = self.pre_check(&tx).await;

Expand All @@ -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));
Expand Down Expand Up @@ -865,23 +868,21 @@ 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));
});
}

Some((Ok(verified), submit_snapshot))
}

pub(crate) async fn _test_accept_tx(&self, tx: TransactionView) -> Result<Completed, Reject> {
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));
Expand Down
37 changes: 19 additions & 18 deletions verification/contextual/src/contextual_block_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,24 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a,
}
}

fn fetched_cache<K: IntoIterator<Item = Byte32> + Send + 'static>(
&self,
keys: K,
) -> HashMap<Byte32, CacheEntry> {
fn fetched_cache(&self, rtxs: &'a [Arc<ResolvedTransaction>]) -> HashMap<Byte32, CacheEntry> {
let (sender, receiver) = oneshot::channel();
let txs_verify_cache = Arc::clone(self.txs_verify_cache);
let wtx_hashes: Vec<Byte32> = 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) {
Expand Down Expand Up @@ -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<Byte32> = resolved
.iter()
.skip(1)
.map(|rtx| rtx.transaction.hash())
.collect();

self.fetched_cache(keys)
self.fetched_cache(resolved)
} else {
HashMap::new()
};
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 60b1654

Please sign in to comment.