[PR #6648] [CLOSED] feat(nodes): add an opt-in per-node traffic multiplier #6395

Closed
opened 2026-11-02 04:08:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6648
Author: @Lidociane
Created: 9/24/2026
Status: ❌ Closed

Base: main ← Head: feat/traffic-multiplier


📝 Commits (4)

  • dd0b7fc feat(traffic): bill node traffic deltas at the node's multiplier
  • c545e4e feat(nodes): expose the traffic multiplier on the node API
  • a284176 feat(ui): add the node traffic multiplier field and badge
  • 6f5811e chore(api): regenerate schemas for the node traffic multiplier

📊 Changes

31 files changed (+840 additions, -16 deletions)

View changed files

📝 frontend/public/openapi.json (+32 -3)
📝 frontend/src/generated/examples.ts (+4 -1)
📝 frontend/src/generated/schemas.ts (+23 -0)
📝 frontend/src/generated/types.ts (+3 -0)
📝 frontend/src/generated/zod.ts (+3 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+3 -3)
📝 frontend/src/pages/nodes/NodeFormModal.tsx (+26 -0)
📝 frontend/src/pages/nodes/NodeList.tsx (+29 -0)
📝 frontend/src/schemas/node.ts (+5 -0)
📝 internal/database/db.go (+13 -0)
📝 internal/database/model/model.go (+6 -0)
➕ internal/database/node_traffic_multiplier_migration_test.go (+95 -0)
➕ internal/traffic/multiplier.go (+63 -0)
➕ internal/traffic/multiplier_test.go (+74 -0)
📝 internal/web/service/inbound_node.go (+28 -4)
📝 internal/web/service/node.go (+59 -5)
📝 internal/web/service/node_contract.go (+10 -0)
➕ internal/web/service/node_traffic_multiplier_test.go (+338 -0)
📝 internal/web/translation/ar-EG.json (+2 -0)
📝 internal/web/translation/en-US.json (+2 -0)

...and 11 more files

📄 Description

Summary

Adds an opt-in per-node traffic multiplier: a node's billed traffic is its actual per-sync delta × multiplier (100 = 1x, 150 = 1.5x, 200 = 2x). The default is 100, so an existing install bills exactly as it does today.

Sub-1x multipliers are deliberately out of scope. A node's local traffic switch is decided by raw counters, so a sub-1x node would report less billed traffic than the raw usage its own limits enforce; values below the range are treated as corrupt and heal to 1x.

Two calibers, stated up front: node inbounds keep mirroring the node's raw counters — that is the number the node itself enforces — while client_traffics accumulates billed values, so inbound-level quota checks stay raw. This is the one place where what a node reports and what a client is billed can differ; it is intentional and documented in the package comment. Local master traffic has no node row and keeps billing 1:1 — there is deliberately no multiplier hook on the local accumulation path.

Why

A panel that resells capacity through a node currently has no way to express that a node's bandwidth is worth more than 1:1. Refs #6509.

#4631 and #5791 aimed at the same goal per-inbound / per-client and were blocked by xray-core's statistics granularity: a node reports usage per inbound or per client, not per billing group. A per-node multiplier needs no new statistics path — it is a column on the node row, applied on the sync the master already performs.

Type of change

  • New feature

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Statistics / traffic counters
  • Database / migrations
  • Multi-node (sub-nodes)

How was this tested?

On top of main@95f19b19:

  • gofmt -l . clean, go vet ./... clean, go build ./... and go test ./... pass.
  • Frontend: npm run lint (0 warnings / 0 errors), npm run typecheck and npm run build pass.
  • Generated artifacts are current: npm run gen leaves frontend/src/generated and frontend/public/openapi.json unchanged.
  • New tests pin the invariants: 1x identity, 1.5x/2x scaling, repeated snapshots do not double-bill, a reset does not re-bill history, a multiplier change affects only later deltas, nodes bill independently, adoption seeds stay raw, a renewal adopts billed counters, manual updateTraffic keeps billed semantics, a multiplier-only edit does not flag config_dirty, and the migration runs on SQLite and PostgreSQL.
  • Manual check, with two panels running locally and one registered as a node of the other: the Nodes list shows a gold 1.50x badge next to the node carrying the multiplier, while a node left at the default shows no badge at all; editing that node renders the Traffic multiplier field as 1.50x with its hint. The per-node stats dialog on the mobile layout lists a Traffic multiplier row as well.

Screenshots / recordings

The node list with the 1.50x badge next to de-fra-1 and no badge on the node left at the default:

![Node list showing the 1.50x badge and a default node without one]
01-nodes-list-badge

The node edit form, with the multiplier field rendered as 1.50x and its hint:

![Node edit form showing the Traffic multiplier field]
02-node-form-multiplier

Breaking changes

None for existing installs. The new column defaults to 100 and a startup migration backfills the NULLs an older SQLite ALTER TABLE leaves behind, so upgrading installs keep billing 1:1. The API change is additive: trafficMultiplier is a new response field and an optional request field — clients that do not send it keep the stored value.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/MHSanaei/3x-ui/pull/6648 **Author:** [@Lidociane](https://github.com/Lidociane) **Created:** 9/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/traffic-multiplier` --- ### 📝 Commits (4) - [`dd0b7fc`](https://github.com/MHSanaei/3x-ui/commit/dd0b7fc724d4f814a0baa48831f360b36a61cabe) feat(traffic): bill node traffic deltas at the node's multiplier - [`c545e4e`](https://github.com/MHSanaei/3x-ui/commit/c545e4e8a3cc92afcd427a84a6c518c5919b9400) feat(nodes): expose the traffic multiplier on the node API - [`a284176`](https://github.com/MHSanaei/3x-ui/commit/a284176b2f29ad70ecbbb3364ef1ca6d374096fa) feat(ui): add the node traffic multiplier field and badge - [`6f5811e`](https://github.com/MHSanaei/3x-ui/commit/6f5811e2f2a24a886876eec4b2003a0928bfa888) chore(api): regenerate schemas for the node traffic multiplier ### 📊 Changes **31 files changed** (+840 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+32 -3) 📝 `frontend/src/generated/examples.ts` (+4 -1) 📝 `frontend/src/generated/schemas.ts` (+23 -0) 📝 `frontend/src/generated/types.ts` (+3 -0) 📝 `frontend/src/generated/zod.ts` (+3 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+3 -3) 📝 `frontend/src/pages/nodes/NodeFormModal.tsx` (+26 -0) 📝 `frontend/src/pages/nodes/NodeList.tsx` (+29 -0) 📝 `frontend/src/schemas/node.ts` (+5 -0) 📝 `internal/database/db.go` (+13 -0) 📝 `internal/database/model/model.go` (+6 -0) ➕ `internal/database/node_traffic_multiplier_migration_test.go` (+95 -0) ➕ `internal/traffic/multiplier.go` (+63 -0) ➕ `internal/traffic/multiplier_test.go` (+74 -0) 📝 `internal/web/service/inbound_node.go` (+28 -4) 📝 `internal/web/service/node.go` (+59 -5) 📝 `internal/web/service/node_contract.go` (+10 -0) ➕ `internal/web/service/node_traffic_multiplier_test.go` (+338 -0) 📝 `internal/web/translation/ar-EG.json` (+2 -0) 📝 `internal/web/translation/en-US.json` (+2 -0) _...and 11 more files_ </details> ### 📄 Description ## Summary Adds an opt-in per-node traffic multiplier: a node's billed traffic is its actual per-sync delta × multiplier (100 = 1x, 150 = 1.5x, 200 = 2x). The default is 100, so an existing install bills exactly as it does today. Sub-1x multipliers are deliberately out of scope. A node's local traffic switch is decided by raw counters, so a sub-1x node would report less billed traffic than the raw usage its own limits enforce; values below the range are treated as corrupt and heal to 1x. Two calibers, stated up front: node inbounds keep mirroring the node's raw counters — that is the number the node itself enforces — while `client_traffics` accumulates billed values, so inbound-level quota checks stay raw. This is the one place where what a node reports and what a client is billed can differ; it is intentional and documented in the package comment. Local master traffic has no node row and keeps billing 1:1 — there is deliberately no multiplier hook on the local accumulation path. ## Why A panel that resells capacity through a node currently has no way to express that a node's bandwidth is worth more than 1:1. Refs #6509. #4631 and #5791 aimed at the same goal per-inbound / per-client and were blocked by xray-core's statistics granularity: a node reports usage per inbound or per client, not per billing group. A per-node multiplier needs no new statistics path — it is a column on the node row, applied on the sync the master already performs. ## Type of change - [x] New feature ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [x] Statistics / traffic counters - [x] Database / migrations - [x] Multi-node (sub-nodes) ## How was this tested? On top of main@95f19b19: - `gofmt -l .` clean, `go vet ./...` clean, `go build ./...` and `go test ./...` pass. - Frontend: `npm run lint` (0 warnings / 0 errors), `npm run typecheck` and `npm run build` pass. - Generated artifacts are current: `npm run gen` leaves `frontend/src/generated` and `frontend/public/openapi.json` unchanged. - New tests pin the invariants: 1x identity, 1.5x/2x scaling, repeated snapshots do not double-bill, a reset does not re-bill history, a multiplier change affects only later deltas, nodes bill independently, adoption seeds stay raw, a renewal adopts billed counters, manual updateTraffic keeps billed semantics, a multiplier-only edit does not flag config_dirty, and the migration runs on SQLite and PostgreSQL. - Manual check, with two panels running locally and one registered as a node of the other: the Nodes list shows a gold `1.50x` badge next to the node carrying the multiplier, while a node left at the default shows no badge at all; editing that node renders the Traffic multiplier field as `1.50x` with its hint. The per-node stats dialog on the mobile layout lists a Traffic multiplier row as well. ## Screenshots / recordings The node list with the `1.50x` badge next to `de-fra-1` and no badge on the node left at the default: ![Node list showing the 1.50x badge and a default node without one] <img width="1988" height="1512" alt="01-nodes-list-badge" src="https://github.com/user-attachments/assets/fb045368-eee1-4248-b026-a3b93eda4766" /> The node edit form, with the multiplier field rendered as `1.50x` and its hint: ![Node edit form showing the Traffic multiplier field] <img width="1988" height="1512" alt="02-node-form-multiplier" src="https://github.com/user-attachments/assets/dce2db42-a1f3-457c-902a-88c73868d8d4" /> ## Breaking changes None for existing installs. The new column defaults to 100 and a startup migration backfills the NULLs an older SQLite `ALTER TABLE` leaves behind, so upgrading installs keep billing 1:1. The API change is additive: `trafficMultiplier` is a new response field and an optional request field — clients that do not send it keep the stored value. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:27 +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
MHSanaei/3x-ui#6395
No description provided.