diff --git a/ethereum/rpc/backend/backend.go b/ethereum/rpc/backend/backend.go index c3911bbaee..aedf5aacb1 100644 --- a/ethereum/rpc/backend/backend.go +++ b/ethereum/rpc/backend/backend.go @@ -119,7 +119,7 @@ func (e *EVMBackend) GetBlockByNumber(blockNum types.BlockNumber, fullTx bool) ( return nil, nil } - res, err := e.EthBlockFromTendermint(e.clientCtx, e.queryClient, resBlock.Block, fullTx) + res, err := e.EthBlockFromTendermint(resBlock.Block, fullTx) if err != nil { e.logger.Debug("EthBlockFromTendermint failed", "height", height, "error", err.Error()) } @@ -140,13 +140,11 @@ func (e *EVMBackend) GetBlockByHash(hash common.Hash, fullTx bool) (map[string]i return nil, nil } - return e.EthBlockFromTendermint(e.clientCtx, e.queryClient, resBlock.Block, fullTx) + return e.EthBlockFromTendermint(resBlock.Block, fullTx) } // EthBlockFromTendermint returns a JSON-RPC compatible Ethereum block from a given Tendermint block. func (e *EVMBackend) EthBlockFromTendermint( - clientCtx client.Context, - queryClient evmtypes.QueryClient, block *tmtypes.Block, fullTx bool, ) (map[string]interface{}, error) { @@ -206,15 +204,32 @@ func (e *EVMBackend) EthBlockFromTendermint( } } - blockBloomResp, err := queryClient.BlockBloom(types.ContextWithHeight(block.Height), &evmtypes.QueryBlockBloomRequest{}) + blockBloomResp, err := e.queryClient.BlockBloom(types.ContextWithHeight(block.Height), &evmtypes.QueryBlockBloomRequest{}) if err != nil { e.logger.Debug("failed to query BlockBloom", "height", block.Height, "error", err.Error()) blockBloomResp = &evmtypes.QueryBlockBloomResponse{Bloom: ethtypes.Bloom{}.Bytes()} } + req := &evmtypes.QueryValidatorAccountRequest{ + ConsAddress: sdk.ConsAddress(block.Header.ProposerAddress).String(), + } + + res, err := e.queryClient.ValidatorAccount(e.ctx, req) + if err != nil { + e.logger.Debug("failed to query validator operator address", "cons-address", req.ConsAddress, "error", err.Error()) + return nil, err + } + + addr, err := sdk.AccAddressFromBech32(res.AccountAddress) + if err != nil { + return nil, err + } + + validatorAddr := common.BytesToAddress(addr) + bloom := ethtypes.BytesToBloom(blockBloomResp.Bloom) - formattedBlock := types.FormatBlock(block.Header, block.Size(), ethermint.DefaultRPCGasLimit, new(big.Int).SetUint64(gasUsed), ethRPCTxs, bloom) + formattedBlock := types.FormatBlock(block.Header, block.Size(), ethermint.DefaultRPCGasLimit, new(big.Int).SetUint64(gasUsed), ethRPCTxs, bloom, validatorAddr) return formattedBlock, nil } diff --git a/ethereum/rpc/types/utils.go b/ethereum/rpc/types/utils.go index 89ff1727f0..1f5c48bbb7 100644 --- a/ethereum/rpc/types/utils.go +++ b/ethereum/rpc/types/utils.go @@ -151,6 +151,7 @@ func BlockMaxGasFromConsensusParams(ctx context.Context, clientCtx client.Contex func FormatBlock( header tmtypes.Header, size int, gasLimit int64, gasUsed *big.Int, transactions interface{}, bloom ethtypes.Bloom, + validatorAddr common.Address, ) map[string]interface{} { if len(header.DataHash) == 0 { header.DataHash = tmbytes.HexBytes(common.Hash{}.Bytes()) @@ -164,7 +165,7 @@ func FormatBlock( "sha3Uncles": ethtypes.EmptyUncleHash, // No uncles in Tendermint "logsBloom": bloom, "stateRoot": hexutil.Bytes(header.AppHash), - "miner": common.Address{}, + "miner": validatorAddr, "mixHash": common.Hash{}, "difficulty": (*hexutil.Big)(big.NewInt(0)), "extraData": "",