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

ibid mechanism broken #161

Closed
katelynsills opened this issue May 4, 2019 · 9 comments
Closed

ibid mechanism broken #161

katelynsills opened this issue May 4, 2019 · 9 comments
Labels
SwingSet package: SwingSet

Comments

@katelynsills
Copy link
Contributor

I came across an issue when I was trying to return an array that contains the same presence twice. It errors with the message, 'ibid out of range'.

When notifyFulfillToData (line 409 of liveSlots.js on my branch) is called, it has the following as arguments:

  • promiseID: 20
  • data: "[{"@\qclass":"slot","index":0},{"@\qclass":"ibid","index":1}]" (slashes added to not tag qclass)
  • slots: [{type: "import", id: 11}]

MarkM says: "The ibid mechanism is broken because the replacer during serialization assigns ibid indices in preorder whereas the JSON reviver only sees objects in post order, and therefore has different ibid indices."

@warner
Copy link
Member

warner commented May 6, 2019

Can you make this into a unit test? I just tried a simple set of arrays (serialize([a1,a2,a3,a3,a2,a1])) and it seems to serialize correctly, but that case isn't introducing any new objects in the post-replacer data, and it sounds like that's the core problem.

The test should probably go into test-marshal.js in "serialize exports". If you can write a test that fails and post it here (or put it on a branch), I'll try to find the fix.

@katelynsills
Copy link
Contributor Author

katelynsills commented May 6, 2019 via email

katelynsills referenced this issue in Agoric/SwingSet May 6, 2019
@katelynsills
Copy link
Contributor Author

I added a unit test here: Agoric/SwingSet@e6c6350

@warner
Copy link
Member

warner commented May 9, 2019

Ah, yeah, this will be tricky. We're saving a lot of code by relying upon the built-in JSON serialization features. But the replacer hook of JSON.stringify is executed on the way into each node during a depth-first traversal, while the reviver hook of JSON.parse is run on the way out of each node. As a result, numbering the nodes by order of appearance to these hooks gets a completely different ordering.

Worst case we'll have to write our own deserializer. It might also be possible to serialize the data, unserialize it (without a reviver), then re-serialize it with a replacer that changes the ibid index for each node to match the other numbering order. Or do the same thing on the receiving side. Neither is particularly appealing.

@erights
Copy link
Member

erights commented May 9, 2019

I have some ideas here, to talk about when we're next in at the same time. In the meantime, Agoric/SwingSet@508982d safely turns ibids off in a way that should work well enough in the absence of cycles. However, it will expand pass-by-copy dags into trees.

@warner
Copy link
Member

warner commented May 10, 2019

That quick fix sounds good, and our marshalling layer will already combine multiple refs to the same import/export slot into a single index (even without the ibid mechanism). I'll land that now, and then we can defer the full fix until later.

@dckc
Copy link
Member

dckc commented Jun 2, 2019

Can you use a path rather than an index, a la cycle?

@erights
Copy link
Member

erights commented Jun 3, 2019

Can you use a path rather than an index, a la cycle?

Perhaps. Opened https://github.com/Agoric/SwingSet/issues/66 to track. Closing this one though, since ibids with indexes are no longer broken.

@warner
Copy link
Member

warner commented Dec 4, 2019

in the old repo. this was SwingSet issue 30

@warner warner transferred this issue from Agoric/SwingSet Dec 4, 2019
@warner warner added the SwingSet package: SwingSet label Dec 4, 2019
dckc pushed a commit to dckc/agoric-sdk that referenced this issue Dec 5, 2019
* add simple exchange
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwingSet package: SwingSet
Projects
None yet
Development

No branches or pull requests

4 participants