feat(shared): add the worldstate tree for world-scope state #29
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
scope/assets
scope/client
scope/networking
scope/renderer
scope/scripting
scope/server
scope/shared
scope/workspace
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Synvael/synvael!29
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/worldstate-tree"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What does this PR do?
I added the container for world-scope state: one
SYNW-framed file per domain underworldstate/, with the server code to load and save it. No domain ships yet, so nothing calls it.crates/shared/src/save/worldstate.rs: newDomain, a lowercase[a-z0-9_]file stem plus the format version of its payload. It has no public constructor.Domain::newis aconst fnthat asserts the name is non-empty, uses onlya-z,0-9and_, and is not a Windows reserved device name (con,nul,com1and the like), so a malformed declaration stops the build.DOMAINSis the empty list of engine domains, and tests declareTEST_DOMAINundercfg(test).encodeanddecode, generic over aserdepayload. The framing mirrors the player record (magicSYNW, the domain'su32version, flags, two lengths, zstd postcard payload), with the version taken from the domain rather than a shared constant.decoderefuses a wrong magic (BadMagic), any version other than the domain's (UnsupportedVersion), an uncompressed length over 64 MiB (DeclaredLengthTooLarge), a length that disagrees with the header, and bytes after the payload.encoderefuses a payloaddecodewould reject, so a save that succeeds can be read back.MAX_RECORD_LENis the largest filedecodecan accept.crates/shared/src/save/error.rs: newSaveError::TrailingBytes.crates/shared/src/paths.rs: the publicworldstate_diris gone.worldstate_path(world, &Domain)andworldstate_path_in(world_dir, &Domain)are the only resolvers, so nothing outsidepaths.rscan name another file underworldstate/.crates/server/src/save/worldstate_file.rs:loadreturns the payload'sDefaultwhen the domain file is absent, and an error when it exists but does not decode, leaving the file untouched. It reads at mostMAX_RECORD_LENbytes.savewrites through the existingatomic_write. Both carry adead_codeexpectation with its reason, since no caller exists yet.crates/server/Cargo.toml: the server now depends onserde, already a workspace dependency.sharedgains none.docs/save_format.md: theworldstate/layout, its three properties, and the record limit under "Decoding untrusted records".Why is this change necessary?
State that belongs to the world as a whole and grows with play, such as corruption zones, structure instances and settlement timestamps, has no home today and does not belong in
level.dat. I wanted the container and its ownership rule in place before the first system that needs one, so that system does not set the layout for the rest.It has three properties. A missing domain file loads as the domain's empty value, and only absence is empty: a decode error is never turned into a default, because the next save would then overwrite state that may still be recoverable. Each domain refuses any version other than its own with
UnsupportedVersion, as ADR-0015 requires. And no code can obtain aworldstate/path except through a declared domain.Scope of Changes
server, shared, workspace
Testing
Automated, run on this branch:
cargo fmt --all -- --check: clean.cargo clippy --workspace --exclude renderer --exclude client --all-targets --all-features -- -D warnings: clean.cargo test --workspace --exclude renderer --exclude client --all-features --profile ci: all suites passed, 0 failed (net48,scripting25,server116,shared377). One server test,a_block_the_base_game_does_not_register_stays_an_orphaninlevel_file.rs, failed once under parallel load. This branch does not touch that file. It passes alone and on the base branch, and the full run passed three more times.rendererandclientwere excluded because they cannot be built on the machine I ran this on (ninjais missing). This branch does not touch either crate.The new tests cover a record round trip, and decode refusing a wrong magic, another version, an oversized declared length, a truncated record and trailing bytes. They also cover encode refusing an oversized payload, domain names (including the reserved Windows names), the path resolvers, an absent file loading as the default, and a corrupt file being an error that leaves the file untouched.
Manual: none. No domain ships, so there is nothing to exercise in a running game.
Additional Context
Stacks on #24 (feat/entity-chunk-lifecycle); review that one first.
feat/entity-chunk-lifecycle, which is an open pull request. Until that one merges, this diff againstdevalso shows its commits. The changes belonging to this PR are the twelve commits after it.worldstate_dirfrompaths.rs. Nothing else in the workspace called it.level.rsstays untouched.world_format_versionis not designed yet and is out of scope here.Related Issues
None.
Checklist
dev(or a feature branch offdev) and my PR targetsdev.///doc comments for Rust) where necessary.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.