WIP: feat(net): send the world's block table in the handshake ack #31
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!31
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/block-table-handshake"
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?
This PR stacks on
feat/level-v7, which has its own pull request. The diff is against that branch, so it should be reviewed after it. It targetsdevonce that pull request merges.Chunk payloads carry raw
BlockIdhandles and handles are bound per world, so the same block can hold different handles in two worlds. The client never loaded block data, so it could not tell which block a handle named. I made the server send the world's block table in the handshake acknowledgement and made the client bind its own registry against it.HandshakeAckincrates/shared/src/protocol/control.rsgainsblock_ids: Vec<ContentId>, the world'sblock_idsin handle order.PROTOCOL_VERSIONgoes from 5 to 6.MAX_BLOCK_TABLE_LEN(2048 entries),MAX_BLOCK_TABLE_ID_LEN(128 bytes per id) andMAX_BLOCK_TABLE_BYTES(60 KiB counting each id with its wire length prefix). The decoder checks the declared count before reading entries and each id's length before building its string.check_block_tableapplies the same bounds and shares one size function with the decoder.NetworkServer::spawnincrates/net/src/runtime.rstakes the table, and every session's acknowledgement carries it.check_ack_fitsincrates/net/src/handshake.rschecks the table and the whole encoded acknowledgement againstMAX_CONTROL_FRAME_LENbefore any thread or socket exists, so a world that cannot be served fails once at startup.NetErrorgainsBlockTableandAckTooLarge.RegistryBuilder::bind_receivedandbind_received_blocksincrates/shared/src/registry.rsbind against a received table without appending. A block the client registers that the table lacks is aRegistryError, which means the packs differ. A table entry the client does not register is an orphan and resolves as air, as a chunk load does on the server.syn:airmust be at index 0; the check moved intocheck_air_first, whichlevel.datbinding now uses too.scripting::load_datano longer skipsdata/for a client VM, so the client loads the base game's blocks throughload_base_game. No second registration path exists.crates/client/src/blocks.rs(bind_world_blocks) loads the base game and binds it against the received table.App::accept_ackincrates/client/src/main.rscalls it when the handshake completes, hands the bound registry tobind_blocksinchunks.rs, and logs the table length and the registered count. A table the client cannot bind refuses the join and drops the link.crates/server/src/main.rspassesmetadata.block_ids()to the network server through a smallspawn_networkhelper.docs/networking.mddescribes the table, its bounds and the client binding.docs/scripting.mdnow says a client VM loads pack data too.Chunk payloads and their tests are unchanged. Nothing renders differently yet.
Why is this change necessary?
A handle in a chunk payload only means something relative to the world's block table. Without the table the client cannot map a handle to a block, so it draws every face the same colour, and anything that needs to know what a block is (textures, client-side solidity for prediction) has nothing to build on. Sending the table once in the acknowledgement keeps chunk payloads as they are and lets the client resolve every handle the server uses.
Binding without appending matters here. Reusing the server-side
bindwould let a client silently extend its copy of the table, and nothing would look wrong until two clients disagreed on a handle.Scope of Changes
client, server, networking, shared, scripting, workspace
Testing
Automated, run from the worktree on
feat/block-table-handshakeatad2afa0:cargo check -p shared -p net -p client -p server -p scripting: passed.cargo test -p shared -p net -p client -p scripting -p server: passed (shared 384, net 55, client 83, scripting 26, server 111, no failures).cargo clippy --all-targets --all-features -- -D warnings: passed.cargo fmt --all -- --check: passed.New tests cover the decode bounds (entry count, id length, the byte budget on both sides of the 127 and 128 byte boundaries, and agreement between the decoder and
check_block_table), the server refusing a table or acknowledgement that cannot be sent,bind_receivednever appending, a client-only block refusing the bind, an orphan resolving as air, a table whose index 0 is notsyn:airbeing refused, and a loopback handshake test incrates/net/src/tests/runtime.rsthat compares the server's and the client's bound registries at every handle.One run of the server tests failed
a_block_the_base_game_does_not_register_stays_an_orphanwhile the five crates ran together. It passed in isolation and on three further runs. The test and the code it covers are not in this branch's diff.Manual verification: TODO for the maintainer. Start the server and the client, join, and confirm the client log reports a bound block table of the same length as the server's
block_ids. I have not done this.Additional Context
Stacks on #30 (feat/level-v7); review that one first.
PROTOCOL_VERSIONgoes from 5 to 6, so a version 5 client or server is refused at the handshake.assets/relative to the working directory, as the server does.build_ack. Until it lands, a client whose packs differ from the server's finds out when the bind fails, and the join is refused with a local error.Related Issues
None.
Checklist
dev(or a feature branch offdev) and my PR targetsdev. (This branch is stacked onfeat/level-v7, so the pull request targetsdevafter that pull request merges.)///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.