@@ -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
@@ -2532,6 +2536,65 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
2532
2536
// If we can immediately send an Stfu response back , we will.
2533
2537
l .drivePendingStfuSends ()
2534
2538
2539
+ case * lnwire.DynPropose :
2540
+ if ! l .quiescer .isQuiescent () {
2541
+ l .stfuFailf ("cannot process dyn_propose, channel is " +
2542
+ "not quiescent" )
2543
+ }
2544
+
2545
+ res , err := l .dyncommNegotiator .recvDynPropose (* msg )
2546
+ if err != nil {
2547
+ // Failed to process DynPropose...
2548
+ panic ("NOT IMPLEMENTED: error handling recvDynPropose" )
2549
+ }
2550
+
2551
+
2552
+ res .WhenLeft (func (m lnwire.DynAck ) {
2553
+ err := l .channel .ExecDynCommProposal (
2554
+ lntypes .Remote , * msg ,
2555
+ )
2556
+ if err != nil {
2557
+ panic ("NOT IMPLEMENTED: error handling during dyncomm execution" )
2558
+ }
2559
+ l .cfg .Peer .SendMessage (false , & m )
2560
+ })
2561
+
2562
+ res .WhenRight (func (m lnwire.DynReject ) {
2563
+ l .cfg .Peer .SendMessage (false , & m )
2564
+ })
2565
+
2566
+ case * lnwire.DynAck :
2567
+ if ! l .quiescer .isQuiescent () {
2568
+ l .stfuFailf ("cannot process dyn_ack, channel is " +
2569
+ "not quiescent" )
2570
+ }
2571
+
2572
+ propose , err := l .dyncommNegotiator .recvDynAck (* msg )
2573
+ if err != nil {
2574
+ // Failed to process DynAck...
2575
+ panic ("NOT IMPLEMENTED: error handling recvDynAck" )
2576
+ }
2577
+
2578
+ err = l .channel .ExecDynCommProposal (lntypes .Local , propose )
2579
+ if err != nil {
2580
+ panic ("NOT IMPLEMENTED: error handling during dyncomm execution" )
2581
+ }
2582
+
2583
+ l .dyncommNegotiator .reset ()
2584
+
2585
+ case * lnwire.DynReject :
2586
+ if ! l .quiescer .isQuiescent () {
2587
+ l .stfuFailf ("cannot process dyn_reject, channel is " +
2588
+ "not quiescent" )
2589
+ }
2590
+
2591
+ if l .dyncommNegotiator .recvDynReject (* msg ) != nil {
2592
+ // Failed to process DynReject...
2593
+ panic ("NOT IMPLEMENTED: error handling recvDynAck" )
2594
+ }
2595
+
2596
+ l .dyncommNegotiator .reset ()
2597
+
2535
2598
// In the case where we receive a warning message from our peer, just
2536
2599
// log it and move on. We choose not to disconnect from our peer,
2537
2600
// although we "MAY" do so according to the specification.
0 commit comments