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

[CORE-29] Migrate from stoppable to BaseApp#Stop. #660

Merged
merged 1 commit into from
Oct 18, 2023
Merged

[CORE-29] Migrate from stoppable to BaseApp#Stop. #660

merged 1 commit into from
Oct 18, 2023

Conversation

lcwik
Copy link
Contributor

@lcwik lcwik commented Oct 18, 2023

Changelist

Replace stoppable with BaseApp#Stop and remove the global map that stoppable relied on.

Test Plan

Updated existing tests.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

@linear
Copy link

linear bot commented Oct 18, 2023

CORE-29 Gracefully shutdown daemons

Currently the liquidations daemon and prices daemon do not gracefully shutdown when a validator is stopped. This is an issue in the integration tests because when we shutdown the in-process validators, this can cause the daemon goroutines to panic and the test can fail.

However, not panicing is a security risk because it's possible that the validator is running while the daemon (liquidations or prices) is not running. The application assumes that the daemons are always running, and this assumption could lead to subaccounts not getting liquidated / prices not being updated.

As a longer term solution, we should do the following:

  • To fix the tests, we should gracefully stop the daemons when the validator stops running.
  • To fix the security risk, we should determine what failures in the daemon are intermittent and retry them. For persistent failures, we should stop the daemon and the application together.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 18, 2023

Walkthrough

The changes primarily focus on the removal of the "stoppable" package and associated cleanup functions across multiple files. A new field PriceFeedClient is added to the App struct, and a new Close method is implemented. Test functions are updated to reflect these changes. The createServerWithMocks function now requires a *testing.T parameter.

Changes

File(s) Summary
protocol/app/app.go, protocol/app/app_test.go Added PriceFeedClient field to App struct and implemented Close method. Updated test functions accordingly.
protocol/daemons/pricefeed/client/client_integration_test.go, protocol/daemons/pricefeed/client/client_test.go Removed "test" argument from function calls.
protocol/daemons/server/liquidation_test.go, protocol/daemons/server/pricefeed_test.go Added t parameter to createServerWithMocks function calls in test functions.
protocol/daemons/server/server.go, protocol/daemons/server/server_test.go Removed import of "stoppable" package and updated NewServer function. Updated createServerWithMocks function in test file.
protocol/testutil/prices/cli/util.go, protocol/x/blocktime/client/cli/query_test.go, protocol/x/bridge/client/cli/query_test.go, protocol/x/clob/client/cli/..., protocol/x/delaymsg/client/cli/query_test.go, protocol/x/epochs/client/cli/query_epoch_info_test.go, protocol/x/feetiers/client/cli/query_test.go, protocol/x/perpetuals/client/cli/query_perpetual_test.go, protocol/x/prices/client/cli/prices_cli_test.go, protocol/x/rewards/client/cli/query_params_test.go, protocol/x/sending/client/cli/sending_cli_test.go, protocol/x/stats/client/cli/query_test.go, protocol/x/subaccounts/client/cli/query_subaccount_test.go, protocol/x/vest/client/cli/query_vest_entry_test.go Removed import of "stoppable" package and associated cleanup functions.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

Copy link
Contributor

@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

Commits Files that changed from the base of the PR and between c2be0ad and 77155ba.
Files selected for processing (25)
  • protocol/app/app.go (7 hunks)
  • protocol/app/app_test.go (2 hunks)
  • protocol/daemons/pricefeed/client/client_integration_test.go (1 hunks)
  • protocol/daemons/pricefeed/client/client_test.go (1 hunks)
  • protocol/daemons/server/liquidation_test.go (2 hunks)
  • protocol/daemons/server/pricefeed_test.go (4 hunks)
  • protocol/daemons/server/server.go (2 hunks)
  • protocol/daemons/server/server_test.go (7 hunks)
  • protocol/testutil/prices/cli/util.go (2 hunks)
  • protocol/x/blocktime/client/cli/query_test.go (2 hunks)
  • protocol/x/bridge/client/cli/query_test.go (2 hunks)
  • protocol/x/clob/client/cli/cancel_order_cli_test.go (2 hunks)
  • protocol/x/clob/client/cli/liquidations_cli_test.go (2 hunks)
  • protocol/x/clob/client/cli/place_order_cli_test.go (2 hunks)
  • protocol/x/clob/client/cli/query_clob_pair_test.go (2 hunks)
  • protocol/x/delaymsg/client/cli/query_test.go (2 hunks)
  • protocol/x/epochs/client/cli/query_epoch_info_test.go (2 hunks)
  • protocol/x/feetiers/client/cli/query_test.go (2 hunks)
  • protocol/x/perpetuals/client/cli/query_perpetual_test.go (2 hunks)
  • protocol/x/prices/client/cli/prices_cli_test.go (2 hunks)
  • protocol/x/rewards/client/cli/query_params_test.go (2 hunks)
  • protocol/x/sending/client/cli/sending_cli_test.go (2 hunks)
  • protocol/x/stats/client/cli/query_test.go (2 hunks)
  • protocol/x/subaccounts/client/cli/query_subaccount_test.go (2 hunks)
  • protocol/x/vest/client/cli/query_vest_entry_test.go (2 hunks)
Files skipped from review due to trivial changes (19)
  • protocol/daemons/pricefeed/client/client_integration_test.go
  • protocol/daemons/server/liquidation_test.go
  • protocol/daemons/server/server.go
  • protocol/testutil/prices/cli/util.go
  • protocol/x/blocktime/client/cli/query_test.go
  • protocol/x/bridge/client/cli/query_test.go
  • protocol/x/clob/client/cli/liquidations_cli_test.go
  • protocol/x/clob/client/cli/place_order_cli_test.go
  • protocol/x/clob/client/cli/query_clob_pair_test.go
  • protocol/x/delaymsg/client/cli/query_test.go
  • protocol/x/epochs/client/cli/query_epoch_info_test.go
  • protocol/x/feetiers/client/cli/query_test.go
  • protocol/x/perpetuals/client/cli/query_perpetual_test.go
  • protocol/x/prices/client/cli/prices_cli_test.go
  • protocol/x/rewards/client/cli/query_params_test.go
  • protocol/x/sending/client/cli/sending_cli_test.go
  • protocol/x/stats/client/cli/query_test.go
  • protocol/x/subaccounts/client/cli/query_subaccount_test.go
  • protocol/x/vest/client/cli/query_vest_entry_test.go
Additional comments (Suppressed): 22
protocol/x/clob/client/cli/cancel_order_cli_test.go (2)
  • 6-11: The import of the stoppable package has been removed. Ensure that the functionality provided by this package is no longer needed or has been replaced elsewhere in the codebase.

  • 75-79: The cleanup function that was previously stopping all daemon-related services has been removed. If these services are not stopped elsewhere after the tests, this could lead to resource leaks. Please verify that the services are properly stopped after the tests.

protocol/daemons/pricefeed/client/client_test.go (1)
  • 302-302: The uniqueTestIdentifier parameter has been removed from the NewServer function call. Ensure that this change does not affect the functionality of the server or any tests that rely on this parameter.
protocol/app/app.go (7)
  • 14-19: The import statements remain the same, no changes were made.

  • 94-100: The import statement for the stoppable package has been removed, aligning with the PR's goal of replacing the stoppable package with BaseApp#Stop.

  • 282-287: A new field PriceFeedClient has been added to the App struct. Ensure that this new field is properly initialized and used throughout the codebase.

  • 546-551: The appFlags.GrpcAddress argument has been removed from the function call. Ensure that this change does not affect the functionality of the server setup.

  • 601-607: The client variable has been replaced with app.PriceFeedClient. This change aligns with the new field added to the App struct.

  • 613-618: The stoppable.RegisterServiceForTestCleanup(appFlags.GrpcAddress, client) line has been removed, which is consistent with the removal of the stoppable package.

  • 1419-1428: The Close method has been updated to stop the PriceFeedClient and Server if they are not nil. This is a good practice as it ensures that resources are properly released when the application is closed.

-	return app.BaseApp.Close()
+	if app.PriceFeedClient != nil {
+		app.PriceFeedClient.Stop()
+	}
+	if app.Server != nil {
+		app.Server.Stop()
+	}
+	return nil
protocol/daemons/server/pricefeed_test.go (4)
  • 23-29: The changes in this hunk are consistent with the changes described in the pull request summary. The createServerWithMocks function now takes a testing.TB parameter and two *mocks parameters. The WithPriceFeedMarketToExchangePrices method is called on the server instance returned by createServerWithMocks. This is consistent with the previous code.

  • 45-50: The changes in this hunk are consistent with the changes described in the pull request summary. The createServerWithMocks function now takes a testing.TB parameter and two *mocks parameters. The WithPriceFeedMarketToExchangePrices method is not called on the server instance returned by createServerWithMocks, which is consistent with the comment above these lines.

  • 71-77: The changes in this hunk are consistent with the changes described in the pull request summary. The createServerWithMocks function now takes a testing.TB parameter and two *mocks parameters. The WithPriceFeedMarketToExchangePrices method is called on the server instance returned by createServerWithMocks. This is consistent with the previous code.

  • 148-154: The changes in this hunk are consistent with the changes described in the pull request summary. The createServerWithMocks function now takes a testing.TB parameter and two *mocks parameters. The WithPriceFeedMarketToExchangePrices method is called on the server instance returned by createServerWithMocks. This is consistent with the previous code.

protocol/app/app_test.go (2)
  • 1-7: The import statement has been updated to include the gopkg.in/typ.v4/slices package. This package provides utility functions for working with slices in Go. It's used in the new hunk to manipulate the uninitializedFields slice.

  • 95-108: The test case has been updated to handle the PriceFeedClient field. Since PriceFeedClient is hard-coded as disabled in GetDefaultTestAppOptions, it's expected to be uninitialized. The new code checks if PriceFeedClient is in the uninitializedFields slice and removes it if present. This change ensures that the test case doesn't fail due to the expected uninitialized PriceFeedClient field.

- 			uninitializedFields := getUninitializedStructFields(reflect.ValueOf(*dydxApp))
+ 			uninitializedFields := getUninitializedStructFields(reflect.ValueOf(*dydxApp))
+ 			// Note that the PriceFeedClient is currently hard coded as disabled in GetDefaultTestAppOptions.
+ 			// Normally it would be only disabled for non-validating full nodes or for nodes where the
+ 			// price feed client is explicitly disabled.
+ 			if idx := slices.Index(uninitializedFields, "PriceFeedClient"); idx >= 0 {
+ 				slices.Remove(&uninitializedFields, idx)
+ 			}
protocol/daemons/server/server_test.go (6)
  • 40-43: The createServerWithMocks function now takes an additional testing.TB parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 66-72: The createServerWithMocks function now takes an additional testing.TB parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 115-121: The createServerWithMocks function now takes an additional testing.TB parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 167-170: The NewServer function's signature has been modified to remove the uniqueTestIdentifier parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 183-186: The NewServer function's signature has been modified to remove the uniqueTestIdentifier parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 204-218: The createServerWithMocks function now takes a testing.TB parameter and two *mocks parameters, and it calls mockGrpcServer.On("Stop").Return().Once() and t.Cleanup(server.Stop). This is a significant change from the previous version of the function, which did not have these parameters or calls. Ensure that this change does not introduce any unexpected behavior or side effects.

@lcwik lcwik merged commit 315890f into main Oct 18, 2023
17 checks passed
@lcwik lcwik deleted the lukecore29 branch October 18, 2023 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants