rpc: fix JSON-RPC gas used (#558)
Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
f90117c982
commit
644ae50410
@ -177,13 +177,11 @@ func (e *EVMBackend) GetBlockByHash(hash common.Hash, fullTx bool) (map[string]i
|
|||||||
return e.EthBlockFromTendermint(resBlock.Block, fullTx)
|
return e.EthBlockFromTendermint(resBlock.Block, fullTx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EthBlockFromTendermint returns a JSON-RPC compatible Ethereum block from a given Tendermint block.
|
// EthBlockFromTendermint returns a JSON-RPC compatible Ethereum block from a given Tendermint block and its block result.
|
||||||
func (e *EVMBackend) EthBlockFromTendermint(
|
func (e *EVMBackend) EthBlockFromTendermint(
|
||||||
block *tmtypes.Block,
|
block *tmtypes.Block,
|
||||||
fullTx bool,
|
fullTx bool,
|
||||||
) (map[string]interface{}, error) {
|
) (map[string]interface{}, error) {
|
||||||
gasUsed := uint64(0)
|
|
||||||
|
|
||||||
ethRPCTxs := []interface{}{}
|
ethRPCTxs := []interface{}{}
|
||||||
|
|
||||||
for i, txBz := range block.Txs {
|
for i, txBz := range block.Txs {
|
||||||
@ -200,8 +198,6 @@ func (e *EVMBackend) EthBlockFromTendermint(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo: gasUsed does not consider the refund gas so it is incorrect, we need to extract it from the result
|
|
||||||
gasUsed += ethMsg.GetGas()
|
|
||||||
hash := ethMsg.AsTransaction().Hash()
|
hash := ethMsg.AsTransaction().Hash()
|
||||||
if !fullTx {
|
if !fullTx {
|
||||||
ethRPCTxs = append(ethRPCTxs, hash)
|
ethRPCTxs = append(ethRPCTxs, hash)
|
||||||
@ -267,6 +263,19 @@ func (e *EVMBackend) EthBlockFromTendermint(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
e.logger.Error("failed to query consensus params", "error", err.Error())
|
e.logger.Error("failed to query consensus params", "error", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resBlockResult, err := e.clientCtx.Client.BlockResults(e.ctx, &block.Height)
|
||||||
|
if err != nil {
|
||||||
|
e.logger.Debug("EthBlockFromTendermint block result not found", "height", block.Height, "error", err.Error())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
gasUsed := uint64(0)
|
||||||
|
|
||||||
|
for _, txsResult := range resBlockResult.TxsResults {
|
||||||
|
gasUsed += uint64(txsResult.GetGasUsed())
|
||||||
|
}
|
||||||
|
|
||||||
formattedBlock := types.FormatBlock(block.Header, block.Size(), gasLimit, new(big.Int).SetUint64(gasUsed), ethRPCTxs, bloom, validatorAddr)
|
formattedBlock := types.FormatBlock(block.Header, block.Size(), gasLimit, new(big.Int).SetUint64(gasUsed), ethRPCTxs, bloom, validatorAddr)
|
||||||
return formattedBlock, nil
|
return formattedBlock, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user