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/txpool: Improve error responses #30715

Conversation

piersy
Copy link
Contributor

@piersy piersy commented Nov 1, 2024

I noticed that these two responses can make their way back to the transaction
submitter when submitting unsupported tx types.

Adding the extra context makes it easier for the submitter to understand what
went wrong. Particularly in the case of the invalid sender response, which is
returned when an unsupported transaction type is encountered.

I noticed that these two responses can make their way back to the
transaction submitter when submitting unsupported tx types. Adding the
extra context makes it easier for the submitter to understand what went
wrong. Particularly in the case of the invalid sender response, which is
returned when an unsupported transaction type is encountered.
@piersy piersy force-pushed the improve-error-responses-for-invalid-transactions branch from 967c675 to e44cfee Compare November 1, 2024 20:02
@@ -341,7 +341,7 @@ func (p *TxPool) Add(txs []*types.Transaction, local bool, sync bool) []error {
for i, split := range splits {
// If the transaction was rejected by all subpools, mark it unsupported
if split == -1 {
errs[i] = core.ErrTxTypeNotSupported
errs[i] = fmt.Errorf("%w (type %d)", core.ErrTxTypeNotSupported, txs[i].Type())
Copy link
Member

Choose a reason for hiding this comment

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

Please change the format to "%w: received type %d", to keep it consistent with the rest of our error formatting.

@@ -99,7 +99,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
}
// Make sure the transaction is signed properly
if _, err := types.Sender(signer, tx); err != nil {
return ErrInvalidSender
return fmt.Errorf("%w: %w", ErrInvalidSender, err)
Copy link
Member

Choose a reason for hiding this comment

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

The second %w should be %v, I'm not sure having 2 %w formatters is a good idea. It was definitely disallowed in the past. I think they relaxed it now, but it would go against our way of using the errors, so lets keep it the simpler form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrapping mulitple errors like this was introduced in go 1.20 see (https://tip.golang.org/doc/go1.20#errors). Happy to change it, but could you explain why having the two errors wrapped would be problematic for you?

Copy link
Member

Choose a reason for hiding this comment

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

It's mostly about style. If the entire codebase operates on the first being the thing wrapped and the second is just a detail, it's less surprising what happens when you match on errors. If some errors wrap both parts, then a match might match on the end not the beginning. That's fine, if the code is architected to take that into account, which ours isn't really.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation @karalabe.

@karalabe karalabe added this to the 1.14.12 milestone Nov 4, 2024
@karalabe karalabe merged commit 484f0f4 into ethereum:master Nov 4, 2024
3 checks passed
zfy0701 pushed a commit to sentioxyz/go-ethereum that referenced this pull request Dec 3, 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