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

Gas: Reprice state read/write #1346

Closed
Stebalien opened this issue Dec 20, 2022 · 7 comments · Fixed by #1521
Closed

Gas: Reprice state read/write #1346

Stebalien opened this issue Dec 20, 2022 · 7 comments · Fixed by #1521

Comments

@Stebalien
Copy link
Member

We need to account for the cost of looking actors up in the state-tree, and writing them back.

@Stebalien
Copy link
Member Author

Stebalien commented Jan 4, 2023

Currently, we charge very little for state reads and address lookups because we expect heavy caching. However, in an environment where users can manually trigger lookups, this is no longer true.

Unfortunately, given the current number of actors in the network, I'd expect at least 2 IPLD loads (assuming caching) for actor lookups, and likely 4 for address lookups. This comes out to 0.5M and 1M gas, respectively.

That's really expensive. We likely need to find a better approach.

  • Some form of database.
  • Even more aggressive caching.
  • Take caching into account when computing gas costs.

@Stebalien
Copy link
Member Author

Ok, so, some benchmarking. We were hoping that the EVM logic would cost more than the expected address lookup costs. From the EVM, it costs ~21801 gas to lookup a balance by ID. That's:

  1. 14000 gas for the syscall.
  2. ~7801 overhead.

It's ~45792 gas to lookup a balance by address (which, under the hood, resolves an address then looks up an actor). That's:

  1. 14000 * 2 gas for the syscalls.
  2. ~17891 overhead.

The expected cost to, e.g., lookup an address plus an actor is about 6 IPLD loads (or more) which is at least 1M gas (or ~2 orders of magnitude greater).

So we definitely need to charge here.

@Stebalien
Copy link
Member Author

Benchmark: filecoin-project/fvm-bench#7

@Stebalien
Copy link
Member Author

Benchmarking required:

  1. The average cost, in gas, of an uncached load.
  2. The average cost, in bytes, of an update.

Determining the cost of an uncached load may be a bit tricky, unfortunately, due to the caching inside the state tree itself.

Really, it may be easier to simulate these things by:

  1. Loading an actual state-tree.
  2. Performing increasing numbers of random state reads/writes (well, increasing actor IDs should be random enough given that we hash the keys).

@Kubuxu
Copy link
Contributor

Kubuxu commented Jan 16, 2023

Results for updates: https://shuttle-10.estuary.tech/gw/ipfs/bafkreia4ywcghoe57tc5mj455ycboosdoezrfzbwzv445hsfqxizd44yyi/
Also, it includes results for reads, as an update requires a read to perform the write.

Normal gateway link: https://dweb.link/ipfs/bafkreia4ywcghoe57tc5mj455ycboosdoezrfzbwzv445hsfqxizd44yyi , but I'm getting 429 error right now.

@Kubuxu
Copy link
Contributor

Kubuxu commented Jan 16, 2023

Let me know if you want an interpolation of the result for a specific number of state updates in a batch, I can interpolate it from the results.

@Kubuxu
Copy link
Contributor

Kubuxu commented Jan 16, 2023

Frome sentinel, we learned that, on average, we do 262 state updates per epoch.
Which leads to the following operation having to be performed on expectation per state update:

:GetsNo 2.307
:PutsNo 2.307
:PutsBytes 6079.59

@maciejwitowski maciejwitowski assigned Stebalien and unassigned Kubuxu Jan 18, 2023
Stebalien added a commit that referenced this issue Aug 2, 2023
1. We don't intentionally use these anywhere.
2. We _do_ unintentionally use these where we
shouldn't (filecoin-project/builtin-actors#1346).

fixes #1346
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants