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

chore: Update slinky version #1768

Merged
merged 7 commits into from
Jun 26, 2024

Conversation

Eric-Warehime
Copy link
Contributor

@Eric-Warehime Eric-Warehime commented Jun 25, 2024

Changelist

Updates the slinky version, compat methods.

Test Plan

Changes are non state breaking. Can be rolled out in dev/testnet on an isolated basis.

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 the PR has breaking postgres changes to the indexer add the indexer-postgres-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.

Summary by CodeRabbit

  • New Features

    • Introduced NoopPriceApplier for handling price application and retrieval in vote extensions.
    • Added functions to manage currency pairs in the Keeper struct.
  • Refactor

    • Simplified Oracle initialization and removed Prometheus metrics setup.
    • Removed PrometheusServerAddress flag handling.
  • Bug Fixes

    • Added //nolint:staticcheck annotations to suppress static check warnings in gRPC connection functions.
  • Tests

    • Added tests for currency pair retrieval and count functionality.
  • Dependencies

    • Updated several dependencies to their latest versions for improved stability and performance.

Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Walkthrough

The updates broadly refactor and enhance the Slinky protocol, focusing on Oracle initialization and Prometheus metrics management. They eliminate unused imports, clean up the configuration, enhance the Keeper struct with new currency pair management capabilities, and update dependencies. Additionally, they introduce the NoopPriceApplier type and annotate certain gRPC connection calls to suppress static check warnings.

Changes

Files & Directories Description of Changes
protocol/app/app.go Removed unused imports, refactored Oracle initialization, and eliminated Prometheus metrics setup.
protocol/app/vote_extensions/extend_vote_handler.go Added NoopPriceApplier type with methods for handling price applications.
protocol/cmd/dydxprotocold/cmd/config.go Removed PrometheusServerAddress from Oracle initialization in DydxAppConfig.
protocol/daemons/flags/flags.go Eliminated flag and logic associated with PrometheusServerAddress.
protocol/daemons/types/grpc_client.go Added //nolint:staticcheck comments to suppress warnings in grpc.DialContext calls.
protocol/go.mod Updated dependency versions.
protocol/mocks/OracleClient.go Added MarketMap method to OracleClient struct for mocking purposes.
protocol/testing/containertest/node.go Added //nolint:staticcheck comment to grpc.Dial call in createGrpcConn method.
protocol/x/prices/keeper/slinky_adapter.go Added functions managing currency pairs in the Keeper struct.
protocol/x/prices/keeper/slinky_adapter_test.go Introduced tests for currency pair management functions.
protocol/app/vote_extensions/expected_keepers.go, protocol/x/prices/types/types.go Removed GetPrevBlockCPCounter method from PricesKeeper interface.

🐇 In code's enchanted land so grand,
Refine and polish, each command.
Oracles refreshed, Prometheus no more,
Keeper of pairs, richer than before.
Dependencies raised, mocks in sway,
A seamless flow, the rabbit's way.


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 your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Eric-Warehime Eric-Warehime marked this pull request as ready for review June 25, 2024 16:54
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.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 568e95a and 2fecfec.

Files ignored due to path filters (1)
  • protocol/go.sum is excluded by !**/*.sum
Files selected for processing (10)
  • protocol/app/app.go (3 hunks)
  • protocol/app/vote_extensions/extend_vote_handler.go (2 hunks)
  • protocol/cmd/dydxprotocold/cmd/config.go (1 hunks)
  • protocol/daemons/flags/flags.go (3 hunks)
  • protocol/daemons/types/grpc_client.go (2 hunks)
  • protocol/go.mod (13 hunks)
  • protocol/mocks/OracleClient.go (2 hunks)
  • protocol/testing/containertest/node.go (1 hunks)
  • protocol/x/prices/keeper/slinky_adapter.go (1 hunks)
  • protocol/x/prices/keeper/slinky_adapter_test.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • protocol/daemons/flags/flags.go
  • protocol/testing/containertest/node.go
Additional comments not posted (5)
protocol/app/vote_extensions/extend_vote_handler.go (1)

24-32: Introduction of the NoopPriceApplier type and its methods.

The NoopPriceApplier type and its methods ApplyPricesFromVoteExtensions and GetPricesForValidator are added as part of the refactoring. It's important to ensure that these methods are correctly implemented and documented, especially since they return nil or default values. This might indicate a placeholder or minimal implementation.

protocol/mocks/OracleClient.go (1)

20-55: Addition of the MarketMap method to the mock OracleClient.

The MarketMap method is correctly implemented as a mock with appropriate setup for handling variadic CallOption parameters and returning values based on the Called method. Ensure that this mock is used in unit tests to simulate the behavior of the Oracle client accurately.

protocol/x/prices/keeper/slinky_adapter_test.go (1)

117-136: Addition of new test functions for currency pair management.

The test functions TestGetAllCurrencyPairs and TestGetNumCurrencyPairs are added to verify the new functionality related to currency pairs in the slinky_adapter. These tests appear to be well-structured and should effectively validate the correctness of the related functionality.

protocol/x/prices/keeper/slinky_adapter.go (1)

108-149: Enhancements to currency pair management in the Keeper struct.

The new methods GetNumCurrencyPairs, GetNumRemovedCurrencyPairs, and GetAllCurrencyPairs are added to manage currency pairs more effectively. These methods are well-implemented, utilizing efficient iteration and error handling. Ensure that they are integrated properly in the overall workflow of the Keeper.

protocol/go.mod (1)

8-8: Dependency updates reviewed and approved.

All the dependency updates listed are to newer versions, which typically include bug fixes, performance improvements, and security patches. It's crucial to ensure these updates do not introduce breaking changes through thorough testing.

Also applies to: 11-11, 12-12, 13-13, 14-14, 16-16, 22-22, 32-32, 35-35, 37-37, 38-38, 39-39, 49-49, 51-51, 54-54, 55-55, 58-58, 60-60, 62-62, 63-63, 65-65, 70-70, 71-71, 73-73, 74-74

Comment on lines 1596 to 1603
// We are not using the slinky PreBlocker/PriceApplier, so there is no need to pass in PreBlocker here for
// VE handler to work properly.
// Currently the clob PreBlocker assumes that it will only be called during the normal ABCI
// PreBlocker step. Passing in the app PreBlocker here will break that assumption by causing
// the clob PreBlocker to be called unexpectedly. This to leads improperly initialized clob state
// which results in the next block being committed incorrectly.
func(_ sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
return nil, nil
},
// TODO we can move the UpdateMarketPrices in extend vote to this in the future.
vote_extensions.NoopPriceApplier{},
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider Refactoring the Vote Extension Handler Initialization

The comment at line 1596 suggests that the current implementation of the vote_extensions.NoopPriceApplier in the vote_extensions.ExtendVoteHandler might lead to unexpected behaviors due to assumptions about when the PreBlocker is called. This could potentially lead to state inconsistencies or incorrect block commitments.

Recommendation: It would be beneficial to refactor this initialization to ensure that the PreBlocker is only invoked during the expected ABCI lifecycle phase. This might involve reworking the control flow or state management within the handler to prevent unintended side effects.

Comment on lines +58 to +61
Enabled: true,
OracleAddress: "localhost:8080",
ClientTimeout: time.Second * 2,
MetricsEnabled: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for Oracle configuration.

The Oracle configuration in DydxAppConfig lacks error handling for potential connectivity issues with the Oracle server. Given the critical role of Oracles in blockchain applications, robust error handling and fallback mechanisms are essential.

+ // TODO: Add error handling for Oracle connectivity issues.

Committable suggestion was skipped due to low confidence.

Comment on lines +51 to +55
return grpc.DialContext( //nolint:staticcheck
ctx,
endpoint,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithBlock(), //nolint:staticcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Documentation for //nolint:staticcheck annotations is insufficient.

The search results indicate multiple instances of //nolint:staticcheck across various files, but there is no accompanying documentation or comments explaining the usage or justification for these suppressions.

  • File: protocol/daemons/types/grpc_client.go
    • Lines: 51-55

Please ensure that the usage of //nolint:staticcheck is justified and documented to maintain code quality and clarity.

Analysis chain

Review of static analysis suppression annotations in TCP connection setup.

The //nolint:staticcheck annotations are used here as well. Similar to the previous function, ensure that these suppressions are justified and documented.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that these suppressions are documented elsewhere in the repository.

# Test: Search for documentation on nolint usage. Expect: Documentation or comments explaining the usage.
rg "//nolint:staticcheck" -C 5

Length of output: 59316

Comment on lines +32 to +37
return grpc.DialContext( //nolint:staticcheck
ctx,
socketAddress,
grpc.WithTransportCredentials(insecure.NewCredentials()),
// https://github.com/grpc/grpc-go/blob/master/dialoptions.go#L264
grpc.WithBlock(),
grpc.WithBlock(), //nolint:staticcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Lack of justification for //nolint:staticcheck suppressions

The //nolint:staticcheck annotations in the code are not accompanied by any documentation or comments explaining their necessity. This lack of justification could lead to potential issues being overlooked.

  • File: protocol/daemons/types/grpc_client.go
  • Lines: 32-37

Please provide documentation or comments explaining why these static analysis warnings are being suppressed.

Analysis chain

Review of static analysis suppression annotations.

The use of //nolint:staticcheck suppresses warnings from static analysis tools. Ensure that these suppressions are justified and documented, explaining why they are necessary.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that these suppressions are documented elsewhere in the repository.

# Test: Search for documentation on nolint usage. Expect: Documentation or comments explaining the usage.
rg "//nolint:staticcheck" -C 5

Length of output: 59316

@@ -1594,15 +1593,14 @@ func (app *App) initOracle(pricesTxDecoder process.UpdateMarketPriceTxDecoder) {
compression.NewDefaultVoteExtensionCodec(),
compression.NewZLibCompressor(),
),
// We are not using the slinky PreBlocker, so there is no need to pass in PreBlocker here for
// We are not using the slinky PreBlocker/PriceApplier, so there is no need to pass in PreBlocker here for
Copy link
Contributor

@vincentwschau vincentwschau Jun 25, 2024

Choose a reason for hiding this comment

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

Are the PreBlocker comments still relevant after this upgrade w.r.t slinky? Should this comment just call out the lack of use of the slinky PriceApplier?

Copy link
Contributor

Choose a reason for hiding this comment

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

The PreBlocker comment is no longer relevant (VE handler no longer depends on PreBlocker) so I'm aligned w/ removing references to PreBlocker in this commnet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not since we've moved away from using the preblocker here and have a dedicated interface now instead. Will remove.

Comment on lines 109 to 124
func (k Keeper) GetNumCurrencyPairs(ctx sdk.Context) (uint64, error) {
marketPriceStore := k.getMarketPriceStore(ctx)

var numMarketPrices uint64

iterator := marketPriceStore.Iterator(nil, nil)
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
marketPrice := types.MarketPrice{}
k.cdc.MustUnmarshal(iterator.Value(), &marketPrice)
numMarketPrices++
}

return numMarketPrices, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a 1:1 copy of GetPrevBlockCPCounter, looking at the OracleKeeper interface, it doesn't seem like we need the GetPrevBlockCPCounter method anymore?

Copy link
Contributor

@nivasan1 nivasan1 left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -1594,15 +1593,14 @@ func (app *App) initOracle(pricesTxDecoder process.UpdateMarketPriceTxDecoder) {
compression.NewDefaultVoteExtensionCodec(),
compression.NewZLibCompressor(),
),
// We are not using the slinky PreBlocker, so there is no need to pass in PreBlocker here for
// We are not using the slinky PreBlocker/PriceApplier, so there is no need to pass in PreBlocker here for
Copy link
Contributor

Choose a reason for hiding this comment

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

The PreBlocker comment is no longer relevant (VE handler no longer depends on PreBlocker) so I'm aligned w/ removing references to PreBlocker in this commnet

return 0, nil
}

func (k Keeper) GetAllCurrencyPairs(ctx sdk.Context) []slinkytypes.CurrencyPair {
Copy link
Contributor

Choose a reason for hiding this comment

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

this fn should not be used in either the Delta / Default currency-pair strategies (which are what we'd be using in this case), so I'm happy to nop this / mark it explicitly as unimplemented

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I thought about that, but it seemed safer to implement it since we could so that nobody expected this function to work and it silently failed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any issue with GetNumCurrencyPairs returning a number < the length of the slice returned by this method?
There's some extra validation logic in this function that could lead to this happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'm going to no-op this as Nikhil suggested--it's actually not being used at all right now.

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.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
protocol/app/vote_extensions/expected_keepers.go (1)

[!TIP]
Codebase Verification

Line range hint 11-16: Interface Review: Ensure proper integration and usage of PricesKeeper methods post-removal of GetPrevBlockCPCounter.

The GetPrevBlockCPCounter method has been successfully removed from the PricesKeeper interface, and there are no remaining references to this method in the active codebase. However, the mock implementation in protocol/mocks/PricesKeeper.go still contains this method and should be updated to reflect the current interface.

  • protocol/mocks/PricesKeeper.go: Remove the GetPrevBlockCPCounter method from the mock implementation.
Analysis chain

Line range hint 11-16: Interface Review: Ensure proper integration and usage of PricesKeeper methods post-removal of GetPrevBlockCPCounter.

The interface PricesKeeper currently defines methods related to market prices and currency pairs. Given the removal of the GetPrevBlockCPCounter method, it's crucial to ensure that all components that previously depended on this method have been appropriately updated or refactored to work without it.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that no remaining parts of the codebase are trying to use the removed `GetPrevBlockCPCounter` method.

# Test: Search for the method usage. Expect: No occurrences found.
rg --type go 'GetPrevBlockCPCounter'

Length of output: 348



Script:

#!/bin/bash
# Description: Verify if the mock implementation of PricesKeeper with the GetPrevBlockCPCounter method is still in use.

# Test: Search for references to the PricesKeeper mock implementation. Expect: No relevant occurrences found.
rg --type go 'PricesKeeper' --files-with-matches | xargs rg 'GetPrevBlockCPCounter'

Length of output: 393

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2fecfec and 14fe18d.

Files selected for processing (5)
  • protocol/app/app.go (3 hunks)
  • protocol/app/vote_extensions/expected_keepers.go (1 hunks)
  • protocol/x/prices/keeper/slinky_adapter.go (2 hunks)
  • protocol/x/prices/keeper/slinky_adapter_test.go (1 hunks)
  • protocol/x/prices/types/types.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/prices/types/types.go
Files skipped from review as they are similar to previous changes (3)
  • protocol/app/app.go
  • protocol/x/prices/keeper/slinky_adapter.go
  • protocol/x/prices/keeper/slinky_adapter_test.go

@@ -113,3 +113,24 @@ func TestGetPrevBlockCPCounter(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(marketNumber), cpCounter)
}

func TestGetAllCurrencyPairs(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Perhaps also a test that this returns less curreny paris if one has an invalid format?

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 14fe18d and eab0745.

Files selected for processing (2)
  • protocol/x/prices/keeper/slinky_adapter.go (2 hunks)
  • protocol/x/prices/keeper/slinky_adapter_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/x/prices/keeper/slinky_adapter.go
  • protocol/x/prices/keeper/slinky_adapter_test.go

@vincentwschau vincentwschau merged commit 6abbc72 into dydxprotocol:main Jun 26, 2024
19 checks passed
@vincentwschau
Copy link
Contributor

@Mergifyio backport release/protocol/v5.1.x

Copy link
Contributor

mergify bot commented Jun 26, 2024

backport release/protocol/v5.1.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jun 26, 2024
(cherry picked from commit 6abbc72)

# Conflicts:
#	protocol/mocks/OracleClient.go
#	protocol/x/prices/keeper/slinky_adapter_test.go
vincentwschau added a commit that referenced this pull request Jun 26, 2024
Co-authored-by: Eric Warehime <[email protected]>
Co-authored-by: Vincent Chau <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Oct 15, 2024
6 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 13, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants