client-lib: fee support in RedeemNote#935
client-lib: fee support in RedeemNote#935louisinger wants to merge 2 commits intoarkade-os:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughRedeemNotes now initializes a fee estimator from account info, computes and validates per-note input fees (rejecting notes where fees >= note value), aggregates adjusted note amounts, resolves offchain addresses, computes output fees for the transfer, and subtracts output fees from the receiver amount before forming final receivers. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant RedeemNotes
participant FeeEstimator
participant OffchainResolver
participant ReceiverCreator
Caller->>RedeemNotes: request redeem(notes)
RedeemNotes->>FeeEstimator: init from account info
loop per note
RedeemNotes->>FeeEstimator: estimate input fee(note)
FeeEstimator-->>RedeemNotes: input fee
RedeemNotes->>RedeemNotes: validate fee < note.value, adjust amount
end
RedeemNotes->>OffchainResolver: fetch offchain address(es)
OffchainResolver-->>RedeemNotes: address(es)
RedeemNotes->>FeeEstimator: estimate output fee(total amount)
FeeEstimator-->>RedeemNotes: output fee
RedeemNotes->>ReceiverCreator: create receiver(amount - output fee, address)
ReceiverCreator-->>Caller: return receivers
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/client-lib/batch_session.go`:
- Around line 137-142: The check that validates fees vs amount should reject
cases where outputFeesSats is equal to amount as well as greater; update the
conditional in the function that contains the receiver/fees logic (the block
that currently returns "fees (%d) exceed amount (%d)") to use >= instead of > so
it returns an error for fee-equals-amount, preventing receiver.Amount from being
set to zero and avoiding creation of receiversOutput with a zero-valued
receiver.
- Line 116: Guard the uint64 accumulation to prevent silent wrap: in the loop
where amount is incremented using "amount += noteValue - feesSats", first ensure
noteValue >= feesSats (avoid underflow), compute delta := noteValue - feesSats,
then check overflow before adding (e.g., if amount > math.MaxUint64 - delta) and
return an error if it would overflow; update the code paths that use "amount",
"noteValue", and "feesSats" to handle and propagate this error instead of
allowing wrapping.
related to arkade-os/go-sdk#98
@altafan please review
Summary by CodeRabbit