-
Notifications
You must be signed in to change notification settings - Fork 212
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
notifying smart wallet of every vbank balance update is too expensive #5896
Comments
Looks good. I was worried about the 2 queries, since @michaelfig gave me the impression that watching multiple chainStorage nodes requires a websocket each (soon to be an http long-polling thingy each). But the single doorbell addresses that complexity. |
Without If we do either, we should stop describing these as Purses. But I don't understand why we need to. If we do plan to implement them, but just have not yet, then have these methods throw a "not implement yet" error. We could even go to MN-1 with such a promise that we'll eventually implement the full Purse behavioral spec. Or we could rename these to something other than |
That all seems fair. But I'd be concerned if these virtual purses support |
Proposal: How about if we keep the name For now, we have |
This issue is referring to Purse methods agoric-sdk/packages/ERTP/src/types.js Lines 345 to 350 in 7f294a6
An open question is how to remove the hotness from the vat-bank -managed virtual purses. Some options:
I haven't heard #4 proposed yet. Wouldn't that solve the "hot" problem? |
Yes,
Makes the type more complicated.
Adds a distinct supertype, which is more explicit and in-band than 1 or 3. IMO probably best.
Does still impose a burden on clients, even if only temporarily. Advantage of 2 over 1 or 3 is that the type system could help clients reason about when they need to deal with this burden.
As long as clients are only holding the Iterable over time, rather than the Iterator, should be equivalent, and equivalently hard to cool. Unlike Notifiers, if clients do hold a Subscriber Iterator, hotness becomes unavoidable as it can no longer be lossy. But I do not understand the current similarities and differences of the internal mechanisms of Notifiers and Subscribers, so take with much salt. @gibson042 , reactions? |
There are multiple kinds of expense here:
Using Notifier instead of Subscriber moves us away from expense A. Changing the cosmos side to speak only when spoken to (er, notify only when someone asks) moves us away from expense B. But, expense C is still pretty bad. Especially if the on-chain smart wallet automatically subscribes for updates for every single user (so it can publish the balances to the storage node that it uses for all the non-virtual purses). We could easily wind up with just as much cosmos<->swingset traffic as expense B. In other words, lazy notification is only a win if it's actually lazy, and eager clients are not lazy. And, the balances of those VBANK-managed accounts are already in the IAVL tree, and reachable over RPC queries that predate our entire company. So it's a waste of our precious chain CPU time to report those balances into JS just to re-publish them in a second RPC-queryable spot. If some contract code needs to query it occasionally, that's fine, but presenting a Notifier API on it makes it awfully easy to query it constantly, and I think that represents load that we can't afford. |
So we only need to avoid |
Like all our important contracts, I worry about the position we'll be in if we ship without full upgradability. If we have that, then we should (hopefully?) be able to upgrade vat-bank into a form that doesn't use the expensive/eager update mechanisms. But if the load caused by those is large enough, that might interfere with our ability to upgrade them in the first place. So.. maybe? |
#6652 prompts looking at this again |
provisionPool relies on vbank balance notifierThe provision pool responds to incoming cosmos token transfers of, for example, USDC_axl, and trades the incoming assets for IST. agoric-sdk/packages/vats/src/provisionPool.js Line 180 in e208b20
|
To hit the sweet spot between no balance notifications and all notifications, I plan on sending notifications from Golang only for privileged Cosmos "module account" addresses (like the |
Ok... That meets all the requirements I can think of. |
What is the Problem Being Solved?
@michaelfig and I were brainstorming about vat-bank improvements.
As mentioned in #5885, our current vat-bank implementation results in some pretty expensive work being done each time any cosmos-managed balance changes (which includes the RUN and IST balances of every account). The cosmos code sends a VBANK_UPDATE message over the bridge with all the updates, then vat-bank updates an in-RAM copy of those balances. This enables vat-bank to provide a full
Purse
API on the virtual purses it exports to other users.To avoid that work, we'd really prefer to only use those virtual purses for their
.deposit
and.withdraw
methods, and leave balance checking (both one-shot and ongoing notification) to more efficient pathways. The cosmos Bank module already publishes all of those balances to the IAVL tree, and there are well-established RPC tools to query them (a balance query being practically the first thing that any blockchain implements).There are three places that are interested in a balance:
The on-chain smart wallet currently subscribes to balance updates for all the user's purses, both the real ones and the virtual purses that reflect cosmos-side Bank module balances. It publishes a single aggregate record to the IAVL tree (containing a list of purses and their current balances) every time any one of those balances change.
We're thinking that that record should only include the "real" purses, not the vat-bank -managed virtual purses. When the wallet UI wants to render a list of all the user's purses, it should make two queries: one to the on-chain wallet's aggregate record (for the "real" purses), and then a second to the Bank module's normal balance-publishing path (for the denominations that would be represented by virtual purses). Then, there should be a shared event, a "doorbell" of some sort. The wallet UI/frontend watches for that event, and when it happens, it re-performs both queries. The on-chain wallet code triggers this event each time it changes the aggregate record (because one of the "real" purses has changed value). The cosmos Bank module (or vbank module?) also triggers this event when one of the vpurse balances has changed.
That way, we're not doing any on-chain work in reaction to a cosmos Bank balance changing: we just ring the doorbell so the frontend can know it should re-query over RPC.
We're thinking that the virtual Purses exported by vat-bank be stripped down: we remove both
getCurrentBalance
(or have it returnundefined
or something), and we remove thegetNotifier
too. The on-chain wallet shouldn't be querying these anymore, and off-chain code should know that the data is available through the normal cosmos Bank RPC queries.@michaelfig I'm sure I've missed a lot here.. could you help fill in the gaps?
cc @samsiegart @dckc
Description of the Design
Security Considerations
Test Plan
The text was updated successfully, but these errors were encountered: