Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth,rpc: make RPCBlock,RPCTransaction,RPCReceipt as public struct #27265

Closed

Conversation

jsvisa
Copy link
Contributor

@jsvisa jsvisa commented May 14, 2023

This PR moves the RPC Response-related structures, which were originally in the internal/ethapi package, to the rpc package.
This allows third-party clients to access more raw data based on these structures. For example, ethclient.BlockByNumber can only return the types.Block structure:

func (ec *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) {
return ec.getBlock(ctx, "eth_getBlockByHash", hash, true)
}

But on RPC server's side, we do return more data (such as totalDifficulty) in rpcMarshalBlock.

func (s *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (*rpc.RPCBlock, error) {
block, err := rpc.RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
if err != nil {
return nil, err
}
if inclTx {
block.TotalDifficulty = (*hexutil.Big)(s.b.GetTd(ctx, b.Hash()))
}
return block, err
}

jsvisa added 5 commits May 14, 2023 18:36
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
@fjl
Copy link
Contributor

fjl commented May 14, 2023

I'm against adding these in package rpc, and here's why:

  • The ethclient API does not strictly follow the RPC API, and instead provides the data structures as used by go-ethereum core. The idea with this is that code using go-ethereum should only deal with one set of types, namely the ones defined in core/types. This should ensure most code can be used regardless of whether it accesses the blockchain using RPC, or using a p2p node in the same process.

  • package rpc is not a good place for these types. The rpc package is supposed to be a JSON-RPC client/server. Ideally, there should be no Ethereum references in this package. We do have BlockNumber in there, but it's for legacy reasons and BlockNumber isn't a complicated type.

@karalabe karalabe closed this May 15, 2023
@jsvisa
Copy link
Contributor Author

jsvisa commented May 15, 2023

@fjl Thank you for the detailed explanation. And I have some other questions:

  1. If ethclient is not the standard RPC client, are there any RPC clients in Golang, an alternative to web3.py, web3.js?
  2. What do you think of introducing several structures such as RPCBlock in the ethapi module to replace map[string]interface{}?
  3. And what do you think of puting ethapi module outside of internal is a good idea(or why wasn't it out there before)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants