chore: Enhance error handling for staking operations in LiquidStaking#4811
chore: Enhance error handling for staking operations in LiquidStaking#4811sergei-boiko-trustwallet wants to merge 4 commits into
Conversation
Summary by OctaneNew ContractsNo new contracts were added. Updated Contracts
🔗 Commit Hash: 034371b |
There was a problem hiding this comment.
Pull request overview
This PR improves robustness in the LiquidStaking EVM builders by having the internal Strader/Lido action handlers report detailed failures (instead of silently producing incomplete transaction data) and propagating “operation not supported” errors into the Proto::Output status. It also adds a regression test to ensure unsupported Strader operations on BNB_BSC correctly return an error.
Changes:
- Updated
handleStake,handleUnstake, andhandleWithdrawto returnResult<void>and detect unsupported protocol/action combinations. - Updated
buildStraderEVMandbuildLidoEVMto check handler results and populateoutput.statuson failure. - Added a test for Strader withdraw on BNB_BSC returning
ERROR_OPERATION_NOT_SUPPORTED_BY_PROTOCOL.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/LiquidStaking/LiquidStaking.cpp | Introduces Result<void>-based handler error propagation and updates builders to surface unsupported-operation failures. |
| tests/common/LiquidStaking/LiquidStakingTests.cpp | Adds a new test asserting an error for unsupported Strader withdraw on BNB_BSC. |
Comments suppressed due to low confidence (1)
src/LiquidStaking/LiquidStaking.cpp:258
- In
buildLidoEVM, the non-stake action path sets an error status but still falls through tosetTransferDataAndAmount(transfer, payload, amount). In that branchamountis uninitialized, and even if it were initialized the function should not build a transaction after marking the output as an error.
} else {
*output.mutable_status() = generateError(Proto::ERROR_OPERATION_NOT_SUPPORTED_BY_PROTOCOL, "Lido protocol only support stake action for now");
}
internal::setTransferDataAndAmount(transfer, payload, amount);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Binary size comparison➡️ aarch64-apple-ios: 14.31 MB ➡️ aarch64-apple-ios-sim: 14.32 MB ➡️ aarch64-linux-android: 18.73 MB ➡️ armv7-linux-androideabi: 16.17 MB ➡️ wasm32-unknown-emscripten: 13.66 MB |
Overview
Warnings
|
This pull request enhances error handling and robustness in the liquid staking module by updating internal handler functions to return detailed error information, and propagating these errors to the output when operations are not supported. Additionally, a new test case is added to verify correct error reporting for unsupported operations.
Error handling improvements:
handleStake,handleUnstake, andhandleWithdrawfunctions inLiquidStaking.cppto return aResult<void>type, allowing them to signal specific errors when a protocol or operation is not supported, rather than failing silently.buildStraderEVMandbuildLidoEVMbuilder functions to check the result of handler calls and set the output status with an appropriate error code and message if an operation is not supported. [1] [2]Code quality and maintainability:
Result.hinLiquidStaking.cppto support the new error handling mechanism.Testing:
StraderBnbWithdrawErrorto verify that attempting to withdraw with the Strader protocol on BNB_BSC correctly returns an error status, ensuring the new error handling is functioning as intended.