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

Decouple job pipeline tables from the TXM DB #11173

Merged
merged 3 commits into from
Nov 13, 2023
Merged

Conversation

amit-momin
Copy link
Contributor

  • Added SignalCallback boolean flag to the TxRequest and the corresponding signal_callback column to the evm.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.
  • Added a callback_completed column to the evm.txes table to indicate if the callback for the tx has been called.
  • Added method to the TxStore to mark the callback_completed flag as true
  • Updated the method name FindReceiptsPendingConfirmation to FindTxesPendingCallback to better describe the functionality
  • Updated the query in the FindTxesPendingCallback method by replacing the pipeline_runs.state='suspended' condition with signal_callback=true AND callback_completed=false and removed the joins to the pipeline_runs table.
  • Updated the ResumePendingTaskRuns method in the Confirmer to set the callback_completed flag to true after the callback has been called without error.

Copy link
Contributor

github-actions bot commented Nov 3, 2023

I see that you haven't updated any README files. Would it make sense to do so?

@amit-momin amit-momin force-pushed the txm/BCI-1551 branch 3 times, most recently from f37555c to f002bb9 Compare November 3, 2023 22:51
@amit-momin amit-momin marked this pull request as ready for review November 9, 2023 17:52
@amit-momin amit-momin force-pushed the txm/BCI-1551 branch 2 times, most recently from 6de1f5e to f34aa6c Compare November 9, 2023 18:33
Comment on lines 1108 to 1112
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)
Copy link
Contributor

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.

Suggested change
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)

Copy link
Contributor Author

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.

Copy link
Contributor

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).

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

jmank88
jmank88 previously approved these changes Nov 10, 2023
Copy link
Contributor

@prashantkumar1982 prashantkumar1982 left a comment

Choose a reason for hiding this comment

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

Looks pretty good!

@@ -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
Copy link
Contributor

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) {
Copy link
Contributor

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.

@cl-sonarqube-production
Copy link

@prashantkumar1982 prashantkumar1982 added this pull request to the merge queue Nov 13, 2023
Merged via the queue into develop with commit aa02231 Nov 13, 2023
88 checks passed
@prashantkumar1982 prashantkumar1982 deleted the txm/BCI-1551 branch November 13, 2023 20:30
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