Skip to content

Commit cd903d9

Browse files
authored
refactor(pxe): avoid expensive toTx() call when computing tx hash (#23136)
1 parent 5ac3684 commit cd903d9

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

yarn-project/pxe/src/pxe.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,7 @@ export class PXE {
849849
// storing the tags here prevents linkage of txs sent from the same PXE.
850850
const taggingIndexRangesUsedInTheTx = privateExecutionResult.entrypoint.taggingIndexRanges;
851851
if (taggingIndexRangesUsedInTheTx.length > 0) {
852-
// TODO(benesjan): The following is an expensive operation. Figure out a way to avoid it.
853-
const txHash = (await txProvingResult.toTx()).txHash;
852+
const txHash = await txProvingResult.getTxHash();
854853

855854
await this.senderTaggingStore.storePendingIndexes(taggingIndexRangesUsedInTheTx, txHash, jobId);
856855
this.log.debug(`Stored used tagging index ranges as sender for the tx`, {

yarn-project/stdlib/src/tx/proven_tx.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from './private_execution_result.js';
1414
import { type ProvingStats, ProvingTimingsSchema } from './profiling.js';
1515
import { Tx } from './tx.js';
16+
import type { TxHash } from './tx_hash.js';
1617

1718
export class TxProvingResult {
1819
constructor(
@@ -22,6 +23,11 @@ export class TxProvingResult {
2223
public stats?: ProvingStats,
2324
) {}
2425

26+
getTxHash(): Promise<TxHash> {
27+
// Equivalent to `(await this.toTx()).txHash` but skips walking the execution result tree to collect logs.
28+
return Tx.computeTxHash({ data: this.publicInputs });
29+
}
30+
2531
async toTx(): Promise<Tx> {
2632
const contractClassLogs = collectSortedContractClassLogs(this.privateExecutionResult);
2733

0 commit comments

Comments
 (0)