From 02a5e036fcf6e570a8146d06294cc8cd411f71d3 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 8 Jan 2020 13:03:55 +0300 Subject: [PATCH] vm: deduplicate checkMultisigPar Make its logic more clear. --- pkg/vm/vm.go | 60 +++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 9fffc4e15..88bb74b0a 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -1467,46 +1467,44 @@ func checkMultisigPar(v *VM, pkeys [][]byte, sigs [][]byte) bool { loop: for r := range results { + goingForward := true + taskCount-- - if r.signum == s1 { - if k1+1 == k2 { - sigok = r.ok && s1+1 == s2 - if taskCount != 0 && sigok { - continue - } - break loop - } else if r.ok { - if s1+1 == s2 { - if taskCount != 0 && sigok { - continue - } - break loop - } - s1++ + if r.signum == s2 { + goingForward = false + } + if k1+1 == k2 { + sigok = r.ok && s1+1 == s2 + if taskCount != 0 && sigok { + continue } - k1++ - taskCount++ - tasks <- task{pub: v.bytesToPublicKey(pkeys[k1]), signum: s1} - } else { - if k1+1 == k2 { - sigok = r.ok && s1+1 == s2 + break loop + } else if r.ok { + if s1+1 == s2 { if taskCount != 0 && sigok { continue } break loop - } else if r.ok { - if s1+1 == s2 { - if taskCount != 0 && sigok { - continue - } - break loop - } + } + if goingForward { + s1++ + } else { s2-- } - k2-- - taskCount++ - tasks <- task{pub: v.bytesToPublicKey(pkeys[k2]), signum: s2} } + + var nextSig, nextKey int + if goingForward { + k1++ + nextSig = s1 + nextKey = k1 + } else { + k2-- + nextSig = s2 + nextKey = k2 + } + taskCount++ + tasks <- task{pub: v.bytesToPublicKey(pkeys[nextKey]), signum: nextSig} } close(tasks)