-
Notifications
You must be signed in to change notification settings - Fork 170
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
rpc: avoid using BIP340PubKey
in messages
#438
Conversation
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 is awesome!
I was wondering if the performance gain will bring us lower gas costs. Can we also benchmark it? Maybe in another PR ofc |
I thought Cosmos SDK only charges gases for KVStore access, maybe I miss something? |
Aha I just learned that Cosmos-sdk does an automatic gas meter during read/write to the kv. It's up to the developer to do a manual gas meter in each module. ref |
I see, then this PR might not affect the gas usage of existing txs, given that it does not affect access pattern to DB. Would be good if we can take a look on optimising gas usage of certain msgs (e.g., commit randomness) in the coming days |
Hmm generally I like this optimisation but it introduces a danger. Typically we have such checks in the |
I agree with your concern. This indeed changes the contract of There is another way of arguing this property though -- everytime one needs to use the BTC PK corresponding to a |
Without digging much into benchmark, it seems we need to have two separate types (as I agree 10x improvement on the table is bad):
This way callers can differentiate between both types. |
Agreed, it's more clear to distinguish between unverified BTC PKs and verified ones. I changed the BTC PK to bytes in all messages of BTC staking and finality modules, given that we cannot ensure the BTC PKs from users are valid. I did not define a new type for unverified BTC PK since it does not make much sense for a user to wrap its BTC PK to an "unverfiied" struct -- if it's honest then it should use |
BIP340PubKey
in messages
BIP340PubKey
in messagesBIP340PubKey
in messages
Closing this as it will be done in other subsequent PRs |
Based on the profiling result at https://github.com/babylonchain/babylon/files/14107742/profile001.pdf, the
BeginBlock
of BTC staking module has a performance issue -- 100000 BTC delegations will make its execution time to 2-3 seconds on a laptop, and most of the time is spent on unmarshaling BTC PK. The unmarshaling aims to ensure the BTC PK is legitimate when unmarshaling bytes into a BIP340 PK.This PR proposes an optimisation that we perform this check only upon receiving relevant messages (create finality provider, create BTC delegation, submit covenant signatures). Once these stuff are included in DB the BTC PKs are guaranteed to be legitimate so we don't need to check BTC PK format again.
Tried benchmarking locally and this gives us 8x speedup, compared to results in #437.