@@ -235,7 +235,8 @@ func (s *StateMachine[Event, Env]) Stop() {
235
235
//
236
236
// TODO(roasbeef): bool if processed?
237
237
func (s * StateMachine [Event , Env ]) SendEvent (ctx context.Context , event Event ) {
238
- s .log .Debugf ("Sending event: %v" , lnutils .SpewLogClosure (event ))
238
+ s .log .DebugS (ctx , "Sending event" ,
239
+ "event" , lnutils .SpewLogClosure (event ))
239
240
240
241
select {
241
242
case s .events <- event :
@@ -273,7 +274,7 @@ func (s *StateMachine[Event, Env]) SendMessage(ctx context.Context,
273
274
return false
274
275
}
275
276
276
- s .log .Debugf ( "Sending msg: %v " , lnutils .SpewLogClosure (msg ))
277
+ s .log .DebugS ( ctx , "Sending msg" , "msg " , lnutils .SpewLogClosure (msg ))
277
278
278
279
// Otherwise, try to map the message using the default message mapper.
279
280
// If we can't extract an event, then we'll return false to indicate
@@ -344,10 +345,9 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
344
345
// any preconditions as well as post-send events.
345
346
case * SendMsgEvent [Event ]:
346
347
sendAndCleanUp := func () error {
347
- s .log .Debugf ("Sending message to target(%x): " +
348
- "%v" ,
349
- daemonEvent .TargetPeer .SerializeCompressed (),
350
- lnutils .SpewLogClosure (daemonEvent .Msgs ))
348
+ s .log .DebugS (ctx , "Sending message to target" ,
349
+ btclog .Hex6 ("target" , daemonEvent .TargetPeer .SerializeCompressed ()),
350
+ "messages" , lnutils .SpewLogClosure (daemonEvent .Msgs ))
351
351
352
352
err := s .cfg .Daemon .SendMessages (
353
353
daemonEvent .TargetPeer , daemonEvent .Msgs ,
@@ -362,9 +362,8 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
362
362
return fn .MapOptionZ (daemonEvent .PostSendEvent , func (event Event ) error { //nolint:ll
363
363
launched := s .wg .Go (
364
364
ctx , func (ctx context.Context ) {
365
- s .log .Debugf ("Sending " +
366
- "post-send event: %v" ,
367
- lnutils .SpewLogClosure (event ))
365
+ s .log .DebugS (ctx , "Sending post-send event" ,
366
+ "event" , lnutils .SpewLogClosure (event ))
368
367
369
368
s .SendEvent (ctx , event )
370
369
},
@@ -393,7 +392,7 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
393
392
)
394
393
defer predicateTicker .Stop ()
395
394
396
- s .log .Infof ( "Waiting for send predicate to be true" )
395
+ s .log .InfoS ( ctx , "Waiting for send predicate to be true" )
397
396
398
397
for {
399
398
select {
@@ -406,13 +405,11 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
406
405
)
407
406
408
407
if canSend {
409
- s .log .Infof ("Send active " +
410
- "predicate" )
408
+ s .log .InfoS (ctx , "Send active predicate" )
411
409
412
410
err := sendAndCleanUp ()
413
411
if err != nil {
414
- //nolint:ll
415
- s .log .Errorf ("Unable to send message: %v" , err )
412
+ s .log .ErrorS (ctx , "Unable to send message" , err )
416
413
}
417
414
418
415
return
@@ -433,8 +430,8 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
433
430
// If this is a broadcast transaction event, then we'll broadcast with
434
431
// the label attached.
435
432
case * BroadcastTxn :
436
- s .log .Debugf ( "Broadcasting txn, txid=%v " ,
437
- daemonEvent .Tx .TxHash ())
433
+ s .log .DebugS ( ctx , "Broadcasting txn" ,
434
+ "txid" , daemonEvent .Tx .TxHash ())
438
435
439
436
err := s .cfg .Daemon .BroadcastTransaction (
440
437
daemonEvent .Tx , daemonEvent .Label ,
@@ -448,7 +445,8 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
448
445
// The state machine has requested a new event to be sent once a
449
446
// transaction spending a specified outpoint has confirmed.
450
447
case * RegisterSpend [Event ]:
451
- s .log .Debugf ("Registering spend: %v" , daemonEvent .OutPoint )
448
+ s .log .DebugS (ctx , "Registering spend" ,
449
+ "outpoint" , daemonEvent .OutPoint )
452
450
453
451
spendEvent , err := s .cfg .Daemon .RegisterSpendNtfn (
454
452
& daemonEvent .OutPoint , daemonEvent .PkScript ,
@@ -492,7 +490,8 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
492
490
// The state machine has requested a new event to be sent once a
493
491
// specified txid+pkScript pair has confirmed.
494
492
case * RegisterConf [Event ]:
495
- s .log .Debugf ("Registering conf: %v" , daemonEvent .Txid )
493
+ s .log .DebugS (ctx , "Registering conf" ,
494
+ "txid" , daemonEvent .Txid )
496
495
497
496
numConfs := daemonEvent .NumConfs .UnwrapOr (1 )
498
497
confEvent , err := s .cfg .Daemon .RegisterConfirmationsNtfn (
@@ -543,8 +542,8 @@ func (s *StateMachine[Event, Env]) applyEvents(ctx context.Context,
543
542
currentState State [Event , Env ], newEvent Event ) (State [Event , Env ],
544
543
error ) {
545
544
546
- s .log .Debugf ( "Applying new event: %v " ,
547
- lnutils .SpewLogClosure (newEvent ))
545
+ s .log .DebugS ( ctx , "Applying new event" ,
546
+ "event" , lnutils .SpewLogClosure (newEvent ))
548
547
549
548
eventQueue := fn .NewQueue (newEvent )
550
549
@@ -556,8 +555,8 @@ func (s *StateMachine[Event, Env]) applyEvents(ctx context.Context,
556
555
//nolint:ll
557
556
for nextEvent := eventQueue .Dequeue (); nextEvent .IsSome (); nextEvent = eventQueue .Dequeue () {
558
557
err := fn .MapOptionZ (nextEvent , func (event Event ) error {
559
- s .log .Debugf ( "Processing event: %v " ,
560
- lnutils .SpewLogClosure (event ))
558
+ s .log .DebugS ( ctx , "Processing event" ,
559
+ "event" , lnutils .SpewLogClosure (event ))
561
560
562
561
// Apply the state transition function of the current
563
562
// state given this new event and our existing env.
@@ -587,12 +586,8 @@ func (s *StateMachine[Event, Env]) applyEvents(ctx context.Context,
587
586
//
588
587
//nolint:ll
589
588
for _ , inEvent := range events .InternalEvent {
590
- s .log .Debugf ("Adding " +
591
- "new internal event " +
592
- "to queue: %v" ,
593
- lnutils .SpewLogClosure (
594
- inEvent ,
595
- ))
589
+ s .log .DebugS (ctx , "Adding new internal event to queue" ,
590
+ "event" , lnutils .SpewLogClosure (inEvent ))
596
591
597
592
eventQueue .Enqueue (inEvent )
598
593
}
@@ -603,9 +598,9 @@ func (s *StateMachine[Event, Env]) applyEvents(ctx context.Context,
603
598
return err
604
599
}
605
600
606
- s .log .Infof ( "State transition: from_state=%T, " +
607
- "to_state= %T" , currentState ,
608
- transition .NextState )
601
+ s .log .InfoS ( ctx , "State transition" ,
602
+ btclog . Fmt ( "from_state" , " %T" , currentState ) ,
603
+ btclog . Fmt ( "to_state" , "%T" , transition .NextState ) )
609
604
610
605
// With our events processed, we'll now update our
611
606
// internal state.
@@ -631,7 +626,7 @@ func (s *StateMachine[Event, Env]) applyEvents(ctx context.Context,
631
626
// incoming events, and then drives the state machine forward until it reaches
632
627
// a terminal state.
633
628
func (s * StateMachine [Event , Env ]) driveMachine (ctx context.Context ) {
634
- s .log .Debugf ( "Starting state machine" )
629
+ s .log .DebugS ( ctx , "Starting state machine" )
635
630
636
631
currentState := s .cfg .InitialState
637
632
@@ -641,7 +636,7 @@ func (s *StateMachine[Event, Env]) driveMachine(ctx context.Context) {
641
636
return s .executeDaemonEvent (ctx , event )
642
637
})
643
638
if err != nil {
644
- s .log .Errorf ( "Unable to execute init event: %v " , err )
639
+ s .log .ErrorS ( ctx , "Unable to execute init event" , err )
645
640
return
646
641
}
647
642
@@ -661,7 +656,7 @@ func (s *StateMachine[Event, Env]) driveMachine(ctx context.Context) {
661
656
if err != nil {
662
657
s .cfg .ErrorReporter .ReportError (err )
663
658
664
- s .log .Errorf ( "Unable to apply event: %v " , err )
659
+ s .log .ErrorS ( ctx , "Unable to apply event" , err )
665
660
666
661
// An error occurred, so we'll tear down the
667
662
// entire state machine as we can't proceed.
0 commit comments