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

Commit

Permalink
rpc: display block proposer address as the miner address (#290)
Browse files Browse the repository at this point in the history
* rpc: display proser address as the miner address

* use validator operator address
  • Loading branch information
fedekunze authored Jul 14, 2021
1 parent 84febdd commit 5e87661
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
27 changes: 21 additions & 6 deletions ethereum/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion ethereum/rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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": "",
Expand Down

0 comments on commit 5e87661

Please sign in to comment.