-
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-019: Subspace post migration #1157
Conversation
Codecov ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
bdd7f42
to
6a812ba
Compare
5e644dd
to
3df8da9
Compare
k.SetNextAttachmentID(ctx, msg.TargetSubspaceID, newPostID, newAttachmentID+1) | ||
|
||
// Delete the post | ||
k.Keeper.DeletePost(ctx, msg.SubspaceID, msg.PostID) |
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.
DeletePost
calls the PostDeletedHook
, which removes all the incompatibility references managed by other modules already, so no need to implement the PostMovedHook
.
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.
Note to self: DeletePost
calls DeleteAttachment
which removes the poll from the active queue (if it was there).
proto/desmos/posts/v3/msgs.proto
Outdated
@@ -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 |
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.
We should probably add a Since: Desmos 5.1.0
here
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.
Maybe Desmos 6.0.0 is better since it would be Desmos v6 feature on roadmap
x/posts/keeper/msg_server.go
Outdated
} | ||
|
||
// Check the permission to move the post | ||
canMove := post.Author == msg.Owner && k.HasPermission(ctx, msg.TargetSubspaceID, msg.TargetSectionID, msg.Owner, types.PermissionWrite) |
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.
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)
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
965b5e9
to
3b52776
Compare
x/posts/client/cli/cli_test.go
Outdated
{ | ||
name: "invalid subspace id returns error", | ||
args: []string{ | ||
"", "1", "2", "1", |
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.
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
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 | ||
}) |
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.
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
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 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)
x/posts/types/models.go
Outdated
// IsActivePoll tells whether the given attachment represents a active poll or not | ||
func IsActivePoll(attachment Attachment) bool { |
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.
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
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
Co-authored-by: Riccardo <riccardo.montagnin@gmail.com>
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! 💯
k.SetNextAttachmentID(ctx, msg.TargetSubspaceID, newPostID, newAttachmentID+1) | ||
|
||
// Delete the post | ||
k.Keeper.DeletePost(ctx, msg.SubspaceID, msg.PostID) |
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.
Note to self: DeletePost
calls DeleteAttachment
which removes the poll from the active queue (if it was there).
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...
!
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