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

eth: Fix error logging for failed replacement tx #1977

Merged
merged 2 commits into from Aug 3, 2021

Conversation

yondonfu
Copy link
Member

@yondonfu yondonfu commented Aug 3, 2021

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

This PR logs the correct error when a replacement tx fails at submission time.

Specific updates (required)

See commit history.

How did you test each of these updates (required)

N/A

Does this pull request close any open issues?

Related to the logs provided in #1964.

Checklist:

@@ -237,6 +237,7 @@ func TestTransactionManager_Replace(t *testing.T) {
logsAfter = glog.Stats.Info.Lines()
assert.Nil(err)
expTx := types.NewTransaction(1, *stubTx.To(), stubTx.Value(), 100000, calcReplacementGasPrice(stubTx), stubTx.Data())
assert.Equal(tx.Hash(), expTx.Hash())
Copy link
Member Author

Choose a reason for hiding this comment

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

Fun discovery that led to the addition of this assertion as well as the assertion on L253:

The go-ethereum Transaction type maintains a cache for the hash of the tx and the Hash() method will only compute the hash of the tx if the cache is not populated. The internal hash field of the struct is the zero value until Hash() is called for the first time.

Prior to this PR, newSignedTx.Hash() was not called in replace() when an error was not returned from SubmitTransaction(). But, now newSignedTx.Hash() is called in replace() when an error is not returned from SubmitTransaction() because we call newSignedTx.Hash() in the log statement on L188. As a result, without these assertions that call the Hash() method on both tx and expTx, one of the structs would have the zero value for the internal hash field and the assertion comparing tx and expTx would fail. By first calling Hash() on both tx and expTx we ensure that the internal hash field of both structs is populated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nice find, interesting behaviour.

Copy link
Contributor

@kyriediculous kyriediculous 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 3bfd29e into master Aug 3, 2021
@yondonfu yondonfu deleted the yf/fix-replacement-log branch August 3, 2021 20:35
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

2 participants