Skip to content

Commit

Permalink
add comments to operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Dec 12, 2024
1 parent f32e676 commit a90a6eb
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 22 deletions.
4 changes: 3 additions & 1 deletion x/crosschain/simulation/operation_abort_stuck_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import (
"github.com/zeta-chain/node/x/crosschain/types"
)

// SimulateMsgAbortStuckCCTX generates a MsgAbortStuckCCTX with random values
func SimulateMsgAbortStuckCCTX(k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string,
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {

Check failure on line 21 in x/crosschain/simulation/operation_abort_stuck_cctx.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

// Pick a ethereum chain to abort a stuck cctx
chainID := int64(1337)
supportedChains := k.GetObserverKeeper().GetSupportedChains(ctx)
if len(supportedChains) == 0 {
Expand Down Expand Up @@ -56,7 +59,6 @@ func SimulateMsgAbortStuckCCTX(k keeper.Keeper) simtypes.Operation {
), nil, nil
}

// pick a random nonce from the pending nonces between 0 and nonceLow
// If nonce low is the same as nonce high, it means that there are no pending nonces to add trackers for
if pendingNonces.NonceLow == pendingNonces.NonceHigh {
return simtypes.NoOpMsg(
Expand Down
1 change: 0 additions & 1 deletion x/crosschain/simulation/operation_refund_aborted_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func SimulateMsgRefundAbortedCCTX(k keeper.Keeper,
if cctx.CctxStatus.IsAbortRefunded {
continue
}

abortedCctx = cctx
abortedCctxFound = true
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/zeta-chain/node/x/crosschain/types"
)

// SimulateMsgRemoveOutboundTracker generates a MsgRemoveOutboundTracker with random values
func SimulateMsgRemoveOutboundTracker(k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string,
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/zeta-chain/node/x/crosschain/types"
)

// SimulateMsgUpdateRateLimiterFlags generates a MsgUpdateRateLimiterFlags with random values
func SimulateMsgUpdateRateLimiterFlags(k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string,
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {
Expand Down
14 changes: 8 additions & 6 deletions x/crosschain/simulation/operation_update_tss_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func SimulateMsgUpdateTssAddress(k keeper.Keeper) simtypes.Operation {
"no cross chain txs found",
), nil, nil
}

// Pick any cctx with status OutboundMined, and use its index for the migration
// We set the fund migrator directly as we are not simulating MsgMigrateTssFunds
minedCCTX := types.CrossChainTx{}
foundMined := false
for _, cctx := range cctxList {
Expand All @@ -61,16 +64,13 @@ func SimulateMsgUpdateTssAddress(k keeper.Keeper) simtypes.Operation {
), nil, nil
}

// Thee tss migrator is set for all chains supporting tss migration
for _, chain := range supportedChains {
//index := ethcrypto.Keccak256Hash([]byte(fmt.Sprintf("%d", r.Int63()))).Hex()
//cctx := types.CrossChainTx{Index: index,
// CctxStatus: &types.Status{Status: types.CctxStatus_OutboundMined}}
tssmigrator := observertypes.TssFundMigratorInfo{
tssMigrator := observertypes.TssFundMigratorInfo{
ChainId: chain.ChainId,
MigrationCctxIndex: minedCCTX.Index,
}
//k.SetCrossChainTx(ctx, cctx)
k.GetObserverKeeper().SetFundMigrator(ctx, tssmigrator)
k.GetObserverKeeper().SetFundMigrator(ctx, tssMigrator)
}

oldTss, found := k.GetObserverKeeper().GetTSS(ctx)
Expand All @@ -81,6 +81,8 @@ func SimulateMsgUpdateTssAddress(k keeper.Keeper) simtypes.Operation {
"no TSS found",
), nil, nil
}

// Set the new TSS to state
newTss, err := sample.TSSFromRand(r)
newTss.FinalizedZetaHeight = oldTss.FinalizedZetaHeight + 10
newTss.KeyGenZetaHeight = oldTss.KeyGenZetaHeight + 10
Expand Down
7 changes: 2 additions & 5 deletions x/crosschain/simulation/operation_vote_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func operationSimulateVoteInbound(
}
}

// SimulateVoteInbound generates a MsgVoteInbound with random values and delivers it. It also schedules future operations for subsequent votes.
func SimulateVoteInbound(k keeper.Keeper) simtypes.Operation {
observerVotesTransitionMatrix, statePercentageArray, curNumVotesState := ObserverVotesSimulationMatrix()
return func(
Expand All @@ -63,11 +64,6 @@ func SimulateVoteInbound(k keeper.Keeper) simtypes.Operation {
accs []simtypes.Account,
chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
// TODO : randomize these values
// Right now we use a constant value for cctx creation , this is the same as the one used in unit tests for the successful condition.
// TestKeeper_VoteInbound/successfully vote on evm deposit
// But this can improved by adding more randomization

to, from := int64(1337), int64(101)
supportedChains := k.GetObserverKeeper().GetSupportedChains(ctx)
for _, chain := range supportedChains {
Expand All @@ -84,6 +80,7 @@ func SimulateVoteInbound(k keeper.Keeper) simtypes.Operation {
return simtypes.NoOpMsg(types.ModuleName, authz.InboundVoter.String(), "unable to get asset"), nil, err
}

// Generate a random inbound vote , coin type is randomly selected
msg := sample.InboundVoteFromRand(from, to, r, asset)

cf, found := k.GetObserverKeeper().GetCrosschainFlags(ctx)
Expand Down
8 changes: 5 additions & 3 deletions x/crosschain/simulation/operation_vote_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ func operationSimulateVoteOutbound(
}
}

// SimulateVoteOutbound generates a MsgVoteOutbound with random values
// This is the only operation which saves a cctx directly to the store.
// SimulateVoteOutbound generates a MsgVoteOutbound with random values and delivers it.
//It also schedules future operations for subsequent votes.

func SimulateVoteOutbound(k keeper.Keeper) simtypes.Operation {
defaultVote := chains.ReceiveStatus_success
alternativeVote := chains.ReceiveStatus_failed
Expand Down Expand Up @@ -97,6 +98,7 @@ func SimulateVoteOutbound(k keeper.Keeper) simtypes.Operation {
return simtypes.NoOpMsg(types.ModuleName, authz.OutboundVoter.String(), "unable to get asset"), nil, err
}

// Generate a new cctx and save it , which can be used to finalize the outbound
cctx := sample.CCTXfromRand(r, creator, index, to, from, tss.TssPubkey, asset)
msg := types.MsgVoteOutbound{
CctxHash: cctx.Index,
Expand Down Expand Up @@ -158,7 +160,7 @@ func SimulateVoteOutbound(k keeper.Keeper) simtypes.Operation {
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err
}

// We can return error here as we can guarantee that the first vote will be successful.
// We can return error here as we can guarantee that the first vote will be successful.
// Since we query the observer set before adding votes
_, _, err = app.SimDeliver(txGen.TxEncoder(), tx)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/simulation/operation_whitelist_erc20.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 Down Expand Up @@ -40,13 +39,14 @@ func SimulateMsgWhitelistERC20(k keeper.Keeper) simtypes.Operation {
filteredChains := chains.FilterChains(supportedChains, chains.FilterByVM(chains.Vm_evm))

//pick a random chain
// Keep the switch case to add solana support in future
// TODO : https://github.com/zeta-chain/node/issues/3287
randomChain := filteredChains[r.Intn(len(filteredChains))]
var tokenAddress string
switch {
case randomChain.IsEVMChain():
tokenAddress = sample.EthAddressFromRand(r).String()
default:
fmt.Println("unsupported chain", randomChain.ChainId)
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWhitelistERC20, "unsupported chain"), nil, nil
}

Expand Down
4 changes: 3 additions & 1 deletion x/observer/simulation/operation_add_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateAddObserver generates a TypeMsgAddObserver and delivers it. The message adds an observer to the observer set
// SimulateAddObserver generates a TypeMsgAddObserver and delivers it. This message sets AddNodeAccountOnly to false;
// Therefore, it adds the observer to the observer set
func SimulateAddObserver(k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string,
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {
Expand Down Expand Up @@ -43,6 +44,7 @@ func SimulateAddObserver(k keeper.Keeper) simtypes.Operation {
nodeAccounts := k.GetAllNodeAccount(ctx)

// Pick a random observer which part of the node account but not in the observer set
// New accounts are added to the node account list via SimulateAddObserverNodeAccount
var newObserver string
foundNA := RepeatCheck(func() bool {
newObserver = nodeAccounts[r.Intn(len(nodeAccounts))].Operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

// SimulateAddObserverNodeAccount generates a TypeMsgAddObserver and delivers it.
// This message sets AddNodeAccountOnly to true to it does not add the observer to the observer set
func SimulateAddObserverNodeAccount(k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string,
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {
Expand Down
3 changes: 2 additions & 1 deletion x/observer/simulation/operation_remove_chain_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgRemoveChainParams generates a MsgRemoveChainParams and delivers it.
// SimulateMsgRemoveChainParams generates a MsgRemoveChainParams and delivers it. This message removes a chain from the list
// This is not being run right now as the removal causes a lot of errors for the other operations.
func SimulateMsgRemoveChainParams(k keeper.Keeper) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accounts []simtypes.Account, _ string,
) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {
Expand Down
4 changes: 2 additions & 2 deletions x/observer/simulation/operation_vote_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// operationSimulateVoteTss generates a MsgVoteTSS with random values
func operationSimulateVoteTss(
k keeper.Keeper,
msg types.MsgVoteTSS,
Expand Down Expand Up @@ -52,8 +53,7 @@ func operationSimulateVoteTss(
}
}

// SimulateVoteOutbound generates a MsgVoteOutbound with random values
// This is the only operation which saves a cctx directly to the store.
// SimulateMsgVoteTSS generates a MsgVoteTSS with random values and delivers it, it also schedules future votes for the same ballot
func SimulateMsgVoteTSS(k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand,
Expand Down

0 comments on commit a90a6eb

Please sign in to comment.