refactor(network/shape): de-duplicate the traffic-shaper engine and fix interactive daemon block-node wiring - #949
Merged
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR cleans up internal/network/shape by consolidating duplicated logic (default profile construction, per-class validation, and registry JSON CRUD) while keeping behavior stable, and fixes the interactive daemon service install prompts to correctly populate block-node kubeconfig + orbit namespace needed by the traffic-shaper monitor.
Changes:
- Deduplicates default egress/ingress profile generation via a shared, data-driven
buildDefaultConfig. - Centralizes class-field validation (
rate/ceil/prio) and rate-summing logic to ensure consistent enforcement across verbs. - Fixes interactive daemon installer wiring for the block-node component (sets kubeconfig and prompts for
bn-orbitwhen selected).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/network/shape/defaults.go | Introduces data-driven default profiles and a shared default-config builder. |
| internal/network/shape/manager.go | Replaces duplicated default-provisioning paths with a shared provisionDefaults; removes redundant exported wrapper. |
| internal/network/shape/override.go | Removes dead ClassDirection; reuses shared validators and shared rate-summing helper. |
| internal/network/shape/registry.go | Consolidates device/class registry JSON read/write/remove into generic helpers. |
| internal/network/shape/tc.go | Moves TCRunner interface into a build-tag-free file shared by linux/non-linux implementations. |
| internal/network/shape/tc_linux.go | Removes duplicate TCRunner declaration (now shared from tc.go). |
| internal/network/shape/tc_other.go | Removes duplicate TCRunner declaration (now shared from tc.go). |
| internal/network/shape/validate.go | Adds validateClassFields and sumParseableRatesBps to deduplicate validation and sum checking. |
| internal/ui/prompt/daemon.go | Fixes interactive daemon install prompts to wire BN kubeconfig and prompt for BN orbit when selected. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
alex-au
force-pushed
the
refactor-traffic-shaper-engine
branch
from
July 31, 2026 06:35
16a6b4a to
1b2de20
Compare
This was referenced Jul 31, 2026
Merged
alex-au
force-pushed
the
refactor-traffic-shaper-engine
branch
2 times, most recently
from
August 1, 2026 01:42
5d74784 to
0514a3b
Compare
Behavior-preserving cleanup of code that grew across the traffic-shaper PRs:
- Data-drive the egress/ingress default profiles (new defaults.go) and share
one provisionDefaults method, replacing the twin default*Config builders and
ProvisionDefault{Egress,Ingress} bodies.
- Extract validateClassFields + sumParseableRatesBps, removing the 3x per-class
and 2x budget-check validation duplication.
- Generic registry CRUD (writeConfigJSON/readConfigJSON/removeConfigFile) behind
the existing device/class wrappers.
- Move the TCRunner interface to a build-tag-free tc.go (was declared twice, in
tc_linux.go and tc_other.go).
- Remove dead ClassDirection and the redundant exported RenderAndApplyEgress
(no external callers).
No functional change; all internal/network/shape tests pass unchanged.
Signed-off-by: alex-au <alex.w.aus@gmail.com>
…aller The interactive `daemon service install` path built the block-node component without its kubeconfig or orbit namespace, guarded by a stale "traffic-shaper is stubbed" comment. The monitor is fully wired now, so this produced an incomplete config versus `block node install` and daemon_offer.go (which both set these fields). Set the kubeconfig and prompt for the orbit via the existing but previously unwired bn-orbit prompt and BNOrbit target. Signed-off-by: alex-au <alex.w.aus@gmail.com>
brunodam
force-pushed
the
refactor-traffic-shaper-engine
branch
from
August 1, 2026 01:46
0514a3b to
5fb6409
Compare
Signed-off-by: alex-au <alex.w.aus@gmail.com>
…ify (#951) Signed-off-by: alex-au <alex.w.aus@gmail.com>
…ngle-source tc encoding (#955) Signed-off-by: alex-au <alex.w.aus@gmail.com>
…raffic-shaping (#952) Signed-off-by: alex-au <alex.w.aus@gmail.com>
…work-feature wiring (#957) Signed-off-by: alex-au <alex.w.aus@gmail.com>
alex-au
force-pushed
the
refactor-traffic-shaper-engine
branch
from
August 1, 2026 01:51
5fb6409 to
01a1103
Compare
brunodam
approved these changes
Aug 2, 2026
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.
Description
Behavior-preserving cleanup of the traffic-shaper engine (
internal/network/shape), which accumulated duplication and dead code as the feature landed across ~10 PRs, plus a fix for a real bug in the interactive daemon installer. Net −116 lines; no functional change to the shaping engine.The daemon fix addresses a latent bug: the interactive
daemon service installpath built the block-node component without its kubeconfig or orbit namespace, guarded by a stale"traffic-shaper is stubbed"comment. The monitor is fully wired now, so that path produced an incomplete config versusblock node installanddaemon_offer.go, which both set these fields. Thebn-orbitprompt andBNOrbittarget already existed but were never hooked up.Files changed
internal/network/shape/defaults.go(new)buildDefaultConfiginternal/network/shape/tc.go(new)TCRunnerinterface declarationinternal/network/shape/manager.goprovisionDefaults; drop twindefault*Config+ redundant exportedRenderAndApplyEgress; usevalidateClassFieldsinternal/network/shape/validate.govalidateClassFields+sumParseableRatesBpsinternal/network/shape/override.goClassDirectioninternal/network/shape/registry.gowriteConfigJSON/readConfigJSON/removeConfigFilebehind the device/class wrappersinternal/network/shape/tc_linux.go,tc_other.goTCRunnerinterface declarationinternal/ui/prompt/daemon.goReview guide
Checklist:
defaults.go:64buildDefaultConfig— verifyceilFullclasses emit the trunk rate verbatim (e.g.1gbit, not1000mbit) and percentage classes match the previousmbps*pct/100maths (egress partner 40/70, public 30/70, reserve 30/trunk; ingress 80/10/10 all ceil=trunk).manager.goprovisionDefaults— egress passes anafterWritethat renders+applies the boot script; ingress passesnil(config only, no boot script). Both still run underwithLock.validate.govalidateSumRates— the "device rate unparseable" and "new rate unparseable" early-return skips are preserved (guards the legacy SPEED path, intentionally untouched here).registry.go— error-message wording changed (no test asserts it); behavior identical, mkdir target unchanged.daemon.go— Step 4/5 mirror the consensus-node wiring;bn-orbitis prompted only when the block-node component is selected.Tests:
go test ./internal/network/shape/... ./internal/blocknode/shaper/... ./internal/ui/prompt/... task lintAll pass;
golangci-lintreports 0 issues;go vetclean.Not in scope
The legacy "SPEED" sysfs-fallback render path is deliberately left untouched — it is still reachable via
network shape delete --device egressand legacy on-disk registries, and retiring it needs aDeleteDevice(egress)redesign first (tracked in #946). Two follow-up structural refactors are filed separately: #946 (collapse the render/apply pipeline + single-source tc encoding) and #947 (unify the firewall/traffic-shaping gated-feature wiring).Related Issues