Skip to content

Commit

Permalink
add comments of getTxStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Jun 26, 2024
1 parent a669a9b commit cfc72c7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/zklinkNova/scripts/getTxStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,37 @@ const { task, types } = require('hardhat/config');

require('dotenv').config();

// This command is used to check if a tx of zklink nova is considered to be finalized on Ethereum
// A tx of zklink nova is considered to be finalized on Ethereum means:
// 1. The tx is confirmed on zklink nova
// 2. The block of zklink nova which contain the tx is considered to be finalized on Linea
// 3. The block of Linea which contain the finalize tx of nova is considered to be finalized on Ethereum
task('getTxStatus', 'Get the tx status of nova')
.addParam('txHash', 'The tx hash', undefined, types.string)
.addOptionalParam('useCommit', 'Use commit as the nova finalize tx', true, types.boolean)
.setAction(async taskArgs => {
// This is a tx hash of zklink nova
const txHash = taskArgs.txHash;
// A block of zklink nova must first be committed to Linea, then proven, and finally executed.
// Generally, a block can be committed to Linea in about 10 minutes after it is generated, but proof takes longer, which may take about an hour.
// If `useCommit` set to true, then the finalize time of a nova tx to Linea is about 10 minutes
// Otherwise it may take more than 1 hour
const useCommit = taskArgs.useCommit;
console.log(`Get the status of tx: ${txHash}`);
const zkLinkNovaProvider = new Provider(process.env.ZKLINK_NOVA_RPC);
const lineaProvider = new ethers.JsonRpcProvider(process.env.LINEA_RPC);
const ethereumProvider = new ethers.JsonRpcProvider(process.env.ETHEREUM_RPC);

// We check if the tx is confirmed on zklink nova
const txReceipt = await zkLinkNovaProvider.getTransactionReceipt(txHash);
if (!txReceipt.blockNumber) {
console.log(`Tx status: not confirmed`);
return;
}
console.log(`Tx block: ${txReceipt.blockNumber}`);

// Then we check the finalize status on Linea of the block which contain the tx
// If `useCommit` is true then the finalize time of the block will be about 10 minutes
const blockDetails = await zkLinkNovaProvider.getBlockDetails(txReceipt.blockNumber);
const novaFinalizeTx = useCommit ? blockDetails.commitTxHash : blockDetails.proveTxHash;
if (!novaFinalizeTx) {
Expand All @@ -39,6 +52,9 @@ task('getTxStatus', 'Get the tx status of nova')
}
console.log(`Nova finalize tx block number on linea: ${novaFinalizeTxReceipt.blockNumber}`);

// After the nova block finalize tx is confirmed on linea, we continue to check the status of Linea's tx finalized on Ethereum
// Linea deployed a rollup contract on Ethereum and has a readable interface `function currentL2BlockNumber() external view`
// When the number of a block on Linea is greater or equal to the value of `currentL2BlockNumber` it means the block is finalized on Ethereum
const ethereumChainId = (await ethereumProvider.getNetwork()).chainId;
const network = ethereumChainId === BigInt(1) ? 'linea-mainnet' : 'linea-sepolia';
const lineaSDK = new LineaSDK({
Expand Down

0 comments on commit cfc72c7

Please sign in to comment.