From f1eded3b163dadb35235c00288e424c4311e05ba Mon Sep 17 00:00:00 2001 From: akayi07 Date: Mon, 15 May 2023 02:34:34 +0800 Subject: [PATCH 1/3] add gasFeeLimit --- src/substrate/handler/l1sync.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/substrate/handler/l1sync.ts b/src/substrate/handler/l1sync.ts index e505b32..d9d1d39 100644 --- a/src/substrate/handler/l1sync.ts +++ b/src/substrate/handler/l1sync.ts @@ -17,6 +17,8 @@ import { CommandOp } from "delphinus-l2-client-helper/src/swap"; const ProofPath = path.resolve(__dirname, "..", "..", ".."); +var gasFeeLimit: number; + function getProofPathOfRid(rid: string) { return path.resolve(ProofPath, `${rid}.proof`); } @@ -88,6 +90,17 @@ async function verify( * 3. get hash from db, and check if it is pending in eth */ console.log("Current Verifier Version:" + vid); + + let estimatedGasFee = await bridge.getEstimatedGasFee(command, proof, vid, rid); + console.log("Estimated gas fee is", estimatedGasFee, "ETH"); + 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); @@ -168,6 +181,7 @@ 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; await withL1Client(config, false, (l1client: L1Client) => { return verify( l1client, From f5ddf07e497b17220ef6c24a5fa0848ac9f22eda Mon Sep 17 00:00:00 2001 From: akayi07 Date: Mon, 22 May 2023 14:51:06 +0800 Subject: [PATCH 2/3] bugfix: remove unit --- src/substrate/handler/l1sync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/substrate/handler/l1sync.ts b/src/substrate/handler/l1sync.ts index d9d1d39..7577151 100644 --- a/src/substrate/handler/l1sync.ts +++ b/src/substrate/handler/l1sync.ts @@ -92,7 +92,7 @@ async function verify( console.log("Current Verifier Version:" + vid); let estimatedGasFee = await bridge.getEstimatedGasFee(command, proof, vid, rid); - console.log("Estimated gas fee is", estimatedGasFee, "ETH"); + console.log("Estimated gas fee is", estimatedGasFee); if(typeof estimatedGasFee == "undefined") { console.log("Error: failed to get estimatedGasFee."); process.exit(); From 0fdae4811564930a4311c4af5b6db5512ad3acba Mon Sep 17 00:00:00 2001 From: akayi07 Date: Sun, 28 May 2023 11:02:35 +0800 Subject: [PATCH 3/3] refine the way of calculte gas fee --- src/substrate/handler/l1sync.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/substrate/handler/l1sync.ts b/src/substrate/handler/l1sync.ts index 7577151..44e47d7 100644 --- a/src/substrate/handler/l1sync.ts +++ b/src/substrate/handler/l1sync.ts @@ -18,6 +18,8 @@ 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`); @@ -92,7 +94,8 @@ async function verify( console.log("Current Verifier Version:" + vid); let estimatedGasFee = await bridge.getEstimatedGasFee(command, proof, vid, rid); - console.log("Estimated gas fee is", estimatedGasFee); + 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(); @@ -182,6 +185,8 @@ async function l1SyncHandler(rid: string, op: CommandOp, args: any[]) { 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,