@@ -332,9 +332,8 @@ func (p *ChainPorter) mainEventLoop() {
332
332
func (p * ChainPorter ) advanceState (pkg * sendPackage , kit * parcelKit ) {
333
333
// Continue state transitions whilst state complete has not yet
334
334
// been reached.
335
- for pkg .SendState < SendStateComplete {
336
- log .Infof ("ChainPorter executing state: %v" ,
337
- pkg .SendState )
335
+ for pkg .SendState <= SendStateComplete {
336
+ log .Infof ("ChainPorter executing state: %v" , pkg .SendState )
338
337
339
338
// Before we attempt a state transition, make sure that
340
339
// we aren't trying to shut down.
@@ -360,14 +359,19 @@ func (p *ChainPorter) advanceState(pkg *sendPackage, kit *parcelKit) {
360
359
}
361
360
362
361
// Notify subscribers that the state machine has executed a
363
- // state successfully. The only state that happens in a
364
- // goroutine outside the state machine is sending the proof to
365
- // the receiver using the proof courier service. That goroutine
366
- // will notify the subscribers itself, so we skip it here.
367
- if pkg .SendState < SendStateComplete {
368
- p .publishSubscriberEvent (newAssetSendEvent (
369
- stateToExecute , * updatedPkg ,
370
- ))
362
+ // state successfully.
363
+ p .publishSubscriberEvent (newAssetSendEvent (
364
+ stateToExecute , * updatedPkg ,
365
+ ))
366
+
367
+ // Exit the loop once the state machine has executed its final
368
+ // state.
369
+ if pkg .SendState == SendStateComplete {
370
+ log .Infof ("ChainPorter completed state machine for " +
371
+ "parcel (anchor_txid=%v)" ,
372
+ updatedPkg .OutboundPkg .AnchorTx .TxHash ())
373
+
374
+ return
371
375
}
372
376
373
377
pkg = updatedPkg
@@ -1028,18 +1032,6 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error {
1028
1032
return nil
1029
1033
}
1030
1034
1031
- // At this point, the transfer is fully finalised and successful:
1032
- // - The anchoring transaction has been confirmed on-chain.
1033
- // - The proof(s) have been delivered to the receiver(s).
1034
- // - The database has been updated to reflect the successful transfer.
1035
- log .Infof ("Parcel transfer is fully complete (anchor_txid=%v)" ,
1036
- pkg .OutboundPkg .AnchorTx .TxHash ())
1037
-
1038
- // Send out the final notification that the transfer is complete.
1039
- p .publishSubscriberEvent (newAssetSendEvent (SendStateComplete , * pkg ))
1040
-
1041
- pkg .SendState = SendStateComplete
1042
-
1043
1035
return nil
1044
1036
}
1045
1037
@@ -1631,26 +1623,24 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
1631
1623
// we've stored the sender and receiver proofs in the proof archive.
1632
1624
// We'll now attempt to transfer one or more proofs to the receiver(s).
1633
1625
case SendStateTransferProofs :
1634
- // We'll set the package state to complete early here so the
1635
- // main loop breaks out. We'll continue to attempt proof
1636
- // deliver in the background.
1637
- currentPkg .SendState = SendStateComplete
1638
-
1639
- p .Wg .Add (1 )
1640
- go func () {
1641
- defer p .Wg .Done ()
1626
+ err := p .transferReceiverProof (& currentPkg )
1627
+ if err != nil {
1628
+ return nil , fmt .Errorf ("unable to transfer receiver " +
1629
+ "proof: %w" , err )
1630
+ }
1642
1631
1643
- err := p .transferReceiverProof (& currentPkg )
1644
- if err != nil {
1645
- log .Errorf ("unable to transfer receiver " +
1646
- "proof: %v" , err )
1632
+ currentPkg .SendState = SendStateComplete
1633
+ return & currentPkg , nil
1647
1634
1648
- p .publishSubscriberEvent (newAssetSendErrorEvent (
1649
- err , SendStateTransferProofs ,
1650
- currentPkg ,
1651
- ))
1652
- }
1653
- }()
1635
+ case SendStateComplete :
1636
+ // At this point, the transfer is fully finalised and
1637
+ // successful:
1638
+ // - The anchoring transaction has been confirmed on-chain.
1639
+ // - The proof(s) have been delivered to the receiver(s).
1640
+ // - The database has been updated to reflect the successful
1641
+ // transfer.
1642
+ log .Infof ("Parcel transfer is fully complete (anchor_txid=%v)" ,
1643
+ currentPkg .OutboundPkg .AnchorTx .TxHash ())
1654
1644
1655
1645
return & currentPkg , nil
1656
1646
0 commit comments