-
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
fix gas cost of insert header #309
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.
That's a very clean fix, thanks!
x/btccheckpoint/keeper/keeper.go
Outdated
@@ -347,6 +350,21 @@ func (k Keeper) OnTipChange(ctx sdk.Context) { | |||
k.checkCheckpoints(ctx) | |||
} | |||
|
|||
func (k Keeper) setBtcLightClientUpdated(ctx sdk.Context) { | |||
store := ctx.TransientStore(k.tstoreKey) | |||
store.Set(types.GetBtcLigtClientUpdatedKey(), []byte{1}) |
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.
store.Set(types.GetBtcLigtClientUpdatedKey(), []byte{1}) | |
store.Set(types.GetBtcLightClientUpdatedKey(), []byte{1}) |
x/btccheckpoint/types/keys.go
Outdated
// MemStoreKey defines the in-memory store key | ||
MemStoreKey = "mem_btccheckpoint" | ||
|
||
LatestFinalizedEpochKey = "latestFinalizedEpoch" | ||
|
||
btcLighClientUpdated = "btcLightClientUpdated" |
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.
btcLighClientUpdated = "btcLightClientUpdated" | |
btcLightClientUpdated = "btcLightClientUpdated" |
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 a pretty good use case for transient store!
Currently most costly babylon msg is Insert Header msg from btc light client. The difference is in order of magnitude range. The main reason is that btclightclient exposes hooks for header events to which btccheckpoint subscribes. With each header update it check status of every checkpoint of every non finalized epoch. This mean that gas cost of this operation is around O(numberOfNonFinlizedEpochs * numberOfCheckpointsInEachNonFinalizedEpoch) (+ some some cost of light client itself).
This pr proposes to move all checking logic into EndBlock callback and to use local transient store to check if btc light client have been updated during current block execution.
This:
Gas cost of inserting headers in e2e tests have been reduced almost two times.