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
transaction: add nonce-based monitor #1465
Conversation
6f58fce
to
2e83af4
Compare
a33d1b7
to
5936d42
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Requesting some changes regarding test timeouts (consider raising all of them so that the CI doesn't flake), context propagation can also be improved, with the context fields removed from the struct. I think we've done this before in other places and regretted it, it's better to just pass context from caller and create a root context in the forever loop. Also, some things can be improve as a result in terms of shutdown.
345a769
to
144d721
Compare
144d721
to
4d5efee
Compare
This is a pretty radical rewrite of how transactions are monitored for confirmations.
The primary aim is to be able to:
The way this works is as follows:
Instead of watching transactions individually, the senders nonce is monitored and transactions are checked based on this. The idea is that if the nonce is still lower than that of a pending transaction, there is no point in actually checking the transaction for a receipt. At the same time if the nonce was already used and this was a few blocks ago we can reasonably assume that it will never confirm.
A new component
transaction.Monitor
was introduced for that purpose (primarily because this could be instantiated even without a signer, and also to avoid the locks interfering with the locks of the transaction sending). However other components still wait using thetransaction.Service
as using the monitor directly requires knowing the nonce which only the transaction service does.The
transaction.Service
is now keeping a record of all transactions it sent. In this PR this is only used to look up the nonce later, but in the future this will allow adding users to query past transaction info, query pending transactions and to enable the advanced functionality mentioned above. Because it now uses the monitor underneath thetransaction.Service
can now only wait for its own transactions, not arbitrary ones (but it was never used in that way anyway).In order to test the monitor (which queries many blocks and nonces at different blocks in sequence) a new
transaction.Backend
mock was added which can be used in a more declarative way.