Skip to content

Commit

Permalink
feat(settlements): feature#2234 add default settlements (#324)
Browse files Browse the repository at this point in the history
Changes:

* Added CGS and Rules functionality flows into settlements
* Added default settlement model
  • Loading branch information
vgenev authored Aug 6, 2021
1 parent 9c2611e commit 8ca072f
Show file tree
Hide file tree
Showing 30 changed files with 5,125 additions and 2,440 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,4 @@ workflows:
only: /v[0-9]+(\.[0-9]+)*/
branches:
ignore:
- /.*/
- /.*/
8 changes: 4 additions & 4 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@
* [GET All Participants Positions](mojaloop-technical-overview/central-ledger/admin-operations/4.2.0-get-positions-of-all-participants.md)
* [Transfer Operations](mojaloop-technical-overview/central-ledger/transfers/README.md)
* [Prepare Handler](mojaloop-technical-overview/central-ledger/transfers/1.1.0-prepare-transfer-request.md)
* [Prepare Handler Consume (a)](mojaloop-technical-overview/central-ledger/transfers/1.1.1.a-prepare-handler-consume.md)
* [Prepare Handler Consume (b)](mojaloop-technical-overview/central-ledger/transfers/1.1.1.b-prepare-handler-consume.md)
* [Prepare Handler Consume](mojaloop-technical-overview/central-ledger/transfers/1.1.1.a-prepare-handler-consume.md)
* [Prepare Position Handler](mojaloop-technical-overview/central-ledger/transfers/1.3.0-position-handler-consume.md)
* [Prepare Position Handler v1.1](mojaloop-technical-overview/central-ledger/transfers/1.3.0-position-handler-consume-v1.1.md)
* [Prepare Position Handler](mojaloop-technical-overview/central-ledger/transfers/1.3.1-prepare-position-handler-consume.md)
* [Position Handler Consume (a)](mojaloop-technical-overview/central-ledger/transfers/1.1.2.a-position-handler-consume.md)
* [Position Handler Consume (b)](mojaloop-technical-overview/central-ledger/transfers/1.1.2.b-position-handler-consume.md)
* [Position Handler Consume](mojaloop-technical-overview/central-ledger/transfers/1.1.2.a-position-handler-consume.md)
* [Fulfil Handler](mojaloop-technical-overview/central-ledger/transfers/2.1.0-fulfil-transfer-request.md)
* [Fulfil Handler v1.1](mojaloop-technical-overview/central-ledger/transfers/2.1.0-fulfil-transfer-request-v1.1.md)
* [Fulfil Handler Consume](mojaloop-technical-overview/central-ledger/transfers/2.1.1-fulfil-handler-consume.md)
Expand Down Expand Up @@ -123,6 +121,8 @@
* [Settlement Abort](mojaloop-technical-overview/central-settlements/settlement-process/put-settlement-abort.md)
* [Request Settlement By SPA](mojaloop-technical-overview/central-settlements/settlement-process/get-settlement-by-spa.md)
* [Request Settlements By Params](mojaloop-technical-overview/central-settlements/settlement-process/get-settlements-by-params.md)
* [Gross Settlement Handler](mojaloop-technical-overview/central-settlements/settlement-process/gross-settlement-handler-consume.md)
* [Rules Handler](mojaloop-technical-overview/central-settlements/settlement-process/rules-handler-consume.md)
* [Funds In/Out](mojaloop-technical-overview/central-settlements/funds-in-out/README.md)
* [Reconciliation Transfer Prepare](mojaloop-technical-overview/central-settlements/funds-in-out/reconciliation-transfer-prepare.md)
* [Transfer State and Position Change](mojaloop-technical-overview/central-settlements/funds-in-out/transfer-state-and-position-change.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# How to EDIT the central-ledger-schema-DBeaver.erd file

This is a basic guide on how to successfully view/update the central-ledger-schema-DBeaver.erd file.

## Prerequisites
* Download and install the DBeaver Community DB Manager
* The Mojaloop Central-Ledger MySQL Database needs to be up and running, and connectable by the DBeaver
* You'll also need a text editor
## Steps to follow
* Create a new db connection in DBeaver under Database Navigator tab for the MySQL instance running.
* Under the Projects tab right click and create a New ER Diagram.
* Give the diagram a name and select central-ledger db in the wizard.

* Copy the `central-ledger-schema-DBeaver.erd` file from the documentation module to `DBeaverData/workspace/General/Diagrams` in your DBeaver storage location
* Navigate to the newly created erd file using a text editor, search for `data-source id` and copy its value which looks like `mysql5-171ea991174-1218b6e1bf273693`.
* Navigate with a text editor to the `central-ledger-schema-DBeaver.erd` file in the ER Diagrams directory and replace its `data-source id` value with the one copied from the newly created erd file.
* The `central-ledger-schema-DBeaver.erd` should now show the tables as per the `central-ledger-schema.png`

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ group Prepare Position Handler Consume
**reservedPosition** = participantPosition.{original}reservedValue
**effectivePosition** = currentPosition + reservedPosition
**heldPosition** = effectivePosition + sumTransfersInBatch
**availablePosition** = participantLimit(NetDebitCap) - effectivePosition
**availablePosition** = //if settlement model delay is IMMEDIATE then:// settlementBalance + participantLimit(NetDebitCap) - effectivePosition, //otherwise:// participantLimit(NetDebitCap) - effectivePosition
**sumReserved** = SUM of transfers that have met rule criteria and processed
end note
note over POS_MGMT,DB
Going to reserve the sum of the valid transfers in the batch against the Participants Positon in the Currency of this batch
and calculate the available position for the Participant to use
end note
POS_MGMT -> DB: Select effectivePosition FOR UPDATE from DB for Payer
POS_MGMT -> DB: Select effectivePosition FOR UPDATE from DB for Payer
activate DB
hnote over DB #lightyellow
participantPosition
Expand All @@ -108,8 +108,8 @@ group Prepare Position Handler Consume
end note
deactivate DB
' DB Trans: This is where 1st DB Transaction would end in 2 DB transacation future model for horizontal scaling


POS_MGMT -> DB: Request position limits for Payer Participant
activate DB
hnote over DB #lightyellow
Expand All @@ -120,14 +120,14 @@ group Prepare Position Handler Consume
end note
DB --> POS_MGMT: Return position limits
deactivate DB
POS_MGMT <-> POS_MGMT: **availablePosition** = participantLimit(netDebitCap) - effectivePosition (same as = netDebitCap - currentPosition - reservedPosition)
POS_MGMT <-> POS_MGMT: **availablePosition** = //if settlement model delay is IMMEDIATE then://\n settlementBalance + participantLimit(NetDebitCap) - effectivePosition\n //otherwise://\n participantLimit(NetDebitCap) - effectivePosition\n(same as = (settlementBalance?) + netDebitCap - currentPosition - reservedPosition)
note over POS_MGMT,DB
For each transfer in the batch, validate the availablility of position to meet the transfer amount
this will be as per the position algorithm documented below
end note
POS_MGMT <-> POS_MGMT: Validate availablePosition for each tranfser (see algorithm below)\n<color #FF0000><b>Error code:</b> 4001</color>
note right of POS_MGMT #lightgray
01: sumReserved = 0 // Record the sum of the transfers we allow to progress to RESERVED
01: sumReserved = 0 // Record the sum of the transfers we allow to progress to RESERVED
02: sumProcessed =0 // Record the sum of the transfers already processed in this batch
03: processedTransfers = {} // The list of processed transfers - so that we can store the additional information around the decision. Most importantly the "running" position
04: foreach transfer in reservedTransfers
Expand All @@ -151,7 +151,7 @@ group Prepare Position Handler Consume
Do a bulk insert of the trasnferStateChanges associated with processing, using the result to complete the participantPositionChange and bulk insert of these to persist the running position
end note
POS_MGMT->POS_MGMT: Assess any limit thresholds on the final position\nadding to alarm list if triggered

' DB Trans: This is where 2nd DB Transaction would start in 2 DB transacation future model for horizontal scaling
POS_MGMT->DB: Persist latest position **value** and **reservedValue** to DB for Payer
hnote over DB #lightyellow
Expand All @@ -167,23 +167,23 @@ group Prepare Position Handler Consume
batch INSERT **transferStateChange**
select for update from transfer table where transferId in ([transferBatch.transferId,...])
build list of transferStateChanges from transferBatch

end note
activate DB
deactivate DB

POS_MGMT->POS_MGMT: Populate batchParticipantPositionChange from the resultant transferStateChange and the earlier processedTransfer list

note right of POS_MGMT #lightgray
Effectively:
Effectively:
SET transferStateChangeId = processedTransfer.transferStateChangeId,
participantPositionId = preparedTransfer.participantPositionId,
value = preparedTransfer.positionValue,
reservedValue = preparedTransfer.positionReservedValue
end note
POS_MGMT -> DB: Bulk persist the participant position change for all processedTransfers
hnote over DB #lightyellow
batch INSERT **participantPositionChange**
batch INSERT **participantPositionChange**
end note
activate DB
deactivate DB
Expand Down
Loading

0 comments on commit 8ca072f

Please sign in to comment.