-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix: fix Group-TotalWeight invariant #13116
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,8 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g | |
} | ||
defer groupIt.Close() | ||
|
||
groups := make(map[uint64]group.GroupInfo) | ||
for { | ||
membersWeight, err := groupmath.NewNonNegativeDecFromString("0") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this line failing under some conditions? I'm not understanding how the behavior of parsing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has nothing to do with the fix/changes. The change was to not have nested iterators which a violation of how iterators should be used. |
||
if err != nil { | ||
msg += fmt.Sprintf("error while parsing positive dec zero for group member\n%v\n", err) | ||
return msg, broken | ||
} | ||
var groupInfo group.GroupInfo | ||
_, err = groupIt.LoadNext(&groupInfo) | ||
if errors.ErrORMIteratorDone.Is(err) { | ||
|
@@ -54,6 +50,16 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g | |
return msg, broken | ||
} | ||
|
||
groups[groupInfo.Id] = groupInfo | ||
} | ||
|
||
for _, groupInfo := range groups { | ||
membersWeight, err := groupmath.NewNonNegativeDecFromString("0") | ||
if err != nil { | ||
msg += fmt.Sprintf("error while parsing positive dec zero for group member\n%v\n", err) | ||
return msg, broken | ||
} | ||
|
||
memIt, err := groupMemberByGroupIndex.Get(ctx.KVStore(key), groupInfo.Id) | ||
if err != nil { | ||
msg += fmt.Sprintf("error while returning group member iterator for group with ID %d\n%v\n", groupInfo.Id, err) | ||
|
@@ -77,6 +83,7 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g | |
msg += fmt.Sprintf("error while parsing non-nengative decimal for group member %s\n%v\n", groupMember.Member.Address, err) | ||
return msg, broken | ||
} | ||
|
||
membersWeight, err = groupmath.Add(membersWeight, curMemWeight) | ||
if err != nil { | ||
msg += fmt.Sprintf("decimal addition error while adding group member voting weight to total voting weight\n%v\n", err) | ||
|
@@ -96,5 +103,6 @@ func GroupTotalWeightInvariantHelper(ctx sdk.Context, key storetypes.StoreKey, g | |
break | ||
} | ||
} | ||
|
||
return msg, broken | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the line that fixes the bug? the added
panic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The fix is breaking up the nested for loops into 2 separate single for loops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a patch while I was debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a consensus-breaking change?