@@ -49,12 +49,18 @@ var (
49
49
remoteSigBytes = fromHex ("304502210082235e21a2300022738dabb8e1bbd9d1" +
50
50
"9cfb1e7ab8c30a23b0afbb8d178abcf3022024bf68e256c534ddfaf966b" +
51
51
"f908deb944305596f7bdcc38d69acad7f9c868724" )
52
- remoteSig = sigMustParse (remoteSigBytes )
53
- remoteWireSig = mustWireSig (& remoteSig )
52
+ remoteSig = sigMustParse (remoteSigBytes )
53
+ remoteWireSig = mustWireSig (& remoteSig )
54
+ remoteSigRecordType3 = newSigTlv [tlv.TlvType3 ](remoteWireSig )
55
+ remoteSigRecordType1 = newSigTlv [tlv.TlvType1 ](remoteWireSig )
54
56
55
57
localTx = wire.MsgTx {Version : 2 }
56
58
57
59
closeTx = wire .NewMsgTx (2 )
60
+
61
+ defaultTimeout = 500 * time .Millisecond
62
+ longTimeout = 3 * time .Second
63
+ defaultPoll = 50 * time .Millisecond
58
64
)
59
65
60
66
func sigMustParse (sigBytes []byte ) ecdsa.Signature {
@@ -111,7 +117,7 @@ func assertStateTransitions[Event any, Env protofsm.Environment](
111
117
112
118
for _ , expectedState := range expectedStates {
113
119
newState , err := fn .RecvOrTimeout (
114
- stateSub .NewItemCreated .ChanOut (), 10 * time . Millisecond ,
120
+ stateSub .NewItemCreated .ChanOut (), defaultTimeout ,
115
121
)
116
122
require .NoError (t , err , "expected state: %T" , expectedState )
117
123
@@ -122,7 +128,7 @@ func assertStateTransitions[Event any, Env protofsm.Environment](
122
128
select {
123
129
case newState := <- stateSub .NewItemCreated .ChanOut ():
124
130
t .Fatalf ("unexpected state transition: %v" , newState )
125
- default :
131
+ case <- time . After ( defaultPoll ) :
126
132
}
127
133
}
128
134
@@ -285,10 +291,12 @@ func (r *rbfCloserTestHarness) assertStartupAssertions() {
285
291
}
286
292
287
293
func (r * rbfCloserTestHarness ) assertNoStateTransitions () {
294
+ r .T .Helper ()
295
+
288
296
select {
289
297
case newState := <- r .stateSub .NewItemCreated .ChanOut ():
290
298
r .T .Fatalf ("unexpected state transition: %T" , newState )
291
- case <- time .After (10 * time . Millisecond ):
299
+ case <- time .After (defaultPoll ):
292
300
}
293
301
}
294
302
@@ -436,7 +444,7 @@ func (r *rbfCloserTestHarness) waitForMsgSent() {
436
444
437
445
err := wait .Predicate (func () bool {
438
446
return r .daemonAdapters .msgSent .Load ()
439
- }, time . Second * 3 )
447
+ }, longTimeout )
440
448
require .NoError (r .T , err )
441
449
}
442
450
@@ -642,7 +650,7 @@ func (r *rbfCloserTestHarness) assertSingleRbfIteration(
642
650
// We'll now send in the send offer event, which should trigger 1/2 of
643
651
// the RBF loop, ending us in the LocalOfferSent state.
644
652
r .expectHalfSignerIteration (
645
- initEvent , balanceAfterClose , absoluteFee , noDustExpect ,
653
+ initEvent , balanceAfterClose , absoluteFee , dustExpect ,
646
654
iteration ,
647
655
)
648
656
@@ -693,15 +701,21 @@ func (r *rbfCloserTestHarness) assertSingleRemoteRbfIteration(
693
701
}
694
702
695
703
// Our outer state should transition to ClosingNegotiation state.
696
- r .assertStateTransitions (& ClosingNegotiation {})
704
+ transitions := []RbfState {
705
+ & ClosingNegotiation {},
706
+ }
697
707
698
708
// If this is an iteration, then we'll go from ClosePending ->
699
709
// RemoteCloseStart -> ClosePending. So we'll assert an extra transition
700
710
// here.
701
711
if iteration {
702
- r . assertStateTransitions ( & ClosingNegotiation {})
712
+ transitions = append ( transitions , & ClosingNegotiation {})
703
713
}
704
714
715
+ // Now that we know how many state transitions to expect, we'll wait
716
+ // for them.
717
+ r .assertStateTransitions (transitions ... )
718
+
705
719
// If we examine the final resting state, we should see that the we're
706
720
// now in the ClosePending state for the remote peer.
707
721
currentState := assertStateT [* ClosingNegotiation ](r )
@@ -802,7 +816,7 @@ func newRbfCloserTestHarness(t *testing.T,
802
816
MsgMapper : fn.Some [protofsm.MsgMapper [ProtocolEvent ]](
803
817
msgMapper ,
804
818
),
805
- CustomPollInterval : fn .Some (time . Nanosecond ),
819
+ CustomPollInterval : fn .Some (defaultPoll ),
806
820
}
807
821
808
822
// Before we start we always expect an initial spend event.
@@ -811,10 +825,13 @@ func newRbfCloserTestHarness(t *testing.T,
811
825
).Return (nil )
812
826
813
827
chanCloser := protofsm .NewStateMachine (protoCfg )
814
- chanCloser .Start (ctx )
815
828
829
+ // We register our subscriber before starting the state machine, to make
830
+ // sure we don't miss any events.
816
831
harness .stateSub = chanCloser .RegisterStateEvents ()
817
832
833
+ chanCloser .Start (ctx )
834
+
818
835
harness .chanCloser = & chanCloser
819
836
820
837
return harness
@@ -1284,9 +1301,8 @@ func TestRbfChannelFlushingTransitions(t *testing.T) {
1284
1301
1285
1302
// We'll modify the starting balance to be 3x the required fee
1286
1303
// to ensure that we can pay for the fee.
1287
- flushEvent .ShutdownBalances .LocalBalance = lnwire .NewMSatFromSatoshis ( //nolint:ll
1288
- absoluteFee * 3 ,
1289
- )
1304
+ localBalanceMSat := lnwire .NewMSatFromSatoshis (absoluteFee * 3 )
1305
+ flushEvent .ShutdownBalances .LocalBalance = localBalanceMSat
1290
1306
1291
1307
testName := fmt .Sprintf ("local_can_pay_for_fee/" +
1292
1308
"fresh_flush=%v" , isFreshFlush )
@@ -1304,7 +1320,8 @@ func TestRbfChannelFlushingTransitions(t *testing.T) {
1304
1320
defer closeHarness .stopAndAssert ()
1305
1321
1306
1322
localBalance := flushEvent .ShutdownBalances .LocalBalance
1307
- balanceAfterClose := localBalance .ToSatoshis () - absoluteFee //nolint:ll
1323
+ balanceAfterClose := localBalance .ToSatoshis () -
1324
+ absoluteFee
1308
1325
1309
1326
// If this is a fresh flush, then we expect the state
1310
1327
// to be marked on disk.
@@ -1353,9 +1370,7 @@ func TestRbfChannelFlushingTransitions(t *testing.T) {
1353
1370
CloserScript : remoteAddr ,
1354
1371
CloseeScript : localAddr ,
1355
1372
ClosingSigs : lnwire.ClosingSigs {
1356
- CloserAndClosee : newSigTlv [tlv.TlvType3 ]( //nolint:ll
1357
- remoteWireSig ,
1358
- ),
1373
+ CloserAndClosee : remoteSigRecordType3 ,
1359
1374
},
1360
1375
},
1361
1376
}
@@ -1467,9 +1482,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
1467
1482
CloserNoClosee : newSigTlv [tlv.TlvType1 ](
1468
1483
remoteWireSig ,
1469
1484
),
1470
- CloserAndClosee : newSigTlv [tlv.TlvType3 ]( //nolint:ll
1471
- remoteWireSig ,
1472
- ),
1485
+ CloserAndClosee : remoteSigRecordType3 ,
1473
1486
},
1474
1487
},
1475
1488
}
@@ -1564,9 +1577,7 @@ func TestRbfCloseClosingNegotiationLocal(t *testing.T) {
1564
1577
CloserScript : remoteAddr ,
1565
1578
CloseeScript : remoteAddr ,
1566
1579
ClosingSigs : lnwire.ClosingSigs {
1567
- CloserAndClosee : newSigTlv [tlv.TlvType3 ]( //nolint:ll
1568
- remoteWireSig ,
1569
- ),
1580
+ CloserAndClosee : remoteSigRecordType3 ,
1570
1581
},
1571
1582
},
1572
1583
}
@@ -1732,7 +1743,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1732
1743
closeHarness .assertNoStateTransitions ()
1733
1744
})
1734
1745
1735
- // If our balance, is dust, then the remote party should send a
1746
+ // If our balance is dust, then the remote party should send a
1736
1747
// signature that doesn't include our output.
1737
1748
t .Run ("recv_offer_err_closer_no_closee" , func (t * testing.T ) {
1738
1749
// We'll modify our local balance to be dust.
@@ -1764,9 +1775,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1764
1775
CloserScript : remoteAddr ,
1765
1776
CloseeScript : localAddr ,
1766
1777
ClosingSigs : lnwire.ClosingSigs {
1767
- CloserAndClosee : newSigTlv [tlv.TlvType3 ]( //nolint:ll
1768
- remoteWireSig ,
1769
- ),
1778
+ CloserAndClosee : remoteSigRecordType3 ,
1770
1779
},
1771
1780
},
1772
1781
}
@@ -1792,9 +1801,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1792
1801
CloserScript : remoteAddr ,
1793
1802
CloseeScript : localAddr ,
1794
1803
ClosingSigs : lnwire.ClosingSigs {
1795
- CloserNoClosee : newSigTlv [tlv.TlvType1 ]( //nolint:ll
1796
- remoteWireSig ,
1797
- ),
1804
+ CloserNoClosee : remoteSigRecordType1 ,
1798
1805
},
1799
1806
},
1800
1807
}
@@ -1840,9 +1847,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1840
1847
FeeSatoshis : absoluteFee ,
1841
1848
LockTime : 1 ,
1842
1849
ClosingSigs : lnwire.ClosingSigs {
1843
- CloserAndClosee : newSigTlv [tlv.TlvType3 ]( //nolint:ll
1844
- remoteWireSig ,
1845
- ),
1850
+ CloserAndClosee : remoteSigRecordType3 ,
1846
1851
},
1847
1852
},
1848
1853
}
@@ -1886,9 +1891,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1886
1891
CloserScript : remoteAddr ,
1887
1892
CloseeScript : remoteAddr ,
1888
1893
ClosingSigs : lnwire.ClosingSigs {
1889
- CloserNoClosee : newSigTlv [tlv.TlvType1 ]( //nolint:ll
1890
- remoteWireSig ,
1891
- ),
1894
+ CloserNoClosee : remoteSigRecordType1 ,
1892
1895
},
1893
1896
},
1894
1897
}
@@ -1937,9 +1940,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
1937
1940
FeeSatoshis : absoluteFee ,
1938
1941
LockTime : 1 ,
1939
1942
ClosingSigs : lnwire.ClosingSigs {
1940
- CloserAndClosee : newSigTlv [tlv.TlvType3 ]( //nolint:ll
1941
- remoteWireSig ,
1942
- ),
1943
+ CloserAndClosee : remoteSigRecordType3 ,
1943
1944
},
1944
1945
},
1945
1946
}
@@ -2005,12 +2006,7 @@ func TestRbfCloseErr(t *testing.T) {
2005
2006
// initiate a new local sig).
2006
2007
closeHarness .assertSingleRbfIteration (
2007
2008
localOffer , balanceAfterClose , absoluteFee ,
2008
- noDustExpect , false ,
2009
- )
2010
-
2011
- // We should terminate in the negotiation state.
2012
- closeHarness .assertStateTransitions (
2013
- & ClosingNegotiation {},
2009
+ noDustExpect , true ,
2014
2010
)
2015
2011
})
2016
2012
@@ -2040,9 +2036,7 @@ func TestRbfCloseErr(t *testing.T) {
2040
2036
FeeSatoshis : absoluteFee ,
2041
2037
LockTime : 1 ,
2042
2038
ClosingSigs : lnwire.ClosingSigs {
2043
- CloserAndClosee : newSigTlv [tlv.TlvType3 ]( //nolint:ll
2044
- remoteWireSig ,
2045
- ),
2039
+ CloserAndClosee : remoteSigRecordType3 ,
2046
2040
},
2047
2041
},
2048
2042
}
@@ -2054,7 +2048,7 @@ func TestRbfCloseErr(t *testing.T) {
2054
2048
// sig.
2055
2049
closeHarness .assertSingleRemoteRbfIteration (
2056
2050
feeOffer , balanceAfterClose , absoluteFee , sequence ,
2057
- false , true ,
2051
+ true , true ,
2058
2052
)
2059
2053
})
2060
2054
0 commit comments