Skip to content

Prune dangling alias - #175

Open
chm-diederichs wants to merge 4 commits into
mainfrom
prune-dangling-alias
Open

chm-diederichs wants to merge 4 commits into
mainfrom
prune-dangling-alias

Conversation

@chm-diederichs

Copy link
Copy Markdown
Contributor

No description provided.

@chm-diederichs
chm-diederichs requested a review from a team October 7, 2026 09:39

@lejeunerenard lejeunerenard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concerned about deleting database entries as part of loading a core.

Also noting this depends on:

Comment thread index.js Outdated
Comment on lines +656 to +658
// the core was deleted underneath the alias, drop it so the name mints fresh
await this.storage.deleteAlias(alias, discoveryKey)
return null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread lib/audit.js
dangling && !dryRun ? await store.storage.deleteAlias(alias, discoveryKey) : false

yield { discoveryKey, alias, dangling, pruned }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread test/alias.js
Comment on lines +13 to +17
// 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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rather injectDanglingAlias() this instead of monkey patching it to return a made up key.

Comment thread test/alias.js
Comment on lines +42 to +50
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should add an actual dangling alias instead of monkey patching to pretend there is one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread test/alias.js
Comment on lines +61 to +64
store.storage.deleteAlias = (alias) => {
deleted.push(alias.name)
return Promise.resolve(true)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't, think this needs monkey patching. It can list the aliases afterwards and verify they where deleted instead.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants