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

Add Rate limiter #114

Closed
wants to merge 43 commits into from
Closed

Add Rate limiter #114

wants to merge 43 commits into from

Conversation

trajan0x
Copy link
Contributor

Description

Fixes # (issue)

Checklist

  • New Contracts have been tested
  • Lint has been run
  • I have checked my code and corrected any misspellings

@coveralls
Copy link

coveralls commented Apr 10, 2022

Pull Request Test Coverage Report for Build 2152410060

  • 95 of 125 (76.0%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+4.8%) to 40.552%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contracts/bridge/SynapseBridge.sol 28 33 84.85%
contracts/bridge/libraries/EnumerableMapUpgradeable.sol 8 20 40.0%
contracts/bridge/RateLimiter.sol 40 53 75.47%
Totals Coverage Status
Change from base Build 2096884618: 4.8%
Covered Lines: 783
Relevant Lines: 1785

💛 - Coveralls

}

function retryByKappa(bytes32 kappa) external onlyRole(LIMITER_ROLE) {
(bytes memory toRetry, ) = rateLimited.get(kappa);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check if kappa already exists before calling bridge. I think assumption that all kappas in the queue were not yet processed is too strong to preserve.

if (!IBridge(BRIDGE_ADDRESS).kappaExists(kappa)) {
    (bool success, bytes memory returnData) = BRIDGE_ADDRESS.call(toRetry);
    require(
        success,
        Strings.append("could not call bridge:", _getRevertMsg(returnData))
    );
}
rateLimited.remove(kappa);

);

for (uint8 i = 0; i < attempts; i++) {
(bytes32 kappa, bytes memory toRetry, ) = rateLimited.at(i);
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comment above:
https://github.com/synapsecns/synapse-contracts/pull/114/files#r849141913

Also, some generalization on retrying the kappas is required.

)
);

rateLimited.remove(kappa);
Copy link
Collaborator

@ChiTimesChi ChiTimesChi Apr 13, 2022

Choose a reason for hiding this comment

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

Doing map.remove() in the same for loop as map.at() will break things. Either do two separate loops for iteration and deletion. Or even better, change Map to queue and use peek and poll to get the first element and then delete it.

@trajan0x
Copy link
Contributor Author

Moving to #116 to follow our git flow

@trajan0x trajan0x closed this Apr 13, 2022
@trajan0x trajan0x deleted the rate-limiter branch April 13, 2022 20:20
@trajan0x trajan0x mentioned this pull request May 18, 2022
3 tasks
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.

3 participants