-
Notifications
You must be signed in to change notification settings - Fork 144
Add gas parameters for event validation + calibration harnesses. #1635
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
Conversation
Err(syscall_error!(IllegalArgument; "panic when decoding event cbor from actor").into()) | ||
} | ||
}; | ||
t.stop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now capturing a reading even on deserialization errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be careful about that. We usually don't time failures because it can mess up the number's we're looking for (e.g., we can stop half-way through parsing something).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense here as long as the test harness is controlling for when it's sending malformed input and when it isn't. This allows us to calibrate the costs for invalid CBOR input, although that will be less relevant if/when we move away from the CBOR-based ABI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, fair enough. And the gas charges here are specifically about parsing.
std::iter::repeat_with(move || { | ||
seed = a * seed + c; | ||
seed | ||
seed = Wrapping(a) * seed + Wrapping(c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure why, but the lack of wrapping arithmetics here caused weird side effects during ASCII string generation, which led to weird characters. This is more correct.
@@ -24,7 +24,7 @@ use num_traits::Zero; | |||
use serde::Serialize; | |||
|
|||
pub const WASM_COMPILED_PATH: &str = | |||
"../../target/debug/wbuild/fil_gas_calibration_actor/fil_gas_calibration_actor.compact.wasm"; | |||
"../../target/release/wbuild/fil_gas_calibration_actor/fil_gas_calibration_actor.compact.wasm"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the culprit for some major headaches. We run the harness in --release
profile, which means that we recompile contract changes under the release
profile. Unfortunately the calibration harness was picking the actor up from the debug
profile, which usually contains a stale version.
@Stebalien -- this might have or might have not affected your readings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't matter. I was timing FVM operations, not things within the actors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it should not affect the readings. However, in my case this ended up picking stale actor code more than once, leading to wrong conclusions. So wanted to give you a heads-up just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh.... Damn, I see. I think rust-analyzer's background "let me recompile everything for you and melt a hole in your lap" helped there.
11dcd5b
to
e7c386c
Compare
testing/calibration/contract/fil-gas-calibration-actor/src/lib.rs
Outdated
Show resolved
Hide resolved
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #1635 +/- ##
==========================================
+ Coverage 51.72% 53.33% +1.61%
==========================================
Files 146 146
Lines 14619 14177 -442
==========================================
Hits 7561 7561
+ Misses 7058 6616 -442
|
735bf86
to
d216ed0
Compare
d216ed0
to
b70e55b
Compare
ef1f69e
to
be21bef
Compare
I've updated the benchmarks to cover power of two byte array lengths in the range 32..8KiB in the last entry in the event, which in EVM land will correspond to the event data (which is of arbitrary length). The longer that value gets, the higher the overestimation. We will retain these parameters because the award us good security, and are not too oversized for reasonable inputs (and we prefer to encourage reasonable inputs!). Furthermore, @Stebalien and I revised the theoretical accept costs and made some adjustments (increased to 2 memory allocs, and added cost of hashing). These costs are also somewhat overestimated but award good security (this diagram shows only 1 memcpy and 1 alloc; hiding all deferred costs that happen when committing the events). |
Closes #1109.
Changes
testing/calibration
.data
entry carries a 1-char key:d
).gas-calibration
feature.Choice of gas parameters
These parameters hit the 10gas/ns baseline consistently, with a slight overestimation to cover for the worst case scenario reasonably well (just under 10gas/ns). These parameters do lead to a larger overestimation on the 1-entry case (LOG0 -- pretty rare anyway), but I'm happy living with that.
entries
size
compute_gas
Here is a visual depiction of the above as emitted from the calibration tools:
Here's a closer look at the gas distribution in a violin plot:
Future direction
This exercise has highlighted the fact that CBOR is not a good choice for an exchange format at the ABI level dealing with (future) untrusted inputs. We found that the costs scale with the number of entries (CBOR list items), which we can't learn prior to parsing the event in some way (we could do an O(n) prevalidation though). It's worth revising this choice going forward. Any changes to the ABI will not have externally visible impacts.