mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #5507] [CLOSED] feat(traffic): inbound Traffic Multiplier (per-attachment billing) #5908
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#5908
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/5507
Author: @nima1024m
Created: 6/23/2026
Status: ❌ Closed
Base:
main← Head:feat/inbound-traffic-multiplier📝 Commits (10+)
4562072feat(traffic): add Traffic Multiplier schema and Billed columnsd875c0efeat(traffic): meter per attachment and accrue Billed2731b7afeat(traffic): enforce quota on Billed; clear it on reset/renew342beb7feat(traffic): decode per-attachment identity in IP-limit and online paths0de1eb3feat(traffic): propagate Billed and the multiplier across the node fleeta863913feat(traffic): surface the multiplier in the panel UI and subscriptions5a96df4fix(traffic): address ultra-review findings41248e5fix(traffic): close ultra-review gaps (upgrade double-bill, Real-vs-Billed)8b780fbMerge origin/main into feat/inbound-traffic-multiplier21c985aMerge origin/main (v3.4.0) into feat/inbound-traffic-multiplier📊 Changes
72 files changed (+1448 additions, -130 deletions)
View changed files
📝
frontend/public/openapi.json(+24 -0)📝
frontend/src/generated/examples.ts(+5 -0)📝
frontend/src/generated/schemas.ts(+19 -0)📝
frontend/src/generated/types.ts(+3 -0)📝
frontend/src/generated/zod.ts(+3 -0)📝
frontend/src/lib/remark/remarkVariables.ts(+1 -0)📝
frontend/src/lib/xray/inbound-form-adapter.ts(+4 -0)📝
frontend/src/models/dbinbound.ts(+2 -0)📝
frontend/src/pages/clients/ClientInfoModal.tsx(+15 -2)📝
frontend/src/pages/inbounds/form/InboundFormModal.tsx(+11 -0)📝
frontend/src/pages/inbounds/list/InboundList.tsx(+56 -4)📝
frontend/src/pages/inbounds/list/types.ts(+1 -0)📝
frontend/src/schemas/api/inbound.ts(+2 -0)📝
frontend/src/schemas/client.ts(+4 -0)📝
frontend/src/schemas/forms/inbound-form.ts(+1 -0)📝
frontend/src/test/__snapshots__/inbound-full.test.ts.snap(+8 -0)📝
internal/database/db.go(+27 -0)➕
internal/database/db_backfill_test.go(+73 -0)📝
internal/database/model/client_global_traffic.go(+5 -1)➕
internal/database/model/client_inbound_traffic.go(+28 -0)...and 52 more files
📄 Description
Summary
Adds a per-inbound Traffic Multiplier that scales how fast a client's real traffic draws down their quota — so operators can price premium tunnels (multiplier > 1) and economy tunnels (< 1) differently, with the rate made visible to the end user. Default
1is fully behaviour-preserving.Billing is exact and fair across inbounds: each
(client, inbound)pair is metered separately, each slice is multiplied by its inbound's multiplier, and the slices are summed. Worked example — a client on a 2× and a 0.5× inbound who moves 50 GB and 30 GB is billed50×2 + 30×0.5 = 115 GBagainst quota while Real stays 80 GB.How it works
(client, inbound)is given its own Xray accounting identity"<inboundId>::<email>"; the suffix is an internal detail and is stripped back to the logical email everywhere else (IP-limit grouping, online detection, subscriptions, UI).Feature commits (one per phase)
Inbound.multiplier(0.1–100, default 1), newclient_inbound_trafficsper-attachment table,billed_up/billed_downon client/node/global traffic, idempotent backfill (Billed = Real for existing rows).{MULTIPLIER}subscription token: inbound form field, client modal Real-vs-Billed, an inbounds-list multiplier filter (range buckets + exact values), full localization across all 13 locales, regenerated codegen.Code review — two max-effort rounds
The change was put through two rounds of multi-agent, recall-oriented review (many independent finder angles → adversarial verification → gap sweep), each landing as one additive fix commit. No findings were left unaddressed.
Round 1 —
fix(traffic): address ultra-review findingsRemoveUsernow sends the encoded"<inboundId>::<email>", but the "User not found" already-removed idempotency checks still compared the logical email, so the benign case forced a full core restart (dropping every live connection) on each poll. Now matches the bare"not found"substring at all 5 sites./get/:emailusedTrafficfield all switched to Billed, so what's shown agrees with when service is actually cut.{MULTIPLIER}and the list filter fresh.DelInbounddrops the inbound'sclient_inbound_trafficsrows — no orphan leak / id-reuse double-count.Round 2 —
fix(traffic): close ultra-review gaps (upgrade double-bill, Real-vs-Billed)backfillBilledTrafficseeded Billed onclient_trafficsbut not the per-node delta baselinenode_client_traffics. AutoMigrate addsbilled_*defaulting to 0 whileup/downkeep their pre-upgrade totals, so the first node-sync foldeddeltaBilled = canon.Billed − 0(the node's entire history) on top of the already-backfilled client row — one-time doubling Billed for every node client and instantly depleting any whose quota lay below it. Now seeds the node baseline too. (client_global_trafficsneeds none: overwritten per push and folded with MAX, so a stale 0 can't lower anything.)Up+Down, contradicting the summary badge and the client's actual cut-off state on any non-1× inbound. Switched to Billed. (The usage-range filter and "traffic" sort stay Real — they mean bytes moved; inbound-level depletion stays Real — inbounds have no multiplier.)total − usedequals what enforcement cuts on and they agree with the already-Billed remark tokens.Total − (Up+Down); the two client checks switched to Billed.Testing
getInboundsByEmailreturning every attachment, identity encode/decode round-trip (incl. an embedded::and legacy passthrough),{MULTIPLIER}token rendering.go build ./...and the fullgo test -race -shuffle=on ./internal/...suite pass.npm ci,gen(no codegen diff),typecheck,lint,test(572 pass),build— all green.Upgrade notes
client_trafficsand the per-node baseline since every existing inbound was effectively 1×.Still open (follow-up, not a bug)
client_inbound_trafficsalready persists per-attachment Real + Billed, but the client modal currently surfaces only per-client totals. A read endpoint + modal table would expose the split.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.