# Proof of Flow: A Design Pattern for the Green Energy Market
## 4 Proof of Flow Design Pattern
### The SweepEpoch() Function in Detail  
The Aggregator calls the SweepEpoch() function of ARIA at the beginning of each new epoch. This function carries out the following tasks.  
1. Epoch conclusion and settlement: verify whether the energy quantities, as provided by the Aggregator, during the latest epoch, align with the amounts declared by active DERs. If the reported values match within the error tolerance \(t\), then proceed to step 2, otherwise proceed to step 3.
2. Accredit: calculate the reward for each DER and proceed to step 4.
3. Penalty and deposit withholding: DERs are subject to a penalty when they have produced an average amount of energy below the requested amount without having notified the Aggregator. In this case a percentage of their deposit or credit is withheld as a penalty.
4. Reliability ranking: assess the reliability of each DER in the active pool and update their ranks accordingly.  
\begin{table}
\begin{tabular}{c c c l} \hline \hline
**Sender** & **Signal/Event** & **Function** & **Effect** \\ \hline Aggregator & Activated & EmitCommEvent() & Notifies that a prospective DER has been moved to the active pool and must start providing energy \\ Aggregator & Deactivated & EmitCommEvent() & Notifies that an active DER has been removed from the active pool \\ Aggregator & Adjust & EmitCommEvent() & Asks DERs to adjust energy production levels i \\ Aggregator & Receipt & EmitCommEvent() & Writes payment receipts to wallets ii \\ Aggregator & Warning & EmitCommEvent() & Warns DERs about abnormal energy production \\ Aggregator & ProveTheFlow & ProveTheFlow() & Publishes a Proof of Flow for a blockstamp \\ Aggregator & ProveTheFlows & ProveTheFlow() & Publishes a Proofs of Flow for a period iii \\ Operator & Alert & EmitCommEvent() & Publishes alerts about system status or changes \\ Operator & ProvidePoF & EmitCommEvent() & Requests a Proof of Flow to DERs or the Aggregator for a blockstamp \\ Operator & ProvidePoFs & EmitCommEvent() & Requests a Proofs of Flow to DERs or the Aggregator for a period \\ Operator & Receipt & EmitCommEvent() & Writes payment receipts to wallets iv \\ Operator & Resolution & ResolveDispute() & Publishes the dispute resolution outcome \\ DER & Dispute & RaiseDisputeEvent() & Initiates a dispute addressed to the Operator \\ DER & Unavailability & PowerShortage() & Inform the Aggregator in advance about the inability to provide the \\  & & requested energy \\ DER & ProveTheFlow & ProveTheFlow() & Publishes a Proof of Flow for a blockstamp \\ DER & ProveTheFlows & ProveTheFlow() & Publishes a Proof of Flow for a period \\ \hline \hline \end{tabular}  
* In case of deviations or when power modulation is needed. ii Belonging to DERs that have been rewarded. iii Or a range of blockstamps iv Belonging to the Aggregator or DERs that have been rewarded.  
\end{table}
Table 3: Signals categorization.  
5. DERs removal: remove from the active pool the DERs whose balance has been depleted due to fines and, according to the CalculateRanking() function, those whose rank falls below a specified threshold.
6. Contract expiration: move DERs whose contracts have expired from the active pool to the prospective-DERs list (i.e., they have provided energy for the specified number of epochs, \(d\) given in the contract).
7. Transaction fee allocation and payment: keep track of the gas consumed during its execution and distribute the cost between Aggregator and DERs, deducting it from their credits. This ensures that all parties contribute to covering the execution cost. Then, trigger the Vault to transfer the reward to the DERs' and Aggregator's wallets and emit Receipts events reporting the epoch nonce.
8. Activation: analyze the list of prospective-DERs to identify DERs that meet the criteria for providing energy. The commitment of eligible DERs is formalized by moving their wallet addresses from the prospective-DERs list to the active DERs' pool and publishing the Activated event that alerts DERs, specifying the number of epochs they are required to participate in supplying energy.