-
Notifications
You must be signed in to change notification settings - Fork 237
fix: prevent bank balances query failure due to dispatch FA #411
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
Conversation
📝 WalkthroughWalkthroughThe changes update balance retrieval and iteration methods in Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🔇 Additional comments (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 (
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
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)
x/move/keeper/bank.go (1)
212-213
: Inconsistent error handling approach.The comment suggests ignoring errors, but the method still returns the error. This creates inconsistency with the
GetBalance
method which now suppresses errors.Clarify the error handling intention:
if err != nil { - // ignore error from execute - return nil, nil, err + // Return error from execute - caller should handle appropriately + return nil, nil, err }Or if errors should truly be ignored, implement consistent suppression:
if err != nil { - // ignore error from execute - return nil, nil, err + // ignore error from execute due to dispatchable fungible assets + return nil, nil, nil }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
x/move/keeper/bank.go
(4 hunks)
🔇 Additional comments (2)
x/move/keeper/bank.go (2)
102-133
:✅ Verification successful
Verify the new store walking approach for correctness and performance.
The method has been completely rewritten to use
VMStore.Walk
instead of manual iteration. While this change aligns with the PR objective of individual balance queries, there are several concerns:
- Performance: Each iteration now calls
GetBalance
individually, which executes a separate VM function call- Error handling: Errors are propagated immediately, which could cause iteration to stop early
- Logic verification: Need to ensure the prefix-based walking covers all relevant entries
Let me verify the store walking logic and compare performance characteristics:
Consider adding error recovery or logging for debugging:
return k.VMStore.Walk(ctx, new(collections.Range[[]byte]).Prefix(collections.NewPrefix(prefix)), func(_, value []byte) (stop bool, err error) { storeAddr, err := vmtypes.NewAccountAddressFromBytes(value) if err != nil { + // Log parsing error but continue iteration + k.Logger(ctx).Debug("failed to parse store address", "error", err, "value", fmt.Sprintf("%x", value)) - return true, err + return false, nil }
🏁 Script executed:
#!/bin/bash # Search for other usages of VMStore.Walk to understand the pattern rg -A 15 "VMStore\.Walk" --type go # Look for the old implementation pattern to understand what was replaced rg -A 20 -B 5 "IterateAccountBalances" --type goLength of output: 15579
IterateAccountBalances store-walk usage is sound
- Prefix-based scanning (
types.GetTableEntryPrefix
) is consistent with all otherVMStore.Walk
calls and will cover every table entry.- Immediate error propagation matches the existing pattern in
staking.go
andkeeper.go
; silent error recovery isn’t used elsewhere.- Invoking
GetBalance
per entry incurs one VM call per denomination by design—if this per-balance granularity becomes a bottleneck, consider adding a batched query or caching layer in a follow-up.No changes required.
69-70
:❓ Verification inconclusive
Critical concern: Error suppression may mask legitimate issues.
While ignoring errors from dispatchable fungible assets addresses the immediate dispatch FA failure issue, returning zero balance for all errors could mask legitimate system failures like network issues, VM execution problems, or data corruption.
Consider implementing more granular error handling:
if err != nil { - // ignore fetching error due to dispatchable fungible assets - return sdkmath.ZeroInt(), nil + // Check if error is specifically related to dispatchable fungible assets + if isDispatchFAError(err) { + return sdkmath.ZeroInt(), nil + } + return sdkmath.ZeroInt(), err }Let me verify what types of errors the ExecuteViewFunctionJSON can return to determine if blanket suppression is appropriate:
🏁 Script executed:
#!/bin/bash # Search for error types returned by ExecuteViewFunctionJSON and related dispatch FA error patterns rg -A 10 -B 5 "ExecuteViewFunctionJSON.*error|dispatch.*fungible.*asset.*error" --type goLength of output: 91
🏁 Script executed:
#!/bin/bash # 1. Locate all usages of ExecuteViewFunctionJSON in the repo rg -n "ExecuteViewFunctionJSON" --type go # 2. If any are found, show surrounding context (±5 lines) for each match rg -n -A 5 -B 5 "ExecuteViewFunctionJSON" --type goLength of output: 3578
🏁 Script executed:
#!/bin/bash # Display the implementation of ExecuteViewFunctionJSON in handler.go sed -n '530,600p' x/move/keeper/handler.goLength of output: 1519
Refine error suppression to target only dispatchable FA errors
Blanket‐suppressing all errors and returning a zero balance may conceal genuine failures (e.g. payload build errors, VM aborts, gas or state issues). Instead, detect and ignore only the specific “dispatchable fungible asset” error, propagating all others:
func (k MoveBankKeeper) GetBalance(… ) (sdkmath.Int, error) { - // ignore fetching error due to dispatchable fungible assets - return sdkmath.ZeroInt(), nil + // only suppress dispatchable FA errors + if isDispatchFAError(err) { + return sdkmath.ZeroInt(), nil + } + // propagate any other errors + return sdkmath.ZeroInt(), err }• File: x/move/keeper/bank.go (around lines 69–70)
• Action:
- Determine which errors
ExecuteViewFunctionJSON
can return (payload, VM, gas, etc.).- Implement
isDispatchFAError(err)
to match only the FA‐dispatch error.- Ensure all other errors bubble up for proper visibility and handling.
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
♻️ Duplicate comments (1)
x/move/keeper/bank.go (1)
153-195
: Address pagination logic issues identified in previous review.The current implementation still has the same issues flagged in the previous review:
Variable scope issue: The
coin
variable (line 153) is declared outside the pagination callback and reused, which can cause incorrect data if multiple items are processed.Error handling inconsistency: Mixed return values with some errors returning
true
(lines 163, 171, 177) and others returningfalse
(line 157, 180).Apply the fix suggested in the previous review to resolve variable scope and error handling issues:
-var coin sdk.Coin coins, pageRes, err := query.CollectionFilteredPaginate(ctx, k.VMStore, pageReq, func(_, value []byte) (bool, error) { storeAddr, err := vmtypes.NewAccountAddressFromBytes(value) if err != nil { return false, err } // load metadata from fungible store metadata, _, err := k.Balance(ctx, storeAddr) if err != nil { - return true, err + return false, err } // load denom from metadata denom, err := types.DenomFromMetadataAddress( ctx, k, metadata, ) if err != nil { - return true, err + return false, err } // load balance from primary fungible store amount, err := k.GetBalance(ctx, addr, denom) if err != nil { - return true, err + return false, err } if !amount.IsPositive() { return false, nil } - coin = sdk.NewCoin(denom, amount) return true, nil }, func(_, value []byte) (sdk.Coin, error) { - return coin, nil + // Reconstruct coin in transform callback to avoid scope issues + storeAddr, err := vmtypes.NewAccountAddressFromBytes(value) + if err != nil { + return sdk.Coin{}, err + } + + metadata, _, err := k.Balance(ctx, storeAddr) + if err != nil { + return sdk.Coin{}, err + } + + denom, err := types.DenomFromMetadataAddress(ctx, k, metadata) + if err != nil { + return sdk.Coin{}, err + } + + amount, err := k.GetBalance(ctx, addr, denom) + if err != nil { + return sdk.Coin{}, err + } + + return sdk.NewCoin(denom, amount), nil }, func(o *query.CollectionsPaginateOptions[[]byte]) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
x/move/keeper/bank.go
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Run test and upload codecov
- GitHub Check: golangci-lint
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (actions)
🔇 Additional comments (1)
x/move/keeper/bank.go (1)
69-70
: LGTM: Error handling change aligns with PR objectives.The relaxed error handling to return zero balance when fetching fails addresses the PR objective of preventing bank balance query failures due to dispatch FA issues. This is a sensible approach for maintaining system stability.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #411 +/- ##
==========================================
- Coverage 40.33% 40.26% -0.07%
==========================================
Files 296 296
Lines 27879 27815 -64
==========================================
- Hits 11246 11201 -45
+ Misses 14897 14885 -12
+ Partials 1736 1729 -7
🚀 New features to boost your workflow:
|
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.
lgtm
Description
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...