Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement ADR-20: Post ownership transfer #1145

Merged
merged 36 commits into from
Jun 14, 2023

Conversation

dadamu
Copy link
Contributor

@dadamu dadamu commented May 16, 2023

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@github-actions github-actions bot added the x/CLI label May 16, 2023
@codecov
Copy link

codecov bot commented May 16, 2023

Codecov Report

Patch coverage: 96.53% and project coverage change: +0.47 🎉

Comparison is base (b9244c0) 80.30% compared to head (ff940ce) 80.77%.

❗ Current head ff940ce differs from pull request most recent head 8c4cccc. Consider uploading reports for the commit 8c4cccc to get more accurate results

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     
Impacted Files Coverage Δ
x/posts/module.go 11.92% <0.00%> (-0.25%) ⬇️
x/posts/keeper/grpc_query.go 81.36% <80.00%> (-0.32%) ⬇️
x/posts/keeper/alias_functions.go 69.71% <85.00%> (+2.19%) ⬆️
x/posts/types/genesis.go 94.62% <90.00%> (-1.14%) ⬇️
x/posts/keeper/invariants.go 93.36% <94.44%> (+0.24%) ⬆️
x/posts/types/models.go 81.01% <98.18%> (+1.97%) ⬆️
x/posts/keeper/genesis.go 95.06% <100.00%> (+0.39%) ⬆️
x/posts/keeper/msg_server.go 92.00% <100.00%> (+0.01%) ⬆️
x/posts/keeper/msg_server_post_owner_transfer.go 100.00% <100.00%> (ø)
x/posts/keeper/post_owner_transfer.go 100.00% <100.00%> (ø)
... and 6 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dadamu dadamu force-pushed the paul/DCD-320/implement-adr-20 branch from d4809e7 to bdf4c9e Compare May 16, 2023 11:56
@github-actions github-actions bot added the kind/adr An issue or PR relating to an architectural decision record label May 16, 2023
Comment on lines -71 to +74
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.
Copy link
Contributor Author

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.

@dadamu dadamu force-pushed the paul/DCD-320/implement-adr-20 branch 3 times, most recently from f2b963c to 0449ce5 Compare May 17, 2023 14:10
@dadamu dadamu marked this pull request as ready for review May 18, 2023 11:36
@dadamu dadamu requested a review from a team as a code owner May 18, 2023 11:36
@dadamu dadamu changed the title feat!: implement ADR-20: Post ownership transfer feat: implement ADR-20: Post ownership transfer May 18, 2023
@@ -37,13 +37,6 @@ const (
DefaultWeightMsgGrantAllowance int = 20
DefaultWeightMsgRevokeAllowance int = 5

DefaultWeightMsgCreatePost int = 80
Copy link
Contributor Author

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

Comment on lines +205 to +206
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__.
Copy link
Contributor Author

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

@github-actions github-actions bot added the x/profiles Module that allows to create and manage decentralized social profiles label May 18, 2023
@dadamu dadamu force-pushed the paul/DCD-320/implement-adr-20 branch from 6c84b32 to efb2efd Compare June 5, 2023 08:58
@RiccardoM
Copy link
Contributor

@dadamu Can you rebase this on the master branch please?

@dadamu dadamu force-pushed the paul/DCD-320/implement-adr-20 branch from efb2efd to 7d64bad Compare June 13, 2023 12:18
@dadamu
Copy link
Contributor Author

dadamu commented Jun 13, 2023

@RiccardoM Rebased

//
// Since: Desmos 6.0.0
message MsgAcceptPostOwnerTransfer {
Copy link
Contributor

@RiccardoM RiccardoM Jun 13, 2023

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 79 to 82
// 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")
}
Copy link
Contributor

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

Copy link
Contributor Author

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.

Comment on lines 183 to 187
// 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")
}

Copy link
Contributor

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


// Set the owner to its author for posts
for _, post := range posts {
newPost := types.NewOwnerTransfer(post.Author, post.LastEditedDate).Update(post)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with it, updated

Copy link
Contributor

@RiccardoM RiccardoM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job 💯

@RiccardoM RiccardoM merged commit f0b03d0 into master Jun 14, 2023
34 checks passed
@RiccardoM RiccardoM deleted the paul/DCD-320/implement-adr-20 branch June 14, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/adr An issue or PR relating to an architectural decision record x/CLI x/profiles Module that allows to create and manage decentralized social profiles
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants