-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement ADR-20: Post ownership transfer #1145
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1145 +/- ##
==========================================
+ Coverage 80.30% 80.77% +0.47%
==========================================
Files 189 193 +4
Lines 16675 17159 +484
==========================================
+ Hits 13391 13861 +470
- Misses 2690 2701 +11
- Partials 594 597 +3
☔ View full report in Codecov by Sentry. |
d4809e7
to
bdf4c9e
Compare
IncomingPostOwnerTransferRequestPrefix | SubspaceID | ReceiverAddress | PostID | -> Protobuf(PostOwnerTransferRequest) | ||
PostOwnerTransferRequestPrefix | SubspaceID | PostID | -> Protobuf(PostOwnerTransferRequest) | ||
``` | ||
|
||
This structure enables the receiver to easily manage incoming requests by iterating over all requests with a given subspace ID and receiver address, which will be the most frequently used query. | ||
This structure enables Desmos to easily manage requests by iterating over all requests with a given subspace ID and post ID when a post is moved or deleted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RiccardoM
I have identified an issue with this design: we are unable to determine the post's ownership receiver when it is deleted or moved. This leads to a time complexity of O(n) when deleting a post, as it requires the following steps:
- Iterate over all requests by subspace ID.
- Find the post ID of the request that matches the post to be deleted.
- Delete the corresponding request store key.
To address this issue, I have simplified the store key implementation, resulting in an improved time complexity of O(1) for the post deletion process.
f2b963c
to
0449ce5
Compare
@@ -37,13 +37,6 @@ const ( | |||
DefaultWeightMsgGrantAllowance int = 20 | |||
DefaultWeightMsgRevokeAllowance int = 5 | |||
|
|||
DefaultWeightMsgCreatePost int = 80 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to operation.go
to be easier management
The solution outlined above is fully backwards compatible since it introduces a new __owner__ field for post, but it will require a migration script to update all existing posts. This script will handle the following tasks: | ||
- migrate all posts to set a new __owner__ field to its __author__. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a new field to proto is fully backwards compatible
6c84b32
to
efb2efd
Compare
@dadamu Can you rebase this on the |
efb2efd
to
7d64bad
Compare
@RiccardoM Rebased |
proto/desmos/posts/v3/msgs.proto
Outdated
// | ||
// Since: Desmos 6.0.0 | ||
message MsgAcceptPostOwnerTransfer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to name them Msg[Accept/Cancel/Refuse]PostOwnerTransferRequest
(adding the missing Request
at the end), similar to the Msg[Accept/Cancel/Refuse]DTagTransferRequest
we have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
// Check if the sender has profile | ||
if !k.HasProfile(ctx, msg.Sender) { | ||
return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "you cannot cancel a post owner transfer request without having a profile") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this wanted? If the request was created, it means that the user had the profile at that time. I think we should allow them to cancel the request even if they have deleted them in the meanwhile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should allow all the users to cancel/refuse requests. Updated.
// Check if the receiver has profile | ||
if !k.HasProfile(ctx, msg.Receiver) { | ||
return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "you cannot refuse a post owner transfer request without having a profile") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: we should allow refusing a transfer request even without a profile
x/posts/legacy/v7/store.go
Outdated
|
||
// Set the owner to its author for posts | ||
for _, post := range posts { | ||
newPost := types.NewOwnerTransfer(post.Author, post.LastEditedDate).Update(post) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use the Update
method here. Instead, we should simply update the post's Owner
field manually. This is to avoid having to call a method for nothing and thus reducing the overall migration (which can be quite lengthy)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with it, updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job 💯
Description
This PR implements ADR-20: Post ownership transfer.
Closes: DCD-320
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change