-
Notifications
You must be signed in to change notification settings - Fork 5
Fix decommissioned circle data access in viewer #117
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ contract SavingCircles is ISavingCircles, ReentrancyGuard, OwnableUpgradeable, E | |
| mapping(uint256 id => mapping(uint256 nonce => bool used)) public usedNonces; | ||
| mapping(uint256 id => bool active) public isActive; | ||
| mapping(uint256 id => address[] members) public circleMembers; | ||
| mapping(uint256 id => address owner) public circleOwners; | ||
|
|
||
| /// @dev Requires circle is commissioned by checking if an owner is set | ||
| modifier onlyCommissioned(uint256 _id) { | ||
|
|
@@ -88,6 +89,7 @@ contract SavingCircles is ISavingCircles, ReentrancyGuard, OwnableUpgradeable, E | |
| isMember[_id][owner] = true; | ||
| memberCircles[owner].push(_id); | ||
| circleMembers[_id].push(owner); | ||
| circleOwners[_id] = owner; | ||
|
|
||
| circles[_id] = _circle; | ||
| emit CircleCreated(_id, _circle.token, _circle.depositAmount, _circle.depositInterval); | ||
|
|
@@ -153,7 +155,7 @@ contract SavingCircles is ISavingCircles, ReentrancyGuard, OwnableUpgradeable, E | |
| } | ||
| } | ||
|
|
||
| delete circles[_id]; | ||
| circles[_id].owner = address(0); | ||
| emit CircleDecommissioned(_id); | ||
|
Comment on lines
155
to
159
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -130,7 +130,7 @@ contract SavingCirclesViewer is ISavingCirclesViewer { | |||||||||||||||||
|
|
||||||||||||||||||
| uint256 currentIndex = 0; | ||||||||||||||||||
| for (uint256 i = 0; i < SAVING_CIRCLES.nextId(); i++) { | ||||||||||||||||||
| if (SAVING_CIRCLES.getCircle(i).owner == _user && !_isInArray(i, memberCircleIds)) { | ||||||||||||||||||
| if (_getCircleOwner(i) == _user && !_isInArray(i, memberCircleIds)) { | ||||||||||||||||||
| ownedOnlyIds[currentIndex] = i; | ||||||||||||||||||
| currentIndex++; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -144,7 +144,7 @@ contract SavingCirclesViewer is ISavingCirclesViewer { | |||||||||||||||||
| uint256[] memory memberCircleIds | ||||||||||||||||||
| ) internal view returns (uint256 count) { | ||||||||||||||||||
| for (uint256 i = 0; i < SAVING_CIRCLES.nextId(); i++) { | ||||||||||||||||||
| if (SAVING_CIRCLES.getCircle(i).owner == _user && !_isInArray(i, memberCircleIds)) { | ||||||||||||||||||
| if (_getCircleOwner(i) == _user && !_isInArray(i, memberCircleIds)) { | ||||||||||||||||||
| count++; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -265,14 +265,19 @@ contract SavingCirclesViewer is ISavingCirclesViewer { | |||||||||||||||||
| ) internal view returns (UserCircleData memory circleData) { | ||||||||||||||||||
| circleData.circleId = _circleId; | ||||||||||||||||||
|
|
||||||||||||||||||
| ISavingCircles.Circle memory circle = SAVING_CIRCLES.getCircle(_circleId); | ||||||||||||||||||
| ISavingCircles.Circle memory circle = _getCircle(_circleId); | ||||||||||||||||||
| bool isDecommissioned = SAVING_CIRCLES.isDecommissioned(circle); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (SAVING_CIRCLES.isDecommissioned(circle)) { | ||||||||||||||||||
| if (circle.owner == address(0)) { | ||||||||||||||||||
| circle.owner = SAVING_CIRCLES.circleOwners(_circleId); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+271
to
+273
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would this ever happen?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. he's updating the local circle variable with the owner after decommissioning the circle, but this approach feels messy imo
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It happens after decommission by design: That If we want to move away from
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use circle end = type(uint256).max
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont understand why we should need to restore a historical owner at any point so we should redesign if possible to avoid that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You’re right, and I agree. I chose the I’ll switch to an explicit decommission marker in contract state and remove the owner-reconstruction logic from the viewer. Concretely:
Is this ok? @RonTuretzky
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good to me lmk if you need help on this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sgtm |
||||||||||||||||||
| circleData.circleInfo = circle; | ||||||||||||||||||
|
|
||||||||||||||||||
| if (isDecommissioned) { | ||||||||||||||||||
| circleData.isDecommissioned = true; | ||||||||||||||||||
|
||||||||||||||||||
| circleData.isDecommissioned = true; | |
| circleData.isDecommissioned = true; | |
| // For decommissioned circles, we can still safely derive some fields | |
| // without going through commissioned-only helper flows. | |
| circleData.isOwner = (circle.owner == _user); | |
| circleData.isMember = SAVING_CIRCLES.isMember(_circleId, _user); | |
| _setCircleTimingData(circleData, circle); | |
| _setDepositProgress(circleData, _circleId); |
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.
wouldn't a better design be to designate the 0 index to always be the circle owner?
Uh oh!
There was an error while loading. Please reload this page.
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.
address(0) is equal to "Decommissioned" or "Stack doesn't exist" in our current semantic. What do you mean by 0 index. If you are pointing to the index in the members array, the owner is already the first in the array
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.
then why do we have this mapping? can't we just use that index instead of defining another variable ?
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.
Yes I agree, also in the other PR
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.
Good point. I added
circleOwnersas a way to preserve historical owner afterdecommission()zeroescircle.owner, so the viewer could still display owner data for decommissioned circles.But I agree the cleaner design is to use the existing
circleMembers[id][0].I’ll update this PR to remove the viewer dependency on
circleOwnersand reconstruct historical owner fromcircleMembers[id][0]instead.