@@ -37,26 +37,34 @@ func (m *manager) policyLoop() {
3737 ctx := log .WithLogField (m .ctx , "role" , "policyloop" )
3838
3939 for {
40+ // Wait to be notified, or timeout to run
4041 timer := time .NewTimer (m .policyLoopInterval )
4142 select {
4243 case <- m .inflightUpdate :
43- m .policyLoopCycle (ctx , false )
44- case <- m .inflightStale :
45- m .policyLoopCycle (ctx , true )
4644 case <- timer .C :
47- m .policyLoopCycle (ctx , false )
4845 case <- ctx .Done ():
4946 log .L (ctx ).Infof ("Receipt poller exiting" )
5047 return
5148 }
49+ // Pop whether we were marked stale
50+ stale := false
51+ select {
52+ case <- m .inflightStale :
53+ stale = true
54+ default :
55+ }
56+ m .policyLoopCycle (ctx , stale )
5257 }
5358}
5459
5560func (m * manager ) markInflightStale () {
61+ // First mark that we're stale
5662 select {
5763 case m .inflightStale <- true :
5864 default :
5965 }
66+ // Then ensure we queue a loop that picks up the stale marker
67+ m .markInflightUpdate ()
6068}
6169
6270func (m * manager ) markInflightUpdate () {
@@ -237,6 +245,7 @@ func (m *manager) execPolicy(ctx context.Context, pending *pendingState, syncDel
237245 log .L (ctx ).Errorf ("Policy engine returned error for transaction %s reason=%s: %s" , mtx .ID , reason , err )
238246 m .addError (mtx , reason , err )
239247 } else {
248+ log .L (ctx ).Debugf ("Policy engine executed for tx %s (update=%d,status=%s,hash=%s)" , mtx .ID , update , mtx .Status , mtx .TransactionHash )
240249 if mtx .FirstSubmit != nil && pending .trackingTransactionHash != mtx .TransactionHash {
241250 // If now submitted, add to confirmations manager for receipt checking
242251 m .trackSubmittedTransaction (ctx , pending )
@@ -257,6 +266,7 @@ func (m *manager) execPolicy(ctx context.Context, pending *pendingState, syncDel
257266 }
258267 if completed {
259268 pending .remove = true // for the next time round the loop
269+ log .L (ctx ).Errorf ("Transaction %s marked complete (status=%s): %s" , mtx .ID , mtx .Status , err )
260270 m .markInflightStale ()
261271 }
262272 case policyengine .UpdateDelete :
0 commit comments