feat: EntityStore#23989
Open
mverzilli wants to merge 5 commits into
Open
Conversation
Stores immutable facts about entities keyed by (contract, scope, entity type, entity id), with per-job staged writes flushed atomically on commit. Facts and entities carry an optional block anchor: anchored (retractable) records are deleted when their block is pruned, while unanchored ones survive reorgs as external inputs. Wired into openPxeStores with schema backwards-compatibility coverage.
The block synchronizer rolls the entity store back alongside the note and private event stores when the chain is pruned: entities and facts anchored to orphaned blocks are deleted, unanchored ones survive. EntityStore is registered with the job coordinator so staged facts flush atomically with the other stores on job commit.
Rewrite the chain-pruned entity store test in neutral terms (no offchain-message vocabulary) and extend it to cover entity-level retraction: a retractable entity anchored on the abandoned fork is deleted wholesale including its unanchored fact, while a non-retractable entity survives losing only its anchored fact.
'Anchor' is already taken by the PXE anchor block concept; the block a retractable entity or fact is tied to is now its 'origin block' (FactAnchor -> OriginBlock, anchor -> originBlock). No serialization change: the buffer layout carries no field names, so the stored format and compatibility snapshots are untouched.
stored_fact.ts held both record classes. Give each its own file (stored_fact.ts, stored_entity.ts) with a matching test file, and move the shared primitives they both depend on -- the OriginBlock type, the EntityCoords type, and the scope/entity key derivation -- into a new entity_keys.ts so neither class file imports the other. factRowKeyOf stays with StoredFact as it is fact-specific.
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.
A new store in PXE DB. It's designed to provide generic, persistent, reorg resilient storage to contract developers.
It stores write-only Entities, and each Entity stores 0..N write-only Facts.
An entity is an opaque body with a type, a unique id, isolated to a contract address and scope.
A fact has an opaque body, a type, and belongs to an entity.
Both can be retractable or non-retractable. They are retractable when they are associated to an origin block. They are non-retractable when they are not associated to an origin block.
A retractable entity is transparently made unavailable by PXE when its origin block drops out of the chain. In that case all its facts (retractable or not), are gone with it.
A retractable fact is transparently removed from an entity by PXE when its origin block drops out of the chain. Sibling facts (non-retractable or retractable on a different origin block) remain untouched.
Entities can (and should) be terminated at some point in their lifecycle, to avoid unbounded storage and processing.