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

Enumberable set cleanup #12885

Merged
merged 5 commits into from
Apr 23, 2024
Merged

Enumberable set cleanup #12885

merged 5 commits into from
Apr 23, 2024

Conversation

shileiwill
Copy link
Contributor

No description provided.

Copy link
Contributor

I see you updated files related to core. Please run pnpm changeset in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

Copy link
Contributor

I see you updated files related to contracts. Please run pnpm changeset in the contracts directory to add a changeset.

Comment on lines 358 to 360
for (uint256 idx = 0; idx < s_registrars.length(); idx++) {
s_registrars.remove(s_registrars.at(idx));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is potentially buggy because remove() will adjust the index of items in the set on each delete. I think we need to count backwards instead, like this:

for (int256 idx = int256(s_registrars.length()); idx > -1; idx--) {
  s_registrars.remove(s_registrars.at(idx));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wow, good catch!

I just tested in remix, and indeed, using the above code couldnt remove all, it will have leftover. The right way is to cleanup using reverse order, as you recommended.

I added a foundry test to cover this scenario. If you see this commit , it fails bc of registrar length doesnt match.

with the latest commit, s_registrars is cleaned up properly.

Comment on lines 188 to 190
for (uint256 idx = 0; idx < s_deactivatedTransmitters.length(); idx++) {
s_deactivatedTransmitters.remove(s_deactivatedTransmitters.at(idx));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since s_deactivatedTransmitters is not exposed, i couldnt unit test this guy. I hope the above registrar test can also verify the logic.

Base automatically changed from decimals to develop April 18, 2024 20:21
Comment on lines 580 to 588
(
,
IAutomationV21PlusCommon.OnchainConfigLegacy memory onchainConfig2,
address[] memory signers,
address[] memory transmitters,
uint8 f
) = registry.getState();

assertEq(onchainConfig2.registrars.length, 3);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test the values of the new registrars, instead of just the length? Also, I think this bug is only exposed when decreasing registrars. Could we extend this test so that we decrease from say 3 to 0 and test that all have been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we test the values of the new registrars, instead of just the length?

sure, will do.

I think this bug is only exposed when decreasing registrars. Could we extend this test so that we decrease from say 3 to 0 and test that all have been removed?

This should be already covered. When we setConfig, we remove all existing registrars and set new ones. If you check out this particular commit, and run the foundry test, you should see the test failure. I left it there in a separate commit to showcase this.

ff05527

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome - sorry I missed that

Comment on lines +807 to +815
function _getRegistrars() private pure returns (address[] memory) {
address[] memory registrars = new address[](2);
registrars[0] = address(uint160(uint256(keccak256("registrar1"))));
registrars[1] = address(uint160(uint256(keccak256("registrar2"))));
return registrars;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick - but since the function is only used once, it might be neater to just inline it? not a strong opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason of having this function is that we cant initiate and add elements to the registrars array outside of a function. If you see the original code, the registrars were under contracts.

@cl-sonarqube-production
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@shileiwill shileiwill added this pull request to the merge queue Apr 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants