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

Fix off-by-one in data poster nonce check #2326

Merged
merged 4 commits into from
May 23, 2024
Merged

Conversation

PlasmaPower
Copy link
Collaborator

The "reorg resistant nonce" is really a reorg resistant tx count, which is one higher than the tx nonce that won't be reorged. In other words, if the previous tx is equal to the reorg resistant tx count, then the previous tx can still be reorged (only the one before it is safe). This PR fixes that by comparing it to the new tx nonce. If the new tx nonce is greater than the reorg resistant tx count, then that means that there's a gap between the last safe tx and the new tx we're posting. This would be equivalent to changing the > to a >=, but I thought this way was clearer. I also cleaned up some logging which was logging the variables in the wrong place (they aren't populated in the second log statement).

@PlasmaPower PlasmaPower marked this pull request as ready for review May 22, 2024 02:08
@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label May 22, 2024
return nil
}
} else {
log.Info("DataPoster will send previously unsent batch tx", "nonce", newTx.FullTx.Nonce(), "prevType", precedingTx.FullTx.Type(), "type", newTx.FullTx.Type(), "prevSent", precedingTx.Sent, "latestBlockNumber", latestBlockNumber, "prevBlockNumber", prevBlockNumber, "reorgResistantNonce", reorgResistantNonce)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it needs to be at the inner level here since precedingTx can be nil, and also I put it at that level because didn't want to spam too many of these logs when the tx was previously sent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did you mean to put it in the else? Most of the fields are only populated in the if case which is why I was confused

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the current level of nesting I believe precedingTx is always non-nil, and I changed it to a debug log (instead of info) to make it a bit quieter

Copy link
Member

@Tristan-Wilson Tristan-Wilson left a comment

Choose a reason for hiding this comment

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

LGTM

@PlasmaPower PlasmaPower enabled auto-merge May 23, 2024 00:52
@PlasmaPower PlasmaPower merged commit b85f2eb into master May 23, 2024
10 checks passed
@PlasmaPower PlasmaPower deleted the poster-nonce-switch branch May 23, 2024 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants