diff --git a/proto/pb/sync/sync.pb.go b/proto/pb/sync/sync.pb.go index e54390e18a7c..c49247375e7a 100644 --- a/proto/pb/sync/sync.pb.go +++ b/proto/pb/sync/sync.pb.go @@ -482,11 +482,11 @@ type GetChangeProofRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - StartRootHash []byte `protobuf:"bytes,1,opt,name=start_root_hash,json=startRootHash,proto3" json:"start_root_hash,omitempty"` - EndRootHash []byte `protobuf:"bytes,2,opt,name=end_root_hash,json=endRootHash,proto3" json:"end_root_hash,omitempty"` - StartKey []byte `protobuf:"bytes,3,opt,name=start_key,json=startKey,proto3" json:"start_key,omitempty"` - EndKey []byte `protobuf:"bytes,4,opt,name=end_key,json=endKey,proto3" json:"end_key,omitempty"` - KeyLimit uint32 `protobuf:"varint,5,opt,name=key_limit,json=keyLimit,proto3" json:"key_limit,omitempty"` + StartRootHash []byte `protobuf:"bytes,1,opt,name=start_root_hash,json=startRootHash,proto3" json:"start_root_hash,omitempty"` + EndRootHash []byte `protobuf:"bytes,2,opt,name=end_root_hash,json=endRootHash,proto3" json:"end_root_hash,omitempty"` + StartKey []byte `protobuf:"bytes,3,opt,name=start_key,json=startKey,proto3" json:"start_key,omitempty"` + EndKey *MaybeBytes `protobuf:"bytes,4,opt,name=end_key,json=endKey,proto3" json:"end_key,omitempty"` + KeyLimit uint32 `protobuf:"varint,5,opt,name=key_limit,json=keyLimit,proto3" json:"key_limit,omitempty"` } func (x *GetChangeProofRequest) Reset() { @@ -542,7 +542,7 @@ func (x *GetChangeProofRequest) GetStartKey() []byte { return nil } -func (x *GetChangeProofRequest) GetEndKey() []byte { +func (x *GetChangeProofRequest) GetEndKey() *MaybeBytes { if x != nil { return x.EndKey } @@ -808,10 +808,10 @@ type GetRangeProofRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - RootHash []byte `protobuf:"bytes,1,opt,name=root_hash,json=rootHash,proto3" json:"root_hash,omitempty"` - StartKey []byte `protobuf:"bytes,2,opt,name=start_key,json=startKey,proto3" json:"start_key,omitempty"` - EndKey []byte `protobuf:"bytes,3,opt,name=end_key,json=endKey,proto3" json:"end_key,omitempty"` - KeyLimit uint32 `protobuf:"varint,4,opt,name=key_limit,json=keyLimit,proto3" json:"key_limit,omitempty"` + RootHash []byte `protobuf:"bytes,1,opt,name=root_hash,json=rootHash,proto3" json:"root_hash,omitempty"` + StartKey []byte `protobuf:"bytes,2,opt,name=start_key,json=startKey,proto3" json:"start_key,omitempty"` + EndKey *MaybeBytes `protobuf:"bytes,3,opt,name=end_key,json=endKey,proto3" json:"end_key,omitempty"` + KeyLimit uint32 `protobuf:"varint,4,opt,name=key_limit,json=keyLimit,proto3" json:"key_limit,omitempty"` } func (x *GetRangeProofRequest) Reset() { @@ -860,7 +860,7 @@ func (x *GetRangeProofRequest) GetStartKey() []byte { return nil } -func (x *GetRangeProofRequest) GetEndKey() []byte { +func (x *GetRangeProofRequest) GetEndKey() *MaybeBytes { if x != nil { return x.EndKey } @@ -1453,7 +1453,7 @@ var file_sync_sync_proto_rawDesc = []byte{ 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x42, 0x0a, 0x0a, 0x08, 0x72, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xb6, 0x01, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x43, 0x68, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xc8, 0x01, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x72, 0x74, @@ -1461,148 +1461,150 @@ var file_sync_sync_proto_rawDesc = []byte{ 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x65, 0x6e, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x6e, 0x64, - 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, - 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, - 0xa7, 0x01, 0x0a, 0x18, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x05, - 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, - 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, - 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, - 0x65, 0x79, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x2c, 0x0a, 0x12, 0x65, - 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, - 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, - 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x31, 0x0a, 0x19, 0x56, 0x65, 0x72, - 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x43, 0x0a, 0x18, - 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, - 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, - 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, - 0x66, 0x22, 0xbd, 0x01, 0x0a, 0x18, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, - 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1b, 0x0a, 0x09, 0x73, - 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, - 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, - 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, - 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, - 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, - 0x12, 0x1f, 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, 0x74, 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, - 0x74, 0x22, 0x86, 0x01, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, - 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, - 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, + 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, + 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, + 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, + 0x74, 0x22, 0xa7, 0x01, 0x0a, 0x18, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, + 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x17, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, - 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x3f, 0x0a, 0x15, 0x47, 0x65, - 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x69, 0x0a, 0x17, 0x43, - 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, - 0x4b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, - 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, - 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xd0, 0x01, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2f, 0x0a, 0x14, 0x68, 0x61, 0x64, 0x5f, 0x72, 0x6f, - 0x6f, 0x74, 0x73, 0x5f, 0x69, 0x6e, 0x5f, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x68, 0x61, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x73, 0x49, 0x6e, - 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x30, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, - 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, - 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, - 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, - 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x30, 0x0a, 0x0b, 0x6b, 0x65, 0x79, 0x5f, 0x63, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0a, 0x6b, - 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x22, 0x85, 0x01, 0x0a, 0x0a, 0x52, 0x61, - 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x25, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, - 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, - 0x21, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x03, 0x65, - 0x6e, 0x64, 0x12, 0x2d, 0x0a, 0x0a, 0x6b, 0x65, 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, - 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, - 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x09, 0x6b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, - 0x73, 0x22, 0xe1, 0x01, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x12, - 0x26, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x50, 0x61, - 0x74, 0x68, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x34, 0x0a, 0x0d, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x5f, 0x6f, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, - 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, - 0x52, 0x0b, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x72, 0x48, 0x61, 0x73, 0x68, 0x12, 0x39, 0x0a, - 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, - 0x2e, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, - 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x1a, 0x3b, 0x0a, 0x0d, 0x43, 0x68, 0x69, 0x6c, - 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x45, 0x0a, 0x09, 0x4b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, - 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x4b, 0x0a, 0x0e, - 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x50, 0x61, 0x74, 0x68, 0x12, 0x23, - 0x0a, 0x0d, 0x6e, 0x69, 0x62, 0x62, 0x6c, 0x65, 0x5f, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0c, 0x6e, 0x69, 0x62, 0x62, 0x6c, 0x65, 0x4c, 0x65, 0x6e, - 0x67, 0x74, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x41, 0x0a, 0x0a, 0x4d, 0x61, 0x79, - 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, 0x0a, - 0x0a, 0x69, 0x73, 0x5f, 0x6e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x09, 0x69, 0x73, 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, - 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x32, 0xff, 0x03, 0x0a, 0x02, 0x44, 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, - 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, - 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, - 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, - 0x08, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, - 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x16, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x40, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, - 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, - 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, - 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, - 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, - 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, + 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x2c, 0x0a, + 0x12, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, + 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10, 0x65, 0x78, 0x70, 0x65, 0x63, + 0x74, 0x65, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x31, 0x0a, 0x19, 0x56, + 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x43, + 0x0a, 0x18, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x05, 0x70, 0x72, + 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, + 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, 0x72, + 0x6f, 0x6f, 0x66, 0x22, 0xbd, 0x01, 0x0a, 0x18, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x52, + 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1b, 0x0a, + 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, + 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, + 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, + 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, + 0x69, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, + 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, 0x74, 0x65, 0x73, 0x4c, 0x69, + 0x6d, 0x69, 0x74, 0x22, 0x98, 0x01, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, + 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x74, 0x61, + 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x74, + 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, + 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, + 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, + 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x3f, + 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, + 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, + 0x69, 0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x74, + 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, + 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x67, 0x65, + 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, + 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x0a, + 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xd0, 0x01, 0x0a, 0x0b, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2f, 0x0a, 0x14, 0x68, 0x61, + 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x73, 0x5f, 0x69, 0x6e, 0x5f, 0x68, 0x69, 0x73, 0x74, 0x6f, + 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x68, 0x61, 0x64, 0x52, 0x6f, 0x6f, + 0x74, 0x73, 0x49, 0x6e, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x30, 0x0a, 0x0b, 0x73, + 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2c, 0x0a, + 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x30, 0x0a, 0x0b, 0x6b, + 0x65, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x52, 0x0a, 0x6b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x22, 0x85, 0x01, + 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x25, 0x0a, 0x05, + 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x73, 0x74, + 0x61, 0x72, 0x74, 0x12, 0x21, 0x0a, 0x03, 0x65, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, + 0x65, 0x52, 0x03, 0x65, 0x6e, 0x64, 0x12, 0x2d, 0x0a, 0x0a, 0x6b, 0x65, 0x79, 0x5f, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x09, 0x6b, 0x65, 0x79, 0x56, + 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0xe1, 0x01, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, + 0x6f, 0x64, 0x65, 0x12, 0x26, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x14, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, + 0x65, 0x64, 0x50, 0x61, 0x74, 0x68, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x34, 0x0a, 0x0d, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x5f, 0x6f, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, + 0x79, 0x74, 0x65, 0x73, 0x52, 0x0b, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x72, 0x48, 0x61, 0x73, + 0x68, 0x12, 0x39, 0x0a, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x52, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x1a, 0x3b, 0x0a, 0x0d, + 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x45, 0x0a, 0x09, 0x4b, 0x65, 0x79, + 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, + 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x22, 0x4b, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x50, 0x61, + 0x74, 0x68, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x69, 0x62, 0x62, 0x6c, 0x65, 0x5f, 0x6c, 0x65, 0x6e, + 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0c, 0x6e, 0x69, 0x62, 0x62, 0x6c, + 0x65, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x41, 0x0a, + 0x0a, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x6e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, + 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x32, 0xff, 0x03, 0x0a, 0x02, 0x44, 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, + 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, + 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x40, 0x0a, 0x0e, + 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x54, + 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, + 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, + 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, + 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, + 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, - 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, - 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, - 0x79, 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x10, 0x43, + 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, + 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, + 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, + 0x70, 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1653,40 +1655,42 @@ var file_sync_sync_proto_depIdxs = []int32{ 20, // 5: sync.SyncGetChangeProofRequest.end_key:type_name -> sync.MaybeBytes 15, // 6: sync.SyncGetChangeProofResponse.change_proof:type_name -> sync.ChangeProof 16, // 7: sync.SyncGetChangeProofResponse.range_proof:type_name -> sync.RangeProof - 15, // 8: sync.VerifyChangeProofRequest.proof:type_name -> sync.ChangeProof - 15, // 9: sync.CommitChangeProofRequest.proof:type_name -> sync.ChangeProof - 20, // 10: sync.SyncGetRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 16, // 11: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof - 16, // 12: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof - 17, // 13: sync.ChangeProof.start_proof:type_name -> sync.ProofNode - 17, // 14: sync.ChangeProof.end_proof:type_name -> sync.ProofNode - 18, // 15: sync.ChangeProof.key_changes:type_name -> sync.KeyChange - 17, // 16: sync.RangeProof.start:type_name -> sync.ProofNode - 17, // 17: sync.RangeProof.end:type_name -> sync.ProofNode - 21, // 18: sync.RangeProof.key_values:type_name -> sync.KeyValue - 19, // 19: sync.ProofNode.key:type_name -> sync.SerializedPath - 20, // 20: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes - 22, // 21: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry - 20, // 22: sync.KeyChange.value:type_name -> sync.MaybeBytes - 23, // 23: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty - 2, // 24: sync.DB.GetProof:input_type -> sync.GetProofRequest - 7, // 25: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest - 8, // 26: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest - 10, // 27: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest - 12, // 28: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest - 14, // 29: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest - 1, // 30: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse - 3, // 31: sync.DB.GetProof:output_type -> sync.GetProofResponse - 15, // 32: sync.DB.GetChangeProof:output_type -> sync.ChangeProof - 9, // 33: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse - 23, // 34: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty - 13, // 35: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse - 23, // 36: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty - 30, // [30:37] is the sub-list for method output_type - 23, // [23:30] is the sub-list for method input_type - 23, // [23:23] is the sub-list for extension type_name - 23, // [23:23] is the sub-list for extension extendee - 0, // [0:23] is the sub-list for field type_name + 20, // 8: sync.GetChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 15, // 9: sync.VerifyChangeProofRequest.proof:type_name -> sync.ChangeProof + 15, // 10: sync.CommitChangeProofRequest.proof:type_name -> sync.ChangeProof + 20, // 11: sync.SyncGetRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 20, // 12: sync.GetRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 16, // 13: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof + 16, // 14: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof + 17, // 15: sync.ChangeProof.start_proof:type_name -> sync.ProofNode + 17, // 16: sync.ChangeProof.end_proof:type_name -> sync.ProofNode + 18, // 17: sync.ChangeProof.key_changes:type_name -> sync.KeyChange + 17, // 18: sync.RangeProof.start:type_name -> sync.ProofNode + 17, // 19: sync.RangeProof.end:type_name -> sync.ProofNode + 21, // 20: sync.RangeProof.key_values:type_name -> sync.KeyValue + 19, // 21: sync.ProofNode.key:type_name -> sync.SerializedPath + 20, // 22: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes + 22, // 23: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry + 20, // 24: sync.KeyChange.value:type_name -> sync.MaybeBytes + 23, // 25: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty + 2, // 26: sync.DB.GetProof:input_type -> sync.GetProofRequest + 7, // 27: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest + 8, // 28: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest + 10, // 29: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest + 12, // 30: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest + 14, // 31: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest + 1, // 32: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse + 3, // 33: sync.DB.GetProof:output_type -> sync.GetProofResponse + 15, // 34: sync.DB.GetChangeProof:output_type -> sync.ChangeProof + 9, // 35: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse + 23, // 36: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty + 13, // 37: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse + 23, // 38: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty + 32, // [32:39] is the sub-list for method output_type + 25, // [25:32] is the sub-list for method input_type + 25, // [25:25] is the sub-list for extension type_name + 25, // [25:25] is the sub-list for extension extendee + 0, // [0:25] is the sub-list for field type_name } func init() { file_sync_sync_proto_init() } diff --git a/proto/sync/sync.proto b/proto/sync/sync.proto index 946ec2a840ef..4edbfc685e83 100644 --- a/proto/sync/sync.proto +++ b/proto/sync/sync.proto @@ -71,7 +71,7 @@ message GetChangeProofRequest { bytes start_root_hash = 1; bytes end_root_hash = 2; bytes start_key = 3; - bytes end_key = 4; + MaybeBytes end_key = 4; uint32 key_limit = 5; } @@ -104,7 +104,7 @@ message SyncGetRangeProofRequest { message GetRangeProofRequest { bytes root_hash = 1; bytes start_key = 2; - bytes end_key = 3; + MaybeBytes end_key = 3; uint32 key_limit = 4; } diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 8fa7a3135566..038ff828d0cf 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -61,7 +61,7 @@ type ChangeProofer interface { startRootID ids.ID, endRootID ids.ID, start []byte, - end []byte, + end Maybe[[]byte], maxLength int, ) (*ChangeProof, error) @@ -97,8 +97,8 @@ type RangeProofer interface { GetRangeProofAtRoot( ctx context.Context, rootID ids.ID, - start, - end []byte, + start []byte, + end Maybe[[]byte], maxLength int, ) (*RangeProof, error) @@ -480,8 +480,8 @@ func (db *merkleDB) getProof(ctx context.Context, key []byte) (*Proof, error) { // [start, end]. func (db *merkleDB) GetRangeProof( ctx context.Context, - start, - end []byte, + start []byte, + end Maybe[[]byte], maxLength int, ) (*RangeProof, error) { db.commitLock.RLock() @@ -495,8 +495,8 @@ func (db *merkleDB) GetRangeProof( func (db *merkleDB) GetRangeProofAtRoot( ctx context.Context, rootID ids.ID, - start, - end []byte, + start []byte, + end Maybe[[]byte], maxLength int, ) (*RangeProof, error) { db.commitLock.RLock() @@ -509,8 +509,8 @@ func (db *merkleDB) GetRangeProofAtRoot( func (db *merkleDB) getRangeProofAtRoot( ctx context.Context, rootID ids.ID, - start, - end []byte, + start []byte, + end Maybe[[]byte], maxLength int, ) (*RangeProof, error) { if db.closed { @@ -532,10 +532,10 @@ func (db *merkleDB) GetChangeProof( startRootID ids.ID, endRootID ids.ID, start []byte, - end []byte, + end Maybe[[]byte], maxLength int, ) (*ChangeProof, error) { - if len(end) > 0 && bytes.Compare(start, end) == 1 { + if end.HasValue() && bytes.Compare(start, end.Value()) == 1 { return nil, ErrStartAfterEnd } if startRootID == endRootID { @@ -578,20 +578,18 @@ func (db *merkleDB) GetChangeProof( result.KeyChanges = append(result.KeyChanges, KeyChange{ Key: serializedKey, // create a copy so edits of the []byte don't affect the db - Value: Clone(change.after), + Value: MaybeBind(change.after, slices.Clone[[]byte]), }) } - largestKey := Nothing[[]byte]() + largestKey := end if len(result.KeyChanges) > 0 { largestKey = Some(result.KeyChanges[len(result.KeyChanges)-1].Key) - } else if len(end) > 0 { - largestKey = Some(end) } // Since we hold [db.commitlock] we must still have sufficient // history to recreate the trie at [endRootID]. - historicalView, err := db.getHistoricalViewForRange(endRootID, start, largestKey.Value()) + historicalView, err := db.getHistoricalViewForRange(endRootID, start, largestKey) if err != nil { return nil, err } @@ -1006,14 +1004,12 @@ func (db *merkleDB) VerifyChangeProof( // Find the greatest key in [proof.KeyChanges] // Note that [proof.EndProof] is a proof for this key. // [largestPath] is also used when we add children of proof nodes to [trie] below. - largestPath := Nothing[path]() + largestPath := MaybeBind(end, newPath) if len(proof.KeyChanges) > 0 { // If [proof] has key-value pairs, we should insert children // greater than [end] to ancestors of the node containing [end] // so that we get the expected root ID. largestPath = Some(newPath(proof.KeyChanges[len(proof.KeyChanges)-1].Key)) - } else if end.HasValue() { - largestPath = Some(newPath(end.Value())) } // Make sure the end proof, if given, is well-formed. @@ -1169,7 +1165,7 @@ func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { func (db *merkleDB) getHistoricalViewForRange( rootID ids.ID, start []byte, - end []byte, + end Maybe[[]byte], ) (*trieView, error) { currentRootID := db.getMerkleRoot() diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 3a98536b2c9d..28ecd1acd599 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -259,7 +259,7 @@ func Test_MerkleDB_Commit_Proof_To_Empty_Trie(t *testing.T) { require.NoError(batch.Put([]byte("key3"), []byte("3"))) require.NoError(batch.Write()) - proof, err := db.GetRangeProof(context.Background(), []byte("key1"), []byte("key3"), 10) + proof, err := db.GetRangeProof(context.Background(), []byte("key1"), Some([]byte("key3")), 10) require.NoError(err) freshDB, err := getBasicDB() @@ -289,7 +289,7 @@ func Test_MerkleDB_Commit_Proof_To_Filled_Trie(t *testing.T) { require.NoError(batch.Put([]byte("key3"), []byte("3"))) require.NoError(batch.Write()) - proof, err := db.GetRangeProof(context.Background(), []byte("key1"), []byte("key3"), 10) + proof, err := db.GetRangeProof(context.Background(), []byte("key1"), Some([]byte("key3")), 10) require.NoError(err) freshDB, err := getBasicDB() @@ -768,12 +768,13 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest) { if len(pastRoots) > 0 { root = pastRoots[r.Intn(len(pastRoots))] } - rangeProof, err := db.GetRangeProofAtRoot(context.Background(), root, step.key, step.value, 100) - require.NoError(err) end := Nothing[[]byte]() if len(step.value) > 0 { end = Some(step.value) } + + rangeProof, err := db.GetRangeProofAtRoot(context.Background(), root, step.key, end, 100) + require.NoError(err) require.NoError(rangeProof.Verify( context.Background(), step.key, @@ -787,7 +788,12 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest) { if len(pastRoots) > 1 { root = pastRoots[r.Intn(len(pastRoots))] } - changeProof, err := db.GetChangeProof(context.Background(), startRoot, root, step.key, step.value, 100) + end := Nothing[[]byte]() + if len(step.value) > 0 { + end = Some(step.value) + } + + changeProof, err := db.GetChangeProof(context.Background(), startRoot, root, step.key, end, 100) if startRoot == root { require.ErrorIs(err, errSameRoot) continue @@ -795,10 +801,7 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest) { require.NoError(err) changeProofDB, err := getBasicDB() require.NoError(err) - end := Nothing[[]byte]() - if len(step.value) > 0 { - end = Some(step.value) - } + require.NoError(changeProofDB.VerifyChangeProof( context.Background(), changeProof, diff --git a/x/merkledb/history.go b/x/merkledb/history.go index 870c61848964..4228ca40ea38 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -78,7 +78,7 @@ func newTrieHistory(maxHistoryLookback int) *trieHistory { // Returns up to [maxLength] key-value pair changes with keys in [start, end] that // occurred between [startRoot] and [endRoot]. -func (th *trieHistory) getValueChanges(startRoot, endRoot ids.ID, start, end []byte, maxLength int) (*changeSummary, error) { +func (th *trieHistory) getValueChanges(startRoot, endRoot ids.ID, start []byte, end Maybe[[]byte], maxLength int) (*changeSummary, error) { if maxLength <= 0 { return nil, fmt.Errorf("%w but was %d", ErrInvalidMaxLength, maxLength) } @@ -132,7 +132,7 @@ func (th *trieHistory) getValueChanges(startRoot, endRoot ids.ID, start, end []b ) startPath := newPath(start) - endPath := newPath(end) + endPath := MaybeBind(end, newPath) // For each element in the history in the range between [startRoot]'s // last appearance (exclusive) and [endRoot]'s last appearance (inclusive), @@ -158,7 +158,7 @@ func (th *trieHistory) getValueChanges(startRoot, endRoot ids.ID, start, end []b for key, valueChange := range item.values { // The key is outside the range [start, end]. if (len(startPath) > 0 && key.Compare(startPath) < 0) || - (len(endPath) > 0 && key.Compare(endPath) > 0) { + (end.HasValue() && key.Compare(endPath.Value()) > 0) { continue } @@ -198,7 +198,7 @@ func (th *trieHistory) getValueChanges(startRoot, endRoot ids.ID, start, end []b // for the keys in [start, end]. // If [start] is nil, all keys are considered > [start]. // If [end] is nil, all keys are considered < [end]. -func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start, end []byte) (*changeSummary, error) { +func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start []byte, end Maybe[[]byte]) (*changeSummary, error) { // [lastRootChange] is the last change in the history resulting in [rootID]. lastRootChange, ok := th.lastChanges[rootID] if !ok { @@ -207,7 +207,7 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start, end []byte) ( var ( startPath = newPath(start) - endPath = newPath(end) + endPath = MaybeBind(end, newPath) combinedChanges = newChangeSummary(defaultPreallocationSize) ) @@ -227,7 +227,7 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start, end []byte) ( for key, valueChange := range item.values { if (len(startPath) == 0 || key.Compare(startPath) >= 0) && - (len(endPath) == 0 || key.Compare(endPath) <= 0) { + (endPath.IsNothing() || key.Compare(endPath.Value()) <= 0) { if existing, ok := combinedChanges.values[key]; ok { existing.after = valueChange.before } else { diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index d54465e192e5..1a2a784f3875 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -32,7 +32,7 @@ func Test_History_Simple(t *testing.T) { require.NoError(err) require.Equal([]byte("value"), val) - origProof, err := db.GetRangeProof(context.Background(), []byte("k"), []byte("key3"), 10) + origProof, err := db.GetRangeProof(context.Background(), []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) origRootID := db.root.id @@ -41,7 +41,7 @@ func Test_History_Simple(t *testing.T) { batch = db.NewBatch() require.NoError(batch.Put([]byte("key"), []byte("value0"))) require.NoError(batch.Write()) - newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -50,7 +50,7 @@ func Test_History_Simple(t *testing.T) { require.NoError(batch.Put([]byte("key1"), []byte("value1"))) require.NoError(batch.Put([]byte("key8"), []byte("value8"))) require.NoError(batch.Write()) - newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -58,7 +58,7 @@ func Test_History_Simple(t *testing.T) { batch = db.NewBatch() require.NoError(batch.Put([]byte("k"), []byte("v"))) require.NoError(batch.Write()) - newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -74,7 +74,7 @@ func Test_History_Simple(t *testing.T) { require.NoError(batch.Delete([]byte("key5"))) require.NoError(batch.Delete([]byte("key8"))) require.NoError(batch.Write()) - newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -133,7 +133,7 @@ func Test_History_Large(t *testing.T) { require.NoError(err) roots = append(roots, root) } - proof, err := db.GetRangeProofAtRoot(context.Background(), roots[0], nil, nil, 10) + proof, err := db.GetRangeProofAtRoot(context.Background(), roots[0], nil, Nothing[[]byte](), 10) require.NoError(err) require.NotNil(proof) @@ -182,15 +182,15 @@ func Test_History_Bad_GetValueChanges_Input(t *testing.T) { endRoot := db.getMerkleRoot() // ensure these start as valid calls - _, err = db.history.getValueChanges(toBeDeletedRoot, endRoot, nil, nil, 1) + _, err = db.history.getValueChanges(toBeDeletedRoot, endRoot, nil, Nothing[[]byte](), 1) require.NoError(err) - _, err = db.history.getValueChanges(startRoot, endRoot, nil, nil, 1) + _, err = db.history.getValueChanges(startRoot, endRoot, nil, Nothing[[]byte](), 1) require.NoError(err) - _, err = db.history.getValueChanges(startRoot, endRoot, nil, nil, -1) + _, err = db.history.getValueChanges(startRoot, endRoot, nil, Nothing[[]byte](), -1) require.ErrorIs(err, ErrInvalidMaxLength) - _, err = db.history.getValueChanges(endRoot, startRoot, nil, nil, 1) + _, err = db.history.getValueChanges(endRoot, startRoot, nil, Nothing[[]byte](), 1) require.ErrorIs(err, ErrStartRootNotFound) // trigger the first root to be deleted by exiting the lookback window @@ -199,11 +199,11 @@ func Test_History_Bad_GetValueChanges_Input(t *testing.T) { require.NoError(batch.Write()) // now this root should no longer be present - _, err = db.history.getValueChanges(toBeDeletedRoot, endRoot, nil, nil, 1) + _, err = db.history.getValueChanges(toBeDeletedRoot, endRoot, nil, Nothing[[]byte](), 1) require.ErrorIs(err, ErrStartRootNotFound) // same start/end roots should yield an empty changelist - changes, err := db.history.getValueChanges(endRoot, endRoot, nil, nil, 10) + changes, err := db.history.getValueChanges(endRoot, endRoot, nil, Nothing[[]byte](), 10) require.NoError(err) require.Empty(changes.values) } @@ -227,7 +227,7 @@ func Test_History_Trigger_History_Queue_Looping(t *testing.T) { require.NoError(batch.Write()) origRootID := db.getMerkleRoot() - origProof, err := db.GetRangeProof(context.Background(), []byte("k"), []byte("key3"), 10) + origProof, err := db.GetRangeProof(context.Background(), []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) require.NoError(origProof.Verify( @@ -243,7 +243,7 @@ func Test_History_Trigger_History_Queue_Looping(t *testing.T) { require.NoError(batch.Write()) // ensure that previous root is still present and generates a valid proof - newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify( @@ -259,7 +259,7 @@ func Test_History_Trigger_History_Queue_Looping(t *testing.T) { require.NoError(batch.Write()) // proof from first root shouldn't be generatable since it should have been removed from the history - _, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + _, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.ErrorIs(err, ErrRootIDNotPresent) } @@ -305,7 +305,7 @@ func Test_History_Values_Lookup_Over_Queue_Break(t *testing.T) { endRoot := db.getMerkleRoot() // changes should still be collectable even though the history has had to loop due to hitting max size - changes, err := db.history.getValueChanges(startRoot, endRoot, nil, nil, 10) + changes, err := db.history.getValueChanges(startRoot, endRoot, nil, Nothing[[]byte](), 10) require.NoError(err) require.Contains(changes.values, newPath([]byte("key1"))) require.Equal([]byte("value1"), changes.values[newPath([]byte("key1"))].after.value) @@ -328,7 +328,7 @@ func Test_History_RepeatedRoot(t *testing.T) { require.NoError(batch.Put([]byte("key3"), []byte("value3"))) require.NoError(batch.Write()) - origProof, err := db.GetRangeProof(context.Background(), []byte("k"), []byte("key3"), 10) + origProof, err := db.GetRangeProof(context.Background(), []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) origRootID := db.root.id @@ -339,7 +339,7 @@ func Test_History_RepeatedRoot(t *testing.T) { require.NoError(batch.Put([]byte("key2"), []byte("other"))) require.NoError(batch.Put([]byte("key3"), []byte("other"))) require.NoError(batch.Write()) - newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -351,7 +351,7 @@ func Test_History_RepeatedRoot(t *testing.T) { require.NoError(batch.Put([]byte("key3"), []byte("value3"))) require.NoError(batch.Write()) - newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -370,7 +370,7 @@ func Test_History_ExcessDeletes(t *testing.T) { require.NoError(batch.Put([]byte("key"), []byte("value"))) require.NoError(batch.Write()) - origProof, err := db.GetRangeProof(context.Background(), []byte("k"), []byte("key3"), 10) + origProof, err := db.GetRangeProof(context.Background(), []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) origRootID := db.root.id @@ -383,7 +383,7 @@ func Test_History_ExcessDeletes(t *testing.T) { require.NoError(batch.Delete([]byte("key4"))) require.NoError(batch.Delete([]byte("key5"))) require.NoError(batch.Write()) - newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -402,7 +402,7 @@ func Test_History_DontIncludeAllNodes(t *testing.T) { require.NoError(batch.Put([]byte("key"), []byte("value"))) require.NoError(batch.Write()) - origProof, err := db.GetRangeProof(context.Background(), []byte("k"), []byte("key3"), 10) + origProof, err := db.GetRangeProof(context.Background(), []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) origRootID := db.root.id @@ -411,7 +411,7 @@ func Test_History_DontIncludeAllNodes(t *testing.T) { batch = db.NewBatch() require.NoError(batch.Put([]byte("z"), []byte("z"))) require.NoError(batch.Write()) - newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -430,7 +430,7 @@ func Test_History_Branching2Nodes(t *testing.T) { require.NoError(batch.Put([]byte("key"), []byte("value"))) require.NoError(batch.Write()) - origProof, err := db.GetRangeProof(context.Background(), []byte("k"), []byte("key3"), 10) + origProof, err := db.GetRangeProof(context.Background(), []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) origRootID := db.root.id @@ -439,7 +439,7 @@ func Test_History_Branching2Nodes(t *testing.T) { batch = db.NewBatch() require.NoError(batch.Put([]byte("k"), []byte("v"))) require.NoError(batch.Write()) - newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -458,7 +458,7 @@ func Test_History_Branching3Nodes(t *testing.T) { require.NoError(batch.Put([]byte("key123"), []byte("value123"))) require.NoError(batch.Write()) - origProof, err := db.GetRangeProof(context.Background(), []byte("k"), []byte("key3"), 10) + origProof, err := db.GetRangeProof(context.Background(), []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) origRootID := db.root.id @@ -467,7 +467,7 @@ func Test_History_Branching3Nodes(t *testing.T) { batch = db.NewBatch() require.NoError(batch.Put([]byte("key321"), []byte("value321"))) require.NoError(batch.Write()) - newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), []byte("key3"), 10) + newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, []byte("k"), Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) require.NoError(newProof.Verify(context.Background(), []byte("k"), Some([]byte("key3")), origRootID)) @@ -543,7 +543,7 @@ func Test_Change_List(t *testing.T) { endRoot, err := db.GetMerkleRoot(context.Background()) require.NoError(err) - changes, err := db.history.getValueChanges(startRoot, endRoot, nil, nil, 8) + changes, err := db.history.getValueChanges(startRoot, endRoot, nil, Nothing[[]byte](), 8) require.NoError(err) require.Len(changes.values, 8) } @@ -643,7 +643,7 @@ func TestHistoryGetChangesToRoot(t *testing.T) { name string rootID ids.ID start []byte - end []byte + end Maybe[[]byte] validateFunc func(*require.Assertions, *changeSummary) expectedErr error } @@ -713,7 +713,7 @@ func TestHistoryGetChangesToRoot(t *testing.T) { { name: "third most recent change with end filter", rootID: changes[maxHistoryLen-3].rootID, - end: []byte{byte(maxHistoryLen - 2)}, // Omit values from most recent change + end: Some([]byte{byte(maxHistoryLen - 2)}), // Omit values from most recent change validateFunc: func(require *require.Assertions, got *changeSummary) { require.Len(got.nodes, 2) require.Len(got.values, 1) diff --git a/x/merkledb/maybe.go b/x/merkledb/maybe.go index f5228969f1eb..08d1380bd1d0 100644 --- a/x/merkledb/maybe.go +++ b/x/merkledb/maybe.go @@ -3,12 +3,6 @@ package merkledb -import ( - "bytes" - - "golang.org/x/exp/slices" -) - // Maybe T = Some T | Nothing. // A data wrapper that allows values to be something [Some T] or nothing [Nothing]. // Maybe is used to wrap types: @@ -20,7 +14,7 @@ type Maybe[T any] struct { value T } -// Returns a new Maybe[T] with the value val. +// Some returns a new Maybe[T] with the value val. func Some[T any](val T) Maybe[T] { return Maybe[T]{ value: val, @@ -28,45 +22,43 @@ func Some[T any](val T) Maybe[T] { } } -// Returns a new Maybe[T] with no value. +// Nothing returns a new Maybe[T] with no value. func Nothing[T any]() Maybe[T] { return Maybe[T]{} } -// Returns false iff [m] has a value. +// IsNothing returns false iff [m] has a value. func (m Maybe[T]) IsNothing() bool { return !m.hasValue } -// Returns true iff [m] has a value. +// HasValue returns true iff [m] has a value. func (m Maybe[T]) HasValue() bool { return m.hasValue } -// Returns the value of [m]. +// Value returns the value of [m]. func (m Maybe[T]) Value() T { return m.value } -func Clone(m Maybe[[]byte]) Maybe[[]byte] { - if !m.hasValue { - return Nothing[[]byte]() +// MaybeBind returns Nothing, if [m] is Nothing. +// Otherwise applies [f] to the value of [m] and returns the result as a Some. +func MaybeBind[T, U any](m Maybe[T], f func(T) U) Maybe[U] { + if m.IsNothing() { + return Nothing[U]() } - return Some(slices.Clone(m.value)) + return Some(f(m.Value())) } -// MaybeBytesEquals returns true iff [a] and [b] are equal. -func MaybeBytesEquals(a, b Maybe[[]byte]) bool { - aNothing := a.IsNothing() - bNothing := b.IsNothing() - - if aNothing { - return bNothing +// MaybeEqual returns true if both m1 and m2 are nothing or have the same value according to the equality function +func MaybeEqual[T any](m1 Maybe[T], m2 Maybe[T], equality func(T, T) bool) bool { + if m1.IsNothing() { + return m2.IsNothing() } - if bNothing { + if m2.IsNothing() { return false } - - return bytes.Equal(a.Value(), b.Value()) + return equality(m1.Value(), m2.Value()) } diff --git a/x/merkledb/maybe_test.go b/x/merkledb/maybe_test.go index 3c0bc7c95a2f..08dc8fd48c3b 100644 --- a/x/merkledb/maybe_test.go +++ b/x/merkledb/maybe_test.go @@ -18,7 +18,7 @@ func TestMaybeClone(t *testing.T) { val := []byte{1, 2, 3} originalVal := slices.Clone(val) m := Some(val) - mClone := Clone(m) + mClone := MaybeBind(m, slices.Clone[[]byte]) m.value[0] = 0 require.NotEqual(mClone.value, m.value) require.Equal(originalVal, mClone.value) @@ -27,7 +27,23 @@ func TestMaybeClone(t *testing.T) { // Case: Value is nothing { m := Nothing[[]byte]() - mClone := Clone(m) + mClone := MaybeBind(m, slices.Clone[[]byte]) require.True(mClone.IsNothing()) } } + +func TestMaybeEquality(t *testing.T) { + require := require.New(t) + require.True(MaybeEqual(Nothing[int](), Nothing[int](), func(i int, i2 int) bool { + return i == i2 + })) + require.False(MaybeEqual(Nothing[int](), Some(1), func(i int, i2 int) bool { + return i == i2 + })) + require.False(MaybeEqual(Some(1), Nothing[int](), func(i int, i2 int) bool { + return i == i2 + })) + require.True(MaybeEqual(Some(1), Some(1), func(i int, i2 int) bool { + return i == i2 + })) +} diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index a0ff29ab2a54..c9196c8ed14b 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -125,7 +125,7 @@ func (mr *MockMerkleDBMockRecorder) Get(arg0 interface{}) *gomock.Call { } // GetChangeProof mocks base method. -func (m *MockMerkleDB) GetChangeProof(arg0 context.Context, arg1, arg2 ids.ID, arg3, arg4 []byte, arg5 int) (*ChangeProof, error) { +func (m *MockMerkleDB) GetChangeProof(arg0 context.Context, arg1, arg2 ids.ID, arg3 []byte, arg4 Maybe[[]byte], arg5 int) (*ChangeProof, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetChangeProof", arg0, arg1, arg2, arg3, arg4, arg5) ret0, _ := ret[0].(*ChangeProof) @@ -185,7 +185,7 @@ func (mr *MockMerkleDBMockRecorder) GetRangeProof(arg0, arg1, arg2, arg3 interfa } // GetRangeProofAtRoot mocks base method. -func (m *MockMerkleDB) GetRangeProofAtRoot(arg0 context.Context, arg1 ids.ID, arg2, arg3 []byte, arg4 int) (*RangeProof, error) { +func (m *MockMerkleDB) GetRangeProofAtRoot(arg0 context.Context, arg1 ids.ID, arg2 []byte, arg3 Maybe[[]byte], arg4 int) (*RangeProof, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetRangeProofAtRoot", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(*RangeProof) diff --git a/x/merkledb/node.go b/x/merkledb/node.go index c584b03a65ee..fb0bdeab00dc 100644 --- a/x/merkledb/node.go +++ b/x/merkledb/node.go @@ -5,6 +5,7 @@ package merkledb import ( "golang.org/x/exp/maps" + "golang.org/x/exp/slices" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/hashing" @@ -194,7 +195,7 @@ func (n *node) asProofNode() ProofNode { pn := ProofNode{ KeyPath: n.key.Serialize(), Children: make(map[byte]ids.ID, len(n.children)), - ValueOrHash: Clone(n.valueDigest), + ValueOrHash: MaybeBind(n.valueDigest, slices.Clone[[]byte]), } for index, entry := range n.children { pn.Children[index] = entry.id diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index e0b4c8a82119..e006f0fd4e19 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -164,7 +164,7 @@ func (proof *Proof) Verify(ctx context.Context, expectedRootID ids.ID) error { // Note odd length keys can never match the [proof.Key] since it's bytes, // and thus an even number of nibbles. if (lastNode.KeyPath.hasOddLength() || !bytes.Equal(proof.Key, lastNode.KeyPath.Value)) && - !proof.Value.IsNothing() { + proof.Value.HasValue() { return ErrProofValueDoesntMatch } @@ -194,11 +194,9 @@ func (proof *Proof) Verify(ctx context.Context, expectedRootID ids.ID) error { } func (proof *Proof) ToProto() *pb.Proof { - value := &pb.MaybeBytes{} - if !proof.Value.IsNothing() { - value.Value = proof.Value.Value() - } else { - value.IsNothing = true + value := &pb.MaybeBytes{ + Value: proof.Value.Value(), + IsNothing: proof.Value.IsNothing(), } pbProof := &pb.Proof{ @@ -303,14 +301,12 @@ func (proof *RangeProof) Verify( return err } - largestPath := Nothing[path]() + largestPath := MaybeBind(end, newPath) if len(proof.KeyValues) > 0 { // If [proof] has key-value pairs, we should insert children // greater than [largestKey] to ancestors of the node containing // [largestKey] so that we get the expected root ID. largestPath = Some(newPath(proof.KeyValues[len(proof.KeyValues)-1].Key)) - } else if end.HasValue() { - largestPath = Some(newPath(end.Value())) } // The key-value pairs (allegedly) proven by [proof]. @@ -454,7 +450,7 @@ func verifyAllRangeProofKeyValuesPresent(proof []ProofNode, start path, end Mayb // Skip odd length keys since they cannot have a value (enforced by [verifyProofPath]). if !nodeKey.hasOddLength() && nodePath.Compare(start) >= 0 && (end.IsNothing() || nodePath.Compare(end.Value()) <= 0) { value, ok := keysValues[nodePath] - if !ok && !node.ValueOrHash.IsNothing() { + if !ok && node.ValueOrHash.HasValue() { // We didn't get a key-value pair for this key, but the proof node has a value. return ErrProofNodeHasUnincludedValue } diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index ea8bd042bcaf..648122eb8527 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -163,7 +163,7 @@ func Test_RangeProof_Extra_Value(t *testing.T) { require.NoError(err) require.Equal([]byte{2}, val) - proof, err := db.GetRangeProof(context.Background(), []byte{1}, []byte{5, 5}, 10) + proof, err := db.GetRangeProof(context.Background(), []byte{1}, Some([]byte{5, 5}), 10) require.NoError(err) require.NotNil(proof) @@ -236,7 +236,7 @@ func Test_RangeProof_Verify_Bad_Data(t *testing.T) { require.NoError(err) writeBasicBatch(t, db) - proof, err := db.GetRangeProof(context.Background(), []byte{2}, []byte{3, 0}, 50) + proof, err := db.GetRangeProof(context.Background(), []byte{2}, Some([]byte{3, 0}), 50) require.NoError(err) require.NotNil(proof) @@ -257,10 +257,10 @@ func Test_RangeProof_MaxLength(t *testing.T) { trie, err := dbTrie.NewView() require.NoError(err) - _, err = trie.GetRangeProof(context.Background(), nil, nil, -1) + _, err = trie.GetRangeProof(context.Background(), nil, Nothing[[]byte](), -1) require.ErrorIs(err, ErrInvalidMaxLength) - _, err = trie.GetRangeProof(context.Background(), nil, nil, 0) + _, err = trie.GetRangeProof(context.Background(), nil, Nothing[[]byte](), 0) require.ErrorIs(err, ErrInvalidMaxLength) } @@ -489,7 +489,7 @@ func Test_RangeProof(t *testing.T) { require.NoError(err) writeBasicBatch(t, db) - proof, err := db.GetRangeProof(context.Background(), []byte{1}, []byte{3, 5}, 10) + proof, err := db.GetRangeProof(context.Background(), []byte{1}, Some([]byte{3, 5}), 10) require.NoError(err) require.NotNil(proof) require.Len(proof.KeyValues, 3) @@ -524,7 +524,7 @@ func Test_RangeProof_BadBounds(t *testing.T) { require.NoError(err) // non-nil start/end - proof, err := db.GetRangeProof(context.Background(), []byte{4}, []byte{3}, 50) + proof, err := db.GetRangeProof(context.Background(), []byte{4}, Some([]byte{3}), 50) require.ErrorIs(err, ErrStartAfterEnd) require.Nil(proof) } @@ -545,7 +545,7 @@ func Test_RangeProof_NilStart(t *testing.T) { require.NoError(err) require.Equal([]byte("value1"), val) - proof, err := db.GetRangeProof(context.Background(), nil, []byte("key35"), 2) + proof, err := db.GetRangeProof(context.Background(), nil, Some([]byte("key35")), 2) require.NoError(err) require.NotNil(proof) @@ -577,7 +577,7 @@ func Test_RangeProof_NilEnd(t *testing.T) { writeBasicBatch(t, db) require.NoError(err) - proof, err := db.GetRangeProof(context.Background(), []byte{1}, nil, 2) + proof, err := db.GetRangeProof(context.Background(), []byte{1}, Nothing[[]byte](), 2) require.NoError(err) require.NotNil(proof) @@ -618,7 +618,7 @@ func Test_RangeProof_EmptyValues(t *testing.T) { require.NoError(err) require.Equal([]byte("value1"), val) - proof, err := db.GetRangeProof(context.Background(), []byte("key1"), []byte("key2"), 10) + proof, err := db.GetRangeProof(context.Background(), []byte("key1"), Some([]byte("key2")), 10) require.NoError(err) require.NotNil(proof) @@ -653,7 +653,7 @@ func Test_ChangeProof_Missing_History_For_EndRoot(t *testing.T) { startRoot, err := db.GetMerkleRoot(context.Background()) require.NoError(err) - proof, err := db.GetChangeProof(context.Background(), startRoot, ids.Empty, nil, nil, 50) + proof, err := db.GetChangeProof(context.Background(), startRoot, ids.Empty, nil, Nothing[[]byte](), 50) require.NoError(err) require.NotNil(proof) require.False(proof.HadRootsInHistory) @@ -676,7 +676,7 @@ func Test_ChangeProof_BadBounds(t *testing.T) { require.NoError(err) // non-nil start/end - proof, err := db.GetChangeProof(context.Background(), startRoot, endRoot, []byte("key4"), []byte("key3"), 50) + proof, err := db.GetChangeProof(context.Background(), startRoot, endRoot, []byte("key4"), Some([]byte("key3")), 50) require.ErrorIs(err, ErrStartAfterEnd) require.Nil(proof) } @@ -732,21 +732,21 @@ func Test_ChangeProof_Verify(t *testing.T) { require.NoError(err) // non-nil start/end - proof, err := db.GetChangeProof(context.Background(), startRoot, endRoot, []byte("key21"), []byte("key30"), 50) + proof, err := db.GetChangeProof(context.Background(), startRoot, endRoot, []byte("key21"), Some([]byte("key30")), 50) require.NoError(err) require.NotNil(proof) require.NoError(dbClone.VerifyChangeProof(context.Background(), proof, []byte("key21"), Some([]byte("key30")), db.getMerkleRoot())) // low maxLength - proof, err = db.GetChangeProof(context.Background(), startRoot, endRoot, nil, nil, 5) + proof, err = db.GetChangeProof(context.Background(), startRoot, endRoot, nil, Nothing[[]byte](), 5) require.NoError(err) require.NotNil(proof) require.NoError(dbClone.VerifyChangeProof(context.Background(), proof, nil, Nothing[[]byte](), db.getMerkleRoot())) // nil start/end - proof, err = db.GetChangeProof(context.Background(), startRoot, endRoot, nil, nil, 50) + proof, err = db.GetChangeProof(context.Background(), startRoot, endRoot, nil, Nothing[[]byte](), 50) require.NoError(err) require.NotNil(proof) @@ -757,7 +757,7 @@ func Test_ChangeProof_Verify(t *testing.T) { require.NoError(err) require.Equal(endRoot, newRoot) - proof, err = db.GetChangeProof(context.Background(), startRoot, endRoot, []byte("key20"), []byte("key30"), 50) + proof, err = db.GetChangeProof(context.Background(), startRoot, endRoot, []byte("key20"), Some([]byte("key30")), 50) require.NoError(err) require.NotNil(proof) @@ -819,7 +819,7 @@ func Test_ChangeProof_Verify_Bad_Data(t *testing.T) { dbClone, err := getBasicDB() require.NoError(err) - proof, err := db.GetChangeProof(context.Background(), startRoot, endRoot, []byte{2}, []byte{3, 0}, 50) + proof, err := db.GetChangeProof(context.Background(), startRoot, endRoot, []byte{2}, Some([]byte{3, 0}), 50) require.NoError(err) require.NotNil(proof) @@ -1691,15 +1691,19 @@ func FuzzRangeProofInvariants(f *testing.F) { f.Fuzz(func( t *testing.T, start []byte, - end []byte, + endBytes []byte, maxProofLen uint, ) { require := require.New(t) // Make sure proof bounds are valid - if len(end) != 0 && bytes.Compare(start, end) > 0 { + if len(endBytes) != 0 && bytes.Compare(start, endBytes) > 0 { return } + end := Nothing[[]byte]() + if len(endBytes) > 0 { + end = Some(endBytes) + } // Make sure proof length is valid if maxProofLen == 0 { return @@ -1728,7 +1732,7 @@ func FuzzRangeProofInvariants(f *testing.F) { // Make sure the EndProof invariant is maintained switch { - case len(end) == 0: + case end.IsNothing(): if len(rangeProof.KeyValues) == 0 { if len(rangeProof.StartProof) == 0 { require.Len(rangeProof.EndProof, 1) // Just the root @@ -1742,7 +1746,7 @@ func FuzzRangeProofInvariants(f *testing.F) { // EndProof should be a proof for upper range bound. value := Nothing[[]byte]() - upperRangeBoundVal, err := db.Get(end) + upperRangeBoundVal, err := db.Get(endBytes) if err != nil { require.ErrorIs(err, database.ErrNotFound) } else { @@ -1751,7 +1755,7 @@ func FuzzRangeProofInvariants(f *testing.F) { proof := Proof{ Path: rangeProof.EndProof, - Key: end, + Key: endBytes, Value: value, } diff --git a/x/merkledb/trie.go b/x/merkledb/trie.go index 10a340211843..231d6432c438 100644 --- a/x/merkledb/trie.go +++ b/x/merkledb/trie.go @@ -44,7 +44,7 @@ type ReadOnlyTrie interface { getEditableNode(key path) (*node, error) // GetRangeProof generates a proof of up to maxLength smallest key/values with keys between start and end - GetRangeProof(ctx context.Context, start, end []byte, maxLength int) (*RangeProof, error) + GetRangeProof(ctx context.Context, start []byte, end Maybe[[]byte], maxLength int) (*RangeProof, error) database.Iteratee } diff --git a/x/merkledb/trie_test.go b/x/merkledb/trie_test.go index 23b853d59baf..f4356895580e 100644 --- a/x/merkledb/trie_test.go +++ b/x/merkledb/trie_test.go @@ -1391,7 +1391,7 @@ func Test_Trie_ConcurrentInsertAndRangeProof(t *testing.T) { require.Eventually( func() bool { - rangeProof, err := newTrie.GetRangeProof(context.Background(), []byte("key1"), []byte("key3"), 3) + rangeProof, err := newTrie.GetRangeProof(context.Background(), []byte("key1"), Some([]byte("key3")), 3) require.NoError(err) require.NotNil(rangeProof) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 5ca11fdacd32..5ed689a61d87 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -361,7 +361,7 @@ func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { if closestNode.key.Compare(keyPath) == 0 { // There is a node with the given [key]. - proof.Value = Clone(closestNode.value) + proof.Value = MaybeBind(closestNode.value, slices.Clone[[]byte]) return proof, nil } @@ -391,13 +391,14 @@ func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { // [maxLength] must be > 0. func (t *trieView) GetRangeProof( ctx context.Context, - start, end []byte, + start []byte, + end Maybe[[]byte], maxLength int, ) (*RangeProof, error) { ctx, span := t.db.tracer.Start(ctx, "MerkleDB.trieview.GetRangeProof") defer span.End() - if len(end) > 0 && bytes.Compare(start, end) == 1 { + if end.HasValue() && bytes.Compare(start, end.Value()) == 1 { return nil, ErrStartAfterEnd } @@ -424,7 +425,7 @@ func (t *trieView) GetRangeProof( result.KeyValues = make([]KeyValue, 0, initKeyValuesSize) it := t.NewIteratorWithStart(start) - for it.Next() && len(result.KeyValues) < maxLength && (len(end) == 0 || bytes.Compare(it.Key(), end) <= 0) { + for it.Next() && len(result.KeyValues) < maxLength && (end.IsNothing() || bytes.Compare(it.Key(), end.Value()) <= 0) { // clone the value to prevent editing of the values stored within the trie result.KeyValues = append(result.KeyValues, KeyValue{ Key: it.Key(), @@ -449,8 +450,8 @@ func (t *trieView) GetRangeProof( if err != nil { return nil, err } - } else if len(end) > 0 { - endProof, err = t.getProof(ctx, end) + } else if end.HasValue() { + endProof, err = t.getProof(ctx, end.Value()) if err != nil { return nil, err } diff --git a/x/sync/client_test.go b/x/sync/client_test.go index c524b252014a..c1146b8208e8 100644 --- a/x/sync/client_test.go +++ b/x/sync/client_test.go @@ -231,7 +231,7 @@ func TestGetRangeProof(t *testing.T) { start := response.KeyValues[1].Key rootID, err := largeTrieDB.GetMerkleRoot(context.Background()) require.NoError(t, err) - proof, err := largeTrieDB.GetRangeProofAtRoot(context.Background(), rootID, start, nil, defaultRequestKeyLimit) + proof, err := largeTrieDB.GetRangeProofAtRoot(context.Background(), rootID, start, merkledb.Nothing[[]byte](), defaultRequestKeyLimit) require.NoError(t, err) response.KeyValues = proof.KeyValues response.StartProof = proof.StartProof diff --git a/x/sync/g_db/db_client.go b/x/sync/g_db/db_client.go index 45630d87d397..92980a4de726 100644 --- a/x/sync/g_db/db_client.go +++ b/x/sync/g_db/db_client.go @@ -39,14 +39,14 @@ func (c *DBClient) GetChangeProof( startRootID ids.ID, endRootID ids.ID, startKey []byte, - endKey []byte, + endKey merkledb.Maybe[[]byte], keyLimit int, ) (*merkledb.ChangeProof, error) { resp, err := c.client.GetChangeProof(ctx, &pb.GetChangeProofRequest{ StartRootHash: startRootID[:], EndRootHash: endRootID[:], StartKey: startKey, - EndKey: endKey, + EndKey: &pb.MaybeBytes{IsNothing: endKey.IsNothing(), Value: endKey.Value()}, KeyLimit: uint32(keyLimit), }) if err != nil { @@ -109,13 +109,13 @@ func (c *DBClient) GetRangeProofAtRoot( ctx context.Context, rootID ids.ID, startKey []byte, - endKey []byte, + endKey merkledb.Maybe[[]byte], keyLimit int, ) (*merkledb.RangeProof, error) { resp, err := c.client.GetRangeProof(ctx, &pb.GetRangeProofRequest{ RootHash: rootID[:], StartKey: startKey, - EndKey: endKey, + EndKey: &pb.MaybeBytes{IsNothing: endKey.IsNothing(), Value: endKey.Value()}, KeyLimit: uint32(keyLimit), }) if err != nil { diff --git a/x/sync/g_db/db_server.go b/x/sync/g_db/db_server.go index 45b4085b2bfc..9455e3bdefb9 100644 --- a/x/sync/g_db/db_server.go +++ b/x/sync/g_db/db_server.go @@ -52,12 +52,16 @@ func (s *DBServer) GetChangeProof( if err != nil { return nil, err } + end := merkledb.Nothing[[]byte]() + if req.EndKey != nil && !req.EndKey.IsNothing { + end = merkledb.Some(req.EndKey.Value) + } changeProof, err := s.db.GetChangeProof( ctx, startRootID, endRootID, req.StartKey, - req.EndKey, + end, int(req.KeyLimit), ) if err != nil { @@ -125,8 +129,11 @@ func (s *DBServer) GetRangeProof( if err != nil { return nil, err } - - proof, err := s.db.GetRangeProofAtRoot(ctx, rootID, req.StartKey, req.EndKey, int(req.KeyLimit)) + end := merkledb.Nothing[[]byte]() + if req.EndKey != nil && !req.EndKey.IsNothing { + end = merkledb.Some(req.EndKey.Value) + } + proof, err := s.db.GetRangeProofAtRoot(ctx, rootID, req.StartKey, end, int(req.KeyLimit)) if err != nil { return nil, err } diff --git a/x/sync/manager.go b/x/sync/manager.go index e61e0f42e647..d42723284dd5 100644 --- a/x/sync/manager.go +++ b/x/sync/manager.go @@ -592,7 +592,7 @@ func (m *Manager) setError(err error) { // Assumes [m.workLock] is not held. func (m *Manager) completeWorkItem(ctx context.Context, work *workItem, largestHandledKey merkledb.Maybe[[]byte], rootID ids.ID, proofOfLargestKey []merkledb.ProofNode) { // if the last key is equal to the end, then the full range is completed - if !merkledb.MaybeBytesEquals(largestHandledKey, work.end) { + if !merkledb.MaybeEqual(largestHandledKey, work.end, bytes.Equal) { // find the next key to start querying by comparing the proofs for the last completed key nextStartKey, err := m.findNextKey(ctx, largestHandledKey.Value(), work.end.Value(), proofOfLargestKey) if err != nil { @@ -677,7 +677,7 @@ func (m *Manager) enqueueWork(work *workItem) { // find the midpoint between two keys // start is expected to be less than end -// nil on start is treated as all 0's +// nil on start or end is treated as all 0's // nothing on end is treated as all 255's func midPoint(start []byte, end merkledb.Maybe[[]byte]) []byte { length := len(start) @@ -694,7 +694,7 @@ func midPoint(start []byte, end merkledb.Maybe[[]byte]) []byte { } // This check deals with cases where the end has a 255(or is nothing which is treated as all 255s) and the start key ends 255. - // For example, midPoint([255], nil) should be [255, 127], not [255]. + // For example, midPoint([255], nothing) should be [255, 127], not [255]. // The result needs the extra byte added on to the end to deal with the fact that the naive midpoint between 255 and 255 would be 255 if (len(start) > 0 && start[len(start)-1] == 255) && (len(end.Value()) == 0 || end.Value()[len(end.Value())-1] == 255) { length++ diff --git a/x/sync/network_server.go b/x/sync/network_server.go index 264a1b774797..ad386865f727 100644 --- a/x/sync/network_server.go +++ b/x/sync/network_server.go @@ -131,6 +131,13 @@ func (s *NetworkServer) AppRequest( return nil } +func maybeBytesToMaybe(mb *pb.MaybeBytes) merkledb.Maybe[[]byte] { + if mb != nil && !mb.IsNothing { + return merkledb.Some(mb.Value) + } + return merkledb.Nothing[[]byte]() +} + // Generates a change proof and sends it to [nodeID]. func (s *NetworkServer) HandleChangeProofRequest( ctx context.Context, @@ -164,6 +171,7 @@ func (s *NetworkServer) HandleChangeProofRequest( if bytesLimit > maxByteSizeLimit { bytesLimit = maxByteSizeLimit } + end := maybeBytesToMaybe(req.EndKey) // attempt to get a proof within the bytes limit for keyLimit > 0 { @@ -175,7 +183,7 @@ func (s *NetworkServer) HandleChangeProofRequest( if err != nil { return err } - changeProof, err := s.db.GetChangeProof(ctx, startRoot, endRoot, req.StartKey, req.EndKey.Value, int(keyLimit)) + changeProof, err := s.db.GetChangeProof(ctx, startRoot, endRoot, req.StartKey, end, int(keyLimit)) if err != nil { // handle expected errors so clients cannot cause servers to spam warning logs. if errors.Is(err, merkledb.ErrRootIDNotPresent) || errors.Is(err, merkledb.ErrStartRootNotFound) { @@ -247,12 +255,14 @@ func (s *NetworkServer) HandleRangeProofRequest( if bytesLimit > maxByteSizeLimit { bytesLimit = maxByteSizeLimit } + end := maybeBytesToMaybe(req.EndKey) + for keyLimit > 0 { root, err := ids.ToID(req.RootHash) if err != nil { return err } - rangeProof, err := s.db.GetRangeProofAtRoot(ctx, root, req.StartKey, req.EndKey.Value, int(keyLimit)) + rangeProof, err := s.db.GetRangeProofAtRoot(ctx, root, req.StartKey, end, int(keyLimit)) if err != nil { // handle expected errors so clients cannot cause servers to spam warning logs. if errors.Is(err, merkledb.ErrRootIDNotPresent) { diff --git a/x/sync/sync_test.go b/x/sync/sync_test.go index a58615797dfa..cf44b8ce8f78 100644 --- a/x/sync/sync_test.go +++ b/x/sync/sync_test.go @@ -46,7 +46,7 @@ func (client *mockClient) GetChangeProof(ctx context.Context, request *pb.SyncGe if err != nil { return nil, err } - return client.db.GetChangeProof(ctx, startRoot, endRoot, request.StartKey, request.EndKey.Value, int(request.KeyLimit)) + return client.db.GetChangeProof(ctx, startRoot, endRoot, request.StartKey, maybeBytesToMaybe(request.EndKey), int(request.KeyLimit)) } func (client *mockClient) GetRangeProof(ctx context.Context, request *pb.SyncGetRangeProofRequest) (*merkledb.RangeProof, error) { @@ -54,7 +54,7 @@ func (client *mockClient) GetRangeProof(ctx context.Context, request *pb.SyncGet if err != nil { return nil, err } - return client.db.GetRangeProofAtRoot(ctx, root, request.StartKey, request.EndKey.Value, int(request.KeyLimit)) + return client.db.GetRangeProofAtRoot(ctx, root, request.StartKey, maybeBytesToMaybe(request.EndKey), int(request.KeyLimit)) } func Test_Creation(t *testing.T) { @@ -216,7 +216,7 @@ func Test_Sync_FindNextKey_InSync(t *testing.T) { require.NoError(syncer.Start(context.Background())) require.NoError(syncer.Wait(context.Background())) - proof, err := dbToSync.GetRangeProof(context.Background(), nil, nil, 500) + proof, err := dbToSync.GetRangeProof(context.Background(), nil, merkledb.Nothing[[]byte](), 500) require.NoError(err) // the two dbs should be in sync, so next key should be nil @@ -401,7 +401,7 @@ func Test_Sync_FindNextKey_ExtraValues(t *testing.T) { require.NoError(syncer.Start(context.Background())) require.NoError(syncer.Wait(context.Background())) - proof, err := dbToSync.GetRangeProof(context.Background(), nil, nil, 500) + proof, err := dbToSync.GetRangeProof(context.Background(), nil, merkledb.Nothing[[]byte](), 500) require.NoError(err) // add an extra value to local db @@ -421,7 +421,7 @@ func Test_Sync_FindNextKey_ExtraValues(t *testing.T) { require.NoError(dbToSync.Put(midpoint, []byte{1})) - proof, err = dbToSync.GetRangeProof(context.Background(), nil, lastKey, 500) + proof, err = dbToSync.GetRangeProof(context.Background(), nil, merkledb.Some(lastKey), 500) require.NoError(err) // next key at prefix of newly added point @@ -520,7 +520,7 @@ func Test_Sync_FindNextKey_DifferentChild(t *testing.T) { require.NoError(syncer.Start(context.Background())) require.NoError(syncer.Wait(context.Background())) - proof, err := dbToSync.GetRangeProof(context.Background(), nil, nil, 100) + proof, err := dbToSync.GetRangeProof(context.Background(), nil, merkledb.Nothing[[]byte](), 100) require.NoError(err) lastKey := proof.KeyValues[len(proof.KeyValues)-1].Key @@ -530,7 +530,7 @@ func Test_Sync_FindNextKey_DifferentChild(t *testing.T) { require.NoError(dbToSync.Put(lastKey, []byte{2})) - proof, err = dbToSync.GetRangeProof(context.Background(), nil, proof.KeyValues[len(proof.KeyValues)-1].Key, 100) + proof, err = dbToSync.GetRangeProof(context.Background(), nil, merkledb.Some(proof.KeyValues[len(proof.KeyValues)-1].Key), 100) require.NoError(err) nextKey, err := syncer.findNextKey(context.Background(), proof.KeyValues[len(proof.KeyValues)-1].Key, nil, proof.EndProof) @@ -602,7 +602,7 @@ func TestFindNextKeyRandom(t *testing.T) { remoteProof, err := remoteDB.GetRangeProof( context.Background(), rangeStart, - rangeEnd, + merkledb.Some(rangeEnd), rand.Intn(maxProofLen)+1, ) require.NoError(err) @@ -900,7 +900,7 @@ func Test_Sync_Error_During_Sync(t *testing.T) { require.NoError(err) endRoot, err := ids.ToID(request.EndRootHash) require.NoError(err) - return dbToSync.GetChangeProof(ctx, startRoot, endRoot, request.StartKey, request.EndKey.Value, int(request.KeyLimit)) + return dbToSync.GetChangeProof(ctx, startRoot, endRoot, request.StartKey, maybeBytesToMaybe(request.EndKey), int(request.KeyLimit)) }, ).AnyTimes() @@ -978,7 +978,7 @@ func Test_Sync_Result_Correct_Root_Update_Root_During(t *testing.T) { <-updatedRootChan root, err := ids.ToID(request.RootHash) require.NoError(err) - return dbToSync.GetRangeProofAtRoot(ctx, root, request.StartKey, request.EndKey.Value, int(request.KeyLimit)) + return dbToSync.GetRangeProofAtRoot(ctx, root, request.StartKey, maybeBytesToMaybe(request.EndKey), int(request.KeyLimit)) }, ).AnyTimes() client.EXPECT().GetChangeProof(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn( @@ -988,7 +988,7 @@ func Test_Sync_Result_Correct_Root_Update_Root_During(t *testing.T) { require.NoError(err) endRoot, err := ids.ToID(request.EndRootHash) require.NoError(err) - return dbToSync.GetChangeProof(ctx, startRoot, endRoot, request.StartKey, request.EndKey.Value, int(request.KeyLimit)) + return dbToSync.GetChangeProof(ctx, startRoot, endRoot, request.StartKey, maybeBytesToMaybe(request.EndKey), int(request.KeyLimit)) }, ).AnyTimes()