Skip to content

Commit c8d602f

Browse files
committed
wip
1 parent b4d54c8 commit c8d602f

File tree

3 files changed

+39
-48
lines changed

3 files changed

+39
-48
lines changed

modules/rollkitmngr/keeper/grpc_query.go

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package keeper
22

33
import (
44
"context"
5-
"errors"
65

7-
"cosmossdk.io/collections"
86
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
97

108
"github.com/rollkit/go-execution-abci/modules/rollkitmngr/types"
@@ -21,9 +19,31 @@ func NewQueryServer(keeper Keeper) types.QueryServer {
2119
return queryServer{Keeper: keeper}
2220
}
2321

24-
// Sequencers returns the current sequencers.
25-
// Note it is only a wrapper around the staking module's query.
26-
func (q queryServer) Sequencers(ctx context.Context, _ *types.QuerySequencersRequest) (*types.QuerySequencersResponse, error) {
22+
// Attesters returns the current attesters.
23+
// Note it is only a wrapper around the staking module's query (iff the attesters are enabled).
24+
func (q queryServer) Attesters(context.Context, *types.QueryAttestersRequest) (*types.QueryAttestersResponse, error) {
25+
// err := q.NextSequencers.Walk(ctx, nil, func(key uint64, sequencer types.Sequencer) (bool, error) {
26+
// sequencers = append(sequencers, types.SequencerChanges{
27+
// BlockHeight: key,
28+
// Sequencers: []types.Sequencer{sequencer},
29+
// })
30+
// return false, nil
31+
// })
32+
// if err != nil && !errors.Is(err, collections.ErrNotFound) {
33+
// return nil, err
34+
// }
35+
36+
panic("unimplemented")
37+
}
38+
39+
// IsMigrating implements types.QueryServer.
40+
func (q queryServer) IsMigrating(context.Context, *types.QueryIsMigratingRequest) (*types.QueryIsMigratingResponse, error) {
41+
panic("unimplemented")
42+
}
43+
44+
// Attesters returns the current attesters.
45+
// Note it is only a wrapper around the staking module's query (iff the attesters are disabled). Otherwise it fetches from the module state.
46+
func (q queryServer) Sequencer(ctx context.Context, _ *types.QuerySequencerRequest) (*types.QuerySequencerResponse, error) {
2747
vals, err := q.stakingKeeper.GetLastValidators(ctx)
2848
if err != nil {
2949
return nil, sdkerrors.ErrLogic.Wrapf("failed to get last validators")
@@ -33,37 +53,14 @@ func (q queryServer) Sequencers(ctx context.Context, _ *types.QuerySequencersReq
3353
// In the meantime, this is enough to determine if the chain is using rollkit or not.
3454
// There is one false positive for single validators chains, but those are more often local testnets.
3555
if len(vals) > 1 {
36-
return &types.QuerySequencersResponse{}, sdkerrors.ErrLogic.Wrapf("chain is currently not using Rollkit")
37-
}
38-
39-
sequencers := make([]types.Sequencer, len(vals))
40-
for i, val := range vals {
41-
sequencers[i] = types.Sequencer{
42-
Name: val.GetMoniker(),
43-
ConsensusPubkey: val.ConsensusPubkey,
44-
}
45-
}
46-
47-
return &types.QuerySequencersResponse{
48-
Sequencers: sequencers,
49-
}, nil
50-
}
51-
52-
// SequencersChanges returns the planned sequencers changes.
53-
func (q queryServer) SequencersChanges(ctx context.Context, _ *types.QuerySequencersChangesRequest) (*types.QuerySequencersChangesResponse, error) {
54-
var sequencers []types.SequencerChanges
55-
err := q.NextSequencers.Walk(ctx, nil, func(key uint64, sequencer types.Sequencer) (bool, error) {
56-
sequencers = append(sequencers, types.SequencerChanges{
57-
BlockHeight: key,
58-
Sequencers: []types.Sequencer{sequencer},
59-
})
60-
return false, nil
61-
})
62-
if err != nil && !errors.Is(err, collections.ErrNotFound) {
63-
return nil, err
56+
// TODO
57+
// chain is using attesters, fallback to something else
6458
}
6559

66-
return &types.QuerySequencersChangesResponse{
67-
SequencerChanges: sequencers,
60+
return &types.QuerySequencerResponse{
61+
Sequencer: types.Sequencer{
62+
Name: vals[0].GetMoniker(),
63+
ConsensusPubkey: vals[0].ConsensusPubkey,
64+
},
6865
}, nil
6966
}

modules/rollkitmngr/keeper/msg_server.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,21 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
2121
return &msgServer{Keeper: keeper}
2222
}
2323

24-
func (k msgServer) ChangeSequencers(ctx context.Context, msg *types.MsgChangeSequencers) (*types.MsgChangeSequencersResponse, error) {
24+
func (k msgServer) MigrateToRollkit(ctx context.Context, msg *types.MsgRollkitMigrate) (*types.MsgMigrateToRollkitResponse, error) {
2525
if k.authority != msg.Authority {
2626
return nil, govtypes.ErrInvalidSigner.Wrapf("invalid authority; expected %s, got %s", k.authority, msg.Authority)
2727
}
2828

29-
if len(msg.Sequencers) == 0 {
30-
return nil, sdkerrors.ErrNotSupported.Wrapf("a sequencer is required.")
31-
}
32-
33-
if len(msg.Sequencers) > 1 {
34-
return nil, sdkerrors.ErrNotSupported.Wrapf("currently only one sequencer can be set at a time")
35-
}
36-
3729
sdkCtx := sdk.UnwrapSDKContext(ctx)
3830
if msg.BlockHeight < uint64(sdkCtx.BlockHeight()) {
3931
return nil, sdkerrors.ErrInvalidRequest.Wrapf("block height %d must be greater than current block height %d", msg.BlockHeight, sdkCtx.BlockHeight())
4032
}
4133

42-
if err := k.NextSequencers.Set(ctx, msg.BlockHeight, msg.Sequencers[0]); err != nil {
34+
// TODO: set attesters
35+
36+
if err := k.NextSequencers.Set(ctx, msg.BlockHeight, msg.Sequencer); err != nil {
4337
return nil, err
4438
}
4539

46-
return &types.MsgChangeSequencersResponse{}, nil
40+
return &types.MsgMigrateToRollkitResponse{}, nil
4741
}

modules/rollkitmngr/types/codec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
)
1010

1111
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
12-
legacy.RegisterAminoMsg(cdc, &MsgChangeSequencers{}, "rollkitmngr/v1/MsgChangeSequencers")
12+
legacy.RegisterAminoMsg(cdc, &MsgRollkitMigrate{}, "rollkitmngr/v1/MsgRollkitMigrate")
1313
}
1414

1515
// RegisterInterfaces registers the x/sequencer interfaces types with the interface registry
1616
func RegisterInterfaces(registry types.InterfaceRegistry) {
1717
registry.RegisterImplementations((*sdk.Msg)(nil),
18-
&MsgChangeSequencers{},
18+
&MsgRollkitMigrate{},
1919
)
2020

2121
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)

0 commit comments

Comments
 (0)