From e87765b733d90d7a4616031cf3729058e77686ae Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 2 Feb 2021 18:16:23 +0300 Subject: [PATCH] [#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 --- balance/balance_contract.go | 10 ++++++---- container/container_contract.go | 10 ++++++---- neofs/neofs_contract.go | 10 ++++++---- neofsid/neofsid_contract.go | 10 ++++++---- netmap/netmap_contract.go | 10 ++++++---- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/balance/balance_contract.go b/balance/balance_contract.go index 1a6d05e..a5cdad2 100644 --- a/balance/balance_contract.go +++ b/balance/balance_contract.go @@ -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 { diff --git a/container/container_contract.go b/container/container_contract.go index adfdb83..b684f6b 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -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 { diff --git a/neofs/neofs_contract.go b/neofs/neofs_contract.go index a6851df..223f4ad 100644 --- a/neofs/neofs_contract.go +++ b/neofs/neofs_contract.go @@ -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 { diff --git a/neofsid/neofsid_contract.go b/neofsid/neofsid_contract.go index 4708271..ce44de6 100644 --- a/neofsid/neofsid_contract.go +++ b/neofsid/neofsid_contract.go @@ -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 { diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index bd29daf..5cc9b21 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -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 {