Skip to content

Commit

Permalink
Add documentation for our calculation of a _reasonable_ gas fee for s…
Browse files Browse the repository at this point in the history
…torage (#1478)

Closes #1404

---------

Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
  • Loading branch information
MitchTurner and xgreenx authored Nov 15, 2023
1 parent 8fe7cf0 commit 7d791f4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deployment/scripts/chainspec/beta_chainspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"fee_params": {
"gas_price_factor": 92,
"gas_per_byte": 4
"gas_per_byte": 63
},
"chain_id": 0,
"gas_costs": {
Expand Down
2 changes: 1 addition & 1 deletion deployment/scripts/chainspec/dev_chainspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"fee_params": {
"gas_price_factor": 1000000000,
"gas_per_byte": 4
"gas_per_byte": 63
},
"chain_id": 0,
"gas_costs": {
Expand Down
65 changes: 65 additions & 0 deletions docs/fee_calculations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## Fee calculations

### Storage fees

Fuel doesn't currently support separate fees for execution costs vs storage costs.
This is a planned future feature, but in the mean time we need a system for
compensating the network for storing contract data. The temporary solution is
to include an additional cost to op codes that write new data to storage or to
transactions that add new contracts to the chain.

There are a number of ways we might calculate this value; we have decided to go
with a simple calculatoin based on the our target storage growth and working
backward from there.

#### Pessimistic Estimate

If we arbitrarily set the target growth to 500 GB/year, we can ask, "what would
be the gas price if users maxed out each block gas limit with storage?"
This gives us this graph:

| bytes per year | block gas limit | blocks per year | bytes per block | gas per bytes |
| --------------- | --------------- | --------------- | --------------- | ------------- |
| 500,000,000,000 | 10,000,000 | 31536000 | **15,855** | **630.72** |

This is a harsh estimate that isn't taking into the additional base cost of tx
execution and the cost of any additional op codes. It is also assuming that
all blocks would be maxing out the storage.

#### Generous Estimate

Additionally, this will only apply to our early networks, which won't be long-live.
This allows us to take a bigger risk on the storage price and increas it over
time to compensate for users adding a lot of data.

All this included, if we re-estimate the yearly storage limit as 5 TB we get:

| bytes per year | block gas limit | blocks per year | bytes per block | gas per bytes |
| ----------------- | --------------- | --------------- | --------------- | ------------- |
| 5,000,000,000,000 | 10,000,000 | 31536000 | **158,549** | **63.07** |

Giving us a cost per byte of **63 gas** as our initial gas price for storage.

#### Additional justifications

If we compare our numbers to what Ethereum charges for gas, we get similar numbers.

If we had a pessimistic estimate for Ethereum and every block on Ethereum was full of new contract creations:

max_contract_size = 24,000 bytes
gas_per_max_contract = 32,000 + max_contract_size * 200 = 4,832,000

gas_per_block = 30,000,000
contracts_per_block = gas_per_block / gas_per_max_contract = ~6

blocks_per_year = 365 * 24 * 60 * ~5 = ~2628000

yearly_new_contract_bytes = blocks_per_year * contracts_per_block * max_contract_size = **378,432,000,000**

Which rougly lines up with our pessimistic estimate.

#### Conclusion

We'd recommend starting at something like **63 gas/byte**. If this is underpriced,
this will be tested in a testnet before being launched, hopefully giving us
ample time to gather more data and update the price

0 comments on commit 7d791f4

Please sign in to comment.