Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staking/state: fix DelegationsFor queries #2756

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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