Handle Pending Balance Bug (#15123)

* Fix Getter and Add regression test

* changelog
This commit is contained in:
Nishant Das
2025-04-04 12:00:07 +08:00
committed by GitHub
parent 4a1c627f6f
commit efba931610
3 changed files with 13 additions and 1 deletions

View File

@@ -486,7 +486,7 @@ func (b *BeaconState) HasPendingBalanceToWithdraw(idx primitives.ValidatorIndex)
// MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD per slot. A more optimized storage indexing such as a
// lookup map could be used to reduce the complexity marginally.
for _, w := range b.pendingPartialWithdrawals {
if w.Index == idx {
if w.Index == idx && w.Amount > 0 {
return true, nil
}
}

View File

@@ -121,6 +121,10 @@ func TestHasPendingBalanceToWithdraw(t *testing.T) {
Amount: 300,
Index: 3,
},
{
Amount: 0,
Index: 4,
},
},
}
state, err := statenative.InitializeFromProtoUnsafeElectra(pb)
@@ -133,4 +137,9 @@ func TestHasPendingBalanceToWithdraw(t *testing.T) {
ok, err = state.HasPendingBalanceToWithdraw(5)
require.NoError(t, err)
require.Equal(t, false, ok)
// Handle 0 amount case.
ok, err = state.HasPendingBalanceToWithdraw(4)
require.NoError(t, err)
require.Equal(t, false, ok)
}

View File

@@ -0,0 +1,3 @@
### Fixed
- Fix State Getter for pending withdrawal balance.