Skip to content

Commit

Permalink
add msg vote tss
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Dec 11, 2024
1 parent 7c14f50 commit b5181d5
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 76 deletions.
2 changes: 1 addition & 1 deletion simulation/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestFullAppSimulation(t *testing.T) {
zetasimulation.PrintStats(db)
}

// TestFullAppSimulationAfterImport tests the application simulation after importing the state exported from a previous.At a high level,it does the following
// TestAppImportExport tests the application simulation after importing the state exported from a previous.At a high level,it does the following
// 1. It runs a full simulation and exports the state
// 2. It creates a new app, and db
// 3. It imports the exported state into the new app
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/simulation/operation_vote_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func SimulateVoteOutbound(k keeper.Keeper) simtypes.Operation {

err = firstMsg.ValidateBasic()
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to validate first inbound vote"), nil, err
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to validate first outbound vote"), nil, err
}

tx, err := simtestutil.GenSignedMockTx(
Expand Down Expand Up @@ -170,7 +170,7 @@ func SimulateVoteOutbound(k keeper.Keeper) simtypes.Operation {
// Add subsequent votes
observerSet, found := k.GetObserverKeeper().GetObserverSet(ctx)
if !found {
return simtypes.NoOpMsg(types.ModuleName, authz.InboundVoter.String(), "observer set not found"), nil, nil
return simtypes.NoOpMsg(types.ModuleName, authz.OutboundVoter.String(), "observer set not found"), nil, nil
}

// 1) Schedule operations for votes
Expand Down
13 changes: 10 additions & 3 deletions x/observer/keeper/msg_server_vote_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const voteTSSid = "Vote TSS"
func (k msgServer) VoteTSS(goCtx context.Context, msg *types.MsgVoteTSS) (*types.MsgVoteTSSResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// Checks whether a signer is authorized to sign, by checking their address against the observer mapper
// which contains the observer list for the chain and type.
// Checks whether a signer is authorized to sign, by checking if the signer has a node account.
_, found := k.GetNodeAccount(ctx, msg.Creator)
if !found {
return nil, errorsmod.Wrapf(
Expand Down Expand Up @@ -80,6 +79,12 @@ func (k msgServer) VoteTSS(goCtx context.Context, msg *types.MsgVoteTSS) (*types
return &types.MsgVoteTSSResponse{}, errorsmod.Wrap(err, voteTSSid)
}

//if ctx.BlockHeight() == 3 || ctx.BlockHeight() == 4 {
// fmt.Println("Vote added", ctx.BlockHeight(), msg.TssPubkey)
// fmt.Println("Votes", ballot.Votes)
// fmt.Println("VoterList Length", len(ballot.VoterList))
//}

ballot, isFinalized := k.CheckIfFinalizingVote(ctx, ballot)
if !isFinalized {
return &types.MsgVoteTSSResponse{
Expand All @@ -89,6 +94,8 @@ func (k msgServer) VoteTSS(goCtx context.Context, msg *types.MsgVoteTSS) (*types
}, nil
}

//fmt.Println("Ballot finalized", ballot.BallotStatus)

// The ballot is finalized, we check if this is the correct ballot for updating the TSS
// The requirements are
// 1. The keygen is still pending
Expand All @@ -104,7 +111,7 @@ func (k msgServer) VoteTSS(goCtx context.Context, msg *types.MsgVoteTSS) (*types
}, nil
}

// For cases when an observer tries to vote for an older pending ballot, associated with a keygen that was discarded , we would return at this check while still adding the vote to the ballot
// For cases when an observer tries to vote for an older pending ballot, associated with a keygen that was discarded, we would return at this check while still adding the vote to the ballot
if msg.KeygenZetaHeight != keygen.BlockNumber {
return &types.MsgVoteTSSResponse{
VoteFinalized: isFinalized,
Expand Down
13 changes: 6 additions & 7 deletions x/observer/simulation/operation_add_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgAddObserver generates a TypeMsgAddObserver and delivers it. The message adds an observer to the observer set
func SimulateMsgAddObserver(k keeper.Keeper) simtypes.Operation {
// SimulateAddObserver generates a TypeMsgAddObserver and delivers it. The message adds an 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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand Down Expand Up @@ -44,14 +44,13 @@ func SimulateMsgAddObserver(k keeper.Keeper) simtypes.Operation {

// Pick a random observer which part of the node account but not in the observer set
var newObserver string
foundNA := false
for i := 0; i < 10; i++ {
foundNA := RepeatCheck(func() bool {
newObserver = nodeAccounts[r.Intn(len(nodeAccounts))].Operator
if _, found := observerMap[newObserver]; !found {
foundNA = true
break
return true
}
}
return false
})
if !foundNA {
return simtypes.NoOpMsg(
types.ModuleName,
Expand Down
27 changes: 17 additions & 10 deletions x/observer/simulation/operation_add_observer_node_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgAddObserverNodeAccount generates a TypeMsgAddObserver and delivers it.
func SimulateMsgAddObserverNodeAccount(k keeper.Keeper) simtypes.Operation {
// SimulateAddObserverNodeAccount generates a TypeMsgAddObserver and delivers it.
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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand Down Expand Up @@ -49,22 +49,29 @@ func SimulateMsgAddObserverNodeAccount(k keeper.Keeper) simtypes.Operation {
), nil, nil
}
newObserver := ""
for {
foundNewObserver := RepeatCheck(func() bool {
randomValidator := validators[r.Intn(len(validators))]
randomValidatorOperatorAddress, err := types.GetAccAddressFromOperatorAddress(
randomValidator.OperatorAddress,
)
randomValidatorAddress, err := types.GetAccAddressFromOperatorAddress(randomValidator.OperatorAddress)
if err != nil {
continue
return false
}
newObserver = randomValidatorOperatorAddress.String()
newObserver = randomValidatorAddress.String()
err = k.IsValidator(ctx, newObserver)
if err != nil {
continue
return false
}
if _, ok := observerMap[newObserver]; !ok {
break
return true
}
return false
})

if !foundNewObserver {
return simtypes.NoOpMsg(
types.ModuleName,
types.TypeMsgAddObserver,
"no new observer found",
), nil, nil
}

msg := types.MsgAddObserver{
Expand Down
4 changes: 2 additions & 2 deletions x/observer/simulation/operation_disable_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgDisableCCTX generates a MsgDisableCCTX and delivers it.
func SimulateMsgDisableCCTX(k keeper.Keeper) simtypes.Operation {
// SimulateDisableCCTX generates a MsgDisableCCTX and delivers it.
func SimulateDisableCCTX(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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand Down
4 changes: 2 additions & 2 deletions x/observer/simulation/operation_enable_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgEnableCCTX generates a MsgEnableCCTX and delivers it.
func SimulateMsgEnableCCTX(k keeper.Keeper) simtypes.Operation {
// SimulateEnableCCTX generates a MsgEnableCCTX and delivers it.
func SimulateEnableCCTX(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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand Down
20 changes: 14 additions & 6 deletions x/observer/simulation/operation_remove_chain_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,27 @@ func SimulateMsgRemoveChainParams(k keeper.Keeper) simtypes.Operation {
), nil, nil
}

randomChainId := int64(0)
// remove zeta chain from the supported chains
for {
randomExternalChain := int64(0)
foundExternalChain := RepeatCheck(func() bool {
c := supportedChains[r.Intn(len(supportedChains))]
if !c.IsZetaChain() {
randomChainId = c.ChainId
break
randomExternalChain = c.ChainId
return true
}
return false
})

if !foundExternalChain {
return simtypes.NoOpMsg(
types.ModuleName,
types.TypeMsgRemoveChainParams,
"no external chain found",
), nil, nil
}

msg := types.MsgRemoveChainParams{
Creator: policyAccount.Address.String(),
ChainId: randomChainId,
ChainId: randomExternalChain,
}

err = msg.ValidateBasic()
Expand Down
6 changes: 3 additions & 3 deletions x/observer/simulation/operation_reset_chain_nonces.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgResetChainNonces generates a MsgResetChainNonces and delivers it.
func SimulateMsgResetChainNonces(k keeper.Keeper) simtypes.Operation {
// SimulateResetChainNonces generates a MsgResetChainNonces and delivers it.
func SimulateResetChainNonces(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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand All @@ -26,7 +26,7 @@ func SimulateMsgResetChainNonces(k keeper.Keeper) simtypes.Operation {
authAccount := k.GetAuthKeeper().GetAccount(ctx, policyAccount.Address)
spendable := k.GetBankKeeper().SpendableCoins(ctx, authAccount.GetAddress())

randomChain, err := GetExternalChain(ctx, k, r, 10)
randomChain, err := GetExternalChain(ctx, k, r)
if err != nil {
return simtypes.NoOpMsg(
types.ModuleName,
Expand Down
6 changes: 3 additions & 3 deletions x/observer/simulation/operation_update_chain_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgUpdateChainParams generates a MsgUpdateChainParams and delivers it.
func SimulateMsgUpdateChainParams(k keeper.Keeper) simtypes.Operation {
// SimulateUpdateChainParams generates a MsgUpdateChainParams and delivers it.
func SimulateUpdateChainParams(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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand All @@ -26,7 +26,7 @@ func SimulateMsgUpdateChainParams(k keeper.Keeper) simtypes.Operation {
authAccount := k.GetAuthKeeper().GetAccount(ctx, policyAccount.Address)
spendable := k.GetBankKeeper().SpendableCoins(ctx, authAccount.GetAddress())

randomChain, err := GetExternalChain(ctx, k, r, 10)
randomChain, err := GetExternalChain(ctx, k, r)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUpdateChainParams, err.Error()), nil, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgUpdateGasPriceIncreaseFlags generates a MsgUpdateGasPriceIncreaseFlags with random values
func SimulateMsgUpdateGasPriceIncreaseFlags(k keeper.Keeper) simtypes.Operation {
// SimulateUpdateGasPriceIncreaseFlags generates a MsgUpdateGasPriceIncreaseFlags with random values
func SimulateUpdateGasPriceIncreaseFlags(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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand Down
4 changes: 2 additions & 2 deletions x/observer/simulation/operation_update_keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgUpdateKeygen generates a MsgUpdateKeygen and delivers it.
func SimulateMsgUpdateKeygen(k keeper.Keeper) simtypes.Operation {
// SimulateUpdateKeygen generates a MsgUpdateKeygen and delivers it.
func SimulateUpdateKeygen(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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand Down
26 changes: 18 additions & 8 deletions x/observer/simulation/operation_update_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/zeta-chain/node/x/observer/types"
)

// SimulateMsgUpdateObserver generates a TypeMsgUpdateObserver and delivers it.
func SimulateMsgUpdateObserver(k keeper.Keeper) simtypes.Operation {
// SimulateUpdateObserver generates a TypeMsgUpdateObserver and delivers it.
func SimulateUpdateObserver(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) {
policyAccount, err := GetPolicyAccount(ctx, k.GetAuthorityKeeper(), accounts)
Expand All @@ -40,21 +40,31 @@ func SimulateMsgUpdateObserver(k keeper.Keeper) simtypes.Operation {
"no validators found",
), nil, nil
}

newObserver := ""
for {
foundNewObserver := RepeatCheck(func() bool {
randomValidator := validators[r.Intn(len(validators))]
nO, err := types.GetAccAddressFromOperatorAddress(randomValidator.OperatorAddress)
randomValidatorAddress, err := types.GetAccAddressFromOperatorAddress(randomValidator.OperatorAddress)
if err != nil {
continue
return false
}
newObserver = nO.String()
newObserver = randomValidatorAddress.String()
err = k.IsValidator(ctx, newObserver)
if err != nil {
continue
return false
}
if _, ok := observerMap[newObserver]; !ok {
break
return true
}
return false
})

if !foundNewObserver {
return simtypes.NoOpMsg(
types.ModuleName,
types.TypeMsgUpdateObserver,
"no new observer found",
), nil, nil
}

lastBlockCount, found := k.GetLastObserverCount(ctx)
Expand Down
Loading

0 comments on commit b5181d5

Please sign in to comment.