harmony icon indicating copy to clipboard operation
harmony copied to clipboard

store used gas as separate entry

Open hypnagonia opened this issue 4 years ago • 4 comments

Summary

currently getting usedGas is only possible from tx receipt. which requires an extra query for each tx for explorer and increases load on rpc/slowing the syncing speed down

Current Design

tx receipt is only available only in tx receipt payload

Problems

requires an extra query for each tx for explorer and increases load on RPC

Proposal

modify the explorer node to save that data as a separate entry and serve usedGas in getBlockByNumber (with full tx info flag) response

hypnagonia avatar Jul 09 '21 17:07 hypnagonia

I just look through your proposal, you just want to usedGas for each tx in RPC GetBlockByNumber repsonse to you ? or extra new RPC for query usedGas for each tx ? I want to confirm your requirement again. Thanks.

replied to me on discord: to GetBlockByNumber

AlexiaChen avatar Jul 13 '21 01:07 AlexiaChen

Hey .@hypnagonia, the RPC GetBlockByNumber reponse body has 3 version: v1, v2, eth. all three block versions need to support usedGas for each tx with FullTx flag ?

AlexiaChen avatar Jul 14 '21 06:07 AlexiaChen

@hypnagonia @gupadhyaya

Although the PR is almost complete, I have thought about the problems with the design here.

  • Storing a redundant usedGas field in this way will increase the storage pressure on levelDB, and the pressure on writing and reading explorer db will also increase
  • explorer db may be gradually deprecated

Is this design reasonable?

My Proposal

In fact there is no need to store usedGas for each Tx, because there is already an interface like GetReceiptsByHash in the blockchain, which reads all Receipts of the whole block in bulk, probably faster than <txhash, usedGas> which is a DB entries query. I can meet the requirements described by Jenya based on this interface

AlexiaChen avatar Jul 15 '21 01:07 AlexiaChen

agree with @AlexiaChen it is better to utilize GetReceiptsByHash which is just one additional rpc call per block. not a good idea to introduce additional read/write logic in the explorer db.

gupadhyaya avatar Jul 15 '21 04:07 gupadhyaya