diff --git a/.changelog/2752.bugfix.md b/.changelog/2752.bugfix.md new file mode 100644 index 00000000000..0b3d289845a --- /dev/null +++ b/.changelog/2752.bugfix.md @@ -0,0 +1,4 @@ +staking/state: fix DelegationsFor queries + +DelegationFor and DebondingDelegationsFor would stop traversing the state to +soon in some cases. diff --git a/go/consensus/tendermint/apps/staking/state/state.go b/go/consensus/tendermint/apps/staking/state/state.go index c860d636c99..cd927e9b432 100644 --- a/go/consensus/tendermint/apps/staking/state/state.go +++ b/go/consensus/tendermint/apps/staking/state/state.go @@ -246,9 +246,13 @@ func (s *ImmutableState) DelegationsFor(delegatorID signature.PublicKey) (map[si func(key, value []byte) bool { var escrowID signature.PublicKey var decDelegatorID signature.PublicKey - if !delegationKeyFmt.Decode(key, &escrowID, &decDelegatorID) || !decDelegatorID.Equal(delegatorID) { + if !delegationKeyFmt.Decode(key, &escrowID, &decDelegatorID) { return true } + // TODO: add unit test for DelegationsFor. + if !decDelegatorID.Equal(delegatorID) { + return false + } var del staking.Delegation if err := cbor.Unmarshal(value, &del); err != nil { @@ -303,9 +307,13 @@ func (s *ImmutableState) DebondingDelegationsFor(delegatorID signature.PublicKey func(key, value []byte) bool { var escrowID signature.PublicKey var decDelegatorID signature.PublicKey - if !debondingDelegationKeyFmt.Decode(key, &decDelegatorID, &escrowID) || !decDelegatorID.Equal(delegatorID) { + if !debondingDelegationKeyFmt.Decode(key, &decDelegatorID, &escrowID) { return true } + // TODO: add unit test for DebondingDelegationsFor. + if !decDelegatorID.Equal(delegatorID) { + return false + } var deb staking.DebondingDelegation if err := cbor.Unmarshal(value, &deb); err != nil {