@@ -44,7 +44,7 @@ type confirmer struct {
44
44
// NewConfirmer returns a Confirmer that submits Computations to the
45
45
// Orderbook for confirmation. It polls the Orderbook on an interval
46
46
// and checks for consensus on confirmations by waiting until a submitted
47
- // Computation has been confirmed has the confirmation has passed the block
47
+ // Computation has been confirmed and the confirmation has passed the block
48
48
// depth limit.
49
49
func NewConfirmer (computationStore ComputationStorer , fragmentStore OrderFragmentStorer , contract ContractBinder , orderbookPollInterval time.Duration , orderbookBlockDepth uint ) Confirmer {
50
50
return & confirmer {
@@ -84,35 +84,35 @@ func (confirmer *confirmer) Confirm(done <-chan struct{}, coms <-chan Computatio
84
84
return
85
85
}
86
86
87
- go func () {
88
-
89
- // Wait for the confirmation of these orders to pass the depth
90
- // limit
87
+ // Wait for the confirmation of these orders to pass the depth
88
+ // limit
89
+ func (com Computation ) {
91
90
confirmer .confirmingMu .Lock ()
91
+ defer confirmer .confirmingMu .Unlock ()
92
+
92
93
// Check that these orders have not already been confirmed
93
94
if _ , ok := confirmer .confirmed [com .Buy .OrderID ]; ok {
94
- confirmer .confirmingMu .Unlock ()
95
95
return
96
96
}
97
97
if _ , ok := confirmer .confirmed [com .Sell .OrderID ]; ok {
98
- confirmer .confirmingMu .Unlock ()
99
98
return
100
99
}
101
100
102
101
confirmer .confirmingBuyOrders [com .Buy .OrderID ] = time .Now ()
103
102
confirmer .confirmingSellOrders [com .Sell .OrderID ] = time .Now ()
104
- confirmer .confirmingMu .Unlock ()
105
103
106
104
// Confirm Computations on the blockchain and register them for
107
105
// observation (we need to wait for finality)
108
- if err := confirmer .beginConfirmation (com ); err != nil {
109
- // An error in confirmation should not stop the
110
- // Confirmer from monitoring the Computation for
111
- // confirmation (another node might have succeeded), so
112
- // we pass through
113
- logger .Error (err .Error ())
114
- }
115
- }()
106
+ go func () {
107
+ if err := confirmer .beginConfirmation (com ); err != nil {
108
+ // An error in confirmation should not stop the
109
+ // Confirmer from monitoring the Computation for
110
+ // confirmation (another node might have succeeded), so
111
+ // we pass through
112
+ logger .Error (err .Error ())
113
+ }
114
+ }()
115
+ }(com )
116
116
}
117
117
}
118
118
}()
0 commit comments