[PR #4946] [MERGED] Far terrain from a server (2/3): serve horizon:lod tiles #5962

Closed
opened 2026-11-03 05:16:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4946
Author: @ludovic111
Created: 10/31/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: server-asks/lod-server


📝 Commits (6)

  • 557f0da Far terrain from a server: serve horizon:lod tiles
  • 4b7fc5c Far terrain server: replies on the game thread, charged refusals, caught panics
  • 618660d Far terrain server: an unreadable request takes a token too, as the doc says
  • 71245c0 Merge origin/main into the far terrain server branch
  • 8e6281b Merge #4945 (main merged) into #4946
  • 6ee16d8 Merge #4945 (main merged) into #4946

📊 Changes

9 files changed (+512 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/dedicated.rs (+3 -0)
📝 crates/horizon-client/src/game/lan.rs (+7 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+3 -0)
➕ crates/horizon-client/src/game/lan_far.rs (+79 -0)
📝 crates/horizon-client/src/lan/conn.rs (+10 -0)
📝 crates/horizon-client/src/lan/mod.rs (+5 -0)
📝 crates/horizon-client/src/lod_net.rs (+3 -0)
➕ crates/horizon-client/src/lod_net/server.rs (+401 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What and why

Part 2 of 3 of far terrain on servers, on top of #4945. A dedicated server or a LAN world now offers far terrain to Horizon clients and serves their tile requests. Clients don't ask for it yet: that's part 3, so players see no change from this PR alone.

  • Offer: during configuration, only to clients whose minecraft:brand is horizon (lan/conn.rs, next to the quiet-commands offer). A vanilla client hears nothing.
  • Distance: NetConfig.lod_distance. A dedicated server reads it from horizon-lod-distance in server.properties, a Horizon-only key that server.toml sets under [properties]. Off (0) by default, 1024 at most; with 0 there is no offer and no service. A LAN world uses the default too.
  • Only offered clients: requests from a guest whose brand isn't horizon are dropped, the same check the offer is gated on.
  • Per player, so it can't be used to overload the server (lod_net/server.rs Service::request):
    • every request takes a token (64 a second, bursts up to 256), refused or not;
    • at most 8 tiles in flight per player; a slot frees only when the reply is handed to the connection;
    • the tile must lie within the distance of the player's server-side position, and be a whole, aligned tile with a sane stride; otherwise it is refused at once;
    • an unreadable request, or one with no token left, is a strike (a Horizon client never sends one); 64 strikes disconnect the player (multiplayer.disconnect.invalid_packet).
  • Sampling: one "Far terrain server" thread for everyone, started at the first request and running behind the ticks (horizon_threads::behind_server). It takes the players' requests in turn and samples from the level the player is in (Game::lod_source_in). One tile costs 1.4–7 ms on the M4 (lod_grid_bench), and far terrain costs one background core at most.
  • Replies go back to the game thread (Service::deliver, Game::flush_far_terrain): the worker queues each finished reply, and the tick sends them before its flush_all, so they keep their place among the game's packets. A reply waits while that player's connection has more than 1 MiB pending, so a slow reader gets the game's packets first, and holds at most 8 replies at the server.
  • A panic while sampling drops that level's sampler and refuses the tile: every admitted job still gets a reply and frees its slot.
  • game/lan_far.rs handles the payload (lan_actions.rs dispatch).

No tile cache on the server yet: tiles sample live chunks, so a cache needs invalidation from the block log. It's a follow-up; being off by default limits the cost to owners who opt in.

Stack: #4945 → this PR → #4947 (clients).

Checked

Unit tests: a player is held to its slots, its burst and its rate; refusals are charged; strikes end in a kick; a slot frees when the reply is delivered, and a busy connection keeps its reply waiting; players who left are forgotten. A sampler that panics refuses that tile, frees the slot, and the next tile is served. The end-to-end check against a real dedicated server is in part 3, which builds on this.

pr_ready (tools/pr_ready.py --quick --base server-asks/lod-wire on ludovics-mac-mini, against server-asks/lod-wire at fc9cf6382, 7 min 39 s)

Check Result
Scope ⚠️ 9 files, +510 −0; 510 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (2 min 13 s)
rustfmt ✅ (10 s)
clippy ✅ (44 s)
tests: horizon-client ✅ 1346 passed (3 min 54 s)
doc tests ✅ 0 passed (7 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 35 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, lan and 23 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The Scope row: 510 lines, half of them server.rs with its tests; the server can't serve safely without these limits, so it ships as one.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4946 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `server-asks/lod-server` --- ### 📝 Commits (6) - [`557f0da`](https://github.com/horizon-rust/horizon/commit/557f0da93d9cbf26b76595afaf02703476a1ce09) Far terrain from a server: serve horizon:lod tiles - [`4b7fc5c`](https://github.com/horizon-rust/horizon/commit/4b7fc5ca8cd17f5d35327c45f11f30ca5900801e) Far terrain server: replies on the game thread, charged refusals, caught panics - [`618660d`](https://github.com/horizon-rust/horizon/commit/618660d0728e86a4823c724f65168f9947433572) Far terrain server: an unreadable request takes a token too, as the doc says - [`71245c0`](https://github.com/horizon-rust/horizon/commit/71245c0aafc1b743ca19015248576ee1eaca4b88) Merge origin/main into the far terrain server branch - [`8e6281b`](https://github.com/horizon-rust/horizon/commit/8e6281bb91d36d3a2c918a272e91b7d0b64d891e) Merge #4945 (main merged) into #4946 - [`6ee16d8`](https://github.com/horizon-rust/horizon/commit/6ee16d87cbd5acd4198ab5e73f81009108830196) Merge #4945 (main merged) into #4946 ### 📊 Changes **9 files changed** (+512 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/dedicated.rs` (+3 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+7 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+3 -0) ➕ `crates/horizon-client/src/game/lan_far.rs` (+79 -0) 📝 `crates/horizon-client/src/lan/conn.rs` (+10 -0) 📝 `crates/horizon-client/src/lan/mod.rs` (+5 -0) 📝 `crates/horizon-client/src/lod_net.rs` (+3 -0) ➕ `crates/horizon-client/src/lod_net/server.rs` (+401 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why Part 2 of 3 of far terrain on servers, on top of #4945. A dedicated server or a LAN world now offers far terrain to Horizon clients and serves their tile requests. Clients don't ask for it yet: that's part 3, so players see no change from this PR alone. - **Offer**: during configuration, only to clients whose `minecraft:brand` is `horizon` (`lan/conn.rs`, next to the quiet-commands offer). A vanilla client hears nothing. - **Distance**: `NetConfig.lod_distance`. A dedicated server reads it from `horizon-lod-distance` in server.properties, a Horizon-only key that `server.toml` sets under `[properties]`. **Off (0) by default**, 1024 at most; with 0 there is no offer and no service. A LAN world uses the default too. - **Only offered clients**: requests from a guest whose brand isn't `horizon` are dropped, the same check the offer is gated on. - **Per player, so it can't be used to overload the server** (`lod_net/server.rs` `Service::request`): - every request takes a token (64 a second, bursts up to 256), refused or not; - at most 8 tiles in flight per player; a slot frees only when the reply is handed to the connection; - the tile must lie within the distance of the player's server-side position, and be a whole, aligned tile with a sane stride; otherwise it is refused at once; - an unreadable request, or one with no token left, is a strike (a Horizon client never sends one); 64 strikes disconnect the player (`multiplayer.disconnect.invalid_packet`). - **Sampling**: one "Far terrain server" thread for everyone, started at the first request and running behind the ticks (`horizon_threads::behind_server`). It takes the players' requests in turn and samples from the level the player is in (`Game::lod_source_in`). One tile costs 1.4–7 ms on the M4 (`lod_grid_bench`), and far terrain costs one background core at most. - **Replies go back to the game thread** (`Service::deliver`, `Game::flush_far_terrain`): the worker queues each finished reply, and the tick sends them before its `flush_all`, so they keep their place among the game's packets. A reply waits while that player's connection has more than 1 MiB pending, so a slow reader gets the game's packets first, and holds at most 8 replies at the server. - **A panic while sampling** drops that level's sampler and refuses the tile: every admitted job still gets a reply and frees its slot. - `game/lan_far.rs` handles the payload (`lan_actions.rs` dispatch). No tile cache on the server yet: tiles sample live chunks, so a cache needs invalidation from the block log. It's a follow-up; being off by default limits the cost to owners who opt in. Stack: #4945 → **this PR** → #4947 (clients). ## Checked Unit tests: a player is held to its slots, its burst and its rate; refusals are charged; strikes end in a kick; a slot frees when the reply is delivered, and a busy connection keeps its reply waiting; players who left are forgotten. A sampler that panics refuses that tile, frees the slot, and the next tile is served. The end-to-end check against a real dedicated server is in part 3, which builds on this. **pr_ready** (`tools/pr_ready.py --quick --base server-asks/lod-wire` on ludovics-mac-mini, against server-asks/lod-wire at fc9cf6382, 7 min 39 s) | Check | Result | | --- | --- | | Scope | ⚠️ 9 files, +510 −0; 510 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (2 min 13 s) | | rustfmt | ✅ (10 s) | | clippy | ✅ (44 s) | | tests: horizon-client | ✅ 1346 passed (3 min 54 s) | | doc tests | ✅ 0 passed (7 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 35 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, lan and 23 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The Scope row: 510 lines, half of them `server.rs` with its tests; the server can't serve safely without these limits, so it ships as one. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:14 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5962
No description provided.