From fa1234f4d6e468c17c4b6e75e125d343988d5aed Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 5 Nov 2024 18:17:55 -0500 Subject: [PATCH] add comments for observer and fungible operations --- x/fungible/simulation/decoders.go | 1 + x/fungible/simulation/genesis.go | 1 - x/fungible/simulation/operations.go | 18 +++++++++++++----- x/observer/simulation/decoders.go | 1 + x/observer/simulation/operations.go | 19 +++++++++++++------ x/observer/types/keys.go | 1 + 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/x/fungible/simulation/decoders.go b/x/fungible/simulation/decoders.go index 892c09a60d..80e7546808 100644 --- a/x/fungible/simulation/decoders.go +++ b/x/fungible/simulation/decoders.go @@ -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 { diff --git a/x/fungible/simulation/genesis.go b/x/fungible/simulation/genesis.go index b67fa87137..87b947e9ec 100644 --- a/x/fungible/simulation/genesis.go +++ b/x/fungible/simulation/genesis.go @@ -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) } diff --git a/x/fungible/simulation/operations.go b/x/fungible/simulation/operations.go index b0c7fff40d..6222394226 100644 --- a/x/fungible/simulation/operations.go +++ b/x/fungible/simulation/operations.go @@ -1,7 +1,6 @@ package simulation import ( - "fmt" "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" @@ -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 ) @@ -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) { @@ -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} diff --git a/x/observer/simulation/decoders.go b/x/observer/simulation/decoders.go index 45b64bdb7c..7d2bf71aeb 100644 --- a/x/observer/simulation/decoders.go +++ b/x/observer/simulation/decoders.go @@ -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 { diff --git a/x/observer/simulation/operations.go b/x/observer/simulation/operations.go index 4c07e744d6..fa2b6cf14e 100644 --- a/x/observer/simulation/operations.go +++ b/x/observer/simulation/operations.go @@ -1,7 +1,6 @@ package simulation import ( - "fmt" "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" @@ -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 ) @@ -38,16 +46,16 @@ 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 { @@ -55,8 +63,7 @@ func SimulateMsgTypeMsgEnableCCTX(k keeper.Keeper) simtypes.Operation { } 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{ diff --git a/x/observer/types/keys.go b/x/observer/types/keys.go index bb2cdbe8e9..573c38e524 100644 --- a/x/observer/types/keys.go +++ b/x/observer/types/keys.go @@ -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