Conflux-Chain / conflux-portal

:globe_with_meridians: :electric_plug: The ConfluxPortal browser extension enables browsing Conflux blockchain enabled websites.
https://conflux-chain.github.io/conflux-portal-docs
MIT License
69 stars 17 forks source link

Add warning for unnecessarily high gas limit #248

Open Thegaram opened 3 years ago

Thegaram commented 3 years ago

What problem are you trying to solve?

In Ethereum, gas provided but not used by the execution is refunded. In Conflux, on the other hand, we refund at most 25% of the overall gas cost. As this might surprise many users who come from Ethereum, I suggest we add a warning if a user sets gas price to a much higher value than the latest estimate.

Describe the solution you'd like

When Conflux Portal has an estimate available, I suggest we give a warning when the estimated gas charged is larger than gas used by the execution.

Additional context

Here's an example:

gas limit: 1000000
gas price: 10
=> max price: 10000000

gas used: 22339
gas fee: 7500000 (75% of max price)

curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getTransactionByHash","params":["0x42bfc5b8e21a933d8a2340b75675c6487573673e46c9a0e1683415a7d7bc60fe"],"id":1}' -H "Content-Type: application/json" http://mainnet-jsonrpc.conflux-chain.org:12537

{
    "jsonrpc": "2.0",
    "result": {
        "jsonrpc": "2.0",
        "result": {
            "gas": "0xf4240",
            "gasPrice": "0xa",
            ...
        },
        "id": 1
    }
}

curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getTransactionReceipt","params":["0x42bfc5b8e21a933d8a2340b75675c6487573673e46c9a0e1683415a7d7bc60fe"],"id":1}' -H "Content-Type: application/json" http://mainnet-jsonrpc.conflux-chain.org:12537

{
    "jsonrpc": "2.0",
    "result": {
        "gasFee": "0x7270e0",
        "gasUsed": "0x5743",
        ...
    },
    "id": 1
}
lionking062 commented 3 years ago

Good issue. We'll perfect it.

yqrashawn commented 3 years ago

https://app.clickup.com/t/51uf6u