Skip to content

Commit

Permalink
add comments for observer and fungible operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Nov 5, 2024
1 parent c4dfcd7 commit fa1234f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions x/fungible/simulation/decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/zeta-chain/node/x/fungible/types"
)

// TODO Add comments in this pr to explain the purpose of the function
func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
Expand Down
1 change: 0 additions & 1 deletion x/fungible/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

func RandomizedGenState(simState *module.SimulationState) {
// We do not have any params that we need to randomize for this module
// The default state is empty which is sufficient for now , this can be modified later weh we add operations that need existing state data to be processed
fungibleGenesis := types.DefaultGenesis()
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(fungibleGenesis)
}
18 changes: 13 additions & 5 deletions x/fungible/simulation/operations.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package simulation

import (
"fmt"
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -15,11 +14,19 @@ import (
observerTypes "github.com/zeta-chain/node/x/observer/types"
)

// Simulation operation weights constants
// Operation weights are used by the simulation program to simulate the weight of different operations.
// This decides what percentage of a certain type of operation is part of a block.
// Based on the weights assigned in the cosmos sdk modules , 100 seems to the max weight used , and therefore guarantees that at least one operation of that type is present in a block.
// TODO Add more details to comment based on what the number represents in terms of percentage of operations in a block
// https://github.com/zeta-chain/node/issues/3100
const (
OpWeightMsgDeploySystemContracts = "op_weight_msg_deploy_system_contracts"
DefaultWeightMsgDeploySystemContracts = 100
)

// DeployedSystemContracts Use a flag to ensure that the system contracts are deployed only once
// https://github.com/zeta-chain/node/issues/3102
var (
DeployedSystemContracts = false
)
Expand All @@ -41,6 +48,7 @@ func WeightedOperations(
}
}

// SimulateMsgDeploySystemContracts deploy system contracts.It is run only once in first block.
func SimulateMsgDeploySystemContracts(k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, chainID string,
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {
Expand All @@ -50,18 +58,18 @@ func SimulateMsgDeploySystemContracts(k keeper.Keeper) simtypes.Operation {

policies, found := k.GetAuthorityKeeper().GetPolicies(ctx)
if !found {
fmt.Println("Policies not found")
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDeploySystemContracts, "policies not found"), nil, nil
}

admin := policies.Items[0].Address

address, err := observerTypes.GetOperatorAddressFromAccAddress(admin)
if err != nil {
panic(err)
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDeploySystemContracts, "unable to get operator address"), nil, err
}
simAccount, found := simtypes.FindAccount(accounts, address)
if !found {
// TODO : remove panic
panic("admin account not found")
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDeploySystemContracts, "sim account for admin address not found"), nil, nil
}

msg := types.MsgDeploySystemContracts{Creator: admin}
Expand Down
1 change: 1 addition & 0 deletions x/observer/simulation/decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// TODO Add comments in this pr to explain the purpose of the function
func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
Expand Down
19 changes: 13 additions & 6 deletions x/observer/simulation/operations.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package simulation

import (
"fmt"
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -14,8 +13,17 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// Simulation operation weights constants
// Operation weights are used by the simulation program to simulate the weight of different operations.
// This decides what percentage of a certain type of operation is part of a block.
// Based on the weights assigned in the cosmos sdk modules , 100 seems to the max weight used , and therefore guarantees that at least one operation of that type is present in a block.
// TODO Add more details to comment based on what the number represents in terms of percentage of operations in a block
// https://github.com/zeta-chain/node/issues/3100
const (
OpWeightMsgTypeMsgEnableCCTX = "op_weight_msg_enable_crosschain_flags"
OpWeightMsgTypeMsgEnableCCTX = "op_weight_msg_enable_crosschain_flags"
// DefaultWeightMsgTypeMsgEnableCCTX We ues a hight weight for this operation
// to ensure that it is present in the block more number of time than any operation that changes the validator state
// Arrived at this number based on the weights used in the cosmos sdk staking module and through some trial and error
DefaultWeightMsgTypeMsgEnableCCTX = 650
)

Expand All @@ -38,25 +46,24 @@ func WeightedOperations(
}
}

// SimulateMsgTypeMsgEnableCCTX generates a MsgEnableCCTX and delivers it.
func SimulateMsgTypeMsgEnableCCTX(k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, chainID string,
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {

policies, found := k.GetAuthorityKeeper().GetPolicies(ctx)
if !found {
fmt.Println("Policies not found")
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEnableCCTX, "policies not found"), nil, nil
}

// TODO setup simutils package
admin := policies.Items[0].Address
address, err := types.GetOperatorAddressFromAccAddress(admin)
if err != nil {
panic(err)
}
simAccount, found := simtypes.FindAccount(accounts, address)
if !found {
// TODO : remove panic
panic("admin account not found")
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEnableCCTX, "admin account not found"), nil, nil
}

msg := types.MsgEnableCCTX{
Expand Down
1 change: 1 addition & 0 deletions x/observer/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func ChainNoncesKeyPrefix(chainID int64) []byte {
return []byte(strconv.FormatInt(chainID, 10))
}

// Address TODOS for name changes: https://github.com/zeta-chain/node/issues/3098
const (
BlameKey = "Blame-"
// TODO change identifier for VoterKey to BallotKey
Expand Down

0 comments on commit fa1234f

Please sign in to comment.