From de7dbf2a4c2281f87d7500ae52a0ab28bfc73aaf Mon Sep 17 00:00:00 2001 From: Poseidon Date: Thu, 6 Feb 2020 18:39:34 +0800 Subject: [PATCH] fix match collector (#481) * fix match collector * add comment --- application/mov/match_collector.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/application/mov/match_collector.go b/application/mov/match_collector.go index 033194e3..21cd6628 100644 --- a/application/mov/match_collector.go +++ b/application/mov/match_collector.go @@ -63,6 +63,15 @@ func (m *matchCollector) collect() ([]*types.Tx, error) { defer close(m.closeCh) var matchedTxs []*types.Tx + appendMatchedTxs := func(data *matchTxResult) bool { + gasUsed := calcMatchedTxGasUsed(data.matchedTx) + if m.gasLeft -= gasUsed; m.gasLeft >= 0 { + matchedTxs = append(matchedTxs, data.matchedTx) + return false + } + return true + } + completed := 0 for !m.isTimeout() { select { @@ -71,14 +80,20 @@ func (m *matchCollector) collect() ([]*types.Tx, error) { return nil, data.err } - gasUsed := calcMatchedTxGasUsed(data.matchedTx) - if m.gasLeft -= gasUsed; m.gasLeft >= 0 { - matchedTxs = append(matchedTxs, data.matchedTx) - } else { + if done := appendMatchedTxs(data); done { return matchedTxs, nil } case <-m.workerNumCh: if completed++; completed == m.workerNum { + // read the remaining process results + close(m.processCh) + for data := range m.processCh { + if data.err != nil { + return nil, data.err + } + + appendMatchedTxs(data) + } return matchedTxs, nil } } -- 2.11.0