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

Jbowen93/eth hash #70

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
23 changes: 23 additions & 0 deletions rpc/backend/evm_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,13 @@ func (b *Backend) EthBlockFromTendermint(
if err != nil {
return nil, err
}
b.logger.Info("address", "addr", addr)

validatorAddr := common.BytesToAddress(addr)
b.logger.Info("validator address", "validatorAddr", validatorAddr)

headerAddr := common.BytesToAddress(resBlock.Block.Header.ProposerAddress)
b.logger.Info("header address", "headerAddr", headerAddr)

gasLimit, err := types.BlockMaxGasFromConsensusParams(ctx, b.clientCtx, block.Height)
if err != nil {
Expand All @@ -299,12 +304,30 @@ func (b *Backend) EthBlockFromTendermint(
}
gasUsed += uint64(txsResult.GetGasUsed())
}
resBlock.Block.Header.Hash()

formattedBlock := types.FormatBlock(
block.Header, block.Size(),
gasLimit, new(big.Int).SetUint64(gasUsed),
ethRPCTxs, bloom, validatorAddr, baseFee,
)
blockJson, err := json.Marshal(formattedBlock)
if err != nil {
return nil, err
}
b.logger.Info("headerJson", "headerJson", string(blockJson))
var ethHeader ethtypes.Header
err = json.Unmarshal(blockJson, &ethHeader)
if err != nil {
return nil, err
}
b.logger.Info("ethHeader", "ethHeader", ethHeader)

ethHash := ethHeader.Hash()
b.logger.Info("ethHash", "ethHash", ethHash)

formattedBlock["hash"] = ethHash

return formattedBlock, nil
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/namespaces/ethereum/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ func (e *PublicAPI) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *

// GetBlockByHash returns the block identified by hash.
func (e *PublicAPI) GetBlockByHash(hash common.Hash, fullTx bool) (map[string]interface{}, error) {
e.logger.Debug("eth_getBlockByHash", "hash", hash.Hex(), "full", fullTx)
e.logger.Info("eth_getBlockByHash", "hash", hash.Hex(), "full", fullTx)
return e.backend.GetBlockByHash(hash, fullTx)
}

Expand Down
5 changes: 5 additions & 0 deletions rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func FormatBlock(
transactionsRoot = common.BytesToHash(header.DataHash)
}

ethHeader := EthHeaderFromTendermint(header, bloom, baseFee)
ethHeader.GasLimit = uint64(gasLimit)
ethHeader.GasUsed = gasUsed.Uint64()
result := map[string]interface{}{
"number": hexutil.Uint64(header.Height),
"hash": hexutil.Bytes(header.Hash()),
Expand All @@ -123,6 +126,8 @@ func FormatBlock(
"totalDifficulty": (*hexutil.Big)(big.NewInt(0)),
}

// Can we make a "correct" ethtypes.Header?

if baseFee != nil {
result["baseFeePerGas"] = (*hexutil.Big)(baseFee)
}
Expand Down