Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Fix get block #781

Merged
merged 7 commits into from
Nov 26, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions rpc/ethereum/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ func (e *EVMBackend) EthBlockFromTendermint(
return nil, err
}

resBlockResult, err := e.clientCtx.Client.BlockResults(ctx, &block.Height)
if err != nil {
return nil, err
}

txResults := resBlockResult.TxsResults

for i, txBz := range block.Txs {
tx, err := e.clientCtx.TxConfig.TxDecoder()(txBz)
if err != nil {
Expand All @@ -374,10 +381,9 @@ func (e *EVMBackend) EthBlockFromTendermint(

tx := ethMsg.AsTransaction()

// check tx exists on EVM and it has the correct block height
ethTx, err := e.GetTxByEthHash(tx.Hash())
if err != nil || ethTx.Height != block.Height {
e.logger.Debug("failed to query eth tx", "hash", tx.Hash().Hex())
// check tx exists on EVM by cross checking with blockResults
if txResults[i].Code != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Code is not 0, it's EVM tx?
maybe add some comment about it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Code != 0, it's a failed transaction.

e.logger.Debug("invalid tx result code", "hash", tx.Hash().Hex())
continue
}

Expand Down Expand Up @@ -434,15 +440,9 @@ func (e *EVMBackend) EthBlockFromTendermint(
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 {
for _, txsResult := range txResults {
gasUsed += uint64(txsResult.GetGasUsed())
}

Expand Down