chore(metadata): handle deprecated shards field (#1050)

This commit is contained in:
richΛrd 2024-03-12 08:14:25 -04:00 committed by GitHub
parent bdf10a46e4
commit 32be835b5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 63 additions and 18 deletions

View File

@ -28,7 +28,13 @@ type WakuMetadataRequest struct {
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
ClusterId *uint32 `protobuf:"varint,1,opt,name=cluster_id,json=clusterId,proto3,oneof" json:"cluster_id,omitempty"` ClusterId *uint32 `protobuf:"varint,1,opt,name=cluster_id,json=clusterId,proto3,oneof" json:"cluster_id,omitempty"`
Shards []uint32 `protobuf:"varint,2,rep,packed,name=shards,proto3" json:"shards,omitempty"` Shards []uint32 `protobuf:"varint,3,rep,packed,name=shards,proto3" json:"shards,omitempty"`
// Starting from nwaku v0.26, if field 3 contains no data, it will attempt to
// decode this field first assuming it's a packed field, and if that fails,
// attempt to decode as an unpacked field
//
// Deprecated: Marked as deprecated in waku_metadata.proto.
ShardsDeprecated []uint32 `protobuf:"varint,2,rep,name=shards_deprecated,json=shardsDeprecated,proto3" json:"shards_deprecated,omitempty"`
} }
func (x *WakuMetadataRequest) Reset() { func (x *WakuMetadataRequest) Reset() {
@ -77,13 +83,27 @@ func (x *WakuMetadataRequest) GetShards() []uint32 {
return nil return nil
} }
// Deprecated: Marked as deprecated in waku_metadata.proto.
func (x *WakuMetadataRequest) GetShardsDeprecated() []uint32 {
if x != nil {
return x.ShardsDeprecated
}
return nil
}
type WakuMetadataResponse struct { type WakuMetadataResponse struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
ClusterId *uint32 `protobuf:"varint,1,opt,name=cluster_id,json=clusterId,proto3,oneof" json:"cluster_id,omitempty"` ClusterId *uint32 `protobuf:"varint,1,opt,name=cluster_id,json=clusterId,proto3,oneof" json:"cluster_id,omitempty"`
Shards []uint32 `protobuf:"varint,2,rep,packed,name=shards,proto3" json:"shards,omitempty"` Shards []uint32 `protobuf:"varint,3,rep,packed,name=shards,proto3" json:"shards,omitempty"`
// Starting from nwaku v0.26, if field 3 contains no data, it will attempt to
// decode this field first assuming it's a packed field, and if that fails,
// attempt to decode as an unpacked field
//
// Deprecated: Marked as deprecated in waku_metadata.proto.
ShardsDeprecated []uint32 `protobuf:"varint,2,rep,name=shards_deprecated,json=shardsDeprecated,proto3" json:"shards_deprecated,omitempty"`
} }
func (x *WakuMetadataResponse) Reset() { func (x *WakuMetadataResponse) Reset() {
@ -132,25 +152,39 @@ func (x *WakuMetadataResponse) GetShards() []uint32 {
return nil return nil
} }
// Deprecated: Marked as deprecated in waku_metadata.proto.
func (x *WakuMetadataResponse) GetShardsDeprecated() []uint32 {
if x != nil {
return x.ShardsDeprecated
}
return nil
}
var File_waku_metadata_proto protoreflect.FileDescriptor var File_waku_metadata_proto protoreflect.FileDescriptor
var file_waku_metadata_proto_rawDesc = []byte{ var file_waku_metadata_proto_rawDesc = []byte{
0x0a, 0x13, 0x77, 0x61, 0x6b, 0x75, 0x5f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x0a, 0x13, 0x77, 0x61, 0x6b, 0x75, 0x5f, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x77, 0x61, 0x6b, 0x75, 0x2e, 0x6d, 0x65, 0x74, 0x61, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x77, 0x61, 0x6b, 0x75, 0x2e, 0x6d, 0x65, 0x74, 0x61,
0x64, 0x61, 0x74, 0x61, 0x2e, 0x76, 0x31, 0x22, 0x60, 0x0a, 0x13, 0x57, 0x61, 0x6b, 0x75, 0x4d, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x76, 0x31, 0x22, 0x93, 0x01, 0x0a, 0x13, 0x57, 0x61, 0x6b, 0x75,
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x0a, 0x0a, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x22, 0x0a, 0x0a, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20,
0x28, 0x0d, 0x48, 0x00, 0x52, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, 0x64, 0x88, 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, 0x64,
0x01, 0x01, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x68, 0x61, 0x72, 0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x88, 0x01, 0x01, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x68, 0x61, 0x72, 0x64, 0x73, 0x18, 0x03, 0x20,
0x28, 0x0d, 0x52, 0x06, 0x73, 0x68, 0x61, 0x72, 0x64, 0x73, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x63, 0x03, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x68, 0x61, 0x72, 0x64, 0x73, 0x12, 0x31, 0x0a, 0x11, 0x73,
0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x22, 0x61, 0x0a, 0x14, 0x57, 0x61, 0x6b, 0x68, 0x61, 0x72, 0x64, 0x73, 0x5f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64,
0x75, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0d, 0x42, 0x04, 0x10, 0x00, 0x18, 0x01, 0x52, 0x10, 0x73, 0x68,
0x65, 0x12, 0x22, 0x0a, 0x0a, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x61, 0x72, 0x64, 0x73, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x42, 0x0d,
0x01, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x0a, 0x0b, 0x5f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x22, 0x94, 0x01,
0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x68, 0x61, 0x72, 0x64, 0x73, 0x18, 0x0a, 0x14, 0x57, 0x61, 0x6b, 0x75, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65,
0x02, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x68, 0x61, 0x72, 0x64, 0x73, 0x42, 0x0d, 0x0a, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0a, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65,
0x0b, 0x5f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x62, 0x06, 0x70, 0x72, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x09, 0x63, 0x6c,
0x6f, 0x74, 0x6f, 0x33, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x68,
0x61, 0x72, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x68, 0x61, 0x72,
0x64, 0x73, 0x12, 0x31, 0x0a, 0x11, 0x73, 0x68, 0x61, 0x72, 0x64, 0x73, 0x5f, 0x64, 0x65, 0x70,
0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0d, 0x42, 0x04, 0x10,
0x00, 0x18, 0x01, 0x52, 0x10, 0x73, 0x68, 0x61, 0x72, 0x64, 0x73, 0x44, 0x65, 0x70, 0x72, 0x65,
0x63, 0x61, 0x74, 0x65, 0x64, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65,
0x72, 0x5f, 0x69, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

View File

@ -109,6 +109,8 @@ func (wakuM *WakuMetadata) Request(ctx context.Context, peerID peer.ID) (*protoc
request := &pb.WakuMetadataRequest{} request := &pb.WakuMetadataRequest{}
request.ClusterId = clusterID request.ClusterId = clusterID
request.Shards = shards request.Shards = shards
// TODO: remove with nwaku 0.28 deployment
request.ShardsDeprecated = shards // nolint: staticcheck
writer := pbio.NewDelimitedWriter(stream) writer := pbio.NewDelimitedWriter(stream)
reader := pbio.NewDelimitedReader(stream, math.MaxInt32) reader := pbio.NewDelimitedReader(stream, math.MaxInt32)
@ -140,8 +142,15 @@ func (wakuM *WakuMetadata) Request(ctx context.Context, peerID peer.ID) (*protoc
rClusterID := uint16(*response.ClusterId) rClusterID := uint16(*response.ClusterId)
var rShardIDs []uint16 var rShardIDs []uint16
for _, i := range response.Shards { if len(response.Shards) != 0 {
rShardIDs = append(rShardIDs, uint16(i)) for _, i := range response.Shards {
rShardIDs = append(rShardIDs, uint16(i))
}
} else {
// TODO: remove with nwaku 0.28 deployment
for _, i := range response.ShardsDeprecated { // nolint: staticcheck
rShardIDs = append(rShardIDs, uint16(i))
}
} }
rs, err := protocol.NewRelayShards(rClusterID, rShardIDs...) rs, err := protocol.NewRelayShards(rClusterID, rShardIDs...)
@ -177,6 +186,8 @@ func (wakuM *WakuMetadata) onRequest(ctx context.Context) func(network.Stream) {
} else { } else {
response.ClusterId = clusterID response.ClusterId = clusterID
response.Shards = shards response.Shards = shards
// TODO: remove with nwaku 0.28 deployment
response.ShardsDeprecated = shards // nolint: staticcheck
} }
err = writer.WriteMsg(response) err = writer.WriteMsg(response)