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

feat: Query for validator&shard #203

Open
wants to merge 3 commits into
base: feat/todo-error-handling
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion proto/sunrise/da/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ service Query {
rpc AllInvalidity(QueryAllInvalidityRequest) returns (QueryAllInvalidityResponse) {
option (google.api.http).get = "/sunrise/v1/da/all-invalidity";
}
// ValidatorShardIndices
rpc ValidatorShardIndices(QueryValidatorShardIndicesRequest) returns (QueryValidatorShardIndicesResponse) {
option (google.api.http).get = "/sunrise/v1/da/validator-shard-indices";
}
// ZkpProofThreshold
rpc ZkpProofThreshold(QueryZkpProofThresholdRequest) returns (QueryZkpProofThresholdResponse) {
option (google.api.http).get = "/sunrise/v1/da/zkp-proof-threshold";
Expand Down Expand Up @@ -134,6 +138,19 @@ message QueryAllInvalidityResponse {
repeated Invalidity invalidity = 1 [(gogoproto.nullable) = false];
}

// QueryValidatorShardIndicesRequest is request type for the
// Query/ValidatorShardIndices RPC method.
message QueryValidatorShardIndicesRequest {
string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
uint64 shard_count = 2;
}

// QueryValidatorShardIndicesResponse is response type for the
// Query/ValidatorShardIndices RPC method.
message QueryValidatorShardIndicesResponse {
repeated uint64 shard_indices = 1;
}

// QueryZkpProofThresholdRequest is request type for the
// Query/ZkpProofThreshold RPC method.
message QueryZkpProofThresholdRequest {
Expand All @@ -143,7 +160,7 @@ message QueryZkpProofThresholdRequest {
// QueryZkpProofThresholdResponse is response type for the
// Query/ZkpProofThreshold RPC method.
message QueryZkpProofThresholdResponse {
uint64 threshold = 2 [(amino.dont_omitempty) = true];
uint64 threshold = 1 [(amino.dont_omitempty) = true];
}

// QueryProofDeputyRequest is request type for the
Expand Down
5 changes: 4 additions & 1 deletion x/da/keeper/msg_server_submit_validity_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ func (k msgServer) SubmitValidityProof(ctx context.Context, msg *types.MsgSubmit
return nil, errorsmod.Wrap(err, "invalid validator address")
}
valAddr := sdk.ValAddress(validator)
_, err = k.StakingKeeper.Validator(ctx, valAddr)
sdkVal, err := k.StakingKeeper.Validator(ctx, valAddr)
if err != nil {
return nil, errorsmod.Wrap(err, "validator not exists")
}
if !sdkVal.IsBonded() {
return nil, types.ErrValidatorNotBonded
}
if !bytes.Equal(sender, validator) {
deputy, found, err := k.GetProofDeputy(ctx, validator)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions x/da/keeper/query_da.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ func (q queryServer) AllPublishedData(goCtx context.Context, req *types.QueryAll
return &types.QueryAllPublishedDataResponse{Data: data}, nil
}

func (q queryServer) ValidatorShardIndices(goCtx context.Context, req *types.QueryValidatorShardIndicesRequest) (*types.QueryValidatorShardIndicesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

validator, err := q.k.validatorAddressCodec.StringToBytes(req.ValidatorAddress)
if err != nil {
return nil, errorsmod.Wrap(err, "invalid validator address")
}
threshold, err := q.k.GetZkpThreshold(ctx, req.ShardCount)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
indices := types.ShardIndicesForValidator(validator, int64(threshold), int64(req.ShardCount))
shardIndices := make([]uint64, len(indices))
for i, index := range indices {
shardIndices[i] = uint64(index)
}
return &types.QueryValidatorShardIndicesResponse{ShardIndices: shardIndices}, nil
}

func (q queryServer) ZkpProofThreshold(goCtx context.Context, req *types.QueryZkpProofThresholdRequest) (*types.QueryZkpProofThresholdResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
Expand Down
1 change: 1 addition & 0 deletions x/da/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ var (
ErrInvalidDeputy = errors.Register(ModuleName, 1112, "invalid proof deputy")
ErrProofNotFound = errors.Register(ModuleName, 1113, "validity proof not found")
ErrInvalidityNotFound = errors.Register(ModuleName, 1114, "invalidity not found")
ErrValidatorNotBonded = errors.Register(ModuleName, 1115, "validator is not bonded")
)
Loading