Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fip-0100: QAP multiplier for daily_fee #1641

Merged
merged 7 commits into from
Mar 7, 2025

Conversation

rvagg
Copy link
Member

@rvagg rvagg commented Feb 26, 2025

7.4e-15 per 32GiB QAP -> 2.1536e-25 per byte QAP

Closes: #1637

(Draft while I add tests that properly cover this—existing tests that care about fees are all 32GiB QAP)

@rvagg rvagg self-assigned this Feb 26, 2025
@rvagg rvagg linked an issue Feb 26, 2025 that may be closed by this pull request
@rvagg rvagg force-pushed the rvagg/fip-0100/br-cap branch from af5b4bb to 6b49e1a Compare February 26, 2025 23:25
Base automatically changed from rvagg/fip-0100/br-cap to feat/fip-0100 February 26, 2025 23:45
@rvagg rvagg force-pushed the rvagg/fip-0100/qap-multiplier branch from 316be46 to ba4c34d Compare February 28, 2025 04:56
@rvagg rvagg changed the base branch from feat/fip-0100 to steb/fip-0100/fee-replica-update February 28, 2025 06:55
@rvagg rvagg force-pushed the rvagg/fip-0100/qap-multiplier branch from a81bf04 to af442ce Compare February 28, 2025 06:59
@rvagg rvagg marked this pull request as ready for review February 28, 2025 06:59
@rvagg
Copy link
Member Author

rvagg commented Feb 28, 2025

Calling this one done; I've added and extended some tests, I think the coverage is OK for what this does.

@rvagg rvagg force-pushed the rvagg/fip-0100/qap-multiplier branch from af442ce to c6f4a90 Compare February 28, 2025 07:01
@Stebalien
Copy link
Member

What's the rational behind storing the total fee in the sector info instead of storing the fee-per-qap?

  • The fee-per-qap will be smaller (slightly less state).
  • The fee-per-qap won't change (unless 0).

We'd have to multiply the fee-per-qap by the qap when updating the fee, but that seems relatively simple (we can even provide a method on the sector info).

Base automatically changed from steb/fip-0100/fee-replica-update to feat/fip-0100 February 28, 2025 15:19
@rvagg
Copy link
Member Author

rvagg commented Mar 1, 2025

Ugh, now I remember why this didn't feel complete - I need to mess with extensions and snaps in here which do the multiplication thing. Which does go to your point about storing the multiplier rather than the final fee.

The complication I can see would be storing an appropriate QAP multipler daily_fee in the deadline since we're going to have a messy mix of different sector-level QAP. But are you suggesting storing the full fee value in the deadline but only the multiplier in the sector?

SectorOnChainInfo.daily_fee -> SectorOnChainInfo.daily_fee_multiplier (or similar) would probably be in order if we wanted to do this.

@rvagg
Copy link
Member Author

rvagg commented Mar 1, 2025

A SectorOnChainInfo::daily_fee() method as a replacement for the current daily_fee value so that whenever we need it (deadlines, expirationsets), we can easily recalculate.

@Stebalien
Copy link
Member

But are you suggesting storing the full fee value in the deadline but only the multiplier in the sector?

Exactly.

@rvagg
Copy link
Member Author

rvagg commented Mar 1, 2025

Another downside here is that it's not as nice for end users if we return SectorOnChainInfo as it is. Unless we do the calculation and present a modified version with the actual fee. Kind of annoying.

@rvagg
Copy link
Member Author

rvagg commented Mar 3, 2025

Storing full fee in SectorOnChainInfo

  • All queries to get sector info show the fee as it is
  • High accuracy of fee value
  • Straightforward reconciliation and accounting on chain (Deadlines, ExpirationSet)
  • Straightforward testing and verification

Storing fee multiplier in SectorOnChainInfo

  • Getting sector info shows a per-QAP-byte number, needs to be multiplied correctly (also note there's no pure QAP number in SectorOnChainInfo for this multiplication, we have verified weight and duration and you have to untangle them to find QAP)
  • Much smaller per-sector storage requirements
  • Don't need to update fee info in sector for extensions and snaps (still need to update Deadlines and ExpirationSet)

On the size:

  • Full fee, in all cases (32GiB QAP through to 640GiB QAP), requires 8 bytes of storage (e.g. 5,156,022,356,586 for 32, 103,120,447,131,726 for 640 with current CS).
  • Per-byte QAP multiplier requires 3 bytes of storage if we use a BigInt or 2 if we just use a cbor int (e.g. 150 for current CS)
  • Per-kilobyte QAP multiplier requires 5 bytes of storage (153661 for current CS, encodes to same size as plain CBOR or BigInt)

On the accuracy:

  • With full fee, we can achieve fairly high accuracy using pre-scaling before division, we do a little bit of rounding down from the original 7.4e-15 just to get a nicer multiplier -> 2.1536e-25, but it moves in step with small movements of CS
  • If we use a per-byte QAP multiplier then we miss out on scaling opportunities, so we end up with a quantised CS multiplier: CS has to move 4.6M FIL in either direction to change a multiplier (we're currently at a CS of 696.8M, per-byte for steps around this are: 148 for CS values between 687.3M to 691.8M, 149 for 691.8M to 696.6M, 150 for 696.7M to 701.2M)
  • We could increase precision with a per-kilobyte value (5 bytes as above) which quantises CS at 4,534 FIL

@rvagg rvagg force-pushed the rvagg/fip-0100/qap-multiplier branch from 86658a1 to a480906 Compare March 4, 2025 04:21
@rvagg rvagg force-pushed the rvagg/fip-0100/qap-multiplier branch from a480906 to 46186c4 Compare March 4, 2025 04:24
@rvagg
Copy link
Member Author

rvagg commented Mar 4, 2025

Updated the branch with adjustment for snaps and extensions. As far as I can tell the only case where power changes with extensions is if you drop_claims. Fee adjustment is new_power/old_power * fee with a large scale in there to get it accurate. Tests added to confirm that the fee changes appropriately, on top of the existing zero-fee cases where a new fee gets added. I also do some checking of deadline and expiration queue state in the process to confirm it bubbles up into the right places.

@rvagg rvagg force-pushed the rvagg/fip-0100/qap-multiplier branch from 56e1f11 to 9edd353 Compare March 5, 2025 02:34
rvagg added 4 commits March 5, 2025 18:10

Verified

This commit was signed with the committer’s verified signature.
rvagg Rod Vagg
7.4e-15 per 32GiB QAP -> 2.1536e-25 per byte QAP

Closes: #1637

Verified

This commit was signed with the committer’s verified signature.
rvagg Rod Vagg

Verified

This commit was signed with the committer’s verified signature.
rvagg Rod Vagg

Verified

This commit was signed with the committer’s verified signature.
rvagg Rod Vagg
…ation
rvagg added 2 commits March 5, 2025 18:10

Verified

This commit was signed with the committer’s verified signature.
rvagg Rod Vagg

Verified

This commit was signed with the committer’s verified signature.
rvagg Rod Vagg
@rvagg rvagg force-pushed the rvagg/fip-0100/qap-multiplier branch from 9edd353 to 481e181 Compare March 5, 2025 07:12

Verified

This commit was signed with the committer’s verified signature.
rvagg Rod Vagg
To ensure that the numbers we're getting are within expected range—all other
tests work on relative amounts.
@rvagg
Copy link
Member Author

rvagg commented Mar 6, 2025

In the latest commit, 946784f, I added a sanity check in the basic fee test: we should get within 1/5th of a nanoFIL of 5155.58 nanoFil for a fee on 32GiB QAP given a CS of 696.7M. This comes from the original 7.4e-15 multiplier from the FIP, so it's also checking my per-byte multiplier. The rest of the tests do relative amounts so this one helps make sure we're not spinning off wildly without realising it.

@rvagg rvagg merged commit 1845ab6 into feat/fip-0100 Mar 7, 2025
11 checks passed
@rvagg rvagg deleted the rvagg/fip-0100/qap-multiplier branch March 7, 2025 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🎉 Done
Status: 🎉 Done
Development

Successfully merging this pull request may close these issues.

FIP-0100: Account for QAP in daily fee calculation
2 participants