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

fix statedb error during mempool #1702

Merged
merged 7 commits into from
Dec 15, 2023
Merged

fix statedb error during mempool #1702

merged 7 commits into from
Dec 15, 2023

Conversation

tudor-malene
Copy link
Collaborator

@tudor-malene tudor-malene commented Dec 14, 2023

Why this change is needed

Bug mempool:

The mempool needs a statedb during processing.
In the current implementation we were ignoring the "state root" passed in and always returned the head.
This might have caused some weird edge cases ( and maybe flakyness!)

Perf issue mempool:

avoid db query for each tx with new account

Flakyness

get a green build

What changes were made as part of this PR

  • return the statedb for the passed in root
  • use cached batches
  • skip some tests, and increase timeout

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 Dec 14, 2023

Walkthrough

The recent updates to the codebase mainly focus on simplifying and refining the control flow across various components. The StateAt function in the Ethereum chain adapter has been streamlined to directly create a state DB, removing the batch handling complexity. The Storage interface and its implementations now include a new method for accessing the state database, which impacts how state information is retrieved. Test files have been adjusted for better resource management and increased timeouts, while error messaging has been enhanced for clarity during health checks.

Changes

File Path Change Summary
.../evm/ethchainadapter/eth_chainadapter.go Simplified the StateAt function by removing batch handling logic.
.../storage/interfaces.go
.../storage/storage.go
.../txpool/txpool_mock_test.go
Added a new StateDB() method to the Storage interface and its implementations.
.../faucet/faucet_test.go Added a defer function to stop the faucetContainer after starting in tests.
.../walletextension/test/wallet_extension_test.go Modified test to include a skip due to flakiness.
.../obscurogateway/tengateway_test.go Increased timeout duration in transferETHToAddress function for tests.
.../simulation/simulation.go Improved error messaging in checkHealthStatus method when client is not healthy.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ecf49b1 and c0011cc.
Files selected for processing (4)
  • go/enclave/evm/ethchainadapter/eth_chainadapter.go (2 hunks)
  • go/enclave/storage/interfaces.go (1 hunks)
  • go/enclave/storage/storage.go (1 hunks)
  • go/enclave/txpool/txpool_mock_test.go (1 hunks)
Additional comments: 6
go/enclave/evm/ethchainadapter/eth_chainadapter.go (2)
  • 106-106: The change to the StateAt function to directly create a state DB using the provided root hash is consistent with the PR's objective to utilize the "state root" correctly during mempool processing.

  • 103-103: Returning nil, nil from StateAt when the root hash is the empty code hash could lead to ambiguity in error handling. Ensure that all callers of StateAt correctly handle this case.

go/enclave/storage/interfaces.go (1)
  • 142-147: The addition of the StateDB() method to the Storage interface is consistent with the PR's objective to ensure the correct state DB is used during mempool processing. Ensure that all structs implementing the Storage interface are updated to include this new method.
go/enclave/storage/storage.go (2)
  • 111-113: The implementation of the StateDB() method in the storageImpl struct is straightforward and matches the PR's objective to provide access to the underlying state database. This method will allow other parts of the system to retrieve the state.Database instance held by storageImpl.

  • 111-113: Verify that all implementations of the Storage interface have been updated to include the new StateDB() method to maintain compatibility across the codebase.

go/enclave/txpool/txpool_mock_test.go (1)
  • 344-347: The new StateDB method in mockStorage is currently a stub and will panic if called. Ensure that this method is implemented before merging the PR or ensure that tests which might invoke this method handle the panic appropriately.

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 c0011cc and 23b6a4e.
Files selected for processing (1)
  • go/enclave/evm/ethchainadapter/eth_chainadapter.go (3 hunks)
Additional comments: 3
go/enclave/evm/ethchainadapter/eth_chainadapter.go (3)
  • 3-6: The removal of the fmt import indicates that string formatting has been refactored out of this file. This is consistent with the changes in the StateAt function.

  • 83-112: The refactoring of the GetBlock function to check for cached batches before querying the database is a performance optimization. Ensure that the logic for fetching the head batch and its parent is correctly implemented and that the error handling is appropriate.

  • 121-125: The StateAt function has been simplified to directly create a new state DB using the provided root hash. This change is in line with the PR's objective to correctly utilize the "state root" during mempool processing. Confirm that this new approach is correctly integrated with the rest of the system, and that the StateDB() method is correctly implemented in the storage package.

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 23b6a4e and f024672.
Files selected for processing (1)
  • go/enclave/txpool/txpool_mock_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • go/enclave/txpool/txpool_mock_test.go

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 f024672 and ba0875b.
Files selected for processing (1)
  • integration/faucet/faucet_test.go (1 hunks)

Comment on lines +63 to +67
defer func(faucetContainer *container.FaucetContainer) {
err := faucetContainer.Stop()
if err != nil {
fmt.Printf("Could not stop faucet %s", err.Error())
}
Copy link

Choose a reason for hiding this comment

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

The addition of the defer function to stop the faucetContainer is a good practice to ensure resources are cleaned up after the test is done. However, the error handling within the defer function could be improved by using the testing object t to log the error instead of printing it to stdout, which is more idiomatic in test cases.

defer func(faucetContainer *container.FaucetContainer) {
	err := faucetContainer.Stop()
	if err != nil {
-		fmt.Printf("Could not stop faucet %s", err.Error())
+		t.Errorf("Could not stop faucet: %s", err.Error())
	}
}(faucetContainer)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
defer func(faucetContainer *container.FaucetContainer) {
err := faucetContainer.Stop()
if err != nil {
fmt.Printf("Could not stop faucet %s", err.Error())
}
defer func(faucetContainer *container.FaucetContainer) {
err := faucetContainer.Stop()
if err != nil {
t.Errorf("Could not stop faucet: %s", err.Error())
}

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 ba0875b and b4a9e71.
Files selected for processing (2)
  • integration/faucet/faucet_test.go (2 hunks)
  • tools/walletextension/test/wallet_extension_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/test/wallet_extension_test.go
Files skipped from review as they are similar to previous changes (1)
  • integration/faucet/faucet_test.go

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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b4a9e71 and 4b2019a.
Files selected for processing (2)
  • integration/obscurogateway/tengateway_test.go (1 hunks)
  • integration/simulation/simulation.go (1 hunks)
Additional comments: 2
integration/simulation/simulation.go (2)
  • 292-292: The change to include the specific error message in the panic is a good improvement for debugging purposes.

  • 289-295: Verify if using panic for handling health check failures is consistent with the error handling strategy throughout the codebase. Consider a less disruptive error reporting mechanism if this is not the case.

Verification successful

The use of panic for handling health check failures in the checkHealthStatus method is consistent with the error handling strategy throughout the codebase. The pattern of using panic is evident in various parts of the main application code, indicating that it is an accepted practice for handling critical errors that require immediate attention and should halt execution. Therefore, no change is necessary regarding the use of panic in this context.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for panic usage in the codebase to understand its consistency.
rg 'panic\('

Length of output: 21476



Script:

#!/bin/bash
# Filter out test files and tools to focus on the main application code usage of panic
rg 'panic\(' --glob '!*test.go' --glob '!tools/*'

Length of output: 13893

Comment on lines 583 to +586
if err != nil {
return nil, err
}
return integrationCommon.AwaitReceiptEth(context.Background(), client, signedTx.Hash(), 2*time.Second)
return integrationCommon.AwaitReceiptEth(context.Background(), client, signedTx.Hash(), 20*time.Second)
Copy link

Choose a reason for hiding this comment

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

The timeout duration for AwaitReceiptEth in the transferETHToAddress function has been increased from 2 seconds to 20 seconds. This change could potentially reduce flakiness in tests due to network delays or other issues. However, it's important to ensure that this increased timeout does not negatively impact the overall test suite's performance, especially if this function is called multiple times in a test run. If the longer timeout is necessary due to network conditions, consider making it configurable or documenting the reason for this specific value.

@@ -289,7 +289,7 @@ func (s *Simulation) prefundL1Accounts() {
func (s *Simulation) checkHealthStatus() {
for _, client := range s.RPCHandles.ObscuroClients {
if healthy, err := client.Health(); !healthy || err != nil {
panic("Client is not healthy")
panic("Client is not healthy: " + err.Error())
Copy link

Choose a reason for hiding this comment

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

Potential nil pointer dereference when calling err.Error() if err is nil. Add a check to ensure err is not nil before using it.

-			panic("Client is not healthy: " + err.Error())
+			if err != nil {
+				panic("Client is not healthy: " + err.Error())
+			} else {
+				panic("Client is not healthy and no error was provided")
+			}

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
panic("Client is not healthy: " + err.Error())
if err != nil {
panic("Client is not healthy: " + err.Error())
} else {
panic("Client is not healthy and no error was provided")
}

@tudor-malene tudor-malene merged commit c7aee80 into main Dec 15, 2023
2 checks passed
@tudor-malene tudor-malene deleted the tudor/mempool_fixes branch December 15, 2023 10:49
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