multi: add zeroconfacceptor that default rejects if no rpc acceptors

This is a safety mechanism so that zero-conf channels are not accepted
by default if no rpc acceptor exists.
This commit is contained in:
eugene
2022-07-08 17:18:14 -04:00
parent a1cd7734d8
commit c2a4a9adbc
8 changed files with 224 additions and 11 deletions

View File

@@ -1369,6 +1369,18 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
zeroConf = featureVec.IsSet(lnwire.ZeroConfRequired)
scid = featureVec.IsSet(lnwire.ScidAliasRequired)
// If the zero-conf channel type was negotiated, ensure that
// the acceptor allows it.
if zeroConf && !acceptorResp.ZeroConf {
// Fail the funding flow.
flowErr := fmt.Errorf("channel acceptor blocked " +
"zero-conf channel negotiation")
f.failFundingFlow(
peer, msg.PendingChannelID, flowErr,
)
return
}
// If the zero-conf channel type wasn't negotiated and the
// fundee still wants a zero-conf channel, perform more checks.
// Require that both sides have the scid-alias feature bit set.

View File

@@ -25,7 +25,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/chanacceptor"
acpt "github.com/lightningnetwork/lnd/chanacceptor"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channelnotifier"
"github.com/lightningnetwork/lnd/discovery"
@@ -222,6 +222,19 @@ func (m *mockChanEvent) NotifyPendingOpenChannelEvent(outpoint wire.OutPoint,
}
}
// mockZeroConfAcceptor always accepts the channel open request for zero-conf
// channels. It will set the ZeroConf bool in the ChannelAcceptResponse. This
// is needed to properly unit test the zero-conf logic in the funding manager.
type mockZeroConfAcceptor struct{}
func (m *mockZeroConfAcceptor) Accept(
req *acpt.ChannelAcceptRequest) *acpt.ChannelAcceptResponse {
return &acpt.ChannelAcceptResponse{
ZeroConf: true,
}
}
type newChannelMsg struct {
channel *channeldb.OpenChannel
err chan error
@@ -400,7 +413,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
var chanIDSeed [32]byte
chainedAcceptor := chanacceptor.NewChainedAcceptor()
chainedAcceptor := acpt.NewChainedAcceptor()
fundingCfg := Config{
IDKey: privKey.PubKey(),
@@ -556,7 +569,7 @@ func recreateAliceFundingManager(t *testing.T, alice *testNode) {
oldCfg := alice.fundingMgr.cfg
chainedAcceptor := chanacceptor.NewChainedAcceptor()
chainedAcceptor := acpt.NewChainedAcceptor()
f, err := NewFundingManager(Config{
IDKey: oldCfg.IDKey,
@@ -3760,6 +3773,11 @@ func TestFundingManagerZeroConf(t *testing.T) {
*lnwire.NewRawFeatureVector(channelTypeBits...),
)
// Create a default-accept channelacceptor so that the test passes and
// we don't have to use any goroutines.
mockAcceptor := &mockZeroConfAcceptor{}
bob.fundingMgr.cfg.OpenChannelPredicate = mockAcceptor
// Call fundChannel with the zero-conf ChannelType.
fundingTx := fundChannel(
t, alice, bob, fundingAmt, pushAmt, false, 1, updateChan, true,