[#44] Fix processing order in voting

Remove old ballots first so there won't be any
interference with votes of the same tx in the
future after `blockDiff` blocks.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-02-02 18:16:23 +03:00 committed by Alex Vanin
parent b1063e66b9
commit e87765b733
5 changed files with 30 additions and 20 deletions

View file

@ -413,6 +413,11 @@ func vote(ctx storage.Context, id, from []byte) int {
for i := 0; i < len(candidates); i++ {
cnd := candidates[i]
if blockHeight-cnd.block > blockDiff {
continue
}
if bytesEqual(cnd.id, id) {
voters := cnd.n
@ -427,10 +432,7 @@ func vote(ctx storage.Context, id, from []byte) int {
found = len(voters)
}
// do not add old ballots, they are invalid
if blockHeight-cnd.block <= blockDiff {
newCandidates = append(newCandidates, cnd)
}
newCandidates = append(newCandidates, cnd)
}
if found < 0 {

View file

@ -502,6 +502,11 @@ func vote(ctx storage.Context, id, from []byte) int {
for i := 0; i < len(candidates); i++ {
cnd := candidates[i]
if blockHeight-cnd.block > blockDiff {
continue
}
if bytesEqual(cnd.id, id) {
voters := cnd.n
@ -516,10 +521,7 @@ func vote(ctx storage.Context, id, from []byte) int {
found = len(voters)
}
// do not add old ballots, they are invalid
if blockHeight-cnd.block <= blockDiff {
newCandidates = append(newCandidates, cnd)
}
newCandidates = append(newCandidates, cnd)
}
if found < 0 {

View file

@ -556,6 +556,11 @@ func vote(ctx storage.Context, id, from []byte) int {
for i := 0; i < len(candidates); i++ {
cnd := candidates[i]
if blockHeight-cnd.block > blockDiff {
continue
}
if bytesEqual(cnd.id, id) {
voters := cnd.n
@ -570,10 +575,7 @@ func vote(ctx storage.Context, id, from []byte) int {
found = len(voters)
}
// do not add old ballots, they are invalid
if blockHeight-cnd.block <= blockDiff {
newCandidates = append(newCandidates, cnd)
}
newCandidates = append(newCandidates, cnd)
}
if found < 0 {

View file

@ -231,6 +231,11 @@ func vote(ctx storage.Context, id, from []byte) int {
for i := 0; i < len(candidates); i++ {
cnd := candidates[i]
if blockHeight-cnd.block > blockDiff {
continue
}
if bytesEqual(cnd.id, id) {
voters := cnd.n
@ -245,10 +250,7 @@ func vote(ctx storage.Context, id, from []byte) int {
found = len(voters)
}
// do not add old ballots, they are invalid
if blockHeight-cnd.block <= blockDiff {
newCandidates = append(newCandidates, cnd)
}
newCandidates = append(newCandidates, cnd)
}
if found < 0 {

View file

@ -431,6 +431,11 @@ func vote(ctx storage.Context, id, from []byte) int {
for i := 0; i < len(candidates); i++ {
cnd := candidates[i]
if blockHeight-cnd.block > blockDiff {
continue
}
if bytesEqual(cnd.id, id) {
voters := cnd.n
@ -445,10 +450,7 @@ func vote(ctx storage.Context, id, from []byte) int {
found = len(voters)
}
// do not add old ballots, they are invalid
if blockHeight-cnd.block <= blockDiff {
newCandidates = append(newCandidates, cnd)
}
newCandidates = append(newCandidates, cnd)
}
if found < 0 {