feat(model): derive provider bandwidth from settled contract bytes - #413
Closed
Ryanmello07 wants to merge 1 commit into
Closed
feat(model): derive provider bandwidth from settled contract bytes#413Ryanmello07 wants to merge 1 commit into
Ryanmello07 wants to merge 1 commit into
Conversation
transfer_escrow already records real bytes delivered per contract as a byproduct of billing. Deriving throughput from it costs nothing additional and cannot be gamed selectively -- a provider cannot inflate real user traffic without actually being fast for real users. Excludes companion (return-traffic) contracts: a client's return leg settles with the client as destination, which would otherwise misread ordinary users as fast providers. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QtgqtCmKJRXdsQ5ktiqwkg
Contributor
Author
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.
Passive bandwidth signal from already-settled
contract_closebytes: zero additional bandwidth cost and it cannot be gamed selectively, since a provider cannot inflate real user traffic without actually being fast for real users. Advisory only -- nothing in this PR gates provider selection, scoring, orPassesMinimums.ComputePassiveProviderBandwidth(ctx, clientId, window)sumscontract_close.used_transfer_byte_countfor contracts where the provider is the destination andparty = 'destination', divided by the wall-clock spanmax(close_time) - min(create_time)across the matched rows. Returns nil rather than zero when the provider settled no bytes in the window (no history is not measured-zero throughput), and nil rather than dividing by a non-positive span.companion_contract_id IS NULLis the load-bearing clause: a client's return traffic settles as a contract where the CLIENT is the destination, so without the exclusion an ordinary user reads as a very fast provider. Verified against a live deployment: for contracts created in the last day, companion-leg destinations are neverprovide_mode = 3(Public) while primary-leg destinations are. Teeth-checked by deleting the clause -- the companion test then reports 67108864 bytes/sec for a client that never provided.No schema change and no new caller in this PR; storage and consumers follow.
Tests: 3 new tests in
model(derives-from-settled-bytes, nil-when-no-history, excludes-companion-contracts), all passing against a local Postgres/Redis stack with-count=1.go build ./...andgo vet ./...clean,gofmtclean on both new files. Cherry-picked ontomainwith zero conflicts.