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

refactor(run-protocol): vaultDirector to multifacted vobj #5116

Merged
merged 4 commits into from
Apr 19, 2022

Conversation

turadg
Copy link
Member

@turadg turadg commented Apr 14, 2022

closes: #4345

Description

Turns the new vaultDirector into a virtual object.

Security Considerations

State storage to to disk.

Documentation Considerations

--

Testing Considerations

Refactor so it maintains existing tests AMAP, though I did run into a test bug I fixed in 75e3e7

It took me too long to figure out 1c87554 so I think we need more test coverage or some static type validation of what is returned by facets. The problem wasn't detected in unit tests, only integration tests, and was much harder to debug there.

!collateralTypes.has(collateralBrand),
`Collateral brand ${collateralBrand} has already been added`,
);
// TODO put on machineFacet for use again in publicFacet
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I went with is defining this at top scope so it can be shared.

thoughts on that vs giving it a primary facet and letting another reexport?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both approaches seem fine where appropriate. This seems sufficient for this use. I can think of other places where we might want a facet. (I'm considering that for the AMM's singlePool, but that has more justification to be a facet.)

};

/** @type {import('@agoric/vat-data/src/types').FunctionsPlusContext<VaultFactory>} */
const machineBehavior = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the functions within this behavior could be at module-scope. That's how @FUDCo had in the initial defineKind-ization of vault.js. I propose a style of defining behavior objects with the methods inlined so it's easier to navigate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had originally had the behavior functions in vault.js at module scope simply because it was the most similar to what had been there before. @turadg asked me to rewrite them to be inline and I think I like the inline style better in that case. I don't know how it translates to this file however.

mintAndReallocate,
burnDebt,
});
const factoryPowers = Far('vault factory powers', {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will defining a far per vault manager pose any problems for durability @FUDCo ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On general principles it should not be a problem, but the key question is: will you be able to reconstruct the Far from the durable state after resurrection? (I can't discern the answer to that myself that without digging into this code considerably beyond my feeble understanding of what it's doing.) If you can, then it should be no problem; you just need to make sure your startup flow actually does it. Otherwise you'll either need to (a) capture more info in the durable part so that you can reconstruct it or (b) make it durable itself. I don't have an opinion which is more right, as it would depend on the particulars, other than the general advice to take whichever course causes you the least pain.


const machineFacet = Far('vaultFactory machine', machineBehavior);
// XXX accessors for tests
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once we have a way to instantiate a vobj from a state fixture, we don't need these methods. we can just inspect the state after the operations.

@turadg turadg force-pushed the 4345-virtualize-vaultDirector branch from 8305d29 to 1c87554 Compare April 16, 2022 14:41
@turadg turadg marked this pull request as ready for review April 16, 2022 15:22
@turadg turadg requested a review from dtribble as a code owner April 16, 2022 15:22
@turadg turadg force-pushed the 4345-virtualize-vaultDirector branch from 1c87554 to 756e7f2 Compare April 18, 2022 20:32
@turadg turadg force-pushed the 4345-virtualize-vaultDirector branch from 756e7f2 to 90ad0e9 Compare April 19, 2022 22:18
!collateralTypes.has(collateralBrand),
`Collateral brand ${collateralBrand} has already been added`,
);
// TODO put on machineFacet for use again in publicFacet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both approaches seem fine where appropriate. This seems sufficient for this use. I can think of other places where we might want a facet. (I'm considering that for the AMM's singlePool, but that has more justification to be a facet.)

@turadg turadg added the automerge:squash Automatically squash merge label Apr 19, 2022
@mergify mergify bot merged commit 1842a73 into master Apr 19, 2022
@mergify mergify bot deleted the 4345-virtualize-vaultDirector branch April 19, 2022 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:squash Automatically squash merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Virtual Objects in Vaults
3 participants