-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move away from using Vec<u8> to represent raw content key/value #1404
Comments
Can I take this one? |
@etherhood, I would wait for #1403 to be merged first, as it does background for this work. |
I see its merged now, If it is fine with you, I will start on it |
I have added some commits in WIP PR #1431 Should I also change Vec type to Bytes in all places wherever Vec is being used, as I couldn't find RawContentKey being used in |
I would say replacing one type at the time is good (unless they have overlapping uses). Regarding |
Okay thanks, that sounds about right. |
Fixed by #1431 . |
I wouldn't say that this is fully completed. Not all places from above were converted. |
I can finish this, just to be sure, is there places where we would rather use only |
Here is an attempt to make a list (I will also update first post with it):
This list is probably not complete, but I believe this issue can be closed once it's done. Of course, all places that use these should be updated as well (e.g. we shouldn't just copy Ideally, this should be done in several small PRs, each fixing only one or two. Due to their interconnection (especially in |
Just a reminder that when changes like this go into ethportal-api, it affects external projects. Currently, the main one we consider is glados, but it's good to be thinking about what impact we're having on other projects that want to use portal through trin APIs. I'm ambivalent about forcing the API users to add alloy as a dependency for the Bytes. I'm not happy with having IMO it's ugly to have clients have to do something like This is all coming up while working on ethereum/glados#321 |
@morph-dev Aren't these supposed to be |
cough cough Portal Hive purely uses Glados still uses quite a bit of custom method calls, instead of solely using ethportal-api for making Portal JSON-RPC calls. |
I suppose we don't really need
Haha, yes, excellent callout. How are you feeling about the current and proposed API changes, as a "user" of it in Hive? |
These are low level network types, and it's fine for them to use bytes::Bytes. They can easily we wrapped in RawContentKey / RawContentValue if/when needed. But since there is some concerns from other team members, please wait a bit before you continue with your work (until we agree what we want). |
This reply is mostly to @carver's concerns. Happy to discuss this further, either here, or over a call. I understand that there is concern regarding switching from Not using
|
Ok, just organizing my thoughts here, now that I'm done with the API upgrade work. If we end up needing more follow-up, let's do a call. I think we're agreeing on most of this. I definitely get the benefits of I guess where we are currently split is in intentionally hiding away the The one option missing from this list is when a user is forced to convert to a
So in this case: We can't migrate to I think our ethportal API is better if
I do think there's a little bit of "ugh, I have to learn the intricacies of another library" for
For any users of the API library, ever? We already have the first counter-example. I'm sure there are plenty more reasonable ones. I'm happy to say we shouldn't ever use it internally to trin. And we should encourage that pattern in our API docs. |
@carver and I had a chat about this and here is the summary (@carver , let me know if I forgot something):
After looking into more details, I think that public type should still be
With this being said, @carver, let me know if you still think that we should use I will create a PR to update documentation. @etherhood , you can proceed with refactoring (if you still wish to do so). I think everything here is still accurate: #1404 (comment) |
Yup, that looks complete. 👍🏻 for sticking with the alloy version.
To be explicit about this ask: it would be great to see a docstring on each
Hm, though I see that this claim is aspirational at the moment, since we do actually clone all the data on every trin/ethportal-api/src/types/content_key/history.rs Lines 201 to 224 in 454b3e0
Which means that every |
I just created #1543. Let me know there if something else should be clarified.
Yes, I just noticed this as well. And few other API changes that I wanted to improve. So I'm working on small refactoring. For the explicit code that you linked, I believe that converting from But instead of using What do you think? Sidenote: I'm not sure if |
Refactoring that I mentioned are in #1544 |
I will resume working on it. |
@morph-dev Created PR #1552, updating Vec to RawContentKey/RawContentValue or bytes::Bytes wherever applicable, please review. |
Instead of using
Vec<u8>
to represent raw content keys/values, we should use something likealloy_primitives::Bytes
because:We should either wrap or name the type, to avoid potential confusion (e.g. see
RawContentValue
).Other places that should be updated:
FindContent::content_key
- type should beRawContentKey
Content::Content(Vec<u8>)
->Content::Content(RawContentValue)
PopulatedOffer::content
items - type should beVec<(RawContentKey, RawContentValue)>
PopulatedOfferWithResult
RecursiveFindContentResult
- should beRawContentValue
instead ofVec<u8>
FindContentQueryResponse::Content
- should beRawContentValue
FindContentQueryPending::PendingContent.content
- should beRawContentValue
UnvalidatedContent::Content
- should beRawContentValue
ValidatedContent.content
- should beRawContentValue
Vec<u8>
, when it should be eitherRawContentKey
orRawContentValue
bytes::Bytes
instead ofVec<u8>
decode_content_payload
- should accept and returnbytes::Bytes
ProtocolRequest
- should bebytes::Bytes
send_talk_req
- should returnbytes::Bytes
propagate_gossip_cross_thread
andtrace_propagate_gossip_cross_thread
should acceptRawContentValue
instead ofVec<u8>
ContentStore::get
- should returnResult<Option<RawContentValue>>
ContentStore::put
- should returnResult<Vec<(Self::Key, RawContentValue)>, ContentStoreError>
ContentStore
should be updated as wellThe text was updated successfully, but these errors were encountered: