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

feat(mojaloop/#3904): add position event fx timeout reserved batch handling #1035

Merged
merged 46 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9dbea6d
chore: add integration test for batch
kleyow May 14, 2024
051b576
unit
kleyow May 14, 2024
586c811
reenable
kleyow May 14, 2024
5a8dd49
chore: comments
kleyow May 14, 2024
0804d48
feat: added timeout handler implementation
vijayg10 May 15, 2024
bd49e71
test
kleyow May 16, 2024
6357690
cleanup function
kleyow May 16, 2024
d52bc95
Merge branch 'feat/#3904' into feat/fx-#3904
kleyow May 17, 2024
c8dffcd
test
kleyow May 17, 2024
b63b6ca
remove
kleyow May 17, 2024
8d45a09
Merge branch 'feat/#3904' into feat/fx-#3904
kleyow May 17, 2024
ea1a573
reorder
kleyow May 17, 2024
6c4b737
fix potential int test failures
kleyow May 17, 2024
3ecddc5
fix tests
kleyow May 17, 2024
943e4bd
fix: queries
vijayg10 May 17, 2024
5ecd62c
unit tests
kleyow May 17, 2024
3e26986
unskip
kleyow May 17, 2024
ff2a93f
fix potential int test failures
kleyow May 17, 2024
475d28c
Merge branch 'feat/#3904' into feat/fx-#3904
kleyow May 17, 2024
60fe43a
reorder
kleyow May 17, 2024
50be25c
fix replace
kleyow May 17, 2024
425e052
Merge branch 'feat/#3904' into feat/fx-#3904
kleyow May 17, 2024
6cb4d6d
unit tests
kleyow May 17, 2024
7d941a9
Merge remote-tracking branch 'origin/feat/fx-impl' into feat/fx-#3904
kleyow May 17, 2024
d9042f1
fix: int tests
vijayg10 May 20, 2024
b1ec526
fix: issues
vijayg10 May 22, 2024
9dee638
Merge branch feat/fx-impl of https://github.com/mojaloop/central-ledg…
vijayg10 May 22, 2024
7575fca
fix: fx timeout
vijayg10 May 23, 2024
7232df3
chore: update central services shared
vijayg10 May 24, 2024
b3c9322
fix: cicd
vijayg10 May 24, 2024
1ec3662
fix: deps
vijayg10 May 24, 2024
6aff518
fix: lint
vijayg10 May 24, 2024
5edbe94
fix: unit tests
vijayg10 May 24, 2024
659dca2
chore: added unit tests
vijayg10 May 24, 2024
d7e6163
chore: added unit tests
vijayg10 May 27, 2024
6a3ff71
Merge remote-tracking branch 'origin/feat/3902-impl-timeout-handler' …
kleyow May 27, 2024
d78b51d
pull,audit,dep
kleyow May 27, 2024
8b952e4
Merge remote-tracking branch 'origin/feat/fx-impl' into feat/fx-#3904
kleyow May 28, 2024
fc88891
update tests
kleyow May 28, 2024
b1cb0e3
Merge remote-tracking branch 'origin/feat/fx-impl' into feat/fx-#3904
kleyow May 28, 2024
9158406
Merge branch 'feat/fx-impl' into feat/fx-#3904
kleyow May 28, 2024
e630a27
update position query logic
kleyow May 29, 2024
2112f87
Merge remote-tracking branch 'origin/feat/fx-#3904' into feat/fx-#3904
kleyow May 29, 2024
95c6f00
rename
kleyow May 30, 2024
8923c43
add comment
kleyow May 31, 2024
834b3ce
detail
kleyow May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 23 additions & 72 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"@mojaloop/central-services-health": "15.0.0",
"@mojaloop/central-services-logger": "11.3.1",
"@mojaloop/central-services-metrics": "12.0.8",
"@mojaloop/central-services-shared": "18.4.0-snapshot.16",
"@mojaloop/central-services-shared": "18.4.0-snapshot.17",
"@mojaloop/central-services-stream": "11.3.0",
"@mojaloop/database-lib": "11.0.5",
"@mojaloop/event-sdk": "14.1.0",
Expand Down Expand Up @@ -139,7 +139,7 @@
"get-port": "5.1.1",
"jsdoc": "4.0.3",
"jsonpath": "1.1.1",
"nodemon": "3.1.1",
"nodemon": "3.1.2",
"npm-check-updates": "16.14.20",
"nyc": "15.1.0",
"pre-commit": "1.2.2",
Expand Down
40 changes: 36 additions & 4 deletions src/domain/position/binProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const PositionFxPrepareDomain = require('./fx-prepare')
const PositionFulfilDomain = require('./fulfil')
const PositionFxFulfilDomain = require('./fx-fulfil')
const PositionTimeoutReservedDomain = require('./timeout-reserved')
const PositionFxTimeoutReservedDomain = require('./fx-timeout-reserved')
const SettlementModelCached = require('../../models/settlement/settlementModelCached')
const Enum = require('@mojaloop/central-services-shared').Enum
const ErrorHandler = require('@mojaloop/central-services-error-handling')
Expand Down Expand Up @@ -88,6 +89,15 @@ const processBins = async (bins, trx) => {
Enum.Accounts.LedgerEntryType.PRINCIPLE_VALUE
)

// Fetch all RESERVED participantPositionChanges associated with a commitRequestId
// These will contain the value that was reserved for the fxTransfer
// We will use these values to revert the position on timeouts
const fetchedReservedPositionChangesByCommitRequestIds =
await BatchPositionModel.getReservedPositionChangesByCommitRequestIds(
trx,
commitRequestIdList
)
vijayg10 marked this conversation as resolved.
Show resolved Hide resolved

// Pre fetch transfers for all reserve action fulfils
const reservedActionTransfers = await BatchPositionModel.getTransferByIdsForReserve(
trx,
Expand All @@ -106,15 +116,17 @@ const processBins = async (bins, trx) => {
array2.every((element) => array1.includes(element))
// If non-prepare/non-commit action found, log error
// We need to remove this once we implement all the actions
if (!isSubset([
const allowedActions = [
Enum.Events.Event.Action.PREPARE,
Enum.Events.Event.Action.FX_PREPARE,
Enum.Events.Event.Action.COMMIT,
Enum.Events.Event.Action.RESERVE,
Enum.Events.Event.Action.FX_RESERVE,
Enum.Events.Event.Action.TIMEOUT_RESERVED
], actions)) {
Logger.isErrorEnabled && Logger.error('Only prepare/fx-prepare/commit/reserve/timeout reserved actions are allowed in a batch')
Enum.Events.Event.Action.TIMEOUT_RESERVED,
Enum.Events.Event.Action.FX_TIMEOUT_RESERVED
]
if (!isSubset(allowedActions, actions)) {
Logger.isErrorEnabled && Logger.error(`Only ${allowedActions.join()} are allowed in a batch`)
}

const settlementParticipantPosition = positions[accountIdMap[accountID].settlementCurrencyId].value
Expand Down Expand Up @@ -144,6 +156,24 @@ const processBins = async (bins, trx) => {
accumulatedFxTransferStates
)

// If fx-timeout-reserved action found then call processPositionTimeoutReserveBin function
const fxTimeoutReservedActionResult = await PositionFxTimeoutReservedDomain.processPositionFxTimeoutReservedBin(
accountBin[Enum.Events.Event.Action.FX_TIMEOUT_RESERVED],
accumulatedPositionValue,
accumulatedPositionReservedValue,
accumulatedFxTransferStates,
fetchedReservedPositionChangesByCommitRequestIds
)

// Update accumulated values
accumulatedPositionValue = fxTimeoutReservedActionResult.accumulatedPositionValue
accumulatedPositionReservedValue = fxTimeoutReservedActionResult.accumulatedPositionReservedValue
accumulatedFxTransferStates = fxTimeoutReservedActionResult.accumulatedFxTransferStates
// Append accumulated arrays
accumulatedFxTransferStateChanges = accumulatedFxTransferStateChanges.concat(fxTimeoutReservedActionResult.accumulatedFxTransferStateChanges)
accumulatedPositionChanges = accumulatedPositionChanges.concat(fxTimeoutReservedActionResult.accumulatedPositionChanges)
notifyMessages = notifyMessages.concat(fxTimeoutReservedActionResult.notifyMessages)

// Update accumulated values
accumulatedFxTransferStates = fxFulfilActionResult.accumulatedFxTransferStates
// Append accumulated arrays
Expand Down Expand Up @@ -331,6 +361,8 @@ const _getTransferIdList = async (bins) => {
commitRequestIdList.push(item.decodedPayload.commitRequestId)
} else if (action === Enum.Events.Event.Action.FX_RESERVE) {
commitRequestIdList.push(item.message.value.content.uriParams.id)
} else if (action === Enum.Events.Event.Action.FX_TIMEOUT_RESERVED) {
commitRequestIdList.push(item.message.value.content.uriParams.id)
}
})
return { transferIdList, reservedActionTransferIdList, commitRequestIdList }
Expand Down
Loading