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

refactor: Imporve signer confirm tx #2970

Merged
merged 13 commits into from
Jan 10, 2024
Merged

refactor: Imporve signer confirm tx #2970

merged 13 commits into from
Jan 10, 2024

Conversation

htiennv
Copy link
Contributor

@htiennv htiennv commented Dec 28, 2023

This PR using a Ticker for periodically call GetTx by given hash instead of a Timer. This makes the code clean and avoids calling reset Timer multiple times.

It's similar to WaitMined in geth.

Other changes:

  • Add lock when get pollTime

Copy link
Contributor

coderabbitai bot commented Dec 28, 2023

Walkthrough

Walkthrough

The updates involve refining error handling and testing in a Go package. The signer.go file saw the removal of unnecessary dependencies and the enhancement of a function with error checks. A significant refactor was made to the transaction confirmation method to improve its polling mechanism. Correspondingly, the signer_test.go file was updated to improve test coverage, including the introduction of new test scenarios and a function to submit transactions without awaiting confirmation, alongside adjustments to timeouts and assertions.

Changes

File Change Summary
pkg/user/signer.go Removed "strings" import; added "sdkerrors" import; enhanced SubmitPayForBlob with comments and error handling; refactored ConfirmTx for better polling with a ticker.
pkg/user/signer_test.go Imported "fmt"; renamed ConfirmTxTimeout to TestConfirmTx; modified require.Equal arguments order; shortened context timeout; replaced require assertions with assert; added new test cases and submitTxWithoutConfirm function.

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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your comments unless it is explicitly tagged.

  • 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 from git 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.

@celestia-bot celestia-bot requested a review from a team December 28, 2023 14:19
pkg/user/signer.go Outdated Show resolved Hide resolved
@htiennv htiennv changed the title Imporve signer confirm tx. refactor: Imporve signer confirm tx. Dec 28, 2023
evan-forbes
evan-forbes previously approved these changes Jan 2, 2024
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

lgtm

pkg/user/signer.go Outdated Show resolved Hide resolved
@celestia-bot celestia-bot requested a review from a team January 2, 2024 16:02
pkg/user/signer.go Outdated Show resolved Hide resolved
@htiennv htiennv force-pushed the signer branch 2 times, most recently from 747669d to 563a154 Compare January 2, 2024 18:23
pkg/user/signer.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

[question] IDK how this was missed in a previous PR but should https://github.com/htiennv/celestia-app/blob/563a154b4f76e1489bda929b64024677117723ff/pkg/user/signer_test.go#L72 contain a leading Test so that it actually runs in the test suite?

Note: it passes before this PR but fails after so should be addressed prior to merging.

pkg/user/signer.go Outdated Show resolved Hide resolved
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

it looks like we're still seeing quite a few tests fail, so we need to figure out why before we can merge anything. per the other review we should also clean up todo comments

@htiennv
Copy link
Contributor Author

htiennv commented Jan 4, 2024

Oh sorry, I will fix this PR for handle test cases!

pkg/user/signer.go Outdated Show resolved Hide resolved
@htiennv
Copy link
Contributor Author

htiennv commented Jan 6, 2024

I have update this PR, please review it @evan-forbes @rootulp. Thanks!

pkg/user/signer_test.go Outdated Show resolved Hide resolved
@rootulp
Copy link
Collaborator

rootulp commented Jan 7, 2024

Thanks for the ping @htiennv . I'm observing that TestConfirmTxTimeout fails so I pushed a commit that makes that test actually run (by adding the Test prefix).

@htiennv
Copy link
Contributor Author

htiennv commented Jan 7, 2024

Thanks @rootulp, I understand why this test fails, because currently we're checking

require.Equal(s.T(), context.DeadlineExceeded, err)

But in this change I call GetTx before call ctx.Done()

so it reach error looks like:
rpc error: code = DeadlineExceeded desc = context deadline exceeded

So require.Equal(s.T(), context.DeadlineExceeded, err) will fails

I think we can check as follows:

require.Equal(s.T(), strings.Contains(err.Error(), context.DeadlineExceeded.Error()), true)

How do you feel about that?

@rootulp
Copy link
Collaborator

rootulp commented Jan 7, 2024

Hmm, slight nit but also appears fixed with:

	assert.Error(t, err)
	assert.Contains(t, err.Error(), context.DeadlineExceeded.Error())

@celestia-bot celestia-bot requested a review from a team January 8, 2024 03:18
evan-forbes
evan-forbes previously approved these changes Jan 8, 2024
@evan-forbes evan-forbes dismissed their stale review January 8, 2024 12:18

waiting for tests

@celestia-bot celestia-bot requested a review from a team January 9, 2024 02:52
@htiennv
Copy link
Contributor Author

htiennv commented Jan 9, 2024

@rootulp I added some tests for ConfirmTx as you suggest. But I think case 3 (What happens if the tx if found after the second poll) is not necessary and can be ignored.

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test cases! I have a few comments on them

pkg/user/signer_test.go Outdated Show resolved Hide resolved
pkg/user/signer_test.go Outdated Show resolved Hide resolved
pkg/user/signer_test.go Outdated Show resolved Hide resolved
pkg/user/signer_test.go Outdated Show resolved Hide resolved
pkg/user/signer_test.go Outdated Show resolved Hide resolved
pkg/user/signer_test.go Outdated Show resolved Hide resolved
pkg/user/signer_test.go Show resolved Hide resolved
@celestia-bot celestia-bot requested a review from a team January 10, 2024 07:35
pkg/user/signer_test.go Outdated Show resolved Hide resolved
pkg/user/signer_test.go Show resolved Hide resolved
pkg/user/signer_test.go Show resolved Hide resolved
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Great work! Thanks for the PR

pkg/user/signer_test.go Show resolved Hide resolved
@htiennv
Copy link
Contributor Author

htiennv commented Jan 10, 2024

Thanks!

Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

Nice!

@rootulp rootulp merged commit 48a77b8 into celestiaorg:main Jan 10, 2024
29 checks passed
@htiennv htiennv deleted the signer branch January 10, 2024 20:14
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.

4 participants