@@ -384,6 +384,10 @@ type channelLink struct {
384
384
// respect to the quiescence protocol.
385
385
quiescer
386
386
387
+ // dyncommNegotiator is a state machine that tracks active negotiations
388
+ // for Dynamic Commitments.
389
+ dyncommNegotiator
390
+
387
391
// activeQuiescenceRequest is a possibly nil channel that we should
388
392
// send on when we complete quiescence. We close the channel (causing
389
393
// None to be read) if the process fails. Otherwise the inner boolean
@@ -2517,6 +2521,65 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
2517
2521
// If we can immediately send an Stfu response back , we will.
2518
2522
l .drivePendingStfuSends ()
2519
2523
2524
+ case * lnwire.DynPropose :
2525
+ if ! l .quiescer .isQuiescent () {
2526
+ l .stfuFailf ("cannot process dyn_propose, channel is " +
2527
+ "not quiescent" )
2528
+ }
2529
+
2530
+ res , err := l .dyncommNegotiator .recvDynPropose (* msg )
2531
+ if err != nil {
2532
+ // Failed to process DynPropose...
2533
+ panic ("NOT IMPLEMENTED: error handling recvDynPropose" )
2534
+ }
2535
+
2536
+
2537
+ res .WhenLeft (func (m lnwire.DynAck ) {
2538
+ err := l .channel .ExecDynCommProposal (
2539
+ lntypes .Remote , * msg ,
2540
+ )
2541
+ if err != nil {
2542
+ panic ("NOT IMPLEMENTED: error handling during dyncomm execution" )
2543
+ }
2544
+ l .cfg .Peer .SendMessage (false , & m )
2545
+ })
2546
+
2547
+ res .WhenRight (func (m lnwire.DynReject ) {
2548
+ l .cfg .Peer .SendMessage (false , & m )
2549
+ })
2550
+
2551
+ case * lnwire.DynAck :
2552
+ if ! l .quiescer .isQuiescent () {
2553
+ l .stfuFailf ("cannot process dyn_ack, channel is " +
2554
+ "not quiescent" )
2555
+ }
2556
+
2557
+ propose , err := l .dyncommNegotiator .recvDynAck (* msg )
2558
+ if err != nil {
2559
+ // Failed to process DynAck...
2560
+ panic ("NOT IMPLEMENTED: error handling recvDynAck" )
2561
+ }
2562
+
2563
+ err = l .channel .ExecDynCommProposal (lntypes .Local , propose )
2564
+ if err != nil {
2565
+ panic ("NOT IMPLEMENTED: error handling during dyncomm execution" )
2566
+ }
2567
+
2568
+ l .dyncommNegotiator .reset ()
2569
+
2570
+ case * lnwire.DynReject :
2571
+ if ! l .quiescer .isQuiescent () {
2572
+ l .stfuFailf ("cannot process dyn_reject, channel is " +
2573
+ "not quiescent" )
2574
+ }
2575
+
2576
+ if l .dyncommNegotiator .recvDynReject (* msg ) != nil {
2577
+ // Failed to process DynReject...
2578
+ panic ("NOT IMPLEMENTED: error handling recvDynAck" )
2579
+ }
2580
+
2581
+ l .dyncommNegotiator .reset ()
2582
+
2520
2583
// In the case where we receive a warning message from our peer, just
2521
2584
// log it and move on. We choose not to disconnect from our peer,
2522
2585
// although we "MAY" do so according to the specification.
0 commit comments