Skip to content

Commit 1dd6845

Browse files
committed
wip
1 parent f3ef556 commit 1dd6845

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

htlcswitch/link.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ type channelLink struct {
384384
// respect to the quiescence protocol.
385385
quiescer
386386

387+
// dyncommNegotiator is a state machine that tracks active negotiations
388+
// for Dynamic Commitments.
389+
dyncommNegotiator
390+
387391
// activeQuiescenceRequest is a possibly nil channel that we should
388392
// send on when we complete quiescence. We close the channel (causing
389393
// None to be read) if the process fails. Otherwise the inner boolean
@@ -2517,6 +2521,65 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
25172521
// If we can immediately send an Stfu response back , we will.
25182522
l.drivePendingStfuSends()
25192523

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+
25202583
// In the case where we receive a warning message from our peer, just
25212584
// log it and move on. We choose not to disconnect from our peer,
25222585
// although we "MAY" do so according to the specification.

lnwallet/channel.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8449,3 +8449,10 @@ func (lc *LightningChannel) MultiSigKeys() (keychain.KeyDescriptor,
84498449
return lc.channelState.LocalChanCfg.MultiSigKey,
84508450
lc.channelState.RemoteChanCfg.MultiSigKey
84518451
}
8452+
8453+
func (lc *LightningChannel) ExecDynCommProposal(
8454+
initiator lntypes.ChannelParty,
8455+
proposal lnwire.DynPropose,
8456+
) error {
8457+
panic("NOT IMPLEMENTED: LightningChannel.ExecDyncommProposal")
8458+
}

0 commit comments

Comments
 (0)