fix(moss): persist node identity (v0.2.2)#8
Merged
Conversation
The Moss node's libp2p transport identity was regenerated on every launch: moss-ffi delegates identity load/save to host keystore callbacks, but mosh never registered them (Moss_SetKeyStore was listed as a required symbol yet never called), so resolveIdentity() minted a fresh random identity each start. After a restart our peer-id changed, a connected peer kept the stale entry, and the connection flapped (rapid peer_joined/peer_left) instead of re-establishing. Wire a MossKeyStore trait backed by the encrypted redb store (new moss_identity table, AES-256-GCM like everything else), register it and call install_keystore once in PrivateDmState::ready before any node starts. The identity is now stable across restarts. Falls back to an ephemeral identity in in-memory mode. Tests: persistence round-trip for the identity row, and the probe-then-copy keystore callback protocol against a mock store.
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.
Bug
After restart, peers flap (
peer_joined/peer_leftrepeatedly) and the connection never establishes.Root cause
moss-ffi delegates its node identity load/save to host keystore callbacks (
Moss_SetKeyStore). mosh listed the symbol as required but never called it, so moss's load/save pointers stayed nil andresolveIdentity()minted a fresh random libp2p identity on every launch. After a restart our peer-id changed; the remote kept the stale entry → connection churn.Fix
MossKeyStoretrait backed by the encrypted redb store (moss_identitytable, AES-256-GCM + keychain DEK).extern "C"load/save callbacks (probe-then-copy protocol) +install_keystore()bound toMoss_SetKeyStore.PrivateDmState::readybefore any node starts (incl. rehydrate). Ephemeral fallback in in-memory mode.Tests
persistence::moss_identity_round_tripsmoss_ffi::keystore_callbacks_round_trip_identity(probe/buffer protocol vs mock store)Local: fmt ✓ · clippy
-D warnings✓ · nextest 64 passed (1 unrelated flaky recovered), 0 failed.🤖 Generated with Claude Code