Skip to content

WIP: p2panda Migration script#239

Draft
adzialocha wants to merge 16 commits into
adz/p2panda-high-level-apifrom
adz/migrate-documents
Draft

WIP: p2panda Migration script#239
adzialocha wants to merge 16 commits into
adz/p2panda-high-level-apifrom
adz/migrate-documents

Conversation

@adzialocha

@adzialocha adzialocha commented May 25, 2026

Copy link
Copy Markdown
Member

The gist is:

  1. Have a "Reflection protocol version", it's hard-coded somewhere
  2. Have a file where we keep that version as well. If it doesn't match the hard-coded version on startup we run some migration code
  3. After it has run we're updating the file with the latest version
  4. Each migration code is specific to whatever version transition we need

adzialocha added 16 commits May 22, 2026 18:55
This patch integrates the new `p2panda` crate into the "backend" of
Reflection.

`p2panda` is the new all-in-one high-level Node API which should make
usage of p2panda features easier, removing a bunch of code in
`reflection-node` which is now handled in p2panda directly, such as:

* Encoding / Decoding of operations and their message payloads
* Make sure changes to the append-only log are strictly serialized, to
  avoid breaking consistency / integrity of data due to race conditions
* Re-playing all operations on demand, this is required by Reflection to
  re-materialize all state for a document
* Manage header extensions to include log ids and prune flags
* Process local and remotely incoming operations ("ingest", "pruning")
* SQLite storage handling for logs and operations
* Mapping between logs and topics
* De-duplicate messages in ephemeral streams by adding timestamp
* Add public key / signatures to give provenance to ephemeral messages

Some features implemented in `reflection-node` stay as they're adding
functionality _on top_ of `p2panda`. Some of them might be moved there
as well in the future, such as:

* Author Presence: Indicate which authors have contributed to which
  topic and if they're currently online.
  Related issue: p2panda/p2panda#1002
* Persisted Topics: Store to persist all previously used topics

Unfortunately we need to remove one feature for now which is to change
"connection modes", causing the network to be disabled / enabled.
`reflection-node` handled that well in the past by only disabling the
networking layer while keeping the event processing layer intact. We
will have to do something similar in `p2panda` to offer this feature as
well since the new API surface will not allow such low-level access
anymore.

See related issue: p2panda/p2panda#1093

BREAKING CHANGES

These changes introduce breaking changes to the core operation format
(`previous` field was removed) and the header extensions changed which
means that all previously created, persisted operations will _not_ be
compatible anymore.

THIS RESULTS IN LOOSING ALL PREVIOUSLY CREATED DOCUMENTS.

Since `p2panda` is not stable yet this might happen again in the near
future, though this was the most important and largest update and we're
much closer to a stable API and protocol now.

Future SQLite files will be written to a new path, the network id has
also changed now. This prevents "old" nodes talking to "new" ones,
similarily we allow users to retreive old documents from the database.

Final remarks:

Some minor changes in `reflection-doc` where also necessary, I
specifically decided to make `p2panda-core` a concrete dependency there
since too much functionality is used to justify re-exports from
`reflection-node`.
This will assure that users have a chance to recover documents from past
Reflection versions and move them into this new version with a migration
script, etc.
This ensures that we're not able to sync with Reflection users of an
older version.
The new p2panda Node API brings timestamp out-of-the-box from ephemeral
streams, we don't need to provide them ourselves anymore.
There's more stream processing related errors we want to expose to -docs
from p2panda aka -node.

To avoid confusion around two SubscriptionError types I've renamed one
of them which was anyhow more "publishing" related.

I'm considering renaming more types in a subsequent patch to make the
PubSub relationship clearer.
Topic is used already all over the place in p2panda and indicates the
identifier of the topic itself (32 byte string). A stream on top of a
topic is a "topic stream", we can subscribe to it ("topic subscription")
and publish into it, following a PubSub pattern.

Reflection "enhances" these types with "tracking", that is, we know
which topics have been used and which authors are connected to it and
when they are online.

This hopefully clarifies the types a bit better and stays consistent
with naming in p2panda to avoid confusion:

Topic -> TrackedTopic
Author -> TrackedAuthor
Subscription -> TopicStream
SubscribableTopic -> TopicSubscription
@adzialocha adzialocha changed the title WIP: p2panda Migration WIP: p2panda Migration script May 25, 2026
@adzialocha adzialocha force-pushed the adz/p2panda-high-level-api branch 2 times, most recently from 4d52d54 to abfd6e2 Compare June 15, 2026 18:47
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.

1 participant