-
Notifications
You must be signed in to change notification settings - Fork 108
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
- Loading branch information
Showing
20 changed files
with
1,639 additions
and
274 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,65 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
|
||
"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" | ||
) | ||
|
||
func CmdUpdateOperationalFlags() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update-operational-flags", | ||
Short: "Broadcast message UpdateOperationalFlags", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var operationalFlags types.OperationalFlags | ||
|
||
flagSet := cmd.Flags() | ||
file, _ := flagSet.GetString("file") | ||
restartHeight, _ := flagSet.GetInt64("restart-height") | ||
|
||
if file != "" { | ||
file, err := filepath.Abs(file) | ||
if err != nil { | ||
return err | ||
} | ||
file = filepath.Clean(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("file", "", "Path to a JSON file containing OperationalFlags") | ||
cmd.Flags().Int64("restart-height", 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
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,48 @@ | ||
package types | ||
|
||
import ( | ||
cosmoserrors "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const ( | ||
TypeMsgUpdateOperationalFlags = "update_operational_flags" | ||
) | ||
|
||
var _ sdk.Msg = &MsgUpdateOperationalFlags{} | ||
|
||
func NewMsgUpdateOperationalFlags(creator string, flags OperationalFlags) *MsgUpdateOperationalFlags { | ||
return &MsgUpdateOperationalFlags{ | ||
Creator: creator, | ||
OperationalFlags: flags, | ||
} | ||
} | ||
|
||
func (msg *MsgUpdateOperationalFlags) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgUpdateOperationalFlags) Type() string { | ||
return TypeMsgUpdateOperationalFlags | ||
} | ||
|
||
func (msg *MsgUpdateOperationalFlags) GetSigners() []sdk.AccAddress { | ||
creator, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{creator} | ||
} | ||
|
||
func (msg *MsgUpdateOperationalFlags) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgUpdateOperationalFlags) ValidateBasic() error { | ||
if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { | ||
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.