@@ -2,6 +2,7 @@ package chancloser
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"encoding/hex"
6
7
"errors"
7
8
"fmt"
@@ -144,7 +145,9 @@ func assertUnknownEventFail(t *testing.T, startingState ProtocolState) {
144
145
145
146
closeHarness .expectFailure (ErrInvalidStateTransition )
146
147
147
- closeHarness .chanCloser .SendEvent (& unknownEvent {})
148
+ closeHarness .chanCloser .SendEvent (
149
+ context .Background (), & unknownEvent {},
150
+ )
148
151
149
152
// There should be no further state transitions.
150
153
closeHarness .assertNoStateTransitions ()
@@ -481,6 +484,7 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration(
481
484
initEvent ProtocolEvent , balanceAfterClose , absoluteFee btcutil.Amount ,
482
485
dustExpect dustExpectation ) {
483
486
487
+ ctx := context .Background ()
484
488
numFeeCalls := 2
485
489
486
490
// If we're using the SendOfferEvent as a trigger, we only need to call
@@ -527,7 +531,7 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration(
527
531
})
528
532
r .expectMsgSent (msgExpect )
529
533
530
- r .chanCloser .SendEvent (initEvent )
534
+ r .chanCloser .SendEvent (ctx , initEvent )
531
535
532
536
// Based on the init event, we'll either just go to the closing
533
537
// negotiation state, or go through the channel flushing state first.
@@ -582,6 +586,8 @@ func (r *rbfCloserTestHarness) assertSingleRbfIteration(
582
586
initEvent ProtocolEvent , balanceAfterClose , absoluteFee btcutil.Amount ,
583
587
dustExpect dustExpectation ) {
584
588
589
+ ctx := context .Background ()
590
+
585
591
// We'll now send in the send offer event, which should trigger 1/2 of
586
592
// the RBF loop, ending us in the LocalOfferSent state.
587
593
r .expectHalfSignerIteration (
@@ -607,7 +613,7 @@ func (r *rbfCloserTestHarness) assertSingleRbfIteration(
607
613
balanceAfterClose , true ,
608
614
)
609
615
610
- r .chanCloser .SendEvent (localSigEvent )
616
+ r .chanCloser .SendEvent (ctx , localSigEvent )
611
617
612
618
// We should transition to the pending closing state now.
613
619
r .assertLocalClosePending ()
@@ -617,6 +623,8 @@ func (r *rbfCloserTestHarness) assertSingleRemoteRbfIteration(
617
623
initEvent ProtocolEvent , balanceAfterClose , absoluteFee btcutil.Amount ,
618
624
sequence uint32 , iteration bool ) {
619
625
626
+ ctx := context .Background ()
627
+
620
628
// If this is an iteration, then we expect some intermediate states,
621
629
// before we enter the main RBF/sign loop.
622
630
if iteration {
@@ -635,7 +643,7 @@ func (r *rbfCloserTestHarness) assertSingleRemoteRbfIteration(
635
643
absoluteFee , balanceAfterClose , false ,
636
644
)
637
645
638
- r .chanCloser .SendEvent (initEvent )
646
+ r .chanCloser .SendEvent (ctx , initEvent )
639
647
640
648
// Our outer state should transition to ClosingNegotiation state.
641
649
r .assertStateTransitions (& ClosingNegotiation {})
@@ -668,6 +676,8 @@ func assertStateT[T ProtocolState](h *rbfCloserTestHarness) T {
668
676
func newRbfCloserTestHarness (t * testing.T ,
669
677
cfg * harnessCfg ) * rbfCloserTestHarness {
670
678
679
+ ctx := context .Background ()
680
+
671
681
startingHeight := 200
672
682
673
683
chanPoint := randOutPoint (t )
@@ -747,7 +757,7 @@ func newRbfCloserTestHarness(t *testing.T,
747
757
).Return (nil )
748
758
749
759
chanCloser := protofsm .NewStateMachine (protoCfg )
750
- chanCloser .Start ()
760
+ chanCloser .Start (ctx )
751
761
752
762
harness .stateSub = chanCloser .RegisterStateEvents ()
753
763
@@ -769,6 +779,7 @@ func newCloser(t *testing.T, cfg *harnessCfg) *rbfCloserTestHarness {
769
779
// TestRbfChannelActiveTransitions tests the transitions of from the
770
780
// ChannelActive state.
771
781
func TestRbfChannelActiveTransitions (t * testing.T ) {
782
+ ctx := context .Background ()
772
783
localAddr := lnwire .DeliveryAddress (bytes .Repeat ([]byte {0x01 }, 20 ))
773
784
remoteAddr := lnwire .DeliveryAddress (bytes .Repeat ([]byte {0x02 }, 20 ))
774
785
@@ -782,7 +793,7 @@ func TestRbfChannelActiveTransitions(t *testing.T) {
782
793
})
783
794
defer closeHarness .stopAndAssert ()
784
795
785
- closeHarness .chanCloser .SendEvent (& SpendEvent {})
796
+ closeHarness .chanCloser .SendEvent (ctx , & SpendEvent {})
786
797
787
798
closeHarness .assertStateTransitions (& CloseFin {})
788
799
})
@@ -799,7 +810,7 @@ func TestRbfChannelActiveTransitions(t *testing.T) {
799
810
// We don't specify an upfront shutdown addr, and don't specify
800
811
// on here in the vent, so we should call new addr, but then
801
812
// fail.
802
- closeHarness .chanCloser .SendEvent (& SendShutdown {})
813
+ closeHarness .chanCloser .SendEvent (ctx , & SendShutdown {})
803
814
804
815
// We shouldn't have transitioned to a new state.
805
816
closeHarness .assertNoStateTransitions ()
@@ -824,9 +835,9 @@ func TestRbfChannelActiveTransitions(t *testing.T) {
824
835
825
836
// If we send the shutdown event, we should transition to the
826
837
// shutdown pending state.
827
- closeHarness .chanCloser .SendEvent (& SendShutdown {
828
- IdealFeeRate : feeRate ,
829
- } )
838
+ closeHarness .chanCloser .SendEvent (
839
+ ctx , & SendShutdown { IdealFeeRate : feeRate } ,
840
+ )
830
841
closeHarness .assertStateTransitions (& ShutdownPending {})
831
842
832
843
// If we examine the internal state, it should be consistent
@@ -869,9 +880,9 @@ func TestRbfChannelActiveTransitions(t *testing.T) {
869
880
870
881
// Next, we'll emit the recv event, with the addr of the remote
871
882
// party.
872
- closeHarness .chanCloser .SendEvent (& ShutdownReceived {
873
- ShutdownScript : remoteAddr ,
874
- } )
883
+ closeHarness .chanCloser .SendEvent (
884
+ ctx , & ShutdownReceived { ShutdownScript : remoteAddr } ,
885
+ )
875
886
876
887
// We should transition to the shutdown pending state.
877
888
closeHarness .assertStateTransitions (& ShutdownPending {})
@@ -899,6 +910,7 @@ func TestRbfChannelActiveTransitions(t *testing.T) {
899
910
// shutdown ourselves.
900
911
func TestRbfShutdownPendingTransitions (t * testing.T ) {
901
912
t .Parallel ()
913
+ ctx := context .Background ()
902
914
903
915
startingState := & ShutdownPending {}
904
916
@@ -913,7 +925,7 @@ func TestRbfShutdownPendingTransitions(t *testing.T) {
913
925
})
914
926
defer closeHarness .stopAndAssert ()
915
927
916
- closeHarness .chanCloser .SendEvent (& SpendEvent {})
928
+ closeHarness .chanCloser .SendEvent (ctx , & SpendEvent {})
917
929
918
930
closeHarness .assertStateTransitions (& CloseFin {})
919
931
})
@@ -936,7 +948,7 @@ func TestRbfShutdownPendingTransitions(t *testing.T) {
936
948
// We'll now send in a ShutdownReceived event, but with a
937
949
// different address provided in the shutdown message. This
938
950
// should result in an error.
939
- closeHarness .chanCloser .SendEvent (& ShutdownReceived {
951
+ closeHarness .chanCloser .SendEvent (ctx , & ShutdownReceived {
940
952
ShutdownScript : localAddr ,
941
953
})
942
954
@@ -972,9 +984,9 @@ func TestRbfShutdownPendingTransitions(t *testing.T) {
972
984
973
985
// We'll send in a shutdown received event, with the expected
974
986
// co-op close addr.
975
- closeHarness .chanCloser .SendEvent (& ShutdownReceived {
976
- ShutdownScript : remoteAddr ,
977
- } )
987
+ closeHarness .chanCloser .SendEvent (
988
+ ctx , & ShutdownReceived { ShutdownScript : remoteAddr } ,
989
+ )
978
990
979
991
// We should transition to the channel flushing state.
980
992
closeHarness .assertStateTransitions (& ChannelFlushing {})
@@ -1015,7 +1027,7 @@ func TestRbfShutdownPendingTransitions(t *testing.T) {
1015
1027
closeHarness .expectFinalBalances (fn .None [ShutdownBalances ]())
1016
1028
1017
1029
// We'll send in a shutdown received event.
1018
- closeHarness .chanCloser .SendEvent (& ShutdownComplete {})
1030
+ closeHarness .chanCloser .SendEvent (ctx , & ShutdownComplete {})
1019
1031
1020
1032
// We should transition to the channel flushing state.
1021
1033
closeHarness .assertStateTransitions (& ChannelFlushing {})
@@ -1030,6 +1042,7 @@ func TestRbfShutdownPendingTransitions(t *testing.T) {
1030
1042
// transition to the negotiation state.
1031
1043
func TestRbfChannelFlushingTransitions (t * testing.T ) {
1032
1044
t .Parallel ()
1045
+ ctx := context .Background ()
1033
1046
1034
1047
localBalance := lnwire .NewMSatFromSatoshis (10_000 )
1035
1048
remoteBalance := lnwire .NewMSatFromSatoshis (50_000 )
@@ -1082,7 +1095,9 @@ func TestRbfChannelFlushingTransitions(t *testing.T) {
1082
1095
1083
1096
// We'll now send in the event which should trigger
1084
1097
// this code path.
1085
- closeHarness .chanCloser .SendEvent (& chanFlushedEvent )
1098
+ closeHarness .chanCloser .SendEvent (
1099
+ ctx , & chanFlushedEvent ,
1100
+ )
1086
1101
1087
1102
// With the event sent, we should now transition
1088
1103
// straight to the ClosingNegotiation state, with no
@@ -1149,6 +1164,7 @@ func TestRbfChannelFlushingTransitions(t *testing.T) {
1149
1164
// rate.
1150
1165
func TestRbfCloseClosingNegotiationLocal (t * testing.T ) {
1151
1166
t .Parallel ()
1167
+ ctx := context .Background ()
1152
1168
1153
1169
localBalance := lnwire .NewMSatFromSatoshis (40_000 )
1154
1170
remoteBalance := lnwire .NewMSatFromSatoshis (50_000 )
@@ -1232,7 +1248,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
1232
1248
1233
1249
// We should fail as the remote party sent us more than one
1234
1250
// signature.
1235
- closeHarness .chanCloser .SendEvent (localSigEvent )
1251
+ closeHarness .chanCloser .SendEvent (ctx , localSigEvent )
1236
1252
})
1237
1253
1238
1254
// Next, we'll verify that if the balance of the remote party is dust,
@@ -1333,7 +1349,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
1333
1349
singleMsgMatcher [* lnwire.Shutdown ](nil ),
1334
1350
)
1335
1351
1336
- closeHarness .chanCloser .SendEvent (sendShutdown )
1352
+ closeHarness .chanCloser .SendEvent (ctx , sendShutdown )
1337
1353
1338
1354
// We should first transition to the Channel Active state
1339
1355
// momentarily, before transitioning to the shutdown pending
@@ -1367,6 +1383,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
1367
1383
// party.
1368
1384
func TestRbfCloseClosingNegotiationRemote (t * testing.T ) {
1369
1385
t .Parallel ()
1386
+ ctx := context .Background ()
1370
1387
1371
1388
localBalance := lnwire .NewMSatFromSatoshis (40_000 )
1372
1389
remoteBalance := lnwire .NewMSatFromSatoshis (50_000 )
@@ -1416,7 +1433,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1416
1433
FeeSatoshis : absoluteFee * 10 ,
1417
1434
},
1418
1435
}
1419
- closeHarness .chanCloser .SendEvent (feeOffer )
1436
+ closeHarness .chanCloser .SendEvent (ctx , feeOffer )
1420
1437
1421
1438
// We shouldn't have transitioned to a new state.
1422
1439
closeHarness .assertNoStateTransitions ()
@@ -1460,7 +1477,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1460
1477
},
1461
1478
},
1462
1479
}
1463
- closeHarness .chanCloser .SendEvent (feeOffer )
1480
+ closeHarness .chanCloser .SendEvent (ctx , feeOffer )
1464
1481
1465
1482
// We shouldn't have transitioned to a new state.
1466
1483
closeHarness .assertNoStateTransitions ()
@@ -1489,7 +1506,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1489
1506
},
1490
1507
},
1491
1508
}
1492
- closeHarness .chanCloser .SendEvent (feeOffer )
1509
+ closeHarness .chanCloser .SendEvent (ctx , feeOffer )
1493
1510
1494
1511
// We shouldn't have transitioned to a new state.
1495
1512
closeHarness .assertNoStateTransitions ()
@@ -1561,9 +1578,9 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1561
1578
// We'll now simulate the start of the RBF loop, by receiving a
1562
1579
// new Shutdown message from the remote party. This signals
1563
1580
// that they want to obtain a new commit sig.
1564
- closeHarness .chanCloser .SendEvent (& ShutdownReceived {
1565
- ShutdownScript : remoteAddr ,
1566
- } )
1581
+ closeHarness .chanCloser .SendEvent (
1582
+ ctx , & ShutdownReceived { ShutdownScript : remoteAddr } ,
1583
+ )
1567
1584
1568
1585
// Next, we'll receive an offer from the remote party, and
1569
1586
// drive another RBF iteration. This time, we'll increase the
0 commit comments