feat: p4-compatible resource recharging ledger #989
Open
charmful0x wants to merge 33 commits into
Open
Conversation
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.
~recharging-ledger@1.0devicea p4-compatible ledger where balances regenerate over time. each account starts at
maxand refillsrechargeunits everyperiod(default: a 24h bucket -- 86400 units, +1/sec), capped atmax. p4 reads the effective balance for the preflight check and charges metered usage against it -- so instead of a hard prepaid balance, users get a continuously-refilling allowancebalances are integer ledger units (operators pick the granularity). an optional rates provider can return account specific recharge rates -- e.g. the trusted
recharger-ao-balance@1.0boosts the rate based on the account's AO balancebenchmarks
setup
recharger-ao-balance@1.0results (before optimizations)
default recharging-ledger only
results (after)
grace window
added
recharging-ledger-graceas a small post-metering tolerance window -- this dont increase the user's visible/spendable balance.balance/3still return the actual account balance, and p4 still uses that actual balance for preflight checks.the grace only applies at
charge/3: if the post-metering charge drifts slightly below zero, the ledger can accept it down to-Graceinstead of rejecting after the work already ran-> Default:
3600unitsp4-commit-chargeadded
p4-commit-chargeto make thehb_message:commit/2atdev_p4:response/3optional. that signed charge isnt actually read anywhere in the erlang-only p4 + ledger stack (faff, simple-pay, recharging-ledger) -- they all rederive the Req signer from the embedded request withhb_message:signersand never look at the node's signature on the chargethe commit/2 only matters for ledgers in a separate trust domain: the hyper-token lua ledger (it checks the charge committers against admin) and paranoid nodes (
paranoid-verifyre-verifies the request pre-dispatch). so it defaults to ON -- those setups stay untouched -- and only non-paranoid / non-lua-p4 nodes running a local ledger flip it off.that per-charge RSA-4096 sign (~13ms) is the whole gap: the device itself is already ~0.16ms, so skipping the sign drops p4 + to ~19ms (~41%) and p4 + metering -> recharging from ~34ms to ~19ms -- basically on par with rate-limit / faff (see the table above)
-> Default:
truerates cache
added
recharging-ledger-rates-cache-store(+-cache-ttl) to cache the per-account rate fromrecharging-ledger-rates. resolving it is a live HTTP hit to the provider on every charge/balance read -- the cache makes repeat an ETS read insteadopt-in: store defaults to
[](off), reuseshb_store_volatilebenchmarks vs the real
recharger-ao-balance@1.0provider,p4-commit-charge=false(p4 + metering -> recharging (p4-commit-charge=false) ):writes --
POST /~bundler@1.0/txreads --
GET /~p4@1.0/balancecache on pays the provider round-trip once (first-request miss), then serves from ETS: writes ~535 -> ~56ms, reads ~564 -> ~42ms
-> Default:
[](off), ttl600s