Skip to content

Commit

Permalink
Merge pull request #2756 from oasislabs/ptrus/fix/delegations-query-fix
Browse files Browse the repository at this point in the history
staking/state: fix DelegationsFor queries
  • Loading branch information
ptrus authored Mar 10, 2020
2 parents a7a65d7 + fe7cbfa commit f3dec8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .changelog/2756.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 f3dec8e

Please sign in to comment.