-
Notifications
You must be signed in to change notification settings - Fork 198
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
fix: add timeout height option to pk broadcaster #534
base: dev
Are you sure you want to change the base?
Conversation
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
packages/sdk-ts/src/core/tx/broadcaster/MsgBroadcasterWithPk.tsOops! Something went wrong! :( ESLint: 7.32.0 ESLint couldn't find the config "./../../eslintrc.js" to extend from. Please check that the name of the config is correct. The config "./../../eslintrc.js" was referenced from the config file in "/packages/sdk-ts/.eslintrc.js". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. WalkthroughThe changes introduce a new configuration option Changes
Sequence DiagramsequenceDiagram
participant Client
participant MsgBroadcasterWithPk
participant ChainGrpcTendermintApi
participant TransactionApi
Client->>MsgBroadcasterWithPk: Initialize with txTimeoutOnFeeDelegation=true
MsgBroadcasterWithPk->>ChainGrpcTendermintApi: Fetch latest block height
ChainGrpcTendermintApi-->>MsgBroadcasterWithPk: Return block height
MsgBroadcasterWithPk->>MsgBroadcasterWithPk: Calculate timeout height
MsgBroadcasterWithPk->>TransactionApi: Prepare tx with timeout height
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
43bd4c5
to
1430d84
Compare
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/sdk-ts/src/core/tx/broadcaster/MsgBroadcasterWithPk.ts (1)
87-88
: Consider making the property readonly.The property is correctly initialized with a safe default of
false
, but being public allows modification after initialization which could lead to inconsistent behavior. Consider making it readonly to ensure immutability after construction.- public txTimeoutOnFeeDelegation: boolean = false + public readonly txTimeoutOnFeeDelegation: boolean = false
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/sdk-ts/src/core/tx/broadcaster/MsgBroadcasterWithPk.ts
(7 hunks)
🔇 Additional comments (4)
packages/sdk-ts/src/core/tx/broadcaster/MsgBroadcasterWithPk.ts (4)
65-65
: LGTM! Well-typed interface addition.The new option
txTimeoutOnFeeDelegation
is properly typed as an optional boolean in the interface.
112-113
: LGTM! Proper initialization with fallback.The constructor correctly initializes the new option with a fallback to the instance default.
433-433
: LGTM! Improved code readability.The simplified return statement improves readability while maintaining the same functionality.
Line range hint
4-4
: Add unit tests for the new timeout height feature.Please add unit tests to verify:
- The timeout height calculation with fee delegation when enabled
- No timeout height is set when the feature is disabled
- Error handling when block height fetch fails
Would you like me to help generate the unit test cases?
if (txTimeoutOnFeeDelegation) { | ||
const latestBlock = await new ChainGrpcTendermintApi( | ||
endpoints.grpc, | ||
).fetchLatestBlock() | ||
const latestHeight = latestBlock!.header!.height | ||
|
||
timeoutHeight = new BigNumberInBase(latestHeight) | ||
.plus(txTimeout) | ||
.toNumber() | ||
} |
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
Add null checks for latestBlock response.
The code assumes latestBlock
and header
are non-null through the use of the non-null assertion operator (!
). Consider adding explicit null checks to handle potential API failures gracefully.
- const latestBlock = await new ChainGrpcTendermintApi(
- endpoints.grpc,
- ).fetchLatestBlock()
- const latestHeight = latestBlock!.header!.height
+ const latestBlock = await new ChainGrpcTendermintApi(
+ endpoints.grpc,
+ ).fetchLatestBlock()
+ if (!latestBlock?.header?.height) {
+ throw new GeneralException(
+ new Error('Failed to fetch latest block height'),
+ )
+ }
+ const latestHeight = latestBlock.header.height
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (txTimeoutOnFeeDelegation) { | |
const latestBlock = await new ChainGrpcTendermintApi( | |
endpoints.grpc, | |
).fetchLatestBlock() | |
const latestHeight = latestBlock!.header!.height | |
timeoutHeight = new BigNumberInBase(latestHeight) | |
.plus(txTimeout) | |
.toNumber() | |
} | |
if (txTimeoutOnFeeDelegation) { | |
const latestBlock = await new ChainGrpcTendermintApi( | |
endpoints.grpc, | |
).fetchLatestBlock() | |
if (!latestBlock?.header?.height) { | |
throw new GeneralException( | |
new Error('Failed to fetch latest block height'), | |
) | |
} | |
const latestHeight = latestBlock.header.height | |
timeoutHeight = new BigNumberInBase(latestHeight) | |
.plus(txTimeout) | |
.toNumber() | |
} |
Summary by CodeRabbit
New Features
Improvements