This thread aims to clarify the definition of projection functions and their dependency on data discovery and data availability services.
My initial implementation of the balance
projection function for Kudos was:
balance (kind : Kind) (account : PublicKey) : Nat :=
let
ownedResources : Set Commitment := anomaGet (kind, account);
in for (sum := 0) (cm in Set.toList ownedResources)
{let
q := Resource.quantity (commitmentResource cm);
in q + sum};
You, @cwgoes, commented:
They can have custom outputs, but I thought that we defined projection functions as taking as input only the application’s state (i.e. resources associated with the resource logics which define the application)
This make sense to me and I tried to align it with the brainstorming we did yesterday with @degregat , where we discussed also data discovery. We said that an indexing service might take a filter
as an input argument and return a Set Hash
associated with the resources (or data BLOBs in general) having the filtered properties.
Having the set of hashes, the associated resource plaintexts could then be fetched from a data availability service and passed to the projection function.
Does this generally make sense?
If yes, then the balance
projection function implementation would just be
balance (resources : Set Resource) : Nat :=
for (sum := 0) (r in Set.toList resources) {sum + Resource.quantity r};
and I should change the report accordingly.
Error Handling / Sanity Checking
I am now wondering where error handling / sanity checking should take place. Probably, this should take place after the data discovery and data availability service request.
E.g., for the balance
function to work, we would initially query/filter for resources of certain kind
that are owned by a certain accout
. We would then also need to check that the properties actually hold. If not, the indexing or DA service should be penalized (which is, as I understand, where slow games become important).
Afterward, we just can just pass the Set Resource
to the balance
projection function.