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

Contract addresses: Have host fetch L2 Msg Bus address from enclave #1669

Merged
merged 5 commits into from
Nov 29, 2023

Conversation

BedrockSquirrel
Copy link
Collaborator

Why this change is needed

Unlike other network contract deployments the L2 message bus is deployed by the enclave with a sythetic tx.

Until we have a better method available this change has the host fetching that address from the enclave so it can serve it with the other contract addresses.

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Nov 28, 2023

Walkthrough

The changes across various Go files involve the introduction of functionality to handle the L2 message bus address within an enclave context. New functions and methods have been added to interfaces, structs, and RPC-related code to retrieve and verify the L2 message bus address. These additions are part of a broader update to include L2 message bus address information in network configurations and to ensure its availability through RPC calls and network tests.

Changes

File(s) Change Summary
go/common/enclave.go
go/enclave/enclave.go
go/enclave/rpc_server.go
go/host/rpc/enclaverpc/enclave_client.go
Added new functions to handle the retrieval and configuration of the L2 message bus address.
go/common/query_types.go Added a new field L2MessageBusAddress to the ObscuroNetworkInfo struct.
go/enclave/crosschain/processors.go Added a new method GetL2MessageBusAddress to return the L2 message bus address.
go/host/host.go Modified ObscuroConfig function to include the L2 message bus address in the network information.
integration/networktest/actions/l1/important_contracts.go
integration/networktest/tests/bridge/important_contracts_test.go
Introduced network test actions and tests to verify the availability of the L2 message bus address.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1d08a78 and 664a6aa.
Files ignored due to filter (3)
  • go/common/rpc/generated/enclave.pb.go
  • go/common/rpc/generated/enclave.proto
  • go/common/rpc/generated/enclave_grpc.pb.go
Files selected for processing (9)
  • go/common/enclave.go (1 hunks)
  • go/common/query_types.go (1 hunks)
  • go/enclave/crosschain/processors.go (2 hunks)
  • go/enclave/enclave.go (1 hunks)
  • go/enclave/rpc_server.go (1 hunks)
  • go/host/host.go (1 hunks)
  • go/host/rpc/enclaverpc/enclave_client.go (1 hunks)
  • integration/networktest/actions/l1/important_contracts.go (2 hunks)
  • integration/networktest/tests/bridge/important_contracts_test.go (1 hunks)
Additional comments: 7
go/common/query_types.go (1)
  • 89-94: The addition of L2MessageBusAddress to the ObscuroNetworkInfo struct is consistent with the surrounding code and does not require JSON tags or comments based on the existing structure. Ensure that all parts of the codebase that instantiate or use ObscuroNetworkInfo are updated to handle the new field appropriately.
go/enclave/crosschain/processors.go (1)
  • 36-38: The method GetL2MessageBusAddress assumes that GetBusAddress will never return nil. If there's a possibility for GetBusAddress to return nil, this could lead to a nil pointer dereference. Please ensure that GetBusAddress has proper nil checks or document that it will always return a non-nil value.
go/enclave/enclave.go (1)
  • 1381-1383: Ensure that the crossChainProcessors field is properly initialized before calling GetL2MessageBusAddress to prevent potential null reference exceptions.
go/enclave/rpc_server.go (1)
  • 439-439: The function GetL2MessageBusAddress correctly returns the address in byte format, which is consistent with the expected response format for addresses in the system.
go/host/host.go (1)
  • 202-215: The changes to ObscuroConfig to include the L2 message bus address are correctly implemented and match the summary provided.
integration/networktest/actions/l1/important_contracts.go (1)
  • 6-6: The addition of the actions package import is appropriate for the new function VerifyL2MessageBusAddressAvailable.
integration/networktest/tests/bridge/important_contracts_test.go (1)
  • 17-26: The changes to the TestImportantContractsLookup function correctly introduce the intended tests for verifying the setting and retrieval of an important contract's address and the availability of the L2 Message Bus address. Ensure that the hardcoded address 0x64 is appropriate for the test environment.

Comment on lines 141 to 142
// GetL2MessageBusAddress returns the address of the L2 message bus contract
GetL2MessageBusAddress() (gethcommon.Address, SystemError)
Copy link

Choose a reason for hiding this comment

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

The new function GetL2MessageBusAddress should have a comment explaining its purpose, parameters, and return values, as it is an exported function and part of an interface.

Comment on lines 602 to 615
func (c *Client) GetL2MessageBusAddress() (gethcommon.Address, common.SystemError) {
timeoutCtx, cancel := context.WithTimeout(context.Background(), c.config.EnclaveRPCTimeout)
defer cancel()

response, err := c.protoClient.GetL2MessageBusAddress(timeoutCtx, &generated.GetL2MessageBusAddressRequest{})
if err != nil {
return gethcommon.Address{}, syserr.NewRPCError(err)
}
if response != nil && response.SystemError != nil {
return gethcommon.Address{}, syserr.NewInternalError(fmt.Errorf("%s", response.SystemError.ErrorString))
}

return gethcommon.BytesToAddress(response.L2MessageBusAddress), nil
}
Copy link

Choose a reason for hiding this comment

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

The function GetL2MessageBusAddress is implemented correctly and follows the established patterns in the codebase. However, it lacks documentation. It is recommended to add a comment explaining the purpose of the function, its return values, and any potential side effects or error conditions.

func VerifyL2MessageBusAddressAvailable() networktest.Action {
// VerifyOnly because the L2MessageBus should be deployed automatically by the node as a synthetic tx
return actions.VerifyOnlyAction(func(ctx context.Context, network networktest.NetworkConnector) error {
cli, err := obsclient.Dial(network.ValidatorRPCAddress(0))
Copy link

Choose a reason for hiding this comment

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

Consider making the validator index configurable instead of hardcoding it to 0 to improve flexibility in case of multiple validators or changes in network configuration.

return errors.New("L2MessageBusAddress not set")

}
fmt.Println("L2MessageBusAddress: ", networkCfg.L2MessageBusAddress)
Copy link

Choose a reason for hiding this comment

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

Replace fmt.Println with a structured logging approach to ensure that the output can be properly managed and observed in production environments.

Comment on lines 433 to 439
func (s *RPCServer) GetL2MessageBusAddress(_ context.Context, _ *generated.GetL2MessageBusAddressRequest) (*generated.GetL2MessageBusAddressResponse, error) {
address, sysError := s.enclave.GetL2MessageBusAddress()
if sysError != nil {
s.logger.Error("Error getting message bus address", log.ErrKey, sysError)
return &generated.GetL2MessageBusAddressResponse{SystemError: toRPCError(sysError)}, nil
}
return &generated.GetL2MessageBusAddressResponse{L2MessageBusAddress: address.Bytes()}, nil
Copy link

Choose a reason for hiding this comment

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

The new function GetL2MessageBusAddress lacks documentation. It's best practice to provide comments explaining the purpose and usage of exported functions.

Comment on lines 1381 to 1383
func (e *enclaveImpl) GetL2MessageBusAddress() (gethcommon.Address, common.SystemError) {
return e.crossChainProcessors.GetL2MessageBusAddress()
}
Copy link

Choose a reason for hiding this comment

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

The new method GetL2MessageBusAddress is added without documentation. Consider adding a comment explaining the purpose and usage of this method.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 664a6aa and 56b2f4f.
Files selected for processing (2)
  • go/enclave/crosschain/processors.go (2 hunks)
  • integration/networktest/actions/l1/important_contracts.go (2 hunks)
Additional comments: 4
go/enclave/crosschain/processors.go (2)
  • 6-6: The import of the package "github.com/ten-protocol/go-ten/go/common" is correctly added to support the new function's return type.

  • 37-39: The implementation of GetL2MessageBusAddress appears correct, assuming that GetBusAddress from Local handles nil cases properly.

integration/networktest/actions/l1/important_contracts.go (2)
  • 114-114: Consider making the validator index configurable instead of hardcoding it to 0 to improve flexibility in case of multiple validators or changes in network configuration.

  • 127-127: Replace fmt.Println with a structured logging approach to ensure that the output can be properly managed and observed in production environments.

Copy link
Contributor

@otherview otherview left a comment

Choose a reason for hiding this comment

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

Minor name change if that makes sense

go/host/host.go Outdated
Comment on lines 203 to 206
l2MessageBusAddress, err := h.EnclaveClient().GetL2MessageBusAddress()
if err != nil {
return nil, responses.ToInternalError(fmt.Errorf("unable to get L2 message bus address - %w", err))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a generic enclave config method instead of the specific GetL2MessageBusAddress ? Perhaps I'm future-proofing..

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 56b2f4f and 121df71.
Files ignored due to filter (3)
  • go/common/rpc/generated/enclave.pb.go
  • go/common/rpc/generated/enclave.proto
  • go/common/rpc/generated/enclave_grpc.pb.go
Files selected for processing (5)
  • go/common/enclave.go (2 hunks)
  • go/enclave/enclave.go (1 hunks)
  • go/enclave/rpc_server.go (1 hunks)
  • go/host/host.go (1 hunks)
  • go/host/rpc/enclaverpc/enclave_client.go (1 hunks)
Additional comments: 7
go/common/enclave.go (2)
  • 138-142: The addition of GetPublicTransactionData and EnclavePublicConfig to the EnclaveScan interface aligns with the summary and seems to be correctly implemented.

  • 158-160: The EnclavePublicConfig struct is correctly defined with the L2MessageBusAddress field of type gethcommon.Address.

go/enclave/enclave.go (1)
  • 1381-1387: The implementation of EnclavePublicConfig method is correct and follows best practices for error handling and struct creation.
go/enclave/rpc_server.go (1)
  • 439-439: The implementation of EnclavePublicConfig correctly returns the L2 message bus address in byte format, which is consistent with how Ethereum addresses are typically handled in the system.
go/host/host.go (2)
  • 202-215: The changes to the ObscuroConfig function correctly implement the retrieval of the L2 message bus address from the enclave and its inclusion in the ObscuroNetworkInfo struct. This aligns with the pull request's description.

  • 213-213: Verify that the L2MessageBusAddress obtained from the enclave is validated before use in other parts of the codebase to ensure it meets any expected format or security requirements.

go/host/rpc/enclaverpc/enclave_client.go (1)
  • 602-615: The implementation of the EnclavePublicConfig function correctly handles timeouts and errors, and properly constructs the EnclavePublicConfig struct from the RPC response. The code is consistent with the rest of the codebase and follows best practices for error handling and context usage.

Comment on lines +433 to +440
func (s *RPCServer) EnclavePublicConfig(_ context.Context, _ *generated.EnclavePublicConfigRequest) (*generated.EnclavePublicConfigResponse, error) {
enclaveCfg, sysError := s.enclave.EnclavePublicConfig()
if sysError != nil {
s.logger.Error("Error getting message bus address", log.ErrKey, sysError)
return &generated.EnclavePublicConfigResponse{SystemError: toRPCError(sysError)}, nil
}
return &generated.EnclavePublicConfigResponse{L2MessageBusAddress: enclaveCfg.L2MessageBusAddress.Bytes()}, nil
}
Copy link

Choose a reason for hiding this comment

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

The new function EnclavePublicConfig lacks documentation. It's important to maintain consistency and provide clear documentation for all public functions to explain their purpose, parameters, return values, and any side effects or errors they might produce.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 121df71 and c161849.
Files selected for processing (1)
  • go/host/host.go (3 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c161849 and c4759aa.
Files selected for processing (1)
  • go/host/host.go (3 hunks)
Additional comments: 2
go/host/host.go (2)
  • 7-7: The import of github.com/ethereum/go-ethereum/common is correctly added to support the new l2MessageBusAddress field.

  • 48-49: The new field l2MessageBusAddress is correctly added to the host struct to cache the L2 message bus address.

Comment on lines +208 to +213
if h.l2MessageBusAddress == nil {
publicCfg, err := h.EnclaveClient().EnclavePublicConfig()
if err != nil {
return nil, responses.ToInternalError(fmt.Errorf("unable to get L2 message bus address - %w", err))
}
h.l2MessageBusAddress = &publicCfg.L2MessageBusAddress
Copy link

Choose a reason for hiding this comment

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

The potential data race issue when accessing l2MessageBusAddress still exists. Consider adding synchronization, such as a mutex, to prevent multiple goroutines from making redundant calls to EnclaveClient().EnclavePublicConfig().

@BedrockSquirrel BedrockSquirrel merged commit 2fd08a6 into main Nov 29, 2023
2 checks passed
@BedrockSquirrel BedrockSquirrel deleted the matt/serve-l2-msg-bus-addr branch November 29, 2023 13:09
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.

2 participants