Skip to content

Commit

Permalink
staking/state: fix DelegationsFor queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Mar 9, 2020
1 parent 6646ca4 commit f206a2d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .changelog/2752.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
staking/state: fix DelegationsFor queries

DelegationFor and DebondingDelegationsFor would stop traversing the state to
soon in some cases.
12 changes: 10 additions & 2 deletions go/consensus/tendermint/apps/staking/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f206a2d

Please sign in to comment.