Skip to content

Commit ae3abc2

Browse files
committed
wip
1 parent 1448c5e commit ae3abc2

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
@@ -2532,6 +2536,65 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
25322536
// If we can immediately send an Stfu response back , we will.
25332537
l.drivePendingStfuSends()
25342538

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+
25352598
// In the case where we receive a warning message from our peer, just
25362599
// log it and move on. We choose not to disconnect from our peer,
25372600
// 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
@@ -8724,3 +8724,10 @@ func (lc *LightningChannel) MultiSigKeys() (keychain.KeyDescriptor,
87248724
return lc.channelState.LocalChanCfg.MultiSigKey,
87258725
lc.channelState.RemoteChanCfg.MultiSigKey
87268726
}
8727+
8728+
func (lc *LightningChannel) ExecDynCommProposal(
8729+
initiator lntypes.ChannelParty,
8730+
proposal lnwire.DynPropose,
8731+
) error {
8732+
panic("NOT IMPLEMENTED: LightningChannel.ExecDyncommProposal")
8733+
}

0 commit comments

Comments
 (0)