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
Daemon: identify based lookup #2051
base: master
Are you sure you want to change the base?
Conversation
de067fa
to
06d96c8
Compare
73ddc6d
to
7f0acf8
Compare
There are pet name path utilities in |
while this approach can yield some potential optimization, the shortcut needs to be implemented per formula type with hosts/guests being the only candidates at present. It's not clear that this optimization is worth the limitation that lookup values must have a formulaId. This limitation might be avoidable by replacing other design considerations: one interesting finding of identify based lookup via direct lookup is the ability for redirects when crossing multiple network boundaries. If an identifier includes a location (eg network address) for the resource, you can establish a direct connection for accessing the resource, where as direct lookup would have to be proxied across each network boundary. though, this should also supposedly be fixed by captp level handoffs. delegated and resolve both allow multiple path parts to be consumed in one step where possible. this is seen in this implementation for inspector.identify for eval record endowments. For the example path imagine a DNS naming hub in conclusion, it was very interesting to learn the complexity of the design space for something as seemingly simple as path lookups 🤠. I have no idea how common long complicated paths will be, but the insights here may inform other aspects of the system design. |
export const identify = async ({ cancel, cancelled, sockPath, namePath }) => | ||
withEndoBootstrap({ os, process }, async ({ bootstrap }) => { | ||
const defaultHostFormulaIdentifier = 'host'; | ||
const formulaId = await E(bootstrap).identifyFrom( | ||
defaultHostFormulaIdentifier, | ||
namePath, | ||
); | ||
console.log(formulaId); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very close to what I imagined and a step in the right direction.
High level:
- We need an API and a command that can reveal the formula type. I had envisioned that
endo identify
would do that, but perhaps that should have a name likedescribe
. I thinkendo describe
should also be able to print the nonce/swissnum/identifier likeendo describe --id <name>
- Whatever API and command reveals the nonce/swissnum/identifier for a pet name path should probably be producing a URL so maybe that should be called
endo locate <pet-name-path>
and produce the URL by default, including the connection hints for the listening networks. Maybeendo locate --json <path>
gives you the JSON representation. Maybeendo locate --id <path>
trims that back to just the nonce. - Maybe
locate
anddescribe
are the same command or two commands with the same behavior but different defaults.
Nits:
- Let’s get rid of
cancel
,cancelled
, andsockPath
here and where this refactor-cruft was copied from. host
is not a formula identifier anymore. We should always start looking stuff up atE(bootstrap).host()
.- If we move some functions from the endo bootstrap object to host objects, maybe we can just present the primary host facet as the bootstrap object.
- Maybe we should use
process.stdout.write(`${id}\n`)
instead ofconsole.log
just to break the bad habit of confusing the debugger for an output printer. ymmv.
export const show = async ({ cancel, cancelled, sockPath, namePath }) => | ||
withEndoBootstrap({ os, process }, async ({ bootstrap }) => { | ||
const defaultHostFormulaIdentifier = 'host'; | ||
const pet = await E(bootstrap).lookupFrom( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. In my head, lookupFrom
is equivalent to E(E(host).locate(identifier)).lookup(path)
but consolidated. The consolidation might be important since we might want to locate and lookup locally in a single event.
I think we should move the method to Host in order to stay one step away from folding the Endo Bootstrap object into Host objects. They are equally powerful since you can’t get one without the other and there’s little reason to keep them separate.
I’m not attached to the locate(nonce) ~=> identifier
function name, and I think I at least temporarily need the name of this method to be explicitly lookupFromFormulaNumber
, with goal of reducing that to lookupFromIdentifier
when we no longer need to distinguish formula identifier with type from formula number.
const petStore = await provideValueForFormulaIdentifier( | ||
storeFormulaIdentifier, | ||
); | ||
const result = await E(petStore).identify(namePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should definitely rename petStore.locate
to petStore.identify
as this suggests. It should be synchronous, though.
storeFormulaIdentifier = `pet-store-id512:${formulaNumber}`; | ||
} | ||
// eslint-disable-next-line no-use-before-define | ||
const petStore = await provideValueForFormulaIdentifier( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can’t make this synchronous!
const origin = await provideValueForFormulaIdentifier( | ||
originFormulaIdentifier, | ||
); | ||
return E(origin).identify(namePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this is async tail recursive and has to at least reïfy pet stores (an unavoidably async operation), I withdraw my hope that identify
can even be locally synchronous or transactional.
Given that it can’t be synchronous, there’s no reason to bundle up locate(identifier)~.lookup(path)
. They can be peanut and butter: two separate methods that are better together.
]; | ||
|
||
const allowedInspectorFormulaIdentificationsByType = { | ||
eval: ['endowments', 'worker'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure that inspectors generalize this well. endowments
is an array of identifiers and we want the corresponding values, whereas worker
is a single identifier. This does not mention source
which is just a string.
In short, I think we should have a boring identify function for each formula type rather than a generalization because it will be more legible and easier to debug.
const { type: formulaType, number: formulaNumber } = | ||
parseFormulaIdentifier(entryFormulaIdentifier); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the time we get here, we may have removed the type from the formula identifier, but it can be trivially recovered from the controller object for the number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we have a formula for every formula identifier (just the number), it might make sense to just generally store that on the controller too, so we benefit from the memo and avoid redundant reads from the formula store.
@@ -170,7 +171,7 @@ export const makeHostMaker = ({ | |||
* @param {string | 'NONE' | 'SELF' | 'ENDO'} partyName | |||
*/ | |||
const providePowersFormulaIdentifier = async partyName => { | |||
let guestFormulaIdentifier = lookupFormulaIdentifierForName(partyName); | |||
let guestFormulaIdentifier = identifyLocal(partyName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like abbreviating lookupFormulaIdentifierForName
to identifyLocal
generally. That could be one easy-to-review mechanical refactor on its own.
Since the difference between identify
and identifyLocal
is more like identifyPetNamePath
vs identifyPetName
respectively, I could buy identify
(implied pet name path since it’s public API) and identifyName
instead.
/** @type {import('./types.js').IdentifyFn} */ | ||
const identify = async maybeNamePath => { | ||
const namePath = Array.isArray(maybeNamePath) | ||
? maybeNamePath | ||
: [maybeNamePath]; | ||
const [headName, ...namePathRest] = namePath; | ||
const formulaIdentifier = identifyLocal(headName); | ||
if (formulaIdentifier === undefined) { | ||
return undefined; | ||
} else { | ||
return identifyFrom(formulaIdentifier, namePathRest); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No notes.
/** @type {import('./types.js').IdentifyFn} */ | ||
const identify = async maybeNamePath => { | ||
const namePath = Array.isArray(maybeNamePath) | ||
? maybeNamePath | ||
: [maybeNamePath]; | ||
const [headName, ...namePathRest] = namePath; | ||
const formulaIdentifier = identifyLocal(headName); | ||
if (formulaIdentifier === undefined) { | ||
return undefined; | ||
} else { | ||
return identifyFrom(formulaIdentifier, namePathRest); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think this should exist at this level of abstraction but we should factor out an intermediate layer for name hubs between mail and pet store whenever we introduce directories.
identify
takes apetName or namePath
and returns aformulaIdentifier
lookup
can mostly* be built on top ofidentify
.by taking advantage of these two facts, you can potentially reify a smaller subgraph in order to facilitate a
lookup
.here is an example setup with a long lookup path
From this log you can see that in order to perform lookup of
a.b.c.d
it only had to reify:without the hist short-cutting optimization, we get the following log:
From this log you can see that in order to perform lookup of
a.b.c.d
it only had to reify:layering: