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

Remove Geth Bindings From Prysm #11586

Merged
merged 13 commits into from
Nov 17, 2022
Merged

Remove Geth Bindings From Prysm #11586

merged 13 commits into from
Nov 17, 2022

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented Oct 27, 2022

What type of PR is this?

Execution Code Cleanup

What does this PR do? Why is it needed?

Post merge, prysm retrieves raw headers and blocks from geth without using go bindings from the go-ethereum repo. This PR extends this change across all our execution interfacing code so that we can remove some unnecessary interfaces along with supporting gnosis chain changes.

Which issues(s) does this PR fix?

N.A

Other notes for review

@prestonvanloon prestonvanloon self-requested a review October 27, 2022 16:58
@@ -354,6 +355,24 @@ func (s *Service) ExecutionBlocksByHashes(ctx context.Context, hashes []common.H
return execBlks, nil
}

func (s *Service) HeaderByHash(ctx context.Context, hash common.Hash) (*pb.ExecutionBlock, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing doc

return blk, err
}

func (s *Service) HeaderByNumber(ctx context.Context, number *big.Int) (*pb.ExecutionBlock, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing doc

}

func (*RPCClient) Close() {}

func (*RPCClient) CallContext(_ context.Context, _ interface{}, _ string, _ ...interface{}) error {
func (r *RPCClient) CallContext(ctx context.Context, obj interface{}, methodName string, args ...interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing doc

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a test method

@prestonvanloon
Copy link
Member

I don't understand the rationale here. In any case, can we simplify this further?
Keeping a full block in the cache or passing that around seems like extra mem usage that is unnecessary.

We discussed offline that we only need the hash, timestamp and block number. Some subset of the block.

Similar to how LH does it https://github.com/sigp/lighthouse/blob/6d5a2b509fac7b6ffe693866f58ba49989f946d7/common/eth2/src/lighthouse.rs#L314

They have a subset of the block struct they are using. I imagine this is far less memory usage than a full eth1 block with everything in it.

@prestonvanloon
Copy link
Member

OK -- actually I remember why. The go-ethereum structs recompute the hash when you call Hash() and this is incompatible with gnosis structs as they are different. In our case, we can still simplify further by only managing a subset of the response object.

Comment on lines +360 to +378
func (s *Service) HeaderByHash(ctx context.Context, hash common.Hash) (*types.HeaderInfo, error) {
var hdr *types.HeaderInfo
err := s.rpcClient.CallContext(ctx, &hdr, ExecutionBlockByHashMethod, hash, false /* no transactions */)
if err == nil && hdr == nil {
err = ethereum.NotFound
}
return hdr, err
}

// HeaderByNumber returns the relevant header details for the provided block number.
func (s *Service) HeaderByNumber(ctx context.Context, number *big.Int) (*types.HeaderInfo, error) {
var hdr *types.HeaderInfo
err := s.rpcClient.CallContext(ctx, &hdr, ExecutionBlockByNumberMethod, toBlockNumArg(number), false /* no transactions */)
if err == nil && hdr == nil {
err = ethereum.NotFound
}
return hdr, err
}

Copy link
Member

Choose a reason for hiding this comment

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

Do we have any way to test these? Mock rpc client or something? The functionality for returning ethereum.NotFound is something worth testing, unless it is very difficult to do so.

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be possible, I can give it a try

Comment on lines -217 to -221
if err := s.headerCache.AddHeader(blk); err != nil {
return nil, err
}
info, err = types.HeaderToHeaderInfo(blk)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Oh cool, we were already storing a subset of the block information in the caches.

Comment on lines 100 to 103
// fetching eth1 data from the clients.
type RPCDataFetcher interface {
Close()
HeaderByNumber(ctx context.Context, number *big.Int) (*gethTypes.Header, error)
HeaderByHash(ctx context.Context, hash common.Hash) (*gethTypes.Header, error)
}
Copy link
Member

Choose a reason for hiding this comment

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

Delete this whole thing?

@@ -82,7 +84,7 @@ func (g *goodNotifier) StateFeed() *event.Feed {

type goodFetcher struct {
backend *backends.SimulatedBackend
blockNumMap map[uint64]*gethTypes.Header
blockNumMap map[uint64]*pb.ExecutionBlock
Copy link
Member

@prestonvanloon prestonvanloon Oct 28, 2022

Choose a reason for hiding this comment

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

This one is different than the mock rpcClient?

// beacon-chain/execution/testing/mock_execution_chain.go
// RPCClient defines the mock rpc client.
type RPCClient struct {
	Backend     *backends.SimulatedBackend
	BlockNumMap map[uint64]*types.HeaderInfo // not pb.ExecutionBlock
}

Also, can you just use that mock RPCClient?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need the whole mock actually, just deleting it now

Comment on lines 119 to 130
type RPCClientBad struct {
}

func (RPCClientBad) Close() {}
func (RPCClientBad) BatchCall([]gethRPC.BatchElem) error {
return errors.New("rpc client is not initialized")
}

func (RPCClientBad) CallContext(context.Context, interface{}, string, ...interface{}) error {
return ethereum.NotFound
}

Copy link
Member

Choose a reason for hiding this comment

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

This looks like test code?

gballet added a commit to gballet/prysm that referenced this pull request Nov 16, 2022
@nisdas nisdas merged commit 08d63a0 into develop Nov 17, 2022
@delete-merged-branch delete-merged-branch bot deleted the removeGethBindings branch November 17, 2022 09:16
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