@@ -8,16 +8,7 @@ import (
88)
99
1010func (ex * Exchanger ) feedIBTPReceipt (receipt * model.WrappedIBTP ) {
11- var pool * Pool
12- servicePair := fmt .Sprintf ("%s-%s" , receipt .Ibtp .From , receipt .Ibtp .To )
13- act , loaded := ex .receipts .Load (servicePair )
14- if ! loaded {
15- ex .logger .Infof ("new pool for service pair %s at begin index %d" , servicePair , ex .serviceMeta [receipt .Ibtp .From ].ReceiptCounter [receipt .Ibtp .To ]+ 1 )
16- pool = NewPool (ex .serviceMeta [receipt .Ibtp .From ].ReceiptCounter [receipt .Ibtp .To ] + 1 )
17- ex .receipts .Store (servicePair , pool )
18- } else {
19- pool = act .(* Pool )
20- }
11+ pool , loaded := ex .loadPool (receipt .Ibtp .From , receipt .Ibtp .To )
2112 pool .feed (receipt )
2213
2314 if ! loaded {
@@ -70,3 +61,17 @@ func (ex *Exchanger) feedIBTPReceipt(receipt *model.WrappedIBTP) {
7061 }(pool )
7162 }
7263}
64+
65+ func (ex * Exchanger ) loadPool (from , to string ) (* Pool , bool ) {
66+ servicePair := fmt .Sprintf ("%s-%s" , from , to )
67+ beginIndex := ex .serviceMeta [from ].ReceiptCounter [to ] + 1
68+ if ex .callbackMeta [servicePair ]+ 1 > beginIndex {
69+ beginIndex = ex .callbackMeta [servicePair ] + 1
70+ }
71+
72+ ex .logger .Infof ("new pool for service pair %s at begin index %d" , servicePair , beginIndex )
73+ pool := NewPool (beginIndex )
74+ act , loaded := ex .receipts .LoadOrStore (servicePair , pool )
75+
76+ return act .(* Pool ), loaded
77+ }
0 commit comments