filecoin-project / ref-fvm

Reference implementation of the Filecoin Virtual Machine
https://fvm.filecoin.io/
Other
375 stars 131 forks source link

GAS: Determine which syscalls need (re-)pricing #1051

Closed aakoshh closed 1 year ago

aakoshh commented 1 year ago

Similar effort to https://github.com/filecoin-project/ref-fvm/pull/465

Capture the time-to-gas ratio of syscalls, to facilitate an analysis as in https://arxiv.org/pdf/1905.00553v1.pdf

Another, more deterministic approach is explained in https://github.com/near/nearcore/blob/78ae3b1696b308e25a61a6e896e484886829837c/runtime/runtime-params-estimator/emu-cost/README.md I'm not sure how IO is accounted for there.

Stebalien commented 1 year ago

The syscalls that definitely don't need to be repriced are mostly miner/crypto related ones:

aakoshh commented 1 year ago

I went through the syscalls :eyes:

Here are some rough notes I took: syscall-notes.txt

Things I thought might be worth looking into:

Stebalien commented 1 year ago

vm::abort

The message is "for debugging only" and shouldn't have any affect on consensus. It think we just need to:

  1. Set a size limit.
  2. Add yet another debugging flag to the FVM to turn on/off user error messages. We'll set this flag when a user tries to replay a message, but not while validating the chain.
Stebalien commented 1 year ago

Thanks for writing this up!

maciejwitowski commented 1 year ago

@Stebalien @aakoshh what are next steps here?

aakoshh commented 1 year ago

@maciejwitowski I can think of the following:

  1. Add new items to the price list for the operations that don't charge gas at the moment and insert charging calls. Set the price to zero (the existing tests wouldn't pass otherwise). 2.a. Measure the time it takes to execute the syscalls using the V7 tests, to come up with gas price for the new items. 2.b. Extract new test vectors that work with V8 actors and run the gas calibration on them.
  2. Pick some representative hardware config in the cloud and do the gas calibration there.
aakoshh commented 1 year ago

@maciejwitowski following up on my previous comment:

  1. https://github.com/filecoin-project/ref-fvm/pull/1139 is a PR that adds more syscall gas charges
  2. a. https://github.com/filecoin-project/ref-fvm/pull/1148/files (WIP) shows the relationship between gas and time on the tests I ran locally with V7
anorth commented 1 year ago

While we're here, chain state storage is dramatically underpriced relative to message bytes. This was bad but not terrible without user-programmed actors but could become really bad with user-programmed actors, as it will encourage optimisation that will end up being more expensive for the network. Can we make some progress towards rectifying that here? cc @Kubuxu

aakoshh commented 1 year ago

chain state storage is dramatically underpriced relative to message bytes

@anorth could you elaborate? How were the price of message bytes established?

Perhaps unrelated, but we need a conversion factor from in-memory to on-disk storage access times.