-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduces the concept of cancellable transactions. It is now possible to send a TX as `cancellable`, which will output an extra nullifier in the entrypoint function using the tx nonce and a dedicated generator. A subsequent transaction with the same nonce but an empty payload and a higher fee should then picked up by the sequencer, making the original one fail due to the duplicate nullifier. This is not yet implemented in the sequencer and kinda difficult to test at the moment. ## New commands - `get-tx [txHash]`: Poor's man tx inspector/history. Provides a list of recent transactions (supports pagination), their aliases and status. Providing a txHash will inspect it in more detail. <img width="783" alt="Screenshot 2024-08-29 at 12 22 13" src="https://github.com/user-attachments/assets/ad52bb7b-4349-4049-9ca6-bcaa63bbb837"> - `cancel-tx <txHash>`: Cancels a previous transaction (provided it was done via the same wallet and we have the fee info) via its txHash (or alias), using a multiplier to the `inclusionFee` of the original tx. ## Fixes - Should fix earthly compilation for devnet builds
- Loading branch information
Showing
30 changed files
with
331 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { type AccountWalletWithSecretKey, type FeePaymentMethod, SentTx, type TxHash, TxStatus } from '@aztec/aztec.js'; | ||
import { type FeeOptions } from '@aztec/aztec.js/entrypoint'; | ||
import { Fr, type GasSettings } from '@aztec/circuits.js'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
|
||
export async function cancelTx( | ||
wallet: AccountWalletWithSecretKey, | ||
{ | ||
txHash, | ||
gasSettings, | ||
nonce, | ||
cancellable, | ||
}: { txHash: TxHash; gasSettings: GasSettings; nonce: Fr; cancellable: boolean }, | ||
paymentMethod: FeePaymentMethod, | ||
log: LogFn, | ||
) { | ||
const receipt = await wallet.getTxReceipt(txHash); | ||
if (receipt.status !== TxStatus.PENDING || !cancellable) { | ||
log(`Transaction is in status ${receipt.status} and cannot be cancelled`); | ||
return; | ||
} | ||
|
||
const fee: FeeOptions = { | ||
paymentMethod, | ||
gasSettings, | ||
}; | ||
|
||
gasSettings.inclusionFee.mul(new Fr(2)); | ||
|
||
const txRequest = await wallet.createTxExecutionRequest({ | ||
calls: [], | ||
fee, | ||
nonce, | ||
cancellable: true, | ||
}); | ||
|
||
const txPromise = await wallet.proveTx(txRequest, true); | ||
const tx = new SentTx(wallet, wallet.sendTx(txPromise)); | ||
try { | ||
await tx.wait(); | ||
|
||
log('Transaction has been cancelled'); | ||
|
||
const cancelReceipt = await tx.getReceipt(); | ||
log(` Tx fee: ${cancelReceipt.transactionFee}`); | ||
log(` Status: ${cancelReceipt.status}`); | ||
log(` Block number: ${cancelReceipt.blockNumber}`); | ||
log(` Block hash: ${cancelReceipt.blockHash?.toString('hex')}`); | ||
} catch (err: any) { | ||
log(`Could not cancel transaction\n ${err.message}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type PXE, type TxHash } from '@aztec/aztec.js'; | ||
import { inspectTx } from '@aztec/cli/utils'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
|
||
export async function checkTx(client: PXE, txHash: TxHash, statusOnly: boolean, log: LogFn) { | ||
if (statusOnly) { | ||
const receipt = await client.getTxReceipt(txHash); | ||
return receipt.status; | ||
} else { | ||
await inspectTx(client, txHash, log, { includeBlockInfo: true }); | ||
} | ||
} |
Oops, something went wrong.