cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

WithdrawDelegationRewards is complex and error prone

Open rootulp opened this issue 4 months ago • 1 comments

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

  1. Audit this code
  2. Refactor so that it isn't extremely indented and is readable
  3. Add more unit test coverage to increase confidence

cc: @julienrbrt @tac0turtle

rootulp avatar Aug 28 '25 17:08 rootulp

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.

rootulp avatar Aug 28 '25 18:08 rootulp