Agoric / agoric-sdk

monorepo for the Agoric Javascript smart contract platform
Apache License 2.0
327 stars 207 forks source link

avoid round trip in smart wallet vstorage / storageNode writes #10307

Open dckc opened 1 month ago

dckc commented 1 month ago

What is the Problem Being Solved?

While looking at performance of a PSM trade (#6039), we noticed two round trips in each wallet state update - one for serialize and one for setValue:

image

I re-discovered this pattern in

Description of the Design

Have the board marshaller return JSON.stringify(capData) rather than capData. Then the smart wallet can do

  const stringValueP = E(boardMarshaller).serializeAndStringify(objectGraph);
  await E(storageNode).setValue(stringValueP);

and stringValueP can be forwarded to the bridge vat without a round trip back thru the smart wallet.

There's a proof of concept in...

Security Considerations

Scaling Considerations

fewer round trips should scale better

Test Plan

Upgrade Considerations

This would be deployed in an upgrade of walletFactory.

It would be nice to update any other clients that exhibit this pattern, but this issue is scoped to the smart wallet, which is where we see the problem happen most often.

gibson042 commented 1 month ago

We could also enhance the StorageNode API to perform serialization locally:

  const capDataP = E(boardMarshaller).toCapData(objectGraph);
  await E(storageNode).serializeAndSetValue(capDataP);

(which would likely have smaller overall message size by avoiding the double encoding necessary to send an already serialized representation, but may be more difficult to effect because it would require upgrading the bridge vat)