forked from TrueCloudLab/frostfs-contract
[#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++ {
|
for i := 0; i < len(candidates); i++ {
|
||||||
cnd := candidates[i]
|
cnd := candidates[i]
|
||||||
|
|
||||||
|
if blockHeight-cnd.block > blockDiff {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if bytesEqual(cnd.id, id) {
|
if bytesEqual(cnd.id, id) {
|
||||||
voters := cnd.n
|
voters := cnd.n
|
||||||
|
|
||||||
|
@ -427,10 +432,7 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
found = len(voters)
|
found = len(voters)
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not add old ballots, they are invalid
|
newCandidates = append(newCandidates, cnd)
|
||||||
if blockHeight-cnd.block <= blockDiff {
|
|
||||||
newCandidates = append(newCandidates, cnd)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if found < 0 {
|
if found < 0 {
|
||||||
|
|
|
@ -502,6 +502,11 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
|
|
||||||
for i := 0; i < len(candidates); i++ {
|
for i := 0; i < len(candidates); i++ {
|
||||||
cnd := candidates[i]
|
cnd := candidates[i]
|
||||||
|
|
||||||
|
if blockHeight-cnd.block > blockDiff {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if bytesEqual(cnd.id, id) {
|
if bytesEqual(cnd.id, id) {
|
||||||
voters := cnd.n
|
voters := cnd.n
|
||||||
|
|
||||||
|
@ -516,10 +521,7 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
found = len(voters)
|
found = len(voters)
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not add old ballots, they are invalid
|
newCandidates = append(newCandidates, cnd)
|
||||||
if blockHeight-cnd.block <= blockDiff {
|
|
||||||
newCandidates = append(newCandidates, cnd)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if found < 0 {
|
if found < 0 {
|
||||||
|
|
|
@ -556,6 +556,11 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
|
|
||||||
for i := 0; i < len(candidates); i++ {
|
for i := 0; i < len(candidates); i++ {
|
||||||
cnd := candidates[i]
|
cnd := candidates[i]
|
||||||
|
|
||||||
|
if blockHeight-cnd.block > blockDiff {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if bytesEqual(cnd.id, id) {
|
if bytesEqual(cnd.id, id) {
|
||||||
voters := cnd.n
|
voters := cnd.n
|
||||||
|
|
||||||
|
@ -570,10 +575,7 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
found = len(voters)
|
found = len(voters)
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not add old ballots, they are invalid
|
newCandidates = append(newCandidates, cnd)
|
||||||
if blockHeight-cnd.block <= blockDiff {
|
|
||||||
newCandidates = append(newCandidates, cnd)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if found < 0 {
|
if found < 0 {
|
||||||
|
|
|
@ -231,6 +231,11 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
|
|
||||||
for i := 0; i < len(candidates); i++ {
|
for i := 0; i < len(candidates); i++ {
|
||||||
cnd := candidates[i]
|
cnd := candidates[i]
|
||||||
|
|
||||||
|
if blockHeight-cnd.block > blockDiff {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if bytesEqual(cnd.id, id) {
|
if bytesEqual(cnd.id, id) {
|
||||||
voters := cnd.n
|
voters := cnd.n
|
||||||
|
|
||||||
|
@ -245,10 +250,7 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
found = len(voters)
|
found = len(voters)
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not add old ballots, they are invalid
|
newCandidates = append(newCandidates, cnd)
|
||||||
if blockHeight-cnd.block <= blockDiff {
|
|
||||||
newCandidates = append(newCandidates, cnd)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if found < 0 {
|
if found < 0 {
|
||||||
|
|
|
@ -431,6 +431,11 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
|
|
||||||
for i := 0; i < len(candidates); i++ {
|
for i := 0; i < len(candidates); i++ {
|
||||||
cnd := candidates[i]
|
cnd := candidates[i]
|
||||||
|
|
||||||
|
if blockHeight-cnd.block > blockDiff {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if bytesEqual(cnd.id, id) {
|
if bytesEqual(cnd.id, id) {
|
||||||
voters := cnd.n
|
voters := cnd.n
|
||||||
|
|
||||||
|
@ -445,10 +450,7 @@ func vote(ctx storage.Context, id, from []byte) int {
|
||||||
found = len(voters)
|
found = len(voters)
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not add old ballots, they are invalid
|
newCandidates = append(newCandidates, cnd)
|
||||||
if blockHeight-cnd.block <= blockDiff {
|
|
||||||
newCandidates = append(newCandidates, cnd)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if found < 0 {
|
if found < 0 {
|
||||||
|
|
Loading…
Reference in a new issue