Repository navigation
Prune dangling alias - #175
chm-diederichs wants to merge 4 commits into
Conversation
f8e8508 to
27b1f96
Compare
lejeunerenard
left a comment
There was a problem hiding this comment.
Concerned about deleting database entries as part of loading a core.
Also noting this depends on:
| // the core was deleted underneath the alias, drop it so the name mints fresh | ||
| await this.storage.deleteAlias(alias, discoveryKey) | ||
| return null |
There was a problem hiding this comment.
I understand that this is a fix for past dangling core aliases, but its weird to delete as part of reading / opening a core, right?
| dangling && !dryRun ? await store.storage.deleteAlias(alias, discoveryKey) : false | ||
|
|
||
| yield { discoveryKey, alias, dangling, pruned } | ||
| } |
There was a problem hiding this comment.
Deleting the dangling alias in audit is great! Also love the dryRun usage.
Should the yielded value be inconsistent though? I think it could be refactored to be a composite of different types of audits via a type field and maybe an audit so it matches the audit from the first type above, and then return alias, dangling and pruned together as the audit. This could then allow the type of audits to expand over time, but allow discriminating based on type.
Aka the return type would be something like:
{
discoveryKey: Buffer,
key: Buffer,
type: 'core-audit',
audit: ReturnType<typeof core.audit>
} | {
discoveryKey: Buffer,
key: Buffer,
type: 'alias-audit',
audit: { dangling: Boolean, alias: Buffer, pruned: Boolean }
}aka a tagged union type.
Currently code that assumes audit existing will fail.
| // an alias row whose core is gone, as left behind by storages that deleted | ||
| // cores without their alias | ||
| const dangling = crypto.discoveryKey(crypto.keyPair().publicKey) | ||
| const getAlias = store.storage.getAlias.bind(store.storage) | ||
| store.storage.getAlias = (alias) => (alias.name === 'bee' ? dangling : getAlias(alias)) |
There was a problem hiding this comment.
I'd rather injectDanglingAlias() this instead of monkey patching it to return a made up key.
| function injectDanglingAlias(store, name) { | ||
| const discoveryKey = crypto.discoveryKey(crypto.keyPair().publicKey) | ||
| const createAliasStream = store.storage.createAliasStream.bind(store.storage) | ||
| store.storage.createAliasStream = async function* (namespace) { | ||
| yield* createAliasStream(namespace) | ||
| yield { alias: { name, namespace: store.ns }, discoveryKey } | ||
| } | ||
| return discoveryKey | ||
| } |
There was a problem hiding this comment.
This should add an actual dangling alias instead of monkey patching to pretend there is one.
There was a problem hiding this comment.
nit: Helpers should be at the bottom of the file if not nested in the test case. If it doesn't get used above and it's only used below, maybe it should be nested in the test case? Otherwise the bottom of the file is preferable.
| store.storage.deleteAlias = (alias) => { | ||
| deleted.push(alias.name) | ||
| return Promise.resolve(true) | ||
| } |
There was a problem hiding this comment.
Don't, think this needs monkey patching. It can list the aliases afterwards and verify they where deleted instead.
No description provided.