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

Add cost fn hash to caching path #2205

Open
chipshort opened this issue Aug 12, 2024 · 8 comments · May be fixed by #2250
Open

Add cost fn hash to caching path #2205

chipshort opened this issue Aug 12, 2024 · 8 comments · May be fixed by #2250

Comments

@chipshort
Copy link
Collaborator

chipshort commented Aug 12, 2024

Now I was wondering if/how we can turn this function into something we can hash and add to the caching path. Either by serializing the function (some scripting language) or serialize the op -> cost as a table/map. Could you create a ticket for that as mid or long-term improvement?

Originally posted by @webmaster128 in #2204 (comment)

@webmaster128
Copy link
Member

How cracy would it be to implement fn cost in Wasm?

@chipshort
Copy link
Collaborator Author

A little bit crazy. I wouldn't do that just to get a hash of it.
One thing I've been thinking about is using a derive macro that just hashes the incoming source code.

@webmaster128
Copy link
Member

How can we ensure that changes in is_accounting_operator (implemented in the metering middleware) would lead to a different hash? Can we get hash values from normal functions or would it need to be implemented as a macro?

@chipshort
Copy link
Collaborator Author

Hm, that's a tough one. The macro can only access the code that's annotated with it.
But generally, this shouldn't be a problem for us, since we bump the serialization version with each wasmer upgrade anyways (if we want to get really crazy, we can even have a macro that reads our Cargo.toml and hashes the wasmer version).

@chipshort
Copy link
Collaborator Author

So, basically there is https://docs.rs/code-hasher/0.1.0/code_hasher/ and https://docs.rs/include-cargo-toml/0.1.0/include_cargo_toml/, but we could also implement our own, since both of these are very small.

@webmaster128
Copy link
Member

Sounds great. Happy for any implementation that works and that we can replace. So the idea here is to hash together 1. the fn cost source code and wasmer-middlewares version?

@chipshort
Copy link
Collaborator Author

Yes, exactly.

@chipshort
Copy link
Collaborator Author

Another note: We should make sure to backport this to all supported versions when it is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants