-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add coordinated zetaclient restart
feedback updates
- Loading branch information
Showing
22 changed files
with
1,681 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package e2etests | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
observertypes "github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
// TestOperationalFlags tests the functionality of operations flags. | ||
func TestOperationalFlags(r *runner.E2ERunner, _ []string) { | ||
operationalFlagsRes, err := r.Clients.Zetacore.Observer.OperationalFlags( | ||
r.Ctx, | ||
&observertypes.QueryOperationalFlagsRequest{}, | ||
) | ||
require.NoError(r, err) | ||
|
||
// always set to low height so it's ignored by zetaclient | ||
nextRestartHeight := operationalFlagsRes.OperationalFlags.RestartHeight + 1 | ||
|
||
updateMsg := observertypes.NewMsgUpdateOperationalFlags( | ||
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName), | ||
observertypes.OperationalFlags{ | ||
RestartHeight: nextRestartHeight, | ||
}, | ||
) | ||
|
||
_, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, updateMsg) | ||
require.NoError(r, err) | ||
|
||
operationalFlagsRes, err = r.Clients.Zetacore.Observer.OperationalFlags( | ||
r.Ctx, | ||
&observertypes.QueryOperationalFlagsRequest{}, | ||
) | ||
require.NoError(r, err) | ||
require.Equal(r, nextRestartHeight, operationalFlagsRes.OperationalFlags.RestartHeight) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
syntax = "proto3"; | ||
package zetachain.zetacore.observer; | ||
|
||
option go_package = "github.com/zeta-chain/node/x/observer/types"; | ||
|
||
message OperationalFlags { | ||
// Height for a coordinated zetaclient restart. | ||
// Will be ignored if missed. | ||
int64 restart_height = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
func CmdShowOperationalFlags() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "show-operational-flags", | ||
Short: "shows the operational flags", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
params := &types.QueryOperationalFlagsRequest{} | ||
|
||
res, err := queryClient.OperationalFlags(context.Background(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
const ( | ||
fileFlag = "file" | ||
restartHeightFlag = "restart-height" | ||
) | ||
|
||
func CmdUpdateOperationalFlags() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update-operational-flags", | ||
Short: "Broadcast message UpdateOperationalFlags", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, _ []string) (err error) { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var operationalFlags types.OperationalFlags | ||
|
||
flagSet := cmd.Flags() | ||
file, _ := flagSet.GetString(fileFlag) | ||
restartHeight, _ := flagSet.GetInt64(restartHeightFlag) | ||
|
||
if file != "" { | ||
input, err := os.ReadFile(file) // #nosec G304 | ||
if err != nil { | ||
return err | ||
} | ||
err = json.Unmarshal(input, &operationalFlags) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
operationalFlags.RestartHeight = restartHeight | ||
} | ||
|
||
msg := types.NewMsgUpdateOperationalFlags( | ||
clientCtx.GetFromAddress().String(), | ||
operationalFlags, | ||
) | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(fileFlag, "", "Path to a JSON file containing OperationalFlags") | ||
cmd.Flags().Int64(restartHeightFlag, 0, "Height for a coordinated zetaclient restart") | ||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
func (k Keeper) OperationalFlags( | ||
c context.Context, | ||
req *types.QueryOperationalFlagsRequest, | ||
) (*types.QueryOperationalFlagsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
ctx := sdk.UnwrapSDKContext(c) | ||
// ignoring found is intentional | ||
operationalFlags, _ := k.GetOperationalFlags(ctx) | ||
return &types.QueryOperationalFlagsResponse{ | ||
OperationalFlags: operationalFlags, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
authoritytypes "github.com/zeta-chain/node/x/authority/types" | ||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
func (k msgServer) UpdateOperationalFlags( | ||
goCtx context.Context, | ||
msg *types.MsgUpdateOperationalFlags, | ||
) (*types.MsgUpdateOperationalFlagsResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// check permission | ||
err := k.GetAuthorityKeeper().CheckAuthorization(ctx, msg) | ||
if err != nil { | ||
return nil, errors.Wrap(authoritytypes.ErrUnauthorized, err.Error()) | ||
} | ||
|
||
k.Keeper.SetOperationalFlags(ctx, msg.OperationalFlags) | ||
|
||
return &types.MsgUpdateOperationalFlagsResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
func (k Keeper) SetOperationalFlags(ctx sdk.Context, operationalFlags types.OperationalFlags) { | ||
store := ctx.KVStore(k.storeKey) | ||
b := k.cdc.MustMarshal(&operationalFlags) | ||
key := types.KeyPrefix(types.OperationalFlagsKey) | ||
store.Set(key, b) | ||
} | ||
|
||
func (k Keeper) GetOperationalFlags(ctx sdk.Context) (val types.OperationalFlags, found bool) { | ||
found = false | ||
store := ctx.KVStore(k.storeKey) | ||
b := store.Get(types.KeyPrefix(types.OperationalFlagsKey)) | ||
if b == nil { | ||
return | ||
} | ||
found = true | ||
k.cdc.MustUnmarshal(b, &val) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.