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

epoching: smaller epoch interval in simulation #80

Merged
merged 7 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion x/epoching/keeper/epoch_msg_queue.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"fmt"

"github.com/babylonchain/babylon/x/epoching/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -118,6 +120,36 @@ func (k Keeper) HandleQueuedMsg(ctx sdk.Context, msg *types.QueuedMessage) (*sdk

// get the handler function from router
handler := k.router.Handler(unwrappedMsgWithType)

// Create a new Context based off of the existing Context with a MultiStore branch
// in case message processing fails. At this point, the MultiStore is a branch of a branch.
handlerCtx, msCache := cacheTxContext(ctx, msg.TxId, msg.MsgId)

// handle the unwrapped message
return handler(ctx, unwrappedMsgWithType)
result, err := handler(handlerCtx, unwrappedMsgWithType)

if err == nil {
msCache.Write()
}

return result, err
}

// based on a function with the same name in `baseapp.go``
func cacheTxContext(ctx sdk.Context, txid []byte, msgid []byte) (sdk.Context, sdk.CacheMultiStore) {
ms := ctx.MultiStore()
// TODO: https://github.com/cosmos/cosmos-sdk/issues/2824
msCache := ms.CacheMultiStore()
if msCache.TracingEnabled() {
msCache = msCache.SetTracingContext(
sdk.TraceContext(
map[string]interface{}{
"txHash": fmt.Sprintf("%X", txid),
"msgHash": fmt.Sprintf("%X", msgid),
},
),
).(sdk.CacheMultiStore)
}

return ctx.WithMultiStore(msCache), msCache
}
2 changes: 1 addition & 1 deletion x/epoching/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (

// genUnbondingTime returns randomized UnbondingTime
func genEpochInterval(r *rand.Rand) uint64 {
return uint64(r.Intn(250) + 1)
return uint64(r.Intn(10) + 1)
}

// RandomizedGenState generates a random GenesisState for staking
Expand Down
2 changes: 1 addition & 1 deletion x/epoching/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestRandomizedGenState(t *testing.T) {
var epochingGenesis types.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &epochingGenesis)

require.Equal(t, uint64(0x29), epochingGenesis.Params.EpochInterval)
require.Equal(t, uint64(0x1), epochingGenesis.Params.EpochInterval)
}

// TestRandomizedGenState1 tests abnormal scenarios of applying RandomizedGenState.
Expand Down