Closed marc-aurele-besner closed 1 week ago
Name | Link |
---|---|
Latest commit | 0b91d9c02981038b9f08d93d9fc6a39fa0e0160c |
Latest deploy log | https://app.netlify.com/sites/dev-astral/deploys/672aa4c08310650008c323c0 |
Deploy Preview | https://deploy-preview-905--dev-astral.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Here are some key observations to aid the review process:
β±οΈ Estimated effort to review: 2 π΅π΅βͺβͺβͺ |
π§ͺ No relevant tests |
π No security concerns identified |
β‘ Recommended focus areas for review Magic Number The constant `DEFAULT_CHAIN_HEAD_OFFSET` is introduced without explanation for its value (10). Consider adding documentation or comments explaining why this value is chosen. |
Explore these optional code suggestions:
Category | Suggestion | Score |
Possible bug |
Prevent negative values in block height calculations by ensuring sufficient target height___ **Add a check to ensuretargetHeight is greater than DEFAULT_CHAIN_HEAD_OFFSET before subtracting to avoid potential negative values in block height calculations.** [indexers/taurus/consensus/src/mappings/helper.ts [88]](https://github.com/autonomys/astral/pull/905/files#diff-f0ffacaa27f2236bc750ead02caf99cd374df87d2a9102a7250742856250fb02R88-R88) ```diff -if (indexingBlockHeight > BigInt(targetHeight - DEFAULT_CHAIN_HEAD_OFFSET)) +if (targetHeight <= DEFAULT_CHAIN_HEAD_OFFSET) throw new Error("Target height must be greater than chain head offset"); ``` Suggestion importance[1-10]: 8Why: Adding a check to ensure 'targetHeight' is greater than 'DEFAULT_CHAIN_HEAD_OFFSET' is critical to avoid negative values in block height calculations, which could lead to runtime errors or incorrect behavior. | 8 |
Possible issue |
Ensure the chain head offset is a positive integer to avoid calculation errors___ **Consider validatingDEFAULT_CHAIN_HEAD_OFFSET to ensure it is a positive integer to prevent logical errors in chain head offset calculations.** [indexers/taurus/consensus/src/mappings/helper.ts [8]](https://github.com/autonomys/astral/pull/905/files#diff-f0ffacaa27f2236bc750ead02caf99cd374df87d2a9102a7250742856250fb02R8-R8) ```diff -const DEFAULT_CHAIN_HEAD_OFFSET = 10; +if (DEFAULT_CHAIN_HEAD_OFFSET <= 0) throw new Error("Chain head offset must be a positive integer"); ``` Suggestion importance[1-10]: 7Why: Validating the 'DEFAULT_CHAIN_HEAD_OFFSET' as a positive integer is crucial to avoid logical errors in subsequent calculations. This suggestion enhances the robustness of the code by preventing invalid configurations. | 7 |
Enhancement |
Add logging to provide context before throwing errors for easier debugging___ **Consider adding logging before throwing errors to aid in debugging and provide morecontext about the error conditions.** [indexers/taurus/consensus/src/mappings/helper.ts [89]](https://github.com/autonomys/astral/pull/905/files#diff-f0ffacaa27f2236bc750ead02caf99cd374df87d2a9102a7250742856250fb02R89-R89) ```diff +console.error(`Indexing block height: ${indexingBlockHeight}, Target height: ${targetHeight}, Offset: ${DEFAULT_CHAIN_HEAD_OFFSET}`); throw new Error("Indexing too close to the head of the chain, skipping..."); ``` Suggestion importance[1-10]: 5Why: Adding logging before error throwing can significantly aid in debugging by providing more context about the error conditions. This is a useful enhancement, though not as critical as preventing errors or incorrect calculations. | 5 |
User description
Improve chain offset logic
ENV are not directly available inside the handler
PR Type
enhancement
Description
DEFAULT_CHAIN_HEAD_OFFSET
set to 10 for better maintainability.DEFAULT_CHAIN_HEAD_OFFSET
in the functionpreventIndexingTooCloseToTheHeadOfTheChain
.Changes walkthrough π
helper.ts
Refactor chain offset logic to use a constant
indexers/taurus/consensus/src/mappings/helper.ts
DEFAULT_CHAIN_HEAD_OFFSET
with a value of10.
DEFAULT_CHAIN_HEAD_OFFSET
inthe logic.