-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Update TxStore to use parent context created at initialization #10735
Conversation
I see that you haven't updated any CHANGELOG files. Would it make sense to do so? |
I see that you haven't updated any README files. Would it make sense to do so? |
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.
Why are we removing this?
We want TXM to solely be in charge of the TxStore lifecycle so we wanted to move all of the methods to use a parent context created at TxStore initialization. This is also part of the work to untangle the TXM from external components so we didn't want to expose |
Removing |
Yes, we should actually use Context in all places that have origin from an external caller. Only those functions which originate from within the TXM's poller threads can ignore passing in Context. But they still need to use the Context stored in the TxStore. The idea is that if an external caller's call is stuck in a DB operation, and the external caller wants to cancel it, we should be able to cancel that call. |
common/txmgr/txmgr.go
Outdated
if err != nil { | ||
return tx, errors.Wrap(err, "Txm#CreateTransaction") | ||
} | ||
|
||
tx, err = b.txStore.CreateTransaction(txRequest, b.chainID, qs...) | ||
tx, err = b.txStore.CreateTransaction(txRequest, b.chainID) |
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.
Since this call is ultimately coming from an external caller, we should take a param ctx from external caller, and pass the ctx all the way to the evmTxStore.CreateTx(), and in to the DB call.
Thus, if the caller wants to abandon their call, they should be able to.
common/txmgr/types/tx_store.go
Outdated
@@ -96,7 +95,7 @@ type TxHistoryReaper[CHAIN_ID types.ID] interface { | |||
} | |||
|
|||
type UnstartedTxQueuePruner interface { | |||
PruneUnstartedTxQueue(queueSize uint32, subject uuid.UUID, qopts ...pg.QOpt) (n int64, err error) | |||
PruneUnstartedTxQueue(queueSize uint32, subject uuid.UUID, queryTimeout time.Duration) (n int64, err error) |
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.
This should also take ctx, which is coming from the external caller.
} | ||
|
||
// Only to be used directly for atomic transactions internal to the tx store | ||
func (o *evmTxStore) PreloadTxesAtomic(attempts []TxAttempt, qopts ...pg.QOpt) error { |
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.
If this is internal, please rename to preloadTxesAtomic. No need to export this function
I see so I should be using both the context that's passed and the one created during TxStore's initialization. @jmank88 would you have any examples where we have the design pattern to chain multiple contexts? |
Normally contexts are not meant to be stored, and they should only branch, never merge. However, if we are stuck with legacy code, then we can use a new 1.21 feature context.AfterFunc to have one cancel the other. |
551032d
to
e609551
Compare
e609551
to
550c21c
Compare
core/services/vrf/v2/listener_v2.go
Outdated
@@ -917,7 +917,7 @@ func (lsn *listenerV2) enqueueForceFulfillment( | |||
requestID := common.BytesToHash(p.req.req.RequestID().Bytes()) | |||
subID := p.req.req.SubID() | |||
requestTxHash := p.req.req.Raw().TxHash | |||
etx, err = lsn.txm.CreateTransaction(txmgr.TxRequest{ | |||
etx, err = lsn.txm.CreateTransaction(context.TODO(), txmgr.TxRequest{ |
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.
This doesn't seem quite right. If this context is actually used we should probably pass in a non-test object.
e1151fa
to
5dc32ed
Compare
29c5398
to
fe3f8c6
Compare
common/txmgr/types/tx_store.go
Outdated
SaveConfirmedMissingReceiptAttempt(ctx context.Context, timeout time.Duration, attempt *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], broadcastAt time.Time) error | ||
SaveInProgressAttempt(attempt *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error | ||
SaveInsufficientFundsAttempt(timeout time.Duration, attempt *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], broadcastAt time.Time) error | ||
SaveReplacementInProgressAttempt(oldAttempt TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], replacementAttempt *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], qopts ...pg.QOpt) error | ||
SaveReplacementInProgressAttempt(oldAttempt TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], replacementAttempt *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) error | ||
SaveSentAttempt(timeout time.Duration, attempt *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], broadcastAt time.Time) error | ||
SetBroadcastBeforeBlockNum(blockNum int64, chainID CHAIN_ID) error |
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.
This one too originates from ec.ProcessHead(), where we get an external context.
I guess there are more such functions from the above.
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.
I ended up leaving the methods that weren't passed a context upstream through pg.Opts alone but I can wire them up as well
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.
I've added a context parameter to the rest of the TxStore methods and wired them up to contexts upstream except for UpdateTxAttemptInProgressToBroadcast
which will be handled in this PR
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 to me, except the few places in TxStore interface that still are missing ctx, and are called from upstream callers.
32c5e45
to
96e95c8
Compare
96e95c8
to
cb164f6
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.
VRF+BHS changes LGTM
SonarQube Quality Gate |
BCI-1585
pg.Opts
from TxStore methods