[#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:
parent
b1063e66b9
commit
e87765b733
5 changed files with 30 additions and 20 deletions
|
@ -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,11 +432,8 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
if found < 0 {
|
||||
voters := [][]byte{from}
|
||||
|
|
|
@ -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,11 +521,8 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
if found < 0 {
|
||||
voters := [][]byte{from}
|
||||
|
|
|
@ -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,11 +575,8 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
if found < 0 {
|
||||
found = 1
|
||||
|
|
|
@ -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,11 +250,8 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
if found < 0 {
|
||||
voters := [][]byte{from}
|
||||
|
|
|
@ -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,11 +450,8 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
if found < 0 {
|
||||
voters := [][]byte{from}
|
||||
|
|
Loading…
Reference in a new issue