fix(backend): keep a beacon's identity across restarts - #4
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #3 — targets
fix/discovery-crash, so this diff stays to the twofiles it actually changes. Retarget to
mainonce #3 lands.What changes
getStorageDir()suffixed the corestore path withprocess.pid:A beacon's identity is the key of its hypercore, and that hypercore lives in
the corestore. A fresh directory per run meant a shop came back as a
different peer every time it restarted, and every run left a dead corestore
directory behind.
Now the storage root is stable, and
bin.mjspasses the--storagevalue theCLI already accepted — the backend used to ignore it entirely.
Opening a Corestore also moved out of module load and into the first
scan()or
beacon()call, which is what lets the caller pick the root.Running two peers on one machine
That is what the pid suffix bought, and it is the normal way to test this app,
so it still works — via the flag that already existed:
Without it, the second instance now hits Corestore's directory lock. That used
to surface as an unhandled rejection out of rocksdb:
It now says what to do:
Beacon._init()was an uncaught async call in the constructor, so any failurethere became an unhandled rejection. It rejects into an
'error'event now,and
bin.mjslistens — an EventEmitter with no'error'listener throws onemit.
Verified
ID: 9cc02f51e01dthe same id,
9cc02f51e01d. Before this change it came back as adifferent peer.
--storagestill discover each other--storageprints the one-line message, exit 1,no stack trace
pnpm run lint— exit 0pnpm test— 4/4 tests, 5/5 assertsNote
The frontend is untouched.
startTravelerPanel/startBeaconPanelcallbackendFn()with no arguments, so the storage root is bound inbin.mjswhere those callables are built.