firefly
firefly copied to clipboard
Refactor Idempotency logic to reduce boilerplate and increase code readability
See detailed discussion in https://github.com/hyperledger/firefly/pull/1406
Suggested work
- [ ] Combine
txHelperutility intooperationsmanager- Transactions are really grouping constructs of operations, and tracking the events for async completion
- There is weirdness that the
operationshelpers do not have direct access to theidempotencyKey - There is a lot of boilerplate in other packages, joining together
txHandlerandoperationsfunctions
- [ ] Merge the
SubmitNewTransactionandResubmitOperationsfunctions. Return options are:- There is no idempotency key, here's a shiny new TX
- We've never stored a TX for this idempotency key, here's a shiny new TX
- TX already existed for idempotency key all done now - please return without error to the user
- TX was stored, but no operations were stored - here's the existing transaction ID
- All operations in the TX already reached
Pending(or later), 409 to your user - Something else went wrong
- [ ] (Separable) Update idempotency input handling to reject re-submit with different inputs
- Scenario:
- Submit with
input1andidem1, and get to a point ofInitializedoperations - Encounter failure that is not handled via internal retry and returns an error to you
- Re-submit the API call, but this time with
input2andidem1 - Internally FF Core already stored the operations, so re-submits them with
input1(notinput2) - Transaction completes with
input1- we ignored theinput2you provided
- Submit with
- Improved behavior:
- Return an error stating that
input2is not the same asinput1 - Requires per-input handling to detect the operation inputs are the same or not
- Return an error stating that
- Scenario:
@peterbroadhurst
All operations in the TX already reached Pending (or later), 409 to your user
Should this be true for operation requests that have identical payload with what's recorded for a given idempotency key?