cosmos-sdk
cosmos-sdk copied to clipboard
WithdrawDelegationRewards is complex and error prone
Context
https://github.com/celestiaorg/cosmos-sdk/blob/5dc3751cfca46c257d7aa480b4bcf8fbc490225a/x/distribution/keeper/keeper.go#L120-L210
Problem
It's extremely difficult to understand what's happening here. The implementation of CIP-30 + CIP-31 seems extremely complex and I'm concerned there are bugs here (besides https://github.com/celestiaorg/celestia-app/issues/5381)
Proposal
- Audit this code
- Refactor so that it isn't extremely indented and is readable
- Add more unit test coverage to increase confidence
cc: @julienrbrt @tac0turtle
I don't understand why outstanding rewards are only fetched if this line evaluates to true:
if err != nil || del == nil {
IMO this code needs a refactor. Outstanding rewards should always be fetched and claimed.