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

rpcclient: add detailed error types #2138

Merged
merged 2 commits into from
Mar 18, 2024

Conversation

yyforyongyu
Copy link
Contributor

This PR adds detailed error types so the caller can use the structured errors to gain finer control, eg, handling an error resulted from an RBF attempt.

@coveralls
Copy link

coveralls commented Mar 14, 2024

Pull Request Test Coverage Report for Build 8328968456

Details

  • 104 of 105 (99.05%) changed or added relevant lines in 2 files are covered.
  • 11 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.07%) to 56.865%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcclient/errors.go 103 104 99.04%
Files with Coverage Reduction New Missed Lines %
btcutil/gcs/gcs.go 1 81.25%
mempool/mempool.go 1 66.84%
peer/peer.go 9 73.86%
Totals Coverage Status
Change from base Build 8211354034: 0.07%
Covered Lines: 29418
Relevant Lines: 51733

💛 - Coveralls

Copy link
Contributor

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

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

LGTM, just had a few Nits regarding the comments otherwise straightforward PR.

// `sendrawtransaction` with missing inputs.
ErrMissingInputsOrSpent BitcoindRPCErr = iota

// ErrMissingInputs is returned when calling `sendrawtransaction` with
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: :s/ErrMissingInputs/ErrMaxBurnExceeded/g

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

rpcclient/errors.go Outdated Show resolved Hide resolved
rpcclient/errors.go Outdated Show resolved Hide resolved
rpcclient/errors.go Outdated Show resolved Hide resolved
// A timelocked transaction.
"transaction is not finalized": "non-final",
"tried to spend coinbase transaction output": "non-final",
// Minimally-small transaction(in non-witness bytes) that is allowed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Is the comment correct ?

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 totally wrong🤦🏻 now fixed

// Get the error string and turn it into lower case.
btcErr := strings.ToLower(err.Error())
// Error implements the error interface. It returns the error message defined
// in `bitcoind`.
Copy link
Contributor

Choose a reason for hiding this comment

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

should we link the bitcoind code file for the specific error string ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the comments! Think we need to find a way to automatically create these errors, maybe parsing the package https://github.com/bitcoin/bitcoin/tree/master/test/functional

rpcclient/errors.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice!

rpcclient/errors.go Outdated Show resolved Hide resolved
rpcclient/errors.go Outdated Show resolved Hide resolved
This commit adds detailed errors for all possible errors returned from
`sendrawtransaction` or `testmempoolaccept`, enabling upstream callers
to have refined control over the actions to be taken.
This commit changes the `RejectReason` resulted from calling
btcd's `testmempoolaccept` to be un-matched, leaving it to the caller to
decide when and where to match it.
@guggero guggero merged commit 2fc99e0 into btcsuite:master Mar 18, 2024
3 checks passed
@yyforyongyu yyforyongyu deleted the error-matching branch April 3, 2024 21:28
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.

None yet

4 participants