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

pm: Only mark failed tx as redeemed for check tx err #2018

Merged
merged 3 commits into from
Sep 9, 2021

Conversation

yondonfu
Copy link
Member

@yondonfu yondonfu commented Sep 7, 2021

What does this pull request do? Explain your changes. (required)

At the moment, if an error is encountered while calling eth.client.CheckTx() for a ticket redemption tx, the ticket is marked as redeemed with the tx hash set to the null hash (i.e. 0x000...). This behavior is a problem because eth.client.CheckTx() could return an error even if the tx did not fail. For example, an error is returned in the scenario where the tx needs to be replaced, but the required gas price for a replacement exceeds the node's configured max gas price. The consequence of this behavior is that the node incorrectly marks the ticket as redeemed in the node's DB which prevents the node from retrying the ticket and also makes it more difficult to query the DB for redeemable tickets in other tools such as the script in #2014.

This PR introduces logic to only mark tickets for failed redeemed (i.e. revert, OOG) txs as redeemed.

Specific updates (required)

See commit history and in-line code comments.

How did you test each of these updates (required)

Ran unit tests.

Does this pull request close any open issues?

Fixes #2016

Checklist:

@yondonfu yondonfu marked this pull request as draft September 7, 2021 21:52

func isNonRetryableTicketErr(err error) bool {
// The latter check depends on logic in eth.client.CheckTx()
return err == errIsUsedTicket || strings.Contains(err.Error(), "transaction failed")
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't feel great about this string check, but I ran into issues implementing an error type check since the tx failure check occurs in the eth package and importing an error type from the eth package in the pm package would result in an import cycle. There may be a better way to structure this check, but I went with the simple solution of a string check right now accepting the downside of exposing the pm package to the implementation details of eth.client.CheckTx().

@@ -25,8 +25,6 @@ var unixNow = func() int64 {
return time.Now().Unix()
}

type errCheckTx error
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this error type because we really care about whether the error when checking the tx is the result of a tx failure and this is accomplished by the string check in this PR making this error type unnecessary.

ethcommon.Hash{},
err,
}
// FIXME: If there are replacement txs then tx.Hash() could be different
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: Create an issue to track this.

This was a problem before this PR and more substantial changes will be required to address it (i.e. return the tx that was mined from CheckTx()). The negative impact is relatively minimal though - the DB will just end up tracking the wrong tx hash for a redeemed ticket if a replacement tx was mined.

@@ -424,7 +426,8 @@ func (sm *LocalSenderMonitor) redeemWinningTicket(ticket *SignedTicket) (*types.
if monitor.Enabled {
monitor.TicketRedemptionError()
}
return nil, errCheckTx(err)
// Return tx so caller can utilize the tx if it fails
return tx, err
Copy link
Member Author

Choose a reason for hiding this comment

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

This gives the caller access to the hash of a failed tx.

@yondonfu yondonfu marked this pull request as ready for review September 7, 2021 23:23
Copy link
Contributor

@darkdarkdragon darkdarkdragon left a comment

Choose a reason for hiding this comment

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

LGTM

@yondonfu yondonfu merged commit 534e6ce into master Sep 9, 2021
@yondonfu yondonfu deleted the yf/non-retryable-ticket-res branch September 9, 2021 01:43
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.

Winning tickets incorrectly marked as redeemed (txHash 0x0000...)
2 participants