@@ -54,8 +54,8 @@ func (a *Adjudicator) ensureConcluded(ctx context.Context, req channel.Adjudicat
5454 subErr := make (chan error , 1 )
5555 waitCtx , cancel := context .WithCancel (ctx )
5656 go func () {
57+ defer cancel ()
5758 subErr <- sub .Read (ctx , events )
58- cancel ()
5959 }()
6060
6161 // In final Register calls, as the non-initiator, we optimistically wait for
@@ -107,7 +107,7 @@ func (a *Adjudicator) conclude(ctx context.Context, req channel.AdjudicatorReq,
107107 err = errors .WithMessage (a .callConclude (ctx , req , subStates ), "calling conclude" )
108108 }
109109 if IsErrTxFailed (err ) {
110- a .log .Warn ("Calling conclude(Final) failed, waiting for event anyways..." )
110+ a .log .WithError ( err ). Warn ("Calling conclude(Final) failed, waiting for event anyways..." )
111111 } else if err != nil {
112112 return err
113113 }
@@ -133,8 +133,10 @@ func (a *Adjudicator) isConcluded(ctx context.Context, sub *subscription.EventSu
133133 return false , errors .WithMessage (<- subErr , "reading past events" )
134134}
135135
136- // isForceExecuted returns whether a channel is already concluded.
137- func (a * Adjudicator ) isForceExecuted (ctx context.Context , c channel.ID ) (bool , error ) {
136+ // isForceExecuted returns whether a channel is in the forced execution phase.
137+ func (a * Adjudicator ) isForceExecuted (_ctx context.Context , c channel.ID ) (bool , error ) {
138+ ctx , cancel := context .WithCancel (_ctx )
139+ defer cancel ()
138140 sub , err := subscription .NewEventSub (ctx , a .ContractBackend , a .bound , updateEventType (c ), startBlockOffset )
139141 if err != nil {
140142 return false , errors .WithMessage (err , "subscribing" )
@@ -148,8 +150,12 @@ func (a *Adjudicator) isForceExecuted(ctx context.Context, c channel.ID) (bool,
148150 subErr <- sub .ReadPast (ctx , events )
149151 }()
150152 // Read all events and check for force execution.
153+ var lastEvent * subscription.Event
151154 for _e := range events {
152- e := _e .Data .(* adjudicator.AdjudicatorChannelUpdate )
155+ lastEvent = _e
156+ }
157+ if lastEvent != nil {
158+ e := lastEvent .Data .(* adjudicator.AdjudicatorChannelUpdate )
153159 if e .Phase == phaseForceExec {
154160 return true , nil
155161 }
0 commit comments