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

Option to disable attempts to fix sequence mismatch during broadcasting of txs #213

Closed
wants to merge 7 commits into from

Conversation

kakysha
Copy link
Contributor

@kakysha kakysha commented Mar 18, 2024

I want my Async to be truly async, so can't wait for nonce to be synced in case of error

  • added "local" network endpoints

Summary by CodeRabbit

  • New Features
    • Updated error handling logic to automatically fix account sequence mismatches, enhancing transaction reliability.
    • Added support for local network configurations, simplifying local development and testing.

Copy link

coderabbitai bot commented Mar 18, 2024

Walkthrough

The recent updates introduce enhancements to address "account sequence mismatch" errors in the blockchain client by offering an option to automatically resolve these discrepancies. Furthermore, support for configuring a local network has been added, enhancing testing and development flexibility. These changes encompass improvements in error handling, network setup, and client options.

Changes

Files Change Summary
client/chain/chain.go Updated error handling for "account sequence mismatch" by introducing a FixSeqMismatch field in options. Renamed prepareFactory to PrepareFactory.
client/common/network.go, client/common/options.go Added support for configuring a "local" network and integrated the FixSeqMismatch option in client settings.
.coderabbit.yaml Added instructions for test suggestions exclusion in Go files and configured auto-reply in chat.

🐰✨
To the code, we hop and skip,
Fixing mismatches, bit by bit.
A local net, for us to play,
In our digital burrow, night and day.
With every update, we grow, we fit,
In the world of code, we knit.
🌟🐾

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Mar 18, 2024

Codecov Report

Attention: Patch coverage is 0% with 34 lines in your changes are missing coverage. Please review.

Project coverage is 25.10%. Comparing base (8a251c5) to head (ca39171).

Files Patch % Lines
client/common/network.go 0.00% 15 Missing ⚠️
client/chain/chain.go 0.00% 11 Missing ⚠️
client/common/options.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #213      +/-   ##
==========================================
+ Coverage   25.01%   25.10%   +0.09%     
==========================================
  Files          17       17              
  Lines        3022     3011      -11     
==========================================
  Hits          756      756              
+ Misses       2234     2223      -11     
  Partials       32       32              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8a251c5 and 0fd3579.
Files selected for processing (3)
  • client/chain/chain.go (4 hunks)
  • client/common/network.go (1 hunks)
  • client/common/options.go (2 hunks)
Additional comments: 1
client/common/options.go (1)
  • 25-25: The addition of the FixSeqMismatch boolean field to the ClientOptions struct is clear and well-named, effectively allowing for easy configuration of the sequence mismatch handling feature.

Comment on lines +31 to +33
return &ClientOptions{
FixSeqMismatch: true,
}
Copy link

Choose a reason for hiding this comment

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

The default setting of FixSeqMismatch to true in DefaultClientOptions is a good choice for maintaining backward compatibility. However, it's recommended to add tests to cover this new default behavior.

Would you like assistance in creating tests for this new default setting?

Comment on lines +68 to +72
func OptionFixSeqMismatch(fixSeqMismatch bool) ClientOption {
return func(opts *ClientOptions) error {
opts.FixSeqMismatch = fixSeqMismatch
return nil
}
Copy link

Choose a reason for hiding this comment

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

The OptionFixSeqMismatch function provides a flexible way to configure the sequence mismatch handling feature. It's recommended to add tests to ensure this function behaves as expected when configuring the client.

Would you like assistance in creating tests for this configuration option?

Comment on lines +179 to +193
case "local":
return Network{
LcdEndpoint: "",
TmEndpoint: "tcp://localhost:26657",
ChainGrpcEndpoint: "tcp://localhost:9900",
ChainStreamGrpcEndpoint: "",
ExchangeGrpcEndpoint: "",
ExplorerGrpcEndpoint: "",
ChainId: "injective-1",
Fee_denom: "inj",
Name: "local-1",
chainCookieAssistant: &DisabledCookieAssistant{},
exchangeCookieAssistant: &DisabledCookieAssistant{},
explorerCookieAssistant: &DisabledCookieAssistant{},
}
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 "local" case in the LoadNetwork function provides a clear and concise setup for local network configurations. It's recommended to add tests to ensure this new configuration behaves as expected, especially considering the specific endpoints and disabled cookie assistants.

Would you like assistance in creating tests for this new network configuration?

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

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 0fd3579 and 2a7da1e.
Files selected for processing (1)
  • client/chain/chain.go (4 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: 3

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 2a7da1e and b4bd99b.
Files selected for processing (1)
  • client/chain/chain.go (9 hunks)

needed to sdk clients that use own tx factory and want to initialize it
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: 11

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between b4bd99b and a9ea38c.
Files selected for processing (1)
  • client/chain/chain.go (9 hunks)

@@ -605,7 +605,7 @@
res, err := c.broadcastTx(c.ctx, c.txFactory, true, msgs...)

if err != nil {
if strings.Contains(err.Error(), "account sequence mismatch") {
if c.opts.FixSeqMismatch && strings.Contains(err.Error(), "account sequence mismatch") {
Copy link

Choose a reason for hiding this comment

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

The logic to handle sequence mismatches during synchronous transaction broadcasting has been updated to check the FixSeqMismatch option. However, this change lacks test coverage.

Consider adding unit tests to cover the new logic introduced for handling sequence mismatches. This will ensure the feature works as expected and will help catch any potential issues or edge cases.

@@ -668,7 +668,7 @@
c.txFactory = c.txFactory.WithAccountNumber(c.accNum)
res, err := c.broadcastTx(c.ctx, c.txFactory, false, msgs...)
if err != nil {
if strings.Contains(err.Error(), "account sequence mismatch") {
if c.opts.FixSeqMismatch && strings.Contains(err.Error(), "account sequence mismatch") {
Copy link

Choose a reason for hiding this comment

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

Similar to the synchronous broadcast method, the asynchronous transaction broadcasting method now includes logic to handle sequence mismatches. This change is also not covered by tests.

It's important to extend the testing suite to include scenarios that exercise the new asynchronous sequence mismatch handling logic. Ensuring comprehensive test coverage will help maintain the robustness of the transaction broadcasting feature.

@@ -925,7 +887,7 @@
log.Debugln("broadcastTx with nonce", sequence)
res, err := c.broadcastTx(c.ctx, c.txFactory, true, toSubmit...)
if err != nil {
if strings.Contains(err.Error(), "account sequence mismatch") {
if c.opts.FixSeqMismatch && strings.Contains(err.Error(), "account sequence mismatch") {
Copy link

Choose a reason for hiding this comment

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

The logic for handling sequence mismatches during the batch broadcast of transactions is a valuable addition. However, like the other related changes, this update lacks test coverage.

Adding tests for the batch broadcast functionality, especially with the new sequence mismatch handling logic, is crucial for ensuring the reliability and correctness of this feature.

// if the account number and/or the account sequence number are zero (not set),
// they will be queried for and set on the provided Factory. A new Factory with
// the updated fields will be returned.
func (c *chainClient) prepareFactory(clientCtx client.Context, txf tx.Factory) (tx.Factory, error) {
func PrepareFactory(clientCtx client.Context, txf tx.Factory) (tx.Factory, error) {
Copy link

Choose a reason for hiding this comment

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

The PrepareFactory function has been made public, but there's no test coverage for this change.

Adding tests for the PrepareFactory function would ensure its behavior is as expected, especially since it now plays a crucial role in preparing the transaction factory with the correct account sequence and number.

@@ -633,7 +633,7 @@
func (c *chainClient) SimulateMsg(clientCtx client.Context, msgs ...sdk.Msg) (*txtypes.SimulateResponse, error) {
c.txFactory = c.txFactory.WithSequence(c.accSeq)
c.txFactory = c.txFactory.WithAccountNumber(c.accNum)
txf, err := c.prepareFactory(clientCtx, c.txFactory)
txf, err := PrepareFactory(clientCtx, c.txFactory)
Copy link

Choose a reason for hiding this comment

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

The SimulateMsg method has been updated to use the PrepareFactory function, but this change is not covered by tests.

Consider adding tests for the SimulateMsg method to verify that it correctly simulates transactions with the updated transaction factory. This is important for ensuring the accuracy of gas estimation and other simulation outcomes.


func (c *chainClient) buildSignedTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) ([]byte, error) {
Copy link

Choose a reason for hiding this comment

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

The buildSignedTx helper method has been added but is not covered by tests.

Adding unit tests for the buildSignedTx method would help ensure that it correctly builds signed transactions, including simulating transactions when necessary. This is important for the overall reliability of transaction creation and broadcasting.

@@ -709,7 +710,7 @@
c.gasWanted = adjustedGas
}

txf, err := c.prepareFactory(clientCtx, txf)
txf, err := PrepareFactory(clientCtx, txf)
Copy link

Choose a reason for hiding this comment

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

The buildSignedTx method's use of PrepareFactory is not covered by tests.

Ensure that the integration of PrepareFactory within buildSignedTx is tested, particularly to verify that the transaction factory is correctly prepared with the updated account sequence and number before building signed transactions.

}

txBytes, err := clientCtx.TxConfig.TxEncoder()(txn.GetTx())
txBytes, err := c.buildSignedTx(clientCtx, txf, msgs...)
Copy link

Choose a reason for hiding this comment

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

The broadcastTx method's introduction is a significant change that lacks test coverage.

Adding tests for the broadcastTx method is essential to ensure that it correctly broadcasts transactions, handles errors, and optionally awaits transaction inclusion in a block. This is crucial for the robustness of the transaction broadcasting process.

if err != nil {
err = errors.Wrap(err, "failed TxEncoder to encode Tx")
err = errors.Wrap(err, "failed to build signed Tx")
Copy link

Choose a reason for hiding this comment

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

The error handling logic in the broadcastTx method is not covered by tests.

Consider adding tests to cover the error handling logic in the broadcastTx method, especially to ensure that errors are correctly identified, logged, and handled. This will help in maintaining the reliability of the transaction broadcasting feature.

@@ -850,7 +812,7 @@
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
}
// use our own client to broadcast tx
ctx = c.getCookie(ctx)
ctx := c.getCookie(context.Background())
Copy link

Choose a reason for hiding this comment

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

The use of getCookie in the broadcastTx method for setting metadata in the context is not covered by tests.

Adding tests to verify the correct setting of metadata in the context by the getCookie method within broadcastTx would ensure that the necessary metadata is included in the gRPC calls for transaction broadcasting.

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.yaml

Commits Files that changed from the base of the PR and between a9ea38c and 8e00488.
Files selected for processing (1)
  • .coderabbit.yaml (1 hunks)
Files skipped from review due to trivial changes (1)
  • .coderabbit.yaml

@aarmoa
Copy link
Collaborator

aarmoa commented Apr 26, 2024

I am closing this PR because it was created pointing to master instead of dev. I have already created #220 including the same changes.

@aarmoa aarmoa closed this Apr 26, 2024
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