Skip to content

Commit

Permalink
(docs): net flow and consistency check of flow matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminbollen committed Aug 30, 2024
1 parent 3992639 commit 0c0f331
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion docs/docs/advanced-topics/path-based-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,22 @@ Note: flow edge arrays and flow vertices arrays are indexed from 0. Streams are
- `flowEdgeIds = [4]` (fifth edge C-E terimates stream 3)
- `data`

#### Net Flow and consistency check
## Net Flow and Consistency Check

The net flow is not sent as input to the contracts, rather it is included in the diagram to illustrate the consistency check that the contract performs.
For an explicit path of flow edges to be a valid solution to the set of intents expressed in the streams, it must hold that
for every vertex the sum over all flow edges (modulo Circles Id) must equal the sum over all streams (ie. summing the columns).

Streams themselves don't specify an amount though - both to compactify the representation but also to not over-determine the representation. Instead it is checked that for each stream:

- all the terminal edges that reference this stream have the same receiver.
- that each stream lists their terminal flow edge ids in ascending order.
- and that the count of terminal edges that reference a stream, matches the length of the `flowEdgeIds` array of that stream.

By cross-referencing, and checking consistency we ensure that we can use the sum of the terminal edges for a stream as the amount intended to send by that stream.

In our example, all streams only had one terminal flow edge, but in general a flow matrix can have multiple terminal flow edges for a single stream.

## Technical Implementation

The `Hub` contract implements path-based transactions through the `operateFlowMatrix` function. Let's break down its key components:
Expand Down
2 changes: 1 addition & 1 deletion src/hub/TypeDefinitions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract TypeDefinitions {

struct FlowEdge {
uint16 streamSinkId;
uint192 amount; // todo: set this to uint192 (align with demurrage), and leave it to compiler to pad
uint192 amount;
}

struct Stream {
Expand Down

0 comments on commit 0c0f331

Please sign in to comment.