From 71faeda4174a1b1362470ace3b0cf320ad3839fd Mon Sep 17 00:00:00 2001 From: positiveblue Date: Thu, 28 Jul 2022 20:36:56 -0700 Subject: [PATCH] channel acceptor: check channel announcebility/confirmations --- channel_acceptor.go | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/channel_acceptor.go b/channel_acceptor.go index cc472c9..6ccebd1 100644 --- a/channel_acceptor.go +++ b/channel_acceptor.go @@ -174,5 +174,45 @@ func (s *ChannelAcceptor) acceptChannel(_ context.Context, }, nil } - return &lndclient.AcceptorResponse{Accept: true}, nil + fundingFlags := lnwire.FundingFlag(req.ChannelFlags) + isPrivateChan := fundingFlags&lnwire.FFAnnounceChannel == 0 + + // Check that the new channel is announced/unannounced as expected. + if isPrivateChan != expectedChanBid.UnannouncedChannel { + var errMsg string + errTemplate := "expected an %s channel but received an %s one" + + if expectedChanBid.UnannouncedChannel { + errMsg = fmt.Sprintf(errTemplate, "unannounced", + "announced") + } else { + errMsg = fmt.Sprintf(errTemplate, "announced", + "unannounced") + } + + return &lndclient.AcceptorResponse{ + Accept: false, + Error: errMsg, + }, nil + } + + // Check that the channel is a zero conf channel if we were expecting + // one. + if expectedChanBid.ZeroConfChannel { + if !req.WantsZeroConf { + return &lndclient.AcceptorResponse{ + Accept: false, + Error: "expected zero conf channel", + }, nil + } + return &lndclient.AcceptorResponse{ + Accept: true, + MinAcceptDepth: 0, + ZeroConf: true, + }, nil + } + + return &lndclient.AcceptorResponse{ + Accept: true, + }, nil }