| 1 | # Dataspace Protocol Contract Negotiation Architecture |
| 2 | |
| 3 | The EDC will be upgraded to implement and be fully compliant to the __Dataspace Protocol Contract Negotiation Protocol__. This document details the architectural approach that will be taken |
| 4 | to support that protocol. |
| 5 | |
| 6 | ## Backward Compatibility and Migration Support |
| 7 | |
| 8 | It is __NOT__ a goal of the EDC project to provide backward compatibility to the previous IDS implementation. At a declared milestone, once the Dataspace Protocol implementation has reached |
| 9 | a sufficient maturity level, the EDC will switch to the new protocol and remove the old protocol implementation. Users will be responsible for migrating existing EDC installations |
| 10 | as no automated migration facilities will be provided. |
| 11 | |
| 12 | # Goals |
| 13 | |
| 14 | The goals of the Dataspace Protocol support are: |
| 15 | |
| 16 | 1. To be compliant with the Dataspace Protocol Contract Negotiation Protocol. This will involve passing all mandatory tests of the to-be-released IDS Test Compatibility Kit (IDS-TCK). |
| 17 | 2. To support a range of requirements involving externally assisted contract negotiation decisions. These include manual negotiation approval and integration with external systems |
| 18 | to determine state transitions. |
| 19 | 3. To support integration with facilities for producing digital contract signatures and contract non-repudiation. |
| 20 | |
| 21 | # The State Machine |
| 22 | |
| 23 | The IDS Specification Contract Negotiation states are: |
| 24 | |
| 25 | - INITIALIZED, |
| 26 | - REQUESTED, |
| 27 | - OFFERED, |
| 28 | - ACCEPTED, |
| 29 | - AGREED, |
| 30 | - VERIFIED, |
| 31 | - FINALIZED, |
| 32 | - TERMINATED |
| 33 | |
| 34 | The following table defines the mapping between existing EDC states, the corresponding new EDC states, and the IDS specification states. |
| 35 | |
| 36 | | EDC Existing | EDC New | IDS | Transition Function | Notes | |
| 37 | |--------------------|---------------|------------|--------------------------|--------------------------| |
| 38 | | UNSAVED | (remove) | N/A | | This state is not needed | |
| 39 | | INITIAL | INITIAL | N/A | | | |
| 40 | | | | | | | |
| 41 | | REQUESTING | REQUESTING | N/A | | | |
| 42 | | REQUESTED | REQUESTED | REQUESTED | Provider (new & counter) | | |
| 43 | | | | | | | |
| 44 | | PROVIDER_OFFERING | OFFERING | N/A | | | |
| 45 | | PROVIDER_OFFERED | OFFERED | OFFERED | Consumer | | |
| 46 | | CONSUMER_OFFERING | (REQUESTING) | | | | |
| 47 | | CONSUMER_OFFERED | (REQUESTED) | | | | |
| 48 | | | | | | | |
| 49 | | CONSUMER_APPROVING | ACCEPTING | N/A | | | |
| 50 | | CONSUMER_APPROVED | ACCEPTED | ACCEPTED | Provider | | |
| 51 | | | | | | | |
| 52 | | DECLINING | (TERMINATING) | | | | |
| 53 | | DECLINED | (TERMINATED) | | | | |
| 54 | | | | | | | |
| 55 | | CONFIRMING | AGREEING | N/A | | | |
| 56 | | CONFIRMED | AGREED | AGREED | Consumer | | |
| 57 | | | VERIFYING | N/A | | | |
| 58 | | | VERIFIED | VERIFIED | Provider | | |
| 59 | | | FINALIZING | N/A | | | |
| 60 | | | FINALIZED | FINALIZED | Consumer | | |
| 61 | | | TERMINATING | N/A | | | |
| 62 | | | TERMINATED | TERMINATED | P & C | | |
| 63 | | | | | | | |
| 64 | | ERROR | (TERMINATED) | | | | |
| 65 | |
| 66 | # State Transition Functions |
| 67 | |
| 68 | State transition functions (`StateTransitionFunction`) can be registered at specific callback points which are responsible for transitioning the Contract Negotiation State Machine |
| 69 | (CNSM) to a new state. These functions can be used to implement custom workflows. In runtime configurations that support it, transition functions will be called transactionally as |
| 70 | part of the `ContractNegotiationManager` process loop. This will ensure state transitions are atomic. |
| 71 | |
| 72 | `StateTransitionFunction` will operate on `ContractNegotiation` instances. |
| 73 | |
| 74 | ```java |
| 75 | |
| 76 | @FunctionalInterface |
| 77 | public interface StateTransitionFunction { |
| 78 | |
| 79 | Result<Boolean> process(ContractNegotiation negotiation); |
| 80 | |
| 81 | } |
| 82 | ``` |
| 83 | |
| 84 | Note this does not follow immutability principles but has the advantage of simplicity and the ability to enforce proper state transitions in the `ContractNegotiation` instance. |
| 85 | The `Result<Boolean>` response indicates if the `ContractNegotiation` has been updated (true) or not (false), or if processing failed. This can be used to avoid |
| 86 | re-persisting `ContractNegotiation` instances if they have not changed. |
| 87 | |
| 88 | End users will be able to register their own `StateTransitionFunction` implementations to provide custom contract negotiation workflows. For example, a `StateTransitionFunction` |
| 89 | implementation can be registered to be invoked when a consumer request is received (REQUESTED) to support manual approval. The function will be called by |
| 90 | the `ConsumerContractNegotiationManager` during its processing loop. If the request initiates a new negotiation, the function implementation could trigger a process in an external |
| 91 | approval system. In a subsequent processing loop, the `StateTransitionFunction` could check for the completion of the external approval process (e.g. by querying a column in a |
| 92 | table) and updating the `ContractNegotition`. |
| 93 | |
| 94 | # Default StateTransitionFunctions |
| 95 | |
| 96 | The following tabled define the default `StateTransitionFunction`s to use if one is not registered for the specified state transition. |
| 97 | |
| 98 | ## Consumer Default StateTransitionFunctions |
| 99 | |
| 100 | | State | Default StateTransitionFunction | |
| 101 | |-----------|-----------------------------------------------------------------| |
| 102 | | OFFERED | Transition to ACCEPTING if offer matches the original requested | |
| 103 | | AGREED | Transition to VERIFYING | |
| 104 | | FINALIZED | No-op | |
| 105 | | | | |
| 106 | | | | |
| 107 | | | | |
| 108 | |
| 109 | ## Provider Default StateTransitionFunctions |
| 110 | |
| 111 | | State | Default StateTransitionFunction | |
| 112 | |------------|----------------------------------------------------------------------------------| |
| 113 | | REQUESTED | For the initial request transition to AGREED if the offer corresponds to a | |
| 114 | | | provider offer and the consumer evaluates successfully against the offer policy. | |
| 115 | | | | |
| 116 | | ACCEPTED | Transition to AGREEING | |
| 117 | | VERIFIED | Transition to FINALIZING | |
| 118 | | TERMINATED | No-op | |
| 119 | |
| 120 | # HTTP Transition Functions (Phase II) |
| 121 | |
| 122 | The EDC provides the ability to extend the runtime via HTTP endpoints, for example, HTTP provisioning. A similar method should be added for state transitions where an HTTP endpoint |
| 123 | can implement processing logic for one of the defined `StateTransitionFunction` extension points. In addition to invoking an external endpoint, the EDC runtime will need to provide |
| 124 | an HTTP REST controller to serve as a callback for receiving updated `ContractNegotiation` instances. |
| 125 | |
| 126 | ## Callback Endpoint Reliability |
| 127 | |
| 128 | The controller may use the command infrastructure to update a received `ContractNegotiation`. However, since the command infrastructure relies on an in-memory queue, updates will |
| 129 | not be reliable. Three options for addressing this are: |
| 130 | |
| 131 | 1. Make the in-memory queue reliable and persistent. This option is likely to be the most complicated and difficult to achieve as it will require persistence and the ability to |
| 132 | perform message ordering. |
| 133 | 2. Introduce a persistence mechanism for storing intermediate state machine results including `ContractNegotiation` and `TransferProcess,` and updates them using the command |
| 134 | infrastructure in a reliable way (e.g. removing entries once the command processing has been completed). This is still a complicated solution but has the advantage of |
| 135 | using the command infrastructure as a single point for external state machine updates. |
| 136 | 3. Introduce a lock-based synchronous update mechanism for state machine instances including `ContractNegotiation` and `TransferProcess` instances that bypasses the command queue. |
| 137 | This approach has the advantage of relative simplicity but introduces an additional code path for external state machine updates. |
| 138 | |
| 139 | A generic solution should be designed which can be used by other extensions such as the HTTP provisioner to provide reliability guarantees. |
| 140 | |
| 141 | > Note that this feature will also be required for supporting reliable callbacks when a transfer is complete and when a transfer has been suspended. |
| 142 | |
| 143 | |