From 0c0f33167787ff45dea2da3087c1011513a554de Mon Sep 17 00:00:00 2001 From: Benjamin Bollen Date: Fri, 30 Aug 2024 21:53:41 +0100 Subject: [PATCH] (docs): net flow and consistency check of flow matrix --- docs/docs/advanced-topics/path-based-transactions.md | 12 +++++++++++- src/hub/TypeDefinitions.sol | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/docs/advanced-topics/path-based-transactions.md b/docs/docs/advanced-topics/path-based-transactions.md index ea57654..1a11d73 100644 --- a/docs/docs/advanced-topics/path-based-transactions.md +++ b/docs/docs/advanced-topics/path-based-transactions.md @@ -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: diff --git a/src/hub/TypeDefinitions.sol b/src/hub/TypeDefinitions.sol index ba5d4ce..79665bf 100644 --- a/src/hub/TypeDefinitions.sol +++ b/src/hub/TypeDefinitions.sol @@ -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 {