Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[SLT-234] feat(rfq): dynamic block conf wait + receipt x event quote check w/ RPC consensus #3190
[SLT-234] feat(rfq): dynamic block conf wait + receipt x event quote check w/ RPC consensus #3190
Changes from 5 commits
4a87e3d
0aa10b6
3958292
7fca370
353b63c
bfd1761
5bc3004
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Check warning on line 76 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L76
Check warning on line 86 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L85-L86
Check warning on line 94 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L93-L94
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.
🛠️ Refactor suggestion
Improved IsAllowed method logic
The new logic in the
IsAllowed
method provides a more comprehensive check for request validation. The sequence of checks (volume limit, confirmations, and receipt verification) enhances the security and reliability of the rate limiting process.However, consider improving error handling for better debugging:
Consider wrapping errors with more context:
This change will make it easier to trace the origin of errors in logs.
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: codecov/patch
Check warning on line 120 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L120
Check warning on line 149 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L148-L149
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.
New getNumberOfConfirmationsToWait method looks good, but needs a safeguard
The new
getNumberOfConfirmationsToWait
method provides a dynamic way to determine the required confirmations based on the request volume and chain-specific volume limit. The logic is sound, including the special case handling for no limit (when volumeLimitForChain is -1).However, there's a potential issue:
Add a check to prevent division by zero:
This change will prevent a potential panic if the volume limit is set to zero for a chain/token combination.
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: codecov/patch
Check warning on line 248 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L245-L248
Check warning on line 254 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L253-L254
Check warning on line 259 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L258-L259
Check warning on line 264 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L264
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.
Prevent potential index out-of-range panic when accessing receipt logs
Accessing
receipt.Logs[0]
without checking ifreceipt.Logs
is non-empty can result in a runtime panic if the logs slice is empty. To ensure robustness, add a check to verify thatreceipt.Logs
contains at least one entry before accessing it.Apply this diff to add the necessary check:
📝 Committable suggestion
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.
Check for empty receipt logs before accessing the first element
Accessing
receipt.Logs[0]
without verifying thatreceipt.Logs
is not empty can lead to an index out-of-range panic if the slice is empty. Before accessingreceipt.Logs[0].Data
, ensure that there is at least one log entry inreceipt.Logs
.Apply this diff to add the necessary check:
📝 Committable suggestion
Check warning on line 278 in services/rfq/relayer/limiter/limiter.go
Codecov / codecov/patch
services/rfq/relayer/limiter/limiter.go#L272-L278
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.
New checkReceipt method enhances security, but needs a safeguard
The
checkReceipt
method is a valuable addition that verifies transaction receipts and handles potential reorg scenarios. The event parsing and field matching logic provide a robust check for transaction validity.However, there's a potential issue:
Add a check before accessing log data to prevent a potential nil pointer dereference:
This change will prevent a panic if the receipt has no logs, which could happen in certain edge cases.
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: codecov/patch
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.
💡 Codebase verification
rfqFieldsMatch function is not exhaustive
The
rfqFieldsMatch
function currently verifies transaction ID, sender, origin amount, destination amount, and origin token. However, theBridgeRequested
event includes additional fields that should also be matched to ensure comprehensive validation:destChainId
)destToken
)sendChainGas
)Please update the
rfqFieldsMatch
function to include these fields to address the TODO comment and enhance the reliability of the verification process.🔗 Analysis chain
New rfqFieldsMatch function is comprehensive, but needs review
The
rfqFieldsMatch
function provides a thorough comparison of RFQ fields with event data, which is crucial for verifying the integrity of the transaction. The checks cover all essential fields: transaction ID, sender, amounts, and token.However, there's an open question:
The TODO comment suggests that the field matching might not be exhaustive. Please review if there are any additional fields that should be checked. Consider adding checks for:
If these fields are not available in the event data, update the comment to explain why the current checks are sufficient.
This will help ensure that all necessary fields are being verified and improve the robustness of the check.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 352
Script:
Length of output: 186
Script:
Length of output: 648
Script:
Length of output: 6623