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-019: Subspace post migration #1157

Merged
merged 22 commits into from
Jun 12, 2023

Conversation

dadamu
Copy link
Contributor

@dadamu dadamu commented May 23, 2023

Description

This PR implements ADR-019: Subspace post migration.

Closes: DCD-324


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)

@dadamu dadamu requested a review from a team as a code owner May 23, 2023 09:27
@dadamu dadamu marked this pull request as draft May 23, 2023 09:28
@codecov
Copy link

codecov bot commented May 23, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.17 🎉

Comparison is base (fdb18ed) 80.12% compared to head (6482721) 80.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1157      +/-   ##
==========================================
+ Coverage   80.12%   80.30%   +0.17%     
==========================================
  Files         189      189              
  Lines       16526    16675     +149     
==========================================
+ Hits        13242    13391     +149     
  Misses       2690     2690              
  Partials      594      594              
Impacted Files Coverage Δ
x/posts/keeper/msg_server.go 91.99% <100.00%> (+1.57%) ⬆️
x/posts/keeper/polls.go 97.89% <100.00%> (+0.19%) ⬆️
x/posts/types/models.go 79.03% <100.00%> (+1.66%) ⬆️
x/posts/types/msgs.go 97.53% <100.00%> (+0.32%) ⬆️

... and 3 files 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-324/impl-post-transfer branch 2 times, most recently from bdd7f42 to 6a812ba Compare May 29, 2023 07:43
@github-actions github-actions bot added the x/CLI label May 29, 2023
@dadamu dadamu force-pushed the paul/DCD-324/impl-post-transfer branch from 5e644dd to 3df8da9 Compare May 30, 2023 08:54
@dadamu dadamu marked this pull request as ready for review May 30, 2023 09:41
k.SetNextAttachmentID(ctx, msg.TargetSubspaceID, newPostID, newAttachmentID+1)

// Delete the post
k.Keeper.DeletePost(ctx, msg.SubspaceID, msg.PostID)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DeletePost calls the PostDeletedHook, which removes all the incompatibility references managed by other modules already, so no need to implement the PostMovedHook.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: DeletePost calls DeleteAttachment which removes the poll from the active queue (if it was there).

@@ -41,6 +41,9 @@ service Msg {
//
// Since: Desmos 5.0.0
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);

// MovePost allows users to move their own posts to another subspace
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably add a Since: Desmos 5.1.0 here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe Desmos 6.0.0 is better since it would be Desmos v6 feature on roadmap

proto/desmos/posts/v3/msgs.proto Outdated Show resolved Hide resolved
x/posts/keeper/msg_server.go Outdated Show resolved Hide resolved
}

// Check the permission to move the post
canMove := post.Author == msg.Owner && k.HasPermission(ctx, msg.TargetSubspaceID, msg.TargetSectionID, msg.Owner, types.PermissionWrite)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably the post.Author == msg.Owner check should be split, so that the user can know exactly what's wrong (they are not they author of the post)

x/posts/keeper/msg_server.go Show resolved Hide resolved
x/posts/keeper/msg_server.go Outdated Show resolved Hide resolved
dadamu and others added 3 commits June 5, 2023 13:13
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
@dadamu dadamu force-pushed the paul/DCD-324/impl-post-transfer branch from 965b5e9 to 3b52776 Compare June 5, 2023 07:23
@dadamu dadamu requested a review from RiccardoM June 5, 2023 14:28
x/posts/client/cli/tx.go Outdated Show resolved Hide resolved
{
name: "invalid subspace id returns error",
args: []string{
"", "1", "2", "1",
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add the --from flag to all these tests in order to make sure that they don't fail due to the invalid signer address. Otherwise we will not catch errors like the one highlighted above

x/posts/keeper/msg_server.go Outdated Show resolved Hide resolved
x/posts/types/models.go Outdated Show resolved Hide resolved
x/posts/keeper/msg_server.go Outdated Show resolved Hide resolved
x/posts/types/models.go Outdated Show resolved Hide resolved
Comment on lines 553 to 564
newAttachmentID := uint32(0)
k.IteratePostAttachments(ctx, msg.SubspaceID, msg.PostID, func(attachment types.Attachment) (stop bool) {
newAttachmentID++
attachmentMove := types.NewAttachmentMove(msg.TargetSubspaceID, newPostID, newAttachmentID)
updatedAttachment := attachmentMove.Update(attachment)
k.SaveAttachment(ctx, updatedAttachment)

if types.IsActivePoll(updatedAttachment) {
k.InsertActivePollQueue(ctx, updatedAttachment)
}
return false
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this being done? Why can't we preserve the attachment ids that were used inside the old post instead? They are unique to the post itself anyway. If we preserve them we have less writes (which means less gas used) and we can simply set the NextAttachmentID to be max(post attachment ids) + 1 which is way simpler. This way we would also make it easier for external tools that could simply update the post id instead of having to delete the attachments and re-storing them as well

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 you, we should preserve the original attachment id is correct, and if anything wrong invariant will alert when simulation test. I was confused that we should reset id or apply the original id here, finally I decided to reset the id because it will be error if ids are wrongly set.

By the way, I don't think it brings less writes since it actually adds some keys for moved attachments then deleted the original ones. The storage side is performing the same operations like:

store.Set(movedAttachmentKey, movedAttachment)
store.Delete(oldAttachmentKey, oldAttachment)

Comment on lines 667 to 668
// IsActivePoll tells whether the given attachment represents a active poll or not
func IsActivePoll(attachment Attachment) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of relying on a check of FinalTallyResulsts I think it's best to check the storage instead, running through the list of active polls. This would make sure that if there is any bug with the setting of the tally results we do not end up with a bug here as well

dadamu and others added 2 commits June 12, 2023 14:24
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
dadamu and others added 5 commits June 12, 2023 14:26
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
@dadamu dadamu requested a review from RiccardoM June 12, 2023 07:56
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! 💯

k.SetNextAttachmentID(ctx, msg.TargetSubspaceID, newPostID, newAttachmentID+1)

// Delete the post
k.Keeper.DeletePost(ctx, msg.SubspaceID, msg.PostID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self: DeletePost calls DeleteAttachment which removes the poll from the active queue (if it was there).

@RiccardoM RiccardoM merged commit b9244c0 into master Jun 12, 2023
35 checks passed
@RiccardoM RiccardoM deleted the paul/DCD-324/impl-post-transfer branch June 12, 2023 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants