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 StorageNode type #5945

Merged
merged 7 commits into from
Aug 17, 2022
Merged

refactor StorageNode type #5945

merged 7 commits into from
Aug 17, 2022

Conversation

turadg
Copy link
Member

@turadg turadg commented Aug 12, 2022

Description

We have ChainStorageNode and StorageNode but it seems the latter is sufficient. The only difference is the former has clearValue, which is the same as setValue(undefined).

This removes clearValue and replaces ChainStorageNode with StorageNode.

It also renames the makeStorageNode function to distinguish its use case (making a child) and makes childName required.

Security Considerations

--

Documentation Considerations

--

Testing Considerations

CI

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

I like the overall direction, but would prefer to keep the ChainStorageNode type rather than StorageNode (to indicate the dependency upon chain storage semantics).

Also, since you're doing this, how about moving the type definition from packages/notifier/src/types.js to a more logical home, and also providing a definition of what instances of the type represent (e.g., "a node in a hierarchical externally-reachable storage structure that identifies children by restricted ASCII name and is associated with arbitrary string-valued data defaulting to the empty string")?

* @returns {Promise<StorageNode>}
*/
export async function makeStorageNode(chainStorage, childName) {
export async function makeStorageNodeChild(chainStorage, childName) {
Copy link
Member

Choose a reason for hiding this comment

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

I support this rename, and would recommend taking it farther:

Suggested change
export async function makeStorageNodeChild(chainStorage, childName) {
export async function makeStorageNodeChild(storageNode, childName) {

Comment on lines 71 to 75
clearValue() {
handleStorageMessage({ key: path, method: 'set' });
},
Copy link
Member

Choose a reason for hiding this comment

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

This is a hard pill to swallow because there ought to be a conceptual difference between "set to empty" vs. "unset", but factually that is not the case in vstorage.go. So I do not object.

@@ -68,7 +75,7 @@ test('makeChainStorageRoot', async t => {
);
}

rootNode.clearValue();
rootNode.setValue(undefined);
Copy link
Member

Choose a reason for hiding this comment

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

This call is invalid.

Suggested change
rootNode.setValue(undefined);
rootNode.setValue('');

@@ -172,22 +173,22 @@ test('makeChainStorageRoot', async t => {
'level-skipping setValue message',
);

childNode.clearValue();
childNode.setValue(undefined);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
childNode.setValue(undefined);
childNode.setValue('');

);
deepNode.clearValue();
deepNode.setValue(undefined);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
deepNode.setValue(undefined);
deepNode.setValue('');

);
childNode.clearValue();
childNode.setValue(undefined);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
childNode.setValue(undefined);
childNode.setValue('');

@turadg turadg force-pushed the ta/storageNode-cleanup branch from 86e7bfd to 48754ea Compare August 12, 2022 23:50
@turadg turadg requested a review from dtribble as a code owner August 12, 2022 23:50
Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

Thanks!

*
* Vstorage is a hierarchical externally-reachable storage structure that
* identifies children by restricted ASCII name and is associated with arbitrary
* string-valued data defaulting to the empty string.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* string-valued data defaulting to the empty string.
* string-valued data for each node, defaulting to the empty string.

getStoreKey() {
return handleStorageMessage({ key: path, method: 'getStoreKey' });
},
getChildNode(name) {
/** @type {(name: string) => VStorageNode} */
makeChildNode(name) {
Copy link
Member

Choose a reason for hiding this comment

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

In Agoric conventions that I learned in the past few weeks, I think the most appropriate name for this method is provideChildNode ("provide" referring to operations that return a value after creating it if necessary, acknowledging that it might have already existed).

And likewise for makeStorageNodeChild.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think with provide you get the same object on repeated requests. The two methods you suggest renaming actually call makeChainStorageNode which always makes a fresh node. Changing that is out of scope but I can follow up to do that. WDYT @michaelfig ?

@turadg
Copy link
Member Author

turadg commented Aug 15, 2022

I just noticed

export const pathPrefixToConverters = harden({
'swingset:': swingsetPathToCastingSpec,
'vstore:': vstoragePathToCastingSpec,
':': DEFAULT_PATH_CONVERTER,
});
and now I'm not so sure about removing StorageNode.

@michaelfig are there meant to be more than one backing of StorageNode? How do swingset and vstore relate? Is it that swingset is chain and vstore is off-chain?

@turadg turadg force-pushed the ta/storageNode-cleanup branch from 8e4cad2 to a656966 Compare August 15, 2022 20:51
@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Aug 15, 2022
@turadg turadg force-pushed the ta/storageNode-cleanup branch 5 times, most recently from 37430c8 to e1e196c Compare August 16, 2022 18:54
@turadg
Copy link
Member Author

turadg commented Aug 16, 2022

@Mergifyio unqueue

@turadg turadg removed the automerge:rebase Automatically rebase updates, then merge label Aug 16, 2022
@mergify
Copy link
Contributor

mergify bot commented Aug 16, 2022

unqueue

✅ The pull request has been removed from the queue

@mhofman
Copy link
Member

mhofman commented Aug 16, 2022

@Mergifyio queue

@mergify
Copy link
Contributor

mergify bot commented Aug 16, 2022

Sorry but I didn't understand the arguments of the command queue. Please consult the commands documentation 📚.

@mhofman
Copy link
Member

mhofman commented Aug 16, 2022

@Mergifyio refresh

@mergify
Copy link
Contributor

mergify bot commented Aug 16, 2022

refresh

✅ Pull request refreshed

@mhofman
Copy link
Member

mhofman commented Aug 16, 2022

@Mergifyio queue master

@mergify
Copy link
Contributor

mergify bot commented Aug 16, 2022

Sorry but I didn't understand the arguments of the command queue. Please consult the commands documentation 📚.

@mhofman mhofman added the automerge:rebase Automatically rebase updates, then merge label Aug 16, 2022
@turadg turadg force-pushed the ta/storageNode-cleanup branch from e1e196c to 7d56fa8 Compare August 16, 2022 20:33
@turadg turadg removed the automerge:rebase Automatically rebase updates, then merge label Aug 16, 2022
@turadg turadg force-pushed the ta/storageNode-cleanup branch from 7d56fa8 to a67d808 Compare August 16, 2022 23:33
@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Aug 17, 2022
@turadg turadg changed the title remove ChainStorageNode type refactor StorageNode type Aug 17, 2022
@mergify mergify bot merged commit c81ad73 into master Aug 17, 2022
@mergify mergify bot deleted the ta/storageNode-cleanup branch August 17, 2022 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants