Skip to content

txmgr: Restructure internals and add TxNotInMempoolTimeout#5286

Merged
trianglesphere merged 4 commits intodevelopfrom
jg/tx_lifecycle_mgmt
Mar 31, 2023
Merged

txmgr: Restructure internals and add TxNotInMempoolTimeout#5286
trianglesphere merged 4 commits intodevelopfrom
jg/tx_lifecycle_mgmt

Conversation

@trianglesphere
Copy link
Contributor

@trianglesphere trianglesphere commented Mar 29, 2023

Description

This restructures a lot of the internal of transaction sending. It adds a new flag and features where it aborts sending the transaction if the transaction is never seen on the network after a default of 2 minutes (configurable via txmgr flag).

The transaction manager's sendState has been modified to track successful publishes and the time of its creation. If it goes for TxNotInMempoolTimeout time without seeing a successful transaction publish (i.e. it believes the tx is not in the mempool) then it will abort.

The goal of this change is to ensure that the transaction manager does not get stuck in state where the transaction will not get confirmed while not accidentally recording transactions as failed when they in fact succeeded.

TODOs

@changeset-bot
Copy link

changeset-bot bot commented Mar 29, 2023

⚠️ No Changeset found

Latest commit: 9afb543

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Mar 29, 2023

Deploy Preview for opstack-docs canceled.

Name Link
🔨 Latest commit 9afb543
🔍 Latest deploy log https://app.netlify.com/sites/opstack-docs/deploys/6427258303251700085e46ed

@trianglesphere trianglesphere force-pushed the jg/tx_lifecycle_mgmt branch 2 times, most recently from cf37742 to da9fe76 Compare March 29, 2023 16:49
@semgrep-app
Copy link
Contributor

semgrep-app bot commented Mar 29, 2023

Semgrep found 1 unchecked-type-assertion finding:

  • op-bindings/bindings/systemconfig.go: L380

Unchecked type assertion.

Created by unchecked-type-assertion.

@trianglesphere trianglesphere force-pushed the jg/tx_lifecycle_mgmt branch 2 times, most recently from cf59022 to 5e7a716 Compare March 29, 2023 18:22
@trianglesphere trianglesphere changed the title txmgr: Restructure internals txmgr: Restructure internals and add TxNotInMempoolTimeout Mar 29, 2023
@trianglesphere trianglesphere force-pushed the jg/tx_lifecycle_mgmt branch 2 times, most recently from 5e2d5d0 to 2c546e3 Compare March 29, 2023 18:51
@trianglesphere trianglesphere marked this pull request as ready for review March 29, 2023 18:51
@trianglesphere trianglesphere requested review from a team as code owners March 29, 2023 18:51
@trianglesphere trianglesphere requested review from ajsutton, protolambda, sebastianst and zhwrd and removed request for protolambda March 29, 2023 18:51
@codecov
Copy link

codecov bot commented Mar 29, 2023

Codecov Report

Merging #5286 (9afb543) into develop (7354398) will decrease coverage by 3.79%.
The diff coverage is 68.18%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5286      +/-   ##
===========================================
- Coverage    39.93%   36.15%   -3.79%     
===========================================
  Files          382      227     -155     
  Lines        24376    19883    -4493     
  Branches       838        0     -838     
===========================================
- Hits          9734     7188    -2546     
+ Misses       13911    12000    -1911     
+ Partials       731      695      -36     
Flag Coverage Δ
bedrock-go-tests 36.15% <68.18%> (-0.06%) ⬇️
common-ts-tests ?
contracts-bedrock-tests ?
contracts-tests ?
core-utils-tests ?
dtl-tests ?
fault-detector-tests ?
sdk-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
op-service/txmgr/cli.go 43.05% <33.33%> (-0.03%) ⬇️
op-service/txmgr/txmgr.go 78.94% <68.90%> (-3.13%) ⬇️
op-service/txmgr/send_state.go 96.66% <100.00%> (+0.30%) ⬆️

... and 156 files with indirect coverage changes

Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

Generally looks good - left a few clarifying comments. Main concern for me is having to sleep in tests - that's a very common source of intermittency and leads to slower tests.

Copy link
Member

@sebastianst sebastianst left a comment

Choose a reason for hiding this comment

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

I'm wondering, do we even need the async tx sending in send with sendTxAsync via a goroutine and then waiting for the receipt on a channel?

It looks to me like the whole transaction sending loop could also just be a normal synchronous call to publishAndWaitForTx, which would simply return *types.Receipt, error. But maybe I'm just oversimplifying the algorithm here.

@trianglesphere
Copy link
Contributor Author

I'm wondering, do we even need the async tx sending in send with sendTxAsync via a goroutine and then waiting for the receipt on a channel?

It looks to me like the whole transaction sending loop could also just be a normal synchronous call to publishAndWaitForTx, which would simply return *types.Receipt, error. But maybe I'm just oversimplifying the algorithm here.

It's because when we update the gas price, we are waiting for multiple different transaction hashes. Say a tx gets included in L1, but we then published another transaction with a higher gas price before we realize. If we only waited for the second TX we would miss that the first TX we sent got included on L1.

We could make it synchronous by polling every transaction that has been sent

ajsutton
ajsutton previously approved these changes Mar 30, 2023
@ajsutton
Copy link
Contributor

Actually I'm going to dismiss my review and just leave approval to Seb since he has better context. I really just meant to remove my request changes.

@ajsutton ajsutton dismissed their stale review March 30, 2023 22:12

I'm happy with it, but leaving final approval to Seb.

@trianglesphere trianglesphere mentioned this pull request Mar 30, 2023
1 task
@sebastianst
Copy link
Member

I'm wondering, do we even need the async tx sending in send with sendTxAsync via a goroutine and then waiting for the receipt on a channel?
It looks to me like the whole transaction sending loop could also just be a normal synchronous call to publishAndWaitForTx, which would simply return *types.Receipt, error. But maybe I'm just oversimplifying the algorithm here.

It's because when we update the gas price, we are waiting for multiple different transaction hashes. Say a tx gets included in L1, but we then published another transaction with a higher gas price before we realize. If we only waited for the second TX we would miss that the first TX we sent got included on L1.

We could make it synchronous by polling every transaction that has been sent

Ah thanks, that makes sense. If we're running into problems with the current async architecture, I'd vote for this refactor. But fine for now since it works.

Copy link
Member

@sebastianst sebastianst left a comment

Choose a reason for hiding this comment

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

Looks great, just two open questions regarding error strings checking

@trianglesphere
Copy link
Contributor Author

#5286 (comment)
Can't comment on that for some reason. @sebastianst

ethereum.NotFound is correctly returned by the client.

@trianglesphere trianglesphere requested a review from mslipper March 31, 2023 17:25
@mergify
Copy link
Contributor

mergify bot commented Mar 31, 2023

This PR has been added to the merge queue, and will be merged soon.

@mergify
Copy link
Contributor

mergify bot commented Mar 31, 2023

This PR is next in line to be merged, and will be merged as soon as checks pass.

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Mar 31, 2023

This PR is next in line to be merged, and will be merged as soon as checks pass.

@mergify mergify bot removed the on-merge-train label Mar 31, 2023
@trianglesphere
Copy link
Contributor Author

@Mergifyio refresh

@mergify
Copy link
Contributor

mergify bot commented Mar 31, 2023

refresh

✅ Pull request refreshed

@trianglesphere trianglesphere merged commit f0676c1 into develop Mar 31, 2023
@trianglesphere trianglesphere deleted the jg/tx_lifecycle_mgmt branch March 31, 2023 18:46
@mergify
Copy link
Contributor

mergify bot commented Mar 31, 2023

This PR has been added to the merge queue, and will be merged soon.

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.

4 participants