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

Provide PSM chainStorage data to Bulldozer bootstrap #7156

Closed
Tracked by #6645
dckc opened this issue Mar 10, 2023 · 9 comments · Fixed by #7489
Closed
Tracked by #6645

Provide PSM chainStorage data to Bulldozer bootstrap #7156

dckc opened this issue Mar 10, 2023 · 9 comments · Fixed by #7489
Assignees
Labels
cosmic-swingset package: cosmic-swingset enhancement New feature or request SwingSet package: SwingSet vaults_triage DO NOT USE

Comments

@dckc
Copy link
Member

dckc commented Mar 10, 2023

What is the Problem Being Solved?

In order to, for example, restore PSM state from chainStorage (#6645), the post-bulldozer VM has to somehow access the pre-bulldozer chainStorage state such as the list of PSM assets.

Description of the Design

???

Options include:

  • add a getValue() method to the JS chainStorage API
    • looks relatively straightforward (it's already in the go API).
    • But in a Jan 26 discussion with @warner , @warner expressed a desire to avoid reading from SwingSet devices (for reasons that I didn't manage to capture well).
  • put the whole pre-bulldozer state in vatParameters
    • those vatParameters get persisted in the kernel DB, and now replicated back into vstorage

Security Considerations

Scaling Considerations

Test Plan

@dckc dckc added enhancement New feature or request SwingSet package: SwingSet cosmic-swingset package: cosmic-swingset needs-design labels Mar 10, 2023
@rowgraus rowgraus added the vaults_triage DO NOT USE label Mar 13, 2023
@warner
Copy link
Member

warner commented Mar 22, 2023

The data we're talking about is pretty limited:

  • the PSM contracts have roughly 6 parameters to track, I think it's a balance and a mint limit for each denomination
  • the smart-wallet needs a list of addresses, one per account that was provisioned in the pismo chain
    • it does not need their balances, just a Set
    • if/when someone submits a smart-wallet action, their address will be compared against this set to see if they must provision an account first, or if they're already set up

In today's kernel meeting, we agreed:

  • launch-chain.js (the JS side of cosmic-swingset) will be changed to, at startup time, ask the Golang side for the contents of certain IAVL keys
  • it will then format that data into a JSON-shaped blob and deliver it to the kernel in the bootstrapArgs parameter (passed to initializeSwingset)
  • swingset delivers that data to vat-bootstrap (as bootstrap(vats, devices, bootstrapArgs))
  • vat-bootstrap will be changed to disseminate that data to the PSM/wallet vats which need it

@mhofman will mostly be doing the launch-chain.js side (this ticket), and @dckc will mostly be doing the vat-bootstrap side (#6645).

This will result in some specialized knowledge living in an unusual place. The particular set of IAVL keys that hold the PSM/wallet data is a function of the behavior of the pismo-era vats, and the IAVL root key that chain-storage starts from (I think it starts with swingset. or swingset.published. or something). The format of the contents of those keys is defined by those old vats too. But launch-chain.js will be required to have a list of those keys, or some code that knows how to find them, even though launch-chain.js was not involved in putting data there originally.

The alternative, which we rejected, would be for the PSM/smart-wallet vats to get chain-storage read access, whereupon at first launch they could query for data written by their predecessor, and then populate their initial (durable) tables from the results. That would separate the concerns better (new PSM vat is solely responsible for recovering state from the old PSM vat), but would require chain-storage reads, which we believe would interfere with our plans to parallelize vat execution.

Basically if a vat can ever read (synchronously) from a device, the worker hosting that vat would have to stop its execution, send a read request to the kernel, and wait for its response before it could continue execution. The kernel would receive that read request at a time that is uncoordinated with other activity, which looks like a timing race, and a threat to deterministic execution. The parallel execution design will be a lot simpler if we don't have to accomodate this case, and stick to only doing device writes (which can be safely deferred until the end of the vat delivery).

@mhofman
Copy link
Member

mhofman commented Mar 23, 2023

To avoid too much (any) economy logic in cosmic-swingset, it would be preferable for the config to list the keys/path that need to be read/exported and included in the bootstrap args.

@dckc do we have an idea of the kind of vstorage read operations we need? read specific paths? export a whole subtree? dump a list of children and/or entries?

@dckc
Copy link
Member Author

dckc commented Mar 23, 2023

If the swingset config can specify a list of roots (['published.psm', 'published.wallet'] for example) and get an Object.entries() style dump of those subtrees, that would probably work nicely. And no need for history. Just current/latest values.

@mhofman
Copy link
Member

mhofman commented Mar 23, 2023

I would imagine that an export of those subtrees will be more data than we need.

Also from what I recall the "history" is an application concern since it's an append to the same vstorage paths, so you would indeed get the history. Maybe we should look at an export of these subtrees and see what we can do from it.

@dckc dckc removed the needs-design label Apr 19, 2023
@mhofman mhofman changed the title how to get pre-bulldozer chainStorage state into post-bulldozer VM? Provide PSM chainStorage data to Bulldozer bootstrap Apr 19, 2023
@mhofman mhofman self-assigned this Apr 19, 2023
@turadg
Copy link
Member

turadg commented Apr 20, 2023

assigning to @gibson042 who volunteered for this in a chat thread

@turadg turadg assigned gibson042 and unassigned mhofman Apr 20, 2023
@warner
Copy link
Member

warner commented Apr 20, 2023

cc @FUDCo

@dckc
Copy link
Member Author

dckc commented Apr 21, 2023

FYI: I started prototyping by grabbing data straight off mainnet:

/** @type {Array<[key: string, value: string]>} */
const vstorage = [
[
// agd --node https://main.rpc.agoric.net:443 query vstorage data published.agoricNames.brand -o json | jq .value
'published.agoricNames.brand',
'{"blockHeight":"7709173","values":["{\\"body\\":\\"[[\\\\\\"BLD\\\\\\",{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: BLD brand\\\\\\",\\\\\\"index\\\\\\":0}],[\\\\\\"IST\\\\\\",{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: IST brand\\\\\\",\\\\\\"index\\\\\\":1}],[\\\\\\"USDC_axl\\\\\\",{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: USDC_axl brand\\\\\\",\\\\\\"index\\\\\\":2}],[\\\\\\"USDC_grv\\\\\\",{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: USDC_grv brand\\\\\\",\\\\\\"index\\\\\\":3}],[\\\\\\"USDT_axl\\\\\\",{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: USDT_axl brand\\\\\\",\\\\\\"index\\\\\\":4}],[\\\\\\"USDT_grv\\\\\\",{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: USDT_grv brand\\\\\\",\\\\\\"index\\\\\\":5}],[\\\\\\"DAI_axl\\\\\\",{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: DAI_axl brand\\\\\\",\\\\\\"index\\\\\\":6}],[\\\\\\"DAI_grv\\\\\\",{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: DAI_grv brand\\\\\\",\\\\\\"index\\\\\\":7}]]\\",\\"slots\\":[\\"board04312\\",\\"board02314\\",\\"board0223\\",\\"board0566\\",\\"board0188\\",\\"board02810\\",\\"board02656\\",\\"board06458\\"]}"]}',
],
[
'published.psm.IST.USDC_axl.governance',
'{"blockHeight":"9004077","values":["{\\"body\\":\\"{\\\\\\"current\\\\\\":{\\\\\\"Electorate\\\\\\":{\\\\\\"type\\\\\\":\\\\\\"invitation\\\\\\",\\\\\\"value\\\\\\":{\\\\\\"brand\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: Zoe Invitation brand\\\\\\",\\\\\\"index\\\\\\":0},\\\\\\"value\\\\\\":[{\\\\\\"description\\\\\\":\\\\\\"questionPoser\\\\\\",\\\\\\"handle\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: InvitationHandle\\\\\\",\\\\\\"index\\\\\\":1},\\\\\\"installation\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: BundleInstallation\\\\\\",\\\\\\"index\\\\\\":2},\\\\\\"instance\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: InstanceHandle\\\\\\",\\\\\\"index\\\\\\":3}}]}},\\\\\\"GiveMintedFee\\\\\\":{\\\\\\"type\\\\\\":\\\\\\"ratio\\\\\\",\\\\\\"value\\\\\\":{\\\\\\"denominator\\\\\\":{\\\\\\"brand\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"iface\\\\\\":\\\\\\"Alleged: IST brand\\\\\\",\\\\\\"index\\\\\\":4},\\\\\\"value\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"bigint\\\\\\",\\\\\\"digits\\\\\\":\\\\\\"10000\\\\\\"}},\\\\\\"numerator\\\\\\":{\\\\\\"brand\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"index\\\\\\":4},\\\\\\"value\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"bigint\\\\\\",\\\\\\"digits\\\\\\":\\\\\\"0\\\\\\"}}}},\\\\\\"MintLimit\\\\\\":{\\\\\\"type\\\\\\":\\\\\\"amount\\\\\\",\\\\\\"value\\\\\\":{\\\\\\"brand\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"index\\\\\\":4},\\\\\\"value\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"bigint\\\\\\",\\\\\\"digits\\\\\\":\\\\\\"1000000000000\\\\\\"}}},\\\\\\"WantMintedFee\\\\\\":{\\\\\\"type\\\\\\":\\\\\\"ratio\\\\\\",\\\\\\"value\\\\\\":{\\\\\\"denominator\\\\\\":{\\\\\\"brand\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"index\\\\\\":4},\\\\\\"value\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"bigint\\\\\\",\\\\\\"digits\\\\\\":\\\\\\"10000\\\\\\"}},\\\\\\"numerator\\\\\\":{\\\\\\"brand\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"slot\\\\\\",\\\\\\"index\\\\\\":4},\\\\\\"value\\\\\\":{\\\\\\"@qclass\\\\\\":\\\\\\"bigint\\\\\\",\\\\\\"digits\\\\\\":\\\\\\"0\\\\\\"}}}}}}\\",\\"slots\\":[\\"board04016\\",\\"board00917\\",\\"board00218\\",\\"board0074\\",\\"board02314\\"]}"]}',
],

@gibson042
Copy link
Member

@dckc I'm also planning to use that shape (an array of [key: string, value: string] entries). But you do need a full subtree, right?

@dckc
Copy link
Member Author

dckc commented Apr 24, 2023

you do need a full subtree, right?

Yes; in particular, for published.wallet. But it's also convenient for published.psm.IST.

I'm not sure whether I need published.agoricNames or published.agoricNames.brand... that part of my prototype might not survive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cosmic-swingset package: cosmic-swingset enhancement New feature or request SwingSet package: SwingSet vaults_triage DO NOT USE
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants