vechain / thor

A general purpose blockchain highly compatible with Ethereum's ecosystem
GNU Lesser General Public License v3.0
800 stars 247 forks source link

Simulated calculation of gas usage seems to be incorrect #221

Closed wupeaking closed 5 years ago

wupeaking commented 5 years ago

I use the api /accounts/* to calc the gas usage, it seems to be incorrect .

{
  "clauses": [
    {
      "to": "0x0000000000000000000000000000456e65726779",
      "value": "0x0",
      "data": "0xa9059cbb000000000000000000000000e26ecd8538c0754cd16acf9253a1a2110ab83ef30000000000000000000000000000000000000000000000000de0b6b3a7640000"
    }
  ]
}

it returns the gasUsed is 13326 .

but ,The actual gas usage is 36518。 the link

Is it wrong with me?

我想用API /accounts/*来提前模拟实际的gas使用量, 但是不知道为什么这个返回的gasUsed好像和实际的用量差别比较大。

libotony commented 5 years ago

You missed intrinsic gas, check the doc here, intrinsic gas should be calculated locally

漏掉了固有gas, 接口只返回了VM执行的gas

wupeaking commented 5 years ago

哦 那请问一下dataGas是什么呢?@libotony

libotony commented 5 years ago

dataGas 是指对交易中 data 字段所收取的gas也是固有gas的一部分,这个在thor-devkit中有相应的代码实现可供参考

https://github.com/vechain/thor-devkit.js/blob/master/src/transaction.ts#L127-L161

wupeaking commented 5 years ago

tks! 我明白了。

zl03jsj commented 5 years ago

@wupeaking hi, 请问 gasUsed='13326' 这一部分gas 是怎么计算的出来的啊?

libotony commented 5 years ago

@zl03jsj 节点API的返回值

zl03jsj commented 5 years ago

@zl03jsj 节点API的返回值

谢谢大神回复, 能告诉一下哪个API吗, 是web3.eth.estimategas这个吗?

libotony commented 5 years ago

POST /accounts/*

zl03jsj commented 5 years ago

POST /accounts/*

我看看去, 谢谢大神. 果然有这个, 我太不细心了, thanks a lot. :to simulate contract deployment without sending transaction to block chain.

It's useful to estimate gas usage and contract deployment result of a clause.

TIPS: data in request body is the bytecodes of a contract data in response body is the runtime bytecodes assigned to account which the contract to be deployed