Skip to content

Commit

Permalink
feat(sequencer): query paginated (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt authored Jan 8, 2025
1 parent 559cd86 commit 3789c4a
Show file tree
Hide file tree
Showing 16 changed files with 1,823 additions and 564 deletions.
4 changes: 0 additions & 4 deletions proto/types/dymensionxyz/dymension/common/status.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// This file is a modified copy of the common module proto contract. Source:
// https://github.com/dymensionxyz/dymension/blob/f140cd1dd561cefb3e6562cbf4379b88cd16400d/proto/dymensionxyz/dymension/common/.

syntax = "proto3";
package dymensionxyz.dymension.common;

Expand All @@ -11,5 +8,4 @@ option go_package = "github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymens
enum Status {
PENDING = 0;
FINALIZED = 1;
REVERTED = 3;
}
54 changes: 35 additions & 19 deletions proto/types/dymensionxyz/dymension/sequencer/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@ option go_package = "github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymens

// EventIncreasedBond is an event emitted when a sequencer's bond is increased.
message EventIncreasedBond {
// sequencer is the bech32-encoded address of the sequencer which increased its bond
string sequencer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// added_amount is the amount of coins added to the sequencer's bond
cosmos.base.v1beta1.Coin added_amount = 2 [(gogoproto.nullable) = false];
// bond is the new active bond amount of the sequencer
repeated cosmos.base.v1beta1.Coin bond = 3 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}

message EventRotationStarted {
// RollappId defines the rollapp to which the sequencer belongs.
string rollapp_id = 1;
// NextProposerAddr is the bech32-encoded address of the next proposer.
// can be empty if no sequencer is available to be the next proposer.
string next_proposer_addr = 2;
// RewardAddr is a bech32-encoded address of the sequencer's reward address.
string reward_addr = 3;
// WhitelistedRelayers is a list of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
repeated string whitelisted_relayers = 4;
// sequencer is the bech32-encoded address of the sequencer
string sequencer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// added_amount is the amount of coins added to the sequencer's bond
cosmos.base.v1beta1.Coin added_amount = 2 [(gogoproto.nullable) = false];
// bond is the new active bond amount of the sequencer
repeated cosmos.base.v1beta1.Coin bond = 3 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}

message EventUpdateRewardAddress {
Expand All @@ -42,4 +30,32 @@ message EventUpdateWhitelistedRelayers {
string creator = 1;
// Relayers is an array of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
repeated string relayers = 2;
}
}


// On a sequencer kicking the incumbent proposer
message EventKickedProposer {
string rollapp = 3;
// Kicker is the bech32-encoded address of the sequencer who triggered the kick
string kicker = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Proposer is the bech32-encoded address of the proposer who was kicked
string proposer = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// Whenever the proposer changes to a new proposer
message EventProposerChange {
string rollapp = 3;
// Before is the bech32-encoded address of the old proposer
string before = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// After is the bech32-encoded address of the new proposer
string after = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// When a sequencer opt-in status changes
message EventOptInStatusChange {
string rollapp = 3;
// Sequencer is the bech32-encoded address of the old proposer
string sequencer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
bool before = 2;
bool after = 4 ;
}
11 changes: 8 additions & 3 deletions proto/types/dymensionxyz/dymension/sequencer/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "types/dymensionxyz/dymension/sequencer/sequencer.proto";

option go_package = "github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/sequencer";


// GenesisState defines the sequencer module's genesis state.
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];
Expand All @@ -15,11 +16,15 @@ message GenesisState {
// genesisProposers is a list of the defined genesis proposers
repeated GenesisProposer genesisProposers = 3
[ (gogoproto.nullable) = false ];
// bondReductions is a list of all bond reductions
repeated BondReduction bondReductions = 4 [(gogoproto.nullable) = false];
// genesisSuccessor is a list of the defined genesis proposers
repeated GenesisProposer genesisSuccessors = 5
[ (gogoproto.nullable) = false ];
// list of sequencers in the notice queue
repeated string noticeQueue = 4 [ (gogoproto.nullable) = false ];
}

message GenesisProposer {
string address = 1;
string rollappId = 2;
}
}

8 changes: 8 additions & 0 deletions proto/types/dymensionxyz/dymension/sequencer/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ message SequencerMetadata {
repeated SnapshotInfo snapshots = 14;
// gas_price defines the value for each gas unit
string gas_price = 15;
// fee_denom is the base denom for fees
DenomMetadata fee_denom = 16;
}

message ContactDetails {
Expand All @@ -52,3 +54,9 @@ message SnapshotInfo {
// sha-256 checksum value for the snapshot file
string checksum=3;
}

message DenomMetadata {
string display = 1;
string base = 2;
uint32 exponent = 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ option go_package = "github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymens

// OperatingStatus defines the operating status of a sequencer
enum OperatingStatus {
reserved 1;
option (gogoproto.goproto_enum_prefix) = false;
// OPERATING_STATUS_UNBONDED defines a sequencer that is not active and won't
// be scheduled
OPERATING_STATUS_UNBONDED = 0
[ (gogoproto.enumvalue_customname) = "Unbonded" ];
// UNBONDING defines a sequencer that is currently unbonding.
OPERATING_STATUS_UNBONDING = 1
[ (gogoproto.enumvalue_customname) = "Unbonding" ];
// OPERATING_STATUS_BONDED defines a sequencer that is bonded and can be
// scheduled
OPERATING_STATUS_BONDED = 2 [ (gogoproto.enumvalue_customname) = "Bonded" ];
Expand Down
29 changes: 20 additions & 9 deletions proto/types/dymensionxyz/dymension/sequencer/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,36 @@ message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

cosmos.base.v1beta1.Coin min_bond = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "min_bond,omitempty"
];
reserved 1;



// unbonding_time is the time duration of unbonding.
google.protobuf.Duration unbonding_time = 2
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];

reserved 5;
reserved 2;

// notice_period is the time duration of notice period.
// notice period is the duration between the unbond request and the actual
// unbonding starting. the proposer is still bonded during this period.
google.protobuf.Duration notice_period = 3
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];

// LivenessSlashMultiplier multiplies with the tokens of the slashed sequencer to compute the burn amount.
string liveness_slash_multiplier = 4 [
// liveness_slash_min_multiplier multiplies with the tokens of the slashed sequencer to compute the burn amount.
string liveness_slash_min_multiplier = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"liveness_slash_multiplier\"",
(gogoproto.nullable) = false
];
// liveness_slash_min_absolute is the absolute minimum to slash for liveness
cosmos.base.v1beta1.Coin liveness_slash_min_absolute = 6 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "liveness_slash_min_absolute,omitempty"
];

// how much dishonor a sequencer gains on liveness events (+dishonor)
uint64 dishonor_liveness = 7;
// how much honor a sequencer gains on state updates (-dishonor)
uint64 dishonor_state_update = 8;
// the minimum dishonor at which a sequencer can be kicked (<=)
uint64 dishonor_kick_threshold = 9;
}
30 changes: 22 additions & 8 deletions proto/types/dymensionxyz/dymension/sequencer/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,37 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {}

// Queries a Sequencer by address.
rpc Sequencer(QueryGetSequencerRequest) returns (QueryGetSequencerResponse) {}
rpc Sequencer(QueryGetSequencerRequest) returns (QueryGetSequencerResponse) {

}

// Queries a list of Sequencer items.
rpc Sequencers(QuerySequencersRequest) returns (QuerySequencersResponse) {}
rpc Sequencers(QuerySequencersRequest) returns (QuerySequencersResponse) {
}

// Queries a SequencersByRollapp by rollappId.
rpc SequencersByRollapp(QueryGetSequencersByRollappRequest)
returns (QueryGetSequencersByRollappResponse) {}
returns (QueryGetSequencersByRollappResponse) {
}

// Queries a SequencersByRollappByStatus
rpc SequencersByRollappByStatus(QueryGetSequencersByRollappByStatusRequest)
returns (QueryGetSequencersByRollappByStatusResponse) {}
returns (QueryGetSequencersByRollappByStatusResponse) {
}

// Queries the current proposer by rollappId.
rpc GetProposerByRollapp(QueryGetProposerByRollappRequest)
returns (QueryGetProposerByRollappResponse) {}
returns (QueryGetProposerByRollappResponse) {
}

// Queries the next proposer by rollappId.
rpc GetNextProposerByRollapp(QueryGetNextProposerByRollappRequest)
returns (QueryGetNextProposerByRollappResponse) {}
returns (QueryGetNextProposerByRollappResponse) {
}

// Queries a list of proposers.
rpc Proposers(QueryProposersRequest) returns (QueryProposersResponse) {}
rpc Proposers(QueryProposersRequest) returns (QueryProposersResponse) {
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand All @@ -64,19 +72,25 @@ message QuerySequencersResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetSequencersByRollappRequest { string rollappId = 1; }
message QueryGetSequencersByRollappRequest {
string rollappId = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

message QueryGetSequencersByRollappResponse {
repeated Sequencer sequencers = 1 [ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetSequencersByRollappByStatusRequest {
string rollappId = 1;
OperatingStatus status = 2;
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

message QueryGetSequencersByRollappByStatusResponse {
repeated Sequencer sequencers = 1 [ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// Request type for the GetProposerByRollapp RPC method.
Expand Down
32 changes: 19 additions & 13 deletions settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
querytypes "github.com/cosmos/cosmos-sdk/types/query"
"github.com/dymensionxyz/cosmosclient/cosmosclient"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"github.com/google/uuid"
Expand Down Expand Up @@ -404,34 +405,39 @@ func (c *Client) GetSequencerByAddress(address string) (types.Sequencer, error)

// GetAllSequencers returns all sequencers of the given rollapp.
func (c *Client) GetAllSequencers() ([]types.Sequencer, error) {
var res *sequencertypes.QueryGetSequencersByRollappResponse
req := &sequencertypes.QueryGetSequencersByRollappRequest{
RollappId: c.rollappId,
RollappId: c.rollappId,
Pagination: &querytypes.PageRequest{},
}

err := c.RunWithRetry(func() error {
var err error
res, err = c.sequencerQueryClient.SequencersByRollapp(c.ctx, req)
if err == nil {
return nil
}
res := []sequencertypes.Sequencer{}

if status.Code(err) == codes.NotFound {
return retry.Unrecoverable(errors.Join(gerrc.ErrNotFound, err))
err := c.RunWithRetry(func() error {
for {
qres, err := c.sequencerQueryClient.SequencersByRollapp(c.ctx, req)
if err != nil {
if status.Code(err) == codes.NotFound {
return retry.Unrecoverable(errors.Join(gerrc.ErrNotFound, err))
}
return err
}
res = append(res, qres.Sequencers...)
req.Pagination.Key = qres.GetPagination().NextKey
if len(req.Pagination.Key) == 0 {
return nil
}
}
return err
})
if err != nil {
return nil, err
}

// not supposed to happen, but just in case
if res == nil {
return nil, fmt.Errorf("empty response: %w", gerrc.ErrUnknown)
}

var sequencerList []types.Sequencer
for _, sequencer := range res.Sequencers {
for _, sequencer := range res {
dymintPubKey := protoutils.GogoToCosmos(sequencer.DymintPubKey)
var pubKey cryptotypes.PubKey
err := c.protoCodec.UnpackAny(dymintPubKey, &pubKey)
Expand Down
20 changes: 8 additions & 12 deletions types/pb/dymensionxyz/dymension/common/status.pb.go

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

Loading

0 comments on commit 3789c4a

Please sign in to comment.