Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kirill/1226 whitelisted relayers #571

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions proto/sequencers/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";
package rollapp.sequencers.types;

option go_package = "github.com/dymensionxyz/dymension-rdk/x/sequencers/types";

message EventUpdateRewardAddress {
// Operator is the bech32-encoded address of the actor sending the update
string operator = 1;
// RewardAddr is a bech32 encoded sdk acc address
string reward_addr = 2;
}

message EventUpdateWhitelistedRelayers {
// Operator is the bech32-encoded address of the actor sending the update
string operator = 1;
// Relayers is an array of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
repeated string relayers = 2;
}

message EventUpsertSequencer {
// Operator is the bech32-encoded address of the actor sending the update
string operator = 1;
// ConsAddr is a tendermint consensus address
string cons_addr = 2;
// RewardAddr is the bech32-encoded sequencer's reward address
string reward_addr = 3;
// Relayers is an array of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
repeated string relayers = 4;
}
10 changes: 1 addition & 9 deletions proto/sequencers/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ syntax = "proto3";
package rollapp.sequencers.types;

import "gogoproto/gogo.proto";
import "sequencers/params.proto";
import "cosmos/staking/v1beta1/staking.proto";
import "sequencers/sequencers.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/sequencers/types";

message Sequencer {
// Validator is a convenient storage for e.g operator address and consensus pub key
cosmos.staking.v1beta1.Validator validator = 1;
// RewardAddr is the sdk acc address where the sequencer has opted to receive rewards. Empty if not set.
string reward_addr = 2;
}

// GenesisState defines the module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
Expand Down
23 changes: 0 additions & 23 deletions proto/sequencers/params.proto

This file was deleted.

22 changes: 10 additions & 12 deletions proto/sequencers/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ syntax = "proto3";
package rollapp.sequencers.types;

import "gogoproto/gogo.proto";

import "cosmos/staking/v1beta1/staking.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "sequencers/params.proto";

import "sequencers/sequencers.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/sequencers/types";

Expand Down Expand Up @@ -39,47 +37,47 @@ service Query {

// QuerySequencersRequest is request type for Query/Sequencers RPC method.
message QuerySequencersRequest {
// status enables to query for sequencers matching a given status.
// Status enables to query for sequencers matching a given status.
string status = 1;

// pagination defines an optional pagination for the request.
// Pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QuerySequencersResponse is response type for the Query/Sequencers RPC method
message QuerySequencersResponse {
// sequencers contains all the queried sequencers.
// Sequencers contains all the queried sequencers.
repeated cosmos.staking.v1beta1.Validator sequencers = 1
[ (gogoproto.nullable) = false ];

// pagination defines the pagination in the response.
// Pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QuerySequencerRequest is response type for the Query/Sequencer RPC method
message QuerySequencerRequest {
// sequencer_addr defines the sequencer address to query for.
// SequencerAddr defines the sequencer address to query for.
string sequencer_addr = 1;
}

// QuerySequencerResponse is response type for the Query/Sequencer RPC method
message QuerySequencerResponse {
// sequencer defines the the sequencer info.
// Sequencer defines the the sequencer info.
cosmos.staking.v1beta1.Validator sequencer = 1
[ (gogoproto.nullable) = false ];
}

// QueryHistoricalInfoRequest is request type for the Query/HistoricalInfo RPC
// method.
message QueryHistoricalInfoRequest {
// height defines at which height to query the historical info.
// Height defines at which height to query the historical info.
int64 height = 1;
}

// QueryHistoricalInfoResponse is response type for the Query/HistoricalInfo RPC
// method.
message QueryHistoricalInfoResponse {
// hist defines the historical info at the given height.
// Hist defines the historical info at the given height.
cosmos.staking.v1beta1.HistoricalInfo hist = 1;
}

Expand All @@ -88,7 +86,7 @@ message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
// Params holds all the parameters of this module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

40 changes: 40 additions & 0 deletions proto/sequencers/sequencers.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";
package rollapp.sequencers.types;

import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";
import "cosmos/staking/v1beta1/staking.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/sequencers/types";

// Params defines the parameters for the module.
message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

// UnbondingTime is the time duration of unbonding.
google.protobuf.Duration unbonding_time = 1 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
(gogoproto.moretags) = "yaml:\"unbonding_time\""
];

// HistoricalEntries is the number of historical entries to persist.
uint32 historical_entries = 2
[ (gogoproto.moretags) = "yaml:\"historical_entries\"" ];
}

message Sequencer {
// Validator is a convenient storage for e.g operator address and consensus pub key
cosmos.staking.v1beta1.Validator validator = 1;
// RewardAddr is the sdk acc address where the sequencer has opted to receive rewards. Empty if not set.
string reward_addr = 2;
// Relayers is an array of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
repeated string relayers = 3;
}

// WhitelistedRelayers is used for storing the whitelisted relater list in the state
message WhitelistedRelayers {
// Relayers is an array of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
repeated string relayers = 1;
}
45 changes: 28 additions & 17 deletions proto/sequencers/tx.proto
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
syntax = "proto3";
package rollapp.sequencers.types;

import "gogoproto/gogo.proto";
import "cosmos/staking/v1beta1/staking.proto";
import "cosmos/msg/v1/msg.proto";
import "google/protobuf/any.proto";

option go_package = "github.com/dymensionxyz/dymension-rdk/x/sequencers/types";

// Msg defines the Msg service.
service Msg {
rpc CreateSequencer(MsgCreateSequencer) returns (MsgCreateSequencerResponse);
rpc UpdateSequencer(MsgUpdateSequencer) returns (MsgUpdateSequencerResponse);
// Messages
rpc UpdateRewardAddress(MsgUpdateRewardAddress) returns (MsgUpdateRewardAddressResponse);
rpc UpdateWhitelistedRelayers(MsgUpdateWhitelistedRelayers) returns (MsgUpdateWhitelistedRelayersResponse);

// Consensus Messages
rpc UpsertSequencer(ConsensusMsgUpsertSequencer) returns (ConsensusMsgUpsertSequencerResponse);
}

message MsgCreateSequencer {
message MsgUpdateRewardAddress {
option (cosmos.msg.v1.signer) = "operator";
// Operator is the bech32-encoded address of the actor sending the update - must be val addr
// Operator is the bech32-encoded address of the actor sending the update
string operator = 1;
// PubKey is a tendermint consensus pub key
google.protobuf.Any pub_key = 2;
// Signature is operator signed with the private key of pub_key
bytes signature = 3;
// RewardAddr is a bech32 encoded sdk acc address
string reward_addr = 2;
}

message MsgCreateSequencerResponse {
message MsgUpdateRewardAddressResponse {}

message MsgUpdateWhitelistedRelayers {
option (cosmos.msg.v1.signer) = "operator";
// Operator is the bech32-encoded address of the actor sending the update
string operator = 1;
// Relayers is an array of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
repeated string relayers = 2;
}

message MsgUpdateSequencer {
message MsgUpdateWhitelistedRelayersResponse {}

// ConsensusMsgUpsertSequencer is a consensus message to upsert the sequencer.
message ConsensusMsgUpsertSequencer {
option (cosmos.msg.v1.signer) = "operator";
// Operator is the bech32-encoded address of the actor sending the update - must be val addr
// Operator is the bech32-encoded address of the actor sending the update
string operator = 1;
// RewardAddr is a bech32 encoded sdk acc address
// ConsPubKey is a tendermint consensus pub key
google.protobuf.Any cons_pub_key = 2;
// RewardAddr is the bech32-encoded sequencer's reward address
string reward_addr = 3;
// Relayers is an array of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
repeated string relayers = 4;
}

message MsgUpdateSequencerResponse {

}
message ConsensusMsgUpsertSequencerResponse {}
4 changes: 2 additions & 2 deletions server/commands/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/dymensionxyz/dymint/block"
dymintconf "github.com/dymensionxyz/dymint/config"
dymintconv "github.com/dymensionxyz/dymint/conv"

"github.com/dymensionxyz/dymint/store"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/node"
Expand All @@ -17,8 +16,9 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/dymensionxyz/dymension-rdk/utils"
"github.com/spf13/cobra"

"github.com/dymensionxyz/dymension-rdk/utils"
)

// RollbackCmd rollbacks the app multistore to specific height and updates dymint state according to it
Expand Down
71 changes: 71 additions & 0 deletions utils/uevent/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Package uevent is a copy of https://github.com/dymensionxyz/sdk-utils/tree/main/utils/uevent.
// TODO: import sdk-utils directly when the RDK is updated to SDK v0.47 and further.
package uevent

import (
"encoding/json"
"slices"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
abci "github.com/tendermint/tendermint/abci/types"
"golang.org/x/exp/maps"
)

// EmitTypedEvent takes a typed event and emits it.
// The original EmitTypedEvent from cosmos-sdk adds double quotes around the string attributes,
// which makes it difficult, if not impossible to query/subscribe to those events.
// See https://github.com/cosmos/cosmos-sdk/issues/12592 and
// https://github.com/dymensionxyz/sdk-utils/pull/5#discussion_r1724688379
func EmitTypedEvent(ctx sdk.Context, tev proto.Message) error {
event, err := TypedEventToEvent(tev)
if err != nil {
return err
}
ctx.EventManager().EmitEvent(event)
return nil
}

// TypedEventToEvent takes typed event and converts to Event object
func TypedEventToEvent(tev proto.Message) (ev sdk.Event, err error) {
evtType := proto.MessageName(tev)

var evtJSON []byte
evtJSON, err = codec.ProtoMarshalJSON(tev, nil)
if err != nil {
return
}

var attrMap map[string]json.RawMessage
if err = json.Unmarshal(evtJSON, &attrMap); err != nil {
return
}

// sort the keys to ensure the order is always the same
keys := maps.Keys(attrMap)
slices.Sort(keys)

attrs := make([]abci.EventAttribute, 0, len(attrMap))
for _, k := range keys {
v := attrMap[k]
attrs = append(attrs, abci.EventAttribute{
Key: []byte(k),
Value: []byte(removeSurroundingQuotes(v)),
})
}

ev = sdk.Event{
Type: evtType,
Attributes: attrs,
}
return
}

func removeSurroundingQuotes(bz []byte) string {
const dquote = 34
if len(bz) > 1 && bz[0] == dquote && bz[len(bz)-1] == dquote {
return string(bz[1 : len(bz)-1])
}
return string(bz)
}
4 changes: 2 additions & 2 deletions x/sequencers/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension-rdk/x/sequencers/types"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/dymensionxyz/dymension-rdk/x/sequencers/types"
)

type Querier struct {
Expand Down
Loading
Loading