Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implicit canonicalization for pushing a stream to a stream of collections #277

Closed
alari opened this issue Sep 8, 2021 · 0 comments · Fixed by #344
Closed

Add implicit canonicalization for pushing a stream to a stream of collections #277

alari opened this issue Sep 8, 2021 · 0 comments · Fixed by #344
Labels
bug Something isn't working enhancement New feature or request

Comments

@alari
Copy link
Member

alari commented Sep 8, 2021

One of the common patterns in Aqua is building optional values by writing or not writing to a stream:

func toOpt(value: string, flag: bool) -> ?string:
  res: *string
  if flag:
    res <<- value
  <- res

Consider the following snippet:

res_accum: *?string
res_accum <- toOpt("a", true)
res_accum <- toOpt("b", false)
res_accum <- nil

In this case, res_accum is defined as a stream of optional values. Finally it compiles to smth like this:

(match true true
   (ap "a" $res)
)
(ap $res $res_accum)

This code will fail, as $res value is not deterministic: different peers may observe different state of $res. $res, being a stream, forms a locally consistent CRDT, its state may differ for different points of view, and may grow in time.

To use $res safely as a value of type ?string (the return type of the function), it needs to be canonicalized: converted from the mutable $res form to an immutable res form.

Canonicalization is not yet implemented on AquaVM side, but we can think of it as a point of observation:

(can peer_id $res res)

After this can call, res will contain a fixed value of $res for the moment of the first can call on peer_id. All other peers will check that res was derived the right way, get tetraplets, etc.

Until we have this implemented, we can mock can with (call peer_id ("op" "identity") [$res] res). Currently, it does the same: converts argument to a scalar value. But it misses tetraplets.

The task is to add this call implicitly when a stream is pushed into a stream. Once we have native canonicalization support, replace op identity call with it.

@alari alari added bug Something isn't working enhancement New feature or request labels Sep 8, 2021
alari added a commit that referenced this issue Oct 26, 2021
alari added a commit that referenced this issue Oct 26, 2021
* Create opaque names in NamesInterpreter

* Implicit canonicalization for <<- stream

* PR fixes

* Second part of #277
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant