Skip to content

Commit

Permalink
feat: added signer to ConsensusMsgUpsertSequencer (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch authored Oct 29, 2024
1 parent 0e79bec commit af08d71
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 46 deletions.
17 changes: 17 additions & 0 deletions block/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"sync"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/gogo/protobuf/proto"

"github.com/dymensionxyz/dymint/types"
Expand Down Expand Up @@ -36,6 +38,16 @@ func (q *ConsensusMsgQueue) Get() []proto.Message {
return q.queue.DequeueAll()
}

func ConsensusMsgSigner(m proto.Message) (sdk.AccAddress, error) {
switch m.(type) {
case *rdktypes.ConsensusMsgUpsertSequencer:
const RdkSequencersModuleName = "sequencers"
return authtypes.NewModuleAddress(RdkSequencersModuleName), nil
default:
return nil, fmt.Errorf("unknown consensus msg")
}
}

// ConsensusMsgsOnSequencerSetUpdate forms a list of consensus messages to handle the sequencer set update.
func ConsensusMsgsOnSequencerSetUpdate(newSequencers []types.Sequencer) ([]proto.Message, error) {
msgs := make([]proto.Message, 0, len(newSequencers))
Expand All @@ -44,7 +56,12 @@ func ConsensusMsgsOnSequencerSetUpdate(newSequencers []types.Sequencer) ([]proto
if err != nil {
return nil, fmt.Errorf("sequencer consensus public key: %w", err)
}
signer, err := ConsensusMsgSigner(new(rdktypes.ConsensusMsgUpsertSequencer))
if err != nil {
return nil, fmt.Errorf("consensus msg signer: %w", err)
}
msgs = append(msgs, &rdktypes.ConsensusMsgUpsertSequencer{
Signer: signer.String(),
Operator: s.SettlementAddress,
ConsPubKey: protoutils.CosmosToGogo(anyPK),
RewardAddr: s.RewardAddr,
Expand Down
24 changes: 24 additions & 0 deletions block/consensus_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package block_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/dymensionxyz/dymint/block"
sequencertypes "github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/sequencer"
rdktypes "github.com/dymensionxyz/dymint/types/pb/rollapp/sequencers/types"
)

func TestConsensusMsgSigner(t *testing.T) {
t.Run("valid", func(t *testing.T) {
addr, err := block.ConsensusMsgSigner(new(rdktypes.ConsensusMsgUpsertSequencer))
require.NoError(t, err)
require.Equal(t, "cosmos1k3m3ck7fkza9zlwn95p0m73wugf5x4hxf83rqd", addr.String())
})

t.Run("invalid", func(t *testing.T) {
_, err := block.ConsensusMsgSigner(new(sequencertypes.MsgCreateSequencer))
require.Error(t, err)
})
}
9 changes: 9 additions & 0 deletions block/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/tendermint/tendermint/libs/pubsub"
"github.com/tendermint/tendermint/proxy"

block2 "github.com/dymensionxyz/dymint/block"
"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/mempool"
mempoolv1 "github.com/dymensionxyz/dymint/mempool/v1"
Expand Down Expand Up @@ -353,10 +354,14 @@ func TestUpdateInitialSequencerSet(t *testing.T) {
require.Len(block.Data.ConsensusMessages, 2)

// Construct expected messages
signer, err := block2.ConsensusMsgSigner(new(rdktypes.ConsensusMsgUpsertSequencer))
require.NoError(err)

// Msg 1
anyPK1, err := proposer.AnyConsPubKey()
require.NoError(err)
expectedConsMsg1 := &rdktypes.ConsensusMsgUpsertSequencer{
Signer: signer.String(),
Operator: proposer.SettlementAddress,
ConsPubKey: protoutils.CosmosToGogo(anyPK1),
RewardAddr: proposer.RewardAddr,
Expand All @@ -373,6 +378,7 @@ func TestUpdateInitialSequencerSet(t *testing.T) {
anyPK2, err := sequencer.AnyConsPubKey()
require.NoError(err)
expectedConsMsg2 := &rdktypes.ConsensusMsgUpsertSequencer{
Signer: signer.String(),
Operator: sequencer.SettlementAddress,
ConsPubKey: protoutils.CosmosToGogo(anyPK2),
RewardAddr: sequencer.RewardAddr,
Expand Down Expand Up @@ -474,9 +480,12 @@ func TestUpdateExistingSequencerSet(t *testing.T) {
require.Len(block.Data.ConsensusMessages, 1)

// Construct the expected message
signer, err := block2.ConsensusMsgSigner(new(rdktypes.ConsensusMsgUpsertSequencer))
require.NoError(err)
anyPK, err := updatedSequencer.AnyConsPubKey()
require.NoError(err)
expectedConsMsg := &rdktypes.ConsensusMsgUpsertSequencer{
Signer: signer.String(),
Operator: updatedSequencer.SettlementAddress,
ConsPubKey: protoutils.CosmosToGogo(anyPK),
RewardAddr: updatedSequencer.RewardAddr,
Expand Down
20 changes: 13 additions & 7 deletions proto/types/rollapp/sequencers/types/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ message MsgUpdateWhitelistedRelayersResponse {}

// ConsensusMsgUpsertSequencer is a consensus message to upsert the sequencer.
message ConsensusMsgUpsertSequencer {
// Operator is the bech32-encoded address of the actor sending the update
string operator = 1;
// ConsPubKey is a tendermint consensus pub key
google.protobuf.Any cons_pub_key = 2;
option (cosmos.msg.v1.signer) = "signer";

// Signer is the bech32-encoded address of the consensus msg signer.
// Expected to be an authorized address.
string signer = 1;
// Operator is the bech32-encoded address of the sequencer
string operator = 2;
// ConsPubKey is a tendermint consensus pub key of the sequencer
google.protobuf.Any cons_pub_key = 3;
// 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;
string reward_addr = 4;
// Relayers is an array of the whitelisted relayer addresses of the sequencer.
// Addresses are bech32-encoded strings.
repeated string relayers = 5;
}

message ConsensusMsgUpsertSequencerResponse {}
134 changes: 95 additions & 39 deletions types/pb/rollapp/sequencers/types/tx.pb.go

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

0 comments on commit af08d71

Please sign in to comment.