diff --git a/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-ddl-MySQLWorkbench.sql b/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-ddl-MySQLWorkbench.sql index 8e2d4903d..280962173 100644 --- a/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-ddl-MySQLWorkbench.sql +++ b/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-ddl-MySQLWorkbench.sql @@ -415,7 +415,7 @@ CREATE TABLE `migration` ( `batch` int(11) DEFAULT NULL, `migration_time` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=155 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=157 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -448,7 +448,7 @@ CREATE TABLE `participant` ( `createdBy` varchar(128) NOT NULL, PRIMARY KEY (`participantId`), UNIQUE KEY `participant_name_unique` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -498,7 +498,7 @@ CREATE TABLE `participantCurrency` ( CONSTRAINT `participantcurrency_currencyid_foreign` FOREIGN KEY (`currencyId`) REFERENCES `currency` (`currencyid`), CONSTRAINT `participantcurrency_ledgeraccounttypeid_foreign` FOREIGN KEY (`ledgerAccountTypeId`) REFERENCES `ledgerAccountType` (`ledgeraccounttypeid`), CONSTRAINT `participantcurrency_participantid_foreign` FOREIGN KEY (`participantId`) REFERENCES `participant` (`participantid`) -) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -521,7 +521,7 @@ CREATE TABLE `participantEndpoint` ( KEY `participantendpoint_endpointtypeid_index` (`endpointTypeId`), CONSTRAINT `participantendpoint_endpointtypeid_foreign` FOREIGN KEY (`endpointTypeId`) REFERENCES `endpointType` (`endpointtypeid`), CONSTRAINT `participantendpoint_participantid_foreign` FOREIGN KEY (`participantId`) REFERENCES `participant` (`participantid`) -) ENGINE=InnoDB AUTO_INCREMENT=120 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -548,7 +548,7 @@ CREATE TABLE `participantLimit` ( CONSTRAINT `participantlimit_participantcurrencyid_foreign` FOREIGN KEY (`participantCurrencyId`) REFERENCES `participantCurrency` (`participantcurrencyid`), CONSTRAINT `participantlimit_participantlimittypeid_foreign` FOREIGN KEY (`participantLimitTypeId`) REFERENCES `participantLimitType` (`participantlimittypeid`), CONSTRAINT `participantlimit_startafterparticipantpositionchangeid_foreign` FOREIGN KEY (`startAfterParticipantPositionChangeId`) REFERENCES `participantPositionChange` (`participantpositionchangeid`) -) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -603,7 +603,7 @@ CREATE TABLE `participantPosition` ( PRIMARY KEY (`participantPositionId`), KEY `participantposition_participantcurrencyid_index` (`participantCurrencyId`), CONSTRAINT `participantposition_participantcurrencyid_foreign` FOREIGN KEY (`participantCurrencyId`) REFERENCES `participantCurrency` (`participantcurrencyid`) -) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -625,7 +625,7 @@ CREATE TABLE `participantPositionChange` ( KEY `participantpositionchange_transferstatechangeid_index` (`transferStateChangeId`), CONSTRAINT `participantpositionchange_participantpositionid_foreign` FOREIGN KEY (`participantPositionId`) REFERENCES `participantPosition` (`participantpositionid`), CONSTRAINT `participantpositionchange_transferstatechangeid_foreign` FOREIGN KEY (`transferStateChangeId`) REFERENCES `transferStateChange` (`transferstatechangeid`) -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -991,7 +991,7 @@ CREATE TABLE `segment` ( `changedDate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`segmentId`), KEY `segment_keys_index` (`segmentType`,`enumeration`,`tableName`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -1119,6 +1119,7 @@ CREATE TABLE `settlementModel` ( `currencyId` varchar(3) DEFAULT NULL, `requireLiquidityCheck` tinyint(1) NOT NULL DEFAULT '1', `ledgerAccountTypeId` int(10) unsigned NOT NULL, + `autoPositionReset` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`settlementModelId`), UNIQUE KEY `settlementmodel_name_unique` (`name`), KEY `settlementmodel_settlementgranularityid_index` (`settlementGranularityId`), @@ -1570,7 +1571,7 @@ CREATE TABLE `transferExtension` ( PRIMARY KEY (`transferExtensionId`), KEY `transferextension_transferid_foreign` (`transferId`), CONSTRAINT `transferextension_transferid_foreign` FOREIGN KEY (`transferId`) REFERENCES `transfer` (`transferid`) -) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -1625,16 +1626,19 @@ CREATE TABLE `transferParticipant` ( `ledgerEntryTypeId` int(10) unsigned NOT NULL, `amount` decimal(18,4) NOT NULL, `createdDate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `currentStateChangeId` bigint(20) unsigned DEFAULT NULL, PRIMARY KEY (`transferParticipantId`), KEY `transferparticipant_transferid_index` (`transferId`), KEY `transferparticipant_participantcurrencyid_index` (`participantCurrencyId`), KEY `transferparticipant_transferparticipantroletypeid_index` (`transferParticipantRoleTypeId`), KEY `transferparticipant_ledgerentrytypeid_index` (`ledgerEntryTypeId`), + KEY `transferparticipant_currentstatechangeid_foreign` (`currentStateChangeId`), + CONSTRAINT `transferparticipant_currentstatechangeid_foreign` FOREIGN KEY (`currentStateChangeId`) REFERENCES `transferParticipantStateChange` (`transferparticipantstatechangeid`), CONSTRAINT `transferparticipant_ledgerentrytypeid_foreign` FOREIGN KEY (`ledgerEntryTypeId`) REFERENCES `ledgerEntryType` (`ledgerentrytypeid`), CONSTRAINT `transferparticipant_participantcurrencyid_foreign` FOREIGN KEY (`participantCurrencyId`) REFERENCES `participantCurrency` (`participantcurrencyid`), CONSTRAINT `transferparticipant_transferid_foreign` FOREIGN KEY (`transferId`) REFERENCES `transfer` (`transferid`), CONSTRAINT `transferparticipant_transferparticipantroletypeid_foreign` FOREIGN KEY (`transferParticipantRoleTypeId`) REFERENCES `transferParticipantRoleType` (`transferparticipantroletypeid`) -) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -1655,6 +1659,27 @@ CREATE TABLE `transferParticipantRoleType` ( ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `transferParticipantStateChange` +-- + +DROP TABLE IF EXISTS `transferParticipantStateChange`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `transferParticipantStateChange` ( + `transferParticipantStateChangeId` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `transferParticipantId` bigint(20) unsigned NOT NULL, + `settlementWindowStateId` varchar(50) NOT NULL, + `reason` varchar(512) DEFAULT NULL, + `createdDate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`transferParticipantStateChangeId`), + KEY `transferparticipantstatechange_transferparticipantid_index` (`transferParticipantId`), + KEY `transferparticipantstatechange_settlementwindowstateid_index` (`settlementWindowStateId`), + CONSTRAINT `transferparticipantstatechange_settlementwindowstateid_foreign` FOREIGN KEY (`settlementWindowStateId`) REFERENCES `settlementWindowState` (`settlementwindowstateid`), + CONSTRAINT `transferparticipantstatechange_transferparticipantid_foreign` FOREIGN KEY (`transferParticipantId`) REFERENCES `transferParticipant` (`transferparticipantid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `transferRules` -- @@ -1708,7 +1733,7 @@ CREATE TABLE `transferStateChange` ( KEY `transferstatechange_transferstateid_index` (`transferStateId`), CONSTRAINT `transferstatechange_transferid_foreign` FOREIGN KEY (`transferId`) REFERENCES `transfer` (`transferid`), CONSTRAINT `transferstatechange_transferstateid_foreign` FOREIGN KEY (`transferStateId`) REFERENCES `transferState` (`transferstateid`) -) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -1726,7 +1751,7 @@ CREATE TABLE `transferTimeout` ( PRIMARY KEY (`transferTimeoutId`), UNIQUE KEY `transfertimeout_transferid_unique` (`transferId`), CONSTRAINT `transfertimeout_transferid_foreign` FOREIGN KEY (`transferId`) REFERENCES `transfer` (`transferid`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -1792,4 +1817,4 @@ CREATE TABLE `transferTimeout` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2020-01-23 19:33:54 +-- Dump completed on 2020-02-20 22:51:43 diff --git a/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-schema-DBeaver.erd b/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-schema-DBeaver.erd index b9548bc9b..dc18f82f2 100644 --- a/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-schema-DBeaver.erd +++ b/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-schema-DBeaver.erd @@ -1,5 +1,5 @@ - + @@ -35,10 +35,10 @@ - + - + @@ -47,7 +47,7 @@ - + @@ -59,7 +59,7 @@ - + @@ -104,10 +104,10 @@ - + - + @@ -128,7 +128,7 @@ - + @@ -146,6 +146,9 @@ + + + @@ -169,12 +172,14 @@ + + @@ -194,7 +199,8 @@ - + + @@ -212,6 +218,7 @@ + COLOR LEGEND: diff --git a/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-schema.png b/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-schema.png index 8ad147141..6ae8e2e18 100644 Binary files a/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-schema.png and b/mojaloop-technical-overview/central-ledger/assets/database/central-ledger-schema.png differ diff --git a/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.0.plantuml b/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.0.plantuml index 03bfc515c..08c71eb9f 100644 --- a/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.0.plantuml +++ b/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.0.plantuml @@ -41,11 +41,13 @@ actor "DFSP2\nPayee" as DFSP2 boundary "ML API Adapter" as MLAPI control "ML API Notification Event Handler" as NOTIFY_HANDLER boundary "Central Service API" as CSAPI -collections "Fulfil-Topic" as TOPIC_FULFIL +collections "topic-fulfil" as TOPIC_FULFIL control "Fulfil Event Handler" as FULF_HANDLER -collections "topic-transfer-position" as TOPIC_TRANSFER_POSITION -control "Position Event Handler" as POS_HANDLER -collections "Notification-Topic" as TOPIC_NOTIFICATIONS +collections "topic-\nsettlement-model" as TOPIC_SETMODEL +control "Settlement Model\nHandler" as SETMODEL_HANDLER +collections "topic-\ntransfer-position" as TOPIC_TRANSFER_POSITION +control "Position Handler" as POS_HANDLER +collections "topic-\nnotification" as TOPIC_NOTIFICATIONS box "Financial Service Providers" #lightGray participant DFSP1 @@ -61,6 +63,8 @@ box "Central Service" #LightYellow participant CSAPI participant TOPIC_FULFIL participant FULF_HANDLER + participant TOPIC_SETMODEL + participant SETMODEL_HANDLER participant TOPIC_TRANSFER_POSITION participant POS_HANDLER participant TOPIC_NOTIFICATIONS @@ -69,6 +73,7 @@ end box ' start flow activate NOTIFY_HANDLER activate FULF_HANDLER +activate SETMODEL_HANDLER activate POS_HANDLER group DFSP2 sends a Fulfil Success Transfer request DFSP2 <-> DFSP2: Retrieve fulfilment string generated during\nthe quoting process or regenerate it using\n**Local secret** and **ILP Packet** as inputs @@ -138,8 +143,12 @@ group DFSP2 sends a Fulfil Success Transfer request deactivate MLAPI TOPIC_FULFIL <- FULF_HANDLER: Consume message ref over TOPIC_FULFIL, TOPIC_TRANSFER_POSITION: Fulfil Handler Consume (Success) {[[https://github.com/mojaloop/documentation/tree/master/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.1.svg 2.1.1]]} \n + FULF_HANDLER -> TOPIC_SETMODEL: Produce message FULF_HANDLER -> TOPIC_TRANSFER_POSITION: Produce message ||| + TOPIC_SETMODEL <- SETMODEL_HANDLER: Consume message + ref over TOPIC_SETMODEL, SETMODEL_HANDLER: Settlement Model Handler Consume (Success)\n + ||| TOPIC_TRANSFER_POSITION <- POS_HANDLER: Consume message ref over TOPIC_TRANSFER_POSITION, TOPIC_NOTIFICATIONS: Position Handler Consume (Success)\n POS_HANDLER -> TOPIC_NOTIFICATIONS: Produce message diff --git a/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.1.plantuml b/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.1.plantuml index 484af46a6..42f281ef6 100644 --- a/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.1.plantuml +++ b/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-fulfil-2.1.1.plantuml @@ -34,12 +34,13 @@ autonumber ' entity - Database Access Objects ' database - Database Persistance Store ' declare actors -collections "Fulfil-Topic" as TOPIC_FULFIL -control "Fulfil Event Handler" as FULF_HANDLER -collections "Event-Topic" as TOPIC_EVENT -collections "topic-transfer-position" as TOPIC_TRANSFER_POSITION -collections "Notification-Topic" as TOPIC_NOTIFICATIONS -'entity "Transfer Duplicate Facade" as DUP_FACADE +collections "topic-fulfil" as TOPIC_FULFIL +control "Fulfil Event\nHandler" as FULF_HANDLER +collections "topic-event" as TOPIC_EVENT +collections "topic-\ntransfer-position" as TOPIC_TRANSFER_POSITION +collections "topic-\nsettlement-model" as TOPIC_SETMODEL +collections "topic-\nnotification" as TOPIC_NOTIFICATIONS + entity "Position DAO" as POS_DAO database "Central Store" as DB box "Central Service" #LightYellow @@ -47,6 +48,7 @@ box "Central Service" #LightYellow participant FULF_HANDLER participant TOPIC_TRANSFER_POSITION participant TOPIC_EVENT + participant TOPIC_SETMODEL participant TOPIC_NOTIFICATIONS participant POS_DAO participant DB @@ -157,7 +159,38 @@ group Fulfil Handler Consume (Success) note right of FULF_HANDLER #yellow Message: { - id: , + id: , + from: switch, + to: switch, + type: application/json + content: { + payload: { + transferId: {id} + } + }, + metadata: { + event: { + id: , + responseTo: , + type: setmodel, + action: commit, + createdAt: , + state: { + status: "success", + code: 0 + } + } + } + } + end note + FULF_HANDLER -> TOPIC_SETMODEL: Route & Publish settlement model event + activate TOPIC_SETMODEL + deactivate TOPIC_SETMODEL + + note right of FULF_HANDLER #yellow + Message: + { + id: , from: , to: , type: application/json, @@ -200,7 +233,7 @@ group Fulfil Handler Consume (Success) note right of FULF_HANDLER #yellow Message: { - id: , + id: , from: , to: , type: application/json, diff --git a/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-setmodel-2.1.2.plantuml b/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-setmodel-2.1.2.plantuml new file mode 100644 index 000000000..3d8209299 --- /dev/null +++ b/mojaloop-technical-overview/central-ledger/assets/diagrams/sequence/seq-setmodel-2.1.2.plantuml @@ -0,0 +1,122 @@ +/'***** + License + -------------- + Copyright © 2017 Bill & Melinda Gates Foundation + The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + Contributors + -------------- + This is the official list of the Mojaloop project contributors for this file. + Names of the original copyright holders (individuals or organizations) + should be listed with a '*' in the first column. People who have + contributed from an organization can be listed under the organization + that actually holds the copyright for their contributions (see the + Gates Foundation organization for an example). Those individuals should have + their names indented and be marked with a '-'. Email address can be added + optionally within square brackets . + * Gates Foundation + - Name Surname + + * ModusBox + - Georgi Georgiev + -------------- + ******'/ + +@startuml +' declate title +title 2.1.2. Settlement Model Handler Consume +autonumber +' Actor Keys: +' boundary - APIs/Interfaces, etc +' collections - Kafka Topics +' control - Kafka Consumers +' entity - Database Access Objects +' database - Database Persistance Store +' declare actors +collections "topic-\nsettlement-model" as TOPIC_SETMODEL +control "Settlement Model\nHandler" as SETMODEL_HANDLER +collections "topic-event" as TOPIC_EVENT +entity "Settlement DAO" as SET_DAO +database "Central Store" as DB + +box "Central Service" #LightYellow + participant TOPIC_SETMODEL + participant SETMODEL_HANDLER + participant TOPIC_EVENT + participant SET_DAO + participant DB +end box + +' start flow +activate SETMODEL_HANDLER +group Settlement Model Handler Consume + alt Consume Single Message + TOPIC_SETMODEL <- SETMODEL_HANDLER: Consume settlement model\nevent message + activate TOPIC_SETMODEL + deactivate TOPIC_SETMODEL + break + group Validate Event + SETMODEL_HANDLER <-> SETMODEL_HANDLER: Validate event - Rule: type == 'setmodel' && action == 'commit'\nError codes: 2001 + end + end + group Persist Event Information + ||| + SETMODEL_HANDLER -> TOPIC_EVENT: Publish event information + ref over SETMODEL_HANDLER, TOPIC_EVENT: Event Handler Consume\n + ||| + end + + SETMODEL_HANDLER -> SET_DAO: Assign transferParicipant state(s)\nError code: 2003 + activate SET_DAO + group DB TRANSACTION + SET_DAO -> DB: Fetch transfer participant entries + activate DB + hnote over DB #lightyellow + transferParticipant + end note + DB --> SET_DAO: Return **transferParticipantRecords** + deactivate DB + + loop for each transferParticipant + note right of SET_DAO #lightgrey + Settlement models caching to be considered + end note + SET_DAO -> DB: Get settlement model by currency and ledger entry + activate DB + hnote over DB #lightyellow + settlementModel + end note + DB --> SET_DAO: Return **settlementModel** + deactivate DB + + opt settlementModel.delay == 'IMMEDIATE' && settlementModel.granularity == 'GROSS' + SET_DAO -> DB: Set states: CLOSED->PENDING_SETTLEMENT->SETTLED + activate DB + hnote over DB #lightyellow + transferParticipantStateChange + transferParticipant + end note + deactivate DB + else + SET_DAO -> DB: Set state: OPEN + activate DB + hnote over DB #lightyellow + transferParticipantStateChange + transferParticipant + end note + deactivate DB + end + + end + end + SETMODEL_HANDLER <-- SET_DAO: Return success + deactivate SET_DAO + else Consume Batch Messages + note left of SETMODEL_HANDLER #lightblue + To be delivered by future story + end note + end +end +deactivate SETMODEL_HANDLER +@enduml diff --git a/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-settlement-6.2.1.plantuml b/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-settlement-6.2.1.plantuml index 0be3214cc..59d493b43 100644 --- a/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-settlement-6.2.1.plantuml +++ b/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-settlement-6.2.1.plantuml @@ -187,6 +187,8 @@ activate OPERATOR SETTLE_DAO -> DB: Change state to 'PENDING_SETTLEMENT' activate DB hnote over DB #lightyellow + transferParticipantStateChange + transferParticipant settlementWindowContentStateChange settlementWindowContent end hnote diff --git a/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-settlement-6.2.5.plantuml b/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-settlement-6.2.5.plantuml index 6769f4ea6..66e9c65b0 100644 --- a/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-settlement-6.2.5.plantuml +++ b/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-settlement-6.2.5.plantuml @@ -82,10 +82,12 @@ group Acknowledgement of Settlement Transfer activate DB hnote over DB #lightyellow SELECT s.settlementId, ssc.settlementStateId, - ssc.reason, ssc.createdDate + ssc.reason, ssc.createdDate, sm.autoPositionReset FROM **settlement** s JOIN **settlementStateChange** ssc ON ssc.settlementStateChangeId = s.currentStateChangeId + JOIN **settlementModel** sm + ON sm.settlementModelId = s.settlementModelId WHERE s.settlementId = {id} FOR UPDATE end hnote @@ -408,18 +410,20 @@ group Acknowledgement of Settlement Transfer deactivate DB end - alt settlementData.state == 'PENDING_SETTLEMENT' - ||| - ref over SETTLE_DAO, DB: Settlement Transfer Prepare\n\n**Inputs**: settlementId, transactionTimestamp, enums, trx\n - ||| - else settlementData.state == 'PS_TRANSFERS_RECORDED' - ||| - ref over SETTLE_DAO, DB: Settlement Transfer Reserve\n\n**Inputs**: settlementId, transactionTimestamp, enums, trx\n - ||| - else settlementData.state == 'PS_TRANSFERS_RESERVED' - ||| - ref over SETTLE_DAO, DB: Settlement Transfer Commit\n\n**Inputs**: settlementId, transactionTimestamp, enums, trx\n - ||| + opt autoPositionReset == true + alt settlementData.state == 'PENDING_SETTLEMENT' + ||| + ref over SETTLE_DAO, DB: Settlement Transfer Prepare\n\n**Inputs**: settlementId, transactionTimestamp, enums, trx\n + ||| + else settlementData.state == 'PS_TRANSFERS_RECORDED' + ||| + ref over SETTLE_DAO, DB: Settlement Transfer Reserve\n\n**Inputs**: settlementId, transactionTimestamp, enums, trx\n + ||| + else settlementData.state == 'PS_TRANSFERS_RESERVED' + ||| + ref over SETTLE_DAO, DB: Settlement Transfer Commit\n\n**Inputs**: settlementId, transactionTimestamp, enums, trx\n + ||| + end end group Update aggregations, contents & windows @@ -429,6 +433,8 @@ group Acknowledgement of Settlement Transfer deactivate DB hnote over DB #lightyellow settlementContentAggregation + transferParticipantStateChange + transferParticipant settlementWindowContentStateChange settlementWindowContent settlementWindowStateChange diff --git a/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-setwindow-6.1.2.plantuml b/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-setwindow-6.1.2.plantuml index bbc922691..cca5d36cf 100644 --- a/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-setwindow-6.1.2.plantuml +++ b/mojaloop-technical-overview/central-settlements/settlement-process/assets/diagrams/sequence/seq-setwindow-6.1.2.plantuml @@ -221,73 +221,96 @@ group Close Settlement Window iter++ end note - SET_WIN_HANDLER -> SETTLE_DAO: Generate window content and aggregations\nError code: 2001 + SET_WIN_HANDLER -> SETTLE_DAO: Check if all transferParticipant records\nfor the requested window have been set\n(currentStateChangeId is NOT NULL).\nError code: 2001 activate SETTLE_DAO - group DB TRANSACTION: Generate window content and aggregations - note right of SETTLE_DAO #lightgray - let **transactionTimestamp** = now() - end note + SETTLE_DAO -> DB: Use EXISTS query to find NULL currentStateChangeId records + activate DB + hnote over DB #lightyellow + transferFulfilment + transferParticipant + end hnote + deactivate DB + SET_WIN_HANDLER <-- SETTLE_DAO: Return result (success / failure) + deactivate SETTLE_DAO - SETTLE_DAO -> DB: Determine window content and insert - activate DB - hnote over DB #lightyellow - INSERT INTO **settlementWindowContent** (settlementWindowId, ledgerAccountTypeId, - currencyId, createdDate) - SELECT DISTINCT {id} settlementWindowId, pc.ledgerAccountTypeId, - pc.currencyId, transactionTimestamp - FROM **transferFulfilment** tf - JOIN **transferParticipant** tp - ON tp.transferId = tf.transferId - JOIN **participantCurrency** pc - ON pc.participantCurrencyId = tp.participantCurrencyId - WHERE tf.settlementWindowId = {id} - end hnote - deactivate DB + opt transferParticipant records have been processed by central-ledger SettlementModelHandler + SET_WIN_HANDLER -> SETTLE_DAO: Generate window content and aggregations\nError code: 2001 + activate SETTLE_DAO + group DB TRANSACTION: Generate window content and aggregations + note right of SETTLE_DAO #lightgray + let **transactionTimestamp** = now() + end note - SETTLE_DAO -> DB: Aggregate window data and insert - activate DB - hnote over DB #lightyellow - INSERT INTO **settlementContentAggregation** (settlementWindowContentId, participantCurrencyId, - transferParticipantRoleTypeId, ledgerEntryTypeId, currentStateId, createdDate, amount) - SELECT swc.settlementWindowContentId, pc.participantCurrencyId, tp.transferParticipantRoleTypeId, - tp.ledgerEntryTypeId, 'CLOSED', transactionTimestamp, SUM(tp.amount) - FROM **transferFulfilment** tf - JOIN **transferParticipant** tp - ON tf.transferId = tp.transferId - JOIN **participantCurrency** pc - ON pc.participantCurrencyId = tp.participantCurrencyId - JOIN **settlementWindowContent** swc - ON swc.settlementWindowId = tf.settlementWindowId - AND swc.ledgerAccountTypeId = pc.ledgerAccountTypeId - AND swc.currencyId = pc.currencyId - WHERE tf.settlementWindowId = {id} - GROUP BY swc.settlementWindowContentId, pc.participantCurrencyId, - tp.transferParticipantRoleTypeId, tp.ledgerEntryTypeId - end hnote - deactivate DB + SETTLE_DAO -> DB: Change all applicable entries to CLOSED state + activate DB + hnote over DB #lightyellow + transferParticipantStateChange + transferParticipant + + end hnote + deactivate DB - SETTLE_DAO -> DB: Insert initial window content state change - activate DB - hnote over DB #lightyellow - INSERT INTO **settlementWindowContentStateChange** - (settlementWindowContentId, settlementWindowStateId) - SELECT swc.settlementWindowContentId, 'CLOSED' - FROM **settlementWindowContent** swc - WHERE swc.settlementWindowId = {id} - end hnote - deactivate DB + SETTLE_DAO -> DB: Determine window content and insert + activate DB + hnote over DB #lightyellow + INSERT INTO **settlementWindowContent** (settlementWindowId, ledgerAccountTypeId, + currencyId, createdDate) + SELECT DISTINCT {id} settlementWindowId, pc.ledgerAccountTypeId, + pc.currencyId, transactionTimestamp + FROM **transferFulfilment** tf + JOIN **transferParticipant** tp + ON tp.transferId = tf.transferId + JOIN **participantCurrency** pc + ON pc.participantCurrencyId = tp.participantCurrencyId + WHERE tf.settlementWindowId = {id} + end hnote + deactivate DB - SETTLE_DAO -> DB: Update pointers to current state change ids - activate DB - hnote over DB #lightyellow - settlementWindowContent - end hnote - deactivate DB + SETTLE_DAO -> DB: Aggregate window data and insert + activate DB + hnote over DB #lightyellow + INSERT INTO **settlementContentAggregation** (settlementWindowContentId, participantCurrencyId, + transferParticipantRoleTypeId, ledgerEntryTypeId, currentStateId, createdDate, amount) + SELECT swc.settlementWindowContentId, pc.participantCurrencyId, tp.transferParticipantRoleTypeId, + tp.ledgerEntryTypeId, 'CLOSED', transactionTimestamp, SUM(tp.amount) + FROM **transferFulfilment** tf + JOIN **transferParticipant** tp + ON tf.transferId = tp.transferId + JOIN **participantCurrency** pc + ON pc.participantCurrencyId = tp.participantCurrencyId + JOIN **settlementWindowContent** swc + ON swc.settlementWindowId = tf.settlementWindowId + AND swc.ledgerAccountTypeId = pc.ledgerAccountTypeId + AND swc.currencyId = pc.currencyId + WHERE ttf.settlementWindowId = {id} + GROUP BY swc.settlementWindowContentId, pc.participantCurrencyId, + tp.transferParticipantRoleTypeId, tp.ledgerEntryTypeId + end hnote + deactivate DB + + SETTLE_DAO -> DB: Insert initial window content state change + activate DB + hnote over DB #lightyellow + INSERT INTO **settlementWindowContentStateChange** + (settlementWindowContentId, settlementWindowStateId) + SELECT swc.settlementWindowContentId, 'CLOSED' + FROM **settlementWindowContent** swc + WHERE swc.settlementWindowId = {id} + end hnote + deactivate DB + + SETTLE_DAO -> DB: Update pointers to current state change ids + activate DB + hnote over DB #lightyellow + settlementWindowContent + end hnote + deactivate DB + end + SETTLE_DAO --> SET_WIN_HANDLER: Return result (success / failure) + deactivate SETTLE_DAO end - SETTLE_DAO --> SET_WIN_HANDLER: Return result - deactivate SETTLE_DAO - opt success + alt success note right of SET_WIN_HANDLER #lightgray windowContentReady = true end note