-
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
Decouple job pipeline tables from the TXM DB #11173
Conversation
I see that you haven't updated any README files. Would it make sense to do so? |
f37555c
to
f002bb9
Compare
f002bb9
to
0e927ab
Compare
6de1f5e
to
f34aa6c
Compare
common/txmgr/confirmer.go
Outdated
return fmt.Errorf("ResumePendingTaskRuns failed: %w", err) | ||
} | ||
// Mark tx as having completed callback | ||
if err := ec.txStore.UpdateTxCallbackCompleted(ctx, data.ID, ec.chainID); err != nil { | ||
return fmt.Errorf("ResumePendingTaskRuns failed: %w", err) |
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 don't we add some context about the particular calls that failed? The caller of ResumePendingTaskRuns
already knows the method failed generally based on the error returned.
return fmt.Errorf("ResumePendingTaskRuns failed: %w", err) | |
} | |
// Mark tx as having completed callback | |
if err := ec.txStore.UpdateTxCallbackCompleted(ctx, data.ID, ec.chainID); err != nil { | |
return fmt.Errorf("ResumePendingTaskRuns failed: %w", err) | |
return fmt.Errorf("failed to resume calback: %w", err) | |
} | |
// Mark tx as having completed callback | |
if err := ec.txStore.UpdateTxCallbackCompleted(ctx, data.ID, ec.chainID); err != nil { | |
return fmt.Errorf("failed to update callback complete: %w", err) |
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 is wrapping an error from a more inner function, I'm worried I might repeat the same error message. I was under the impression we had this pattern to wrap the error with the function name to create a sort of error stack when this bubbles up to the top.
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.
We are trying to create a stack, but it should be human readable and differentiate between the cases. IMHO including function names in any way is an anti-pattern. We should prefer to add context that the caller cannot already infer themselves (they already know they called ResumePendingTaskRuns
), and we should also prefer not to encode implementation details inside of human facing errors (when someone refactors ResumePendingTaskRuns
, they have to notice all of these strings and update them).
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.
Ok think I agree we shouldn't use function names explicitly. But I feel the only context I should include here is something like resuming pending task runs failed
since the more specific context would be taken care of the underlying error since we're just passing it up here.
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 don't think that message adds any value for calling code which is already well aware of what func was called. What the calling code doesn't know is which of these particular steps failed.
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 might be unnecessarily worrying about redundancy in the error message. I was thinking the calling code would know the step it failed on based on the error returned by the inner method. Like if the UpdateTxCallbackCompleted
method returned a wrapped error with a message such as failed to update callback complete
, it would just duplicate the message if I wrapped the error with a similar message in ResumePendingTaskRuns
. But I guess there could be any number of specific errors underneath so this is alright. Sorry for the back and forth on something that's so simple
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 we are calling something that returns a message that we don't have anything to add to, then it is OK to return the error raw. 🤷
Sorry for the back and forth on something that's so simple
No problem. It seems simpler than it is and there are definitely edge cases.
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.
Good point. I've updated errors to include more context and returning them raw where there isn't any more to add.
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 pretty good!
common/txmgr/types/tx_store.go
Outdated
@@ -35,8 +35,10 @@ type TxStore[ | |||
TxHistoryReaper[CHAIN_ID] | |||
TransactionStore[ADDR, CHAIN_ID, TX_HASH, BLOCK_HASH, SEQ, FEE] | |||
|
|||
// methods for saving & retreiving receipts | |||
FindReceiptsPendingConfirmation(ctx context.Context, blockNum int64, chainID CHAIN_ID) (receiptsPlus []ReceiptPlus[R], err error) | |||
// Find confirmed txes requiring callback but have not yet been signaled |
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.
nit: mention that these are confirrmed, beyond the minConfirmations param. Indicates that these are kind of finalized.
@@ -941,25 +949,40 @@ WHERE evm.tx_attempts.state = 'in_progress' AND evm.txes.from_address = $1 AND e | |||
return attempts, pkgerrors.Wrap(err, "getInProgressEthTxAttempts failed") | |||
} | |||
|
|||
func (o *evmTxStore) FindReceiptsPendingConfirmation(ctx context.Context, blockNum int64, chainID *big.Int) (receiptsPlus []ReceiptPlus, err error) { | |||
// Find confirmed txes requiring callback but have not yet been signaled | |||
func (o *evmTxStore) FindTxesPendingCallback(ctx context.Context, blockNum int64, chainID *big.Int) (receiptsPlus []ReceiptPlus, 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.
Thanks for renaming this fn!
The old name was just soo misleading.
c6fb7d8
to
a8b519c
Compare
SonarQube Quality Gate |
SignalCallback
boolean flag to the TxRequest and the correspondingsignal_callback
column to theevm.txes
table to allow the caller (job pipeline service) to signify it wants the pipeline resume callback to be called when the tx is finalized.callback_completed
column to theevm.txes
table to indicate if the callback for the tx has been called.callback_completed
flag as trueFindReceiptsPendingConfirmation
toFindTxesPendingCallback
to better describe the functionalityFindTxesPendingCallback
method by replacing thepipeline_runs.state='suspended'
condition withsignal_callback=true AND callback_completed=false
and removed the joins to thepipeline_runs
table.ResumePendingTaskRuns
method in the Confirmer to set thecallback_completed
flag to true after the callback has been called without error.