Skip to content

Commit

Permalink
fix: race condition in PXE.getTxReceipt(...) (#3411)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Nov 23, 2023
1 parent 8b2d15e commit 9557a66
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,23 @@ export class PXEService implements PXE {
}

public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
let txReceipt = new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');

// We first check if the tx is in pending (instead of first checking if it is mined) because if we first check
// for mined and then for pending there could be a race condition where the tx is mined between the two checks
// and we would incorrectly return a TxReceipt with status DROPPED
const pendingTx = await this.node.getPendingTxByHash(txHash);
if (pendingTx) {
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
}

const settledTx = await this.node.getTx(txHash);
if (settledTx) {
const deployedContractAddress = settledTx.newContractData.find(
c => !c.contractAddress.equals(AztecAddress.ZERO),
)?.contractAddress;

return new TxReceipt(
txReceipt = new TxReceipt(
txHash,
TxStatus.MINED,
'',
Expand All @@ -371,12 +381,7 @@ export class PXEService implements PXE {
);
}

const pendingTx = await this.node.getPendingTxByHash(txHash);
if (pendingTx) {
return new TxReceipt(txHash, TxStatus.PENDING, '');
}

return new TxReceipt(txHash, TxStatus.DROPPED, 'Tx dropped by P2P node.');
return txReceipt;
}

public async getTx(txHash: TxHash): Promise<L2Tx | undefined> {
Expand Down

0 comments on commit 9557a66

Please sign in to comment.