Skip to content

Commit

Permalink
Receive keep alive messages from pigeon #387
Browse files Browse the repository at this point in the history
  • Loading branch information
Vizualni authored Aug 5, 2022
1 parent 5e7874c commit f11bd88
Show file tree
Hide file tree
Showing 38 changed files with 1,423 additions and 66 deletions.
1 change: 0 additions & 1 deletion proto/valset/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ option go_package = "github.com/palomachain/paloma/x/valset/types";
// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;

}
18 changes: 18 additions & 0 deletions proto/valset/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "valset/params.proto";
import "valset/snapshot.proto";
import "google/protobuf/timestamp.proto";
// this line is used by starport scaffolding # 1

option go_package = "github.com/palomachain/paloma/x/valset/types";
Expand All @@ -26,6 +27,11 @@ service Query {
option (google.api.http).get = "/palomachain/paloma/valset/get_snapshot_by_id/{snapshotId}";
}

// Queries a list of GetValidatorAliveUntil items.
rpc GetValidatorAliveUntil(QueryGetValidatorAliveUntilRequest) returns (QueryGetValidatorAliveUntilResponse) {
option (google.api.http).get = "/palomachain/paloma/valset/get_validator_alive_until";
}

// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -54,4 +60,16 @@ message QueryGetSnapshotByIDResponse {
Snapshot snapshot = 1;
}

message QueryGetValidatorAliveUntilRequest {
bytes valAddress = 1[ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.ValAddress" ];
}

message QueryGetValidatorAliveUntilResponse {
google.protobuf.Timestamp aliveUntil = 1 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true
];
}

// this line is used by starport scaffolding # 3
8 changes: 8 additions & 0 deletions proto/valset/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ option go_package = "github.com/palomachain/paloma/x/valset/types";
// Msg defines the Msg service.
service Msg {
rpc AddExternalChainInfoForValidator(MsgAddExternalChainInfoForValidator) returns (MsgAddExternalChainInfoForValidatorResponse);
rpc KeepAlive(MsgKeepAlive) returns (MsgKeepAliveResponse);
// this line is used by starport scaffolding # proto/tx/rpc
}

Expand All @@ -21,4 +22,11 @@ message MsgAddExternalChainInfoForValidator {
message MsgAddExternalChainInfoForValidatorResponse {
}

message MsgKeepAlive {
string creator = 1;
}

message MsgKeepAliveResponse {
}

// this line is used by starport scaffolding # proto/tx/message
10 changes: 10 additions & 0 deletions util/keeper/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ func IterAll[T codec.ProtoMarshaler](store sdk.KVStore, pu protoUnmarshaler) ([]
return keys, res, nil
}

func IterAllRaw(store sdk.KVStore, pu protoUnmarshaler) (keys [][]byte, values [][]byte, _err error) {
iterator := store.Iterator(nil, nil)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
keys = append(keys, iterator.Key())
values = append(values, iterator.Value())
}
return
}

func IterAllFnc[T codec.ProtoMarshaler](store sdk.KVStore, pu protoUnmarshaler, fnc func([]byte, T) bool) error {
res := []T{}
iterator := store.Iterator(nil, nil)
Expand Down
4 changes: 4 additions & 0 deletions x/consensus/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (k msgServer) AddMessagesSignatures(goCtx context.Context, msg *types.MsgAd
); err != nil {
return nil, err
}
err := k.Keeper.valset.KeepValidatorAlive(ctx, valAddr)
if err != nil {
return nil, err
}

return &types.MsgAddMessagesSignaturesResponse{}, nil
}
5 changes: 5 additions & 0 deletions x/consensus/keeper/msg_server_add_evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ func (k msgServer) AddEvidence(goCtx context.Context, msg *types.MsgAddEvidence)
return nil, err
}

err = k.Keeper.valset.KeepValidatorAlive(ctx, valAddr)
if err != nil {
return nil, err
}

return &types.MsgAddEvidenceResponse{}, nil
}
4 changes: 4 additions & 0 deletions x/consensus/keeper/msg_server_set_public_access_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (k msgServer) SetPublicAccessData(goCtx context.Context, msg *types.MsgSetP
if err != nil {
return nil, err
}
err = k.Keeper.valset.KeepValidatorAlive(ctx, valAddr)
if err != nil {
return nil, err
}

return &types.MsgSetPublicAccessDataResponse{}, nil
}
1 change: 1 addition & 0 deletions x/consensus/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ type ValsetKeeper interface {
GetSigningKey(ctx sdk.Context, valAddr sdk.ValAddress, chainType, chainReferenceID, signedByAddress string) ([]byte, error)
GetCurrentSnapshot(ctx sdk.Context) (*valsettypes.Snapshot, error)
CanAcceptValidator(ctx sdk.Context, valAddr sdk.ValAddress) error
KeepValidatorAlive(ctx sdk.Context, valAddr sdk.ValAddress) error
}
32 changes: 31 additions & 1 deletion x/consensus/types/mocks/QueuedSignedMessageI.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions x/consensus/types/mocks/ValsetKeeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions x/consensus/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/evm/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ type ConsensusKeeper interface {
type ValsetKeeper interface {
FindSnapshotByID(ctx sdk.Context, id uint64) (*valsettypes.Snapshot, error)
GetCurrentSnapshot(ctx sdk.Context) (*valsettypes.Snapshot, error)
KeepValidatorAlive(ctx sdk.Context, valAddr sdk.ValAddress) error
}
14 changes: 14 additions & 0 deletions x/evm/types/mocks/ValsetKeeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions x/valset/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command {

cmd.AddCommand(CmdGetSnapshotByID())

cmd.AddCommand(CmdGetValidatorAliveUntil())

// this line is used by starport scaffolding # 1

return cmd
Expand Down
42 changes: 42 additions & 0 deletions x/valset/client/cli/query_get_validator_alive_until.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/palomachain/paloma/x/valset/types"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdGetValidatorAliveUntil() *cobra.Command {
cmd := &cobra.Command{
Use: "get-validator-alive-until",
Short: "Query GetValidatorAliveUntil",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetValidatorAliveUntilRequest{}

res, err := queryClient.GetValidatorAliveUntil(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
1 change: 1 addition & 0 deletions x/valset/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func GetTxCmd() *cobra.Command {
}

cmd.AddCommand(CmdAddExternalChainInfoForValidator())
cmd.AddCommand(CmdKeepAlive())
// this line is used by starport scaffolding # 1

return cmd
Expand Down
40 changes: 40 additions & 0 deletions x/valset/client/cli/tx_keep_alive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/palomachain/paloma/x/valset/types"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdKeepAlive() *cobra.Command {
cmd := &cobra.Command{
Use: "keep-alive",
Short: "Broadcast message KeepAlive",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgKeepAlive(
clientCtx.GetFromAddress().String(),
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
3 changes: 3 additions & 0 deletions x/valset/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
case *types.MsgAddExternalChainInfoForValidator:
res, err := msgServer.AddExternalChainInfoForValidator(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgKeepAlive:
res, err := msgServer.KeepAlive(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
// this line is used by starport scaffolding # 1
default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
Expand Down
1 change: 1 addition & 0 deletions x/valset/keeper/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

const (
ErrValidatorWithAddrNotFound = whoops.Errorf("validator with addr %s was not found")
ErrValidatorNotInKeepAlive = whoops.Errorf("validator is not in keep alive store %s")
ErrMaxNumberOfExternalAccounts = whoops.Errorf("trying to submit %d accounts while the limit is %d")
ErrValidatorCannotBePigeon = whoops.Errorf("validator %s cannot be a pigeon")

Expand Down
Loading

0 comments on commit f11bd88

Please sign in to comment.