Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/substrate/handler/l1sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { CommandOp } from "delphinus-l2-client-helper/src/swap";

const ProofPath = path.resolve(__dirname, "..", "..", "..");

var gasFeeLimit: number;
var decimals: number;
var symbol: string;

function getProofPathOfRid(rid: string) {
return path.resolve(ProofPath, `${rid}.proof`);
}
Expand Down Expand Up @@ -88,6 +92,18 @@ async function verify(
* 3. get hash from db, and check if it is pending in eth
*/
console.log("Current Verifier Version:" + vid);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never use the process.exit.
We should use throw error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again the bridge if for the whole bridge contract.
getEstimatedGasFee is for verify API's gas fee only so need change the name

let estimatedGasFee = await bridge.getEstimatedGasFee(command, proof, vid, rid);
estimatedGasFee = estimatedGasFee * (10 ** (-decimals));
console.log("Estimated gas fee is", estimatedGasFee, symbol);
if(typeof estimatedGasFee == "undefined") {
console.log("Error: failed to get estimatedGasFee.");
process.exit();
} else if(estimatedGasFee > gasFeeLimit) {
console.log("Error: gas fee is too high.");
process.exit();
}

let tx = bridge.verify(command, proof, vid, rid);
let r = await tx.when("Verify", "transactionHash", (hash: string) => {
console.log("Get transactionHash", hash);
Expand Down Expand Up @@ -168,6 +184,9 @@ async function l1SyncHandler(rid: string, op: CommandOp, args: any[]) {
console.log("----- verify args -----\n");

for (const config of await getEnabledEthConfigs(L1ClientRole.Monitor)) {
gasFeeLimit = config.gasFeeLimit;
decimals = config.nativeCurrency!.decimals;
symbol = config.nativeCurrency!.symbol;
await withL1Client(config, false, (l1client: L1Client) => {
return verify(
l1client,
Expand Down