From 2c9a0398454f20c358696af7ee098de14fa126c0 Mon Sep 17 00:00:00 2001 From: whythat Date: Wed, 10 Oct 2018 11:28:39 +0300 Subject: [PATCH] config: add option to disable incoming push amounts in OpenChannel This is useful for merchant-side prevention of accidental pushes during channel opening. --- config.go | 2 ++ fundingmanager.go | 9 +++++++++ lnwallet/errors.go | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/config.go b/config.go index 26e4c522..a571bacc 100644 --- a/config.go +++ b/config.go @@ -235,6 +235,8 @@ type config struct { NoChanUpdates bool `long:"nochanupdates" description:"If specified, lnd will not request real-time channel updates from connected peers. This option should be used by routing nodes to save bandwidth."` + RejectPush bool `long:"rejectpush" description:"If true, lnd will not accept channel opening requests with non-zero push amounts. This should prevent accidental pushes to merchant nodes."` + net tor.Net Routing *routing.Conf `group:"routing" namespace:"routing"` diff --git a/fundingmanager.go b/fundingmanager.go index 0acfadcf..63457074 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -1032,6 +1032,15 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) { return } + // If request specifies non-zero push amount and 'rejectpush' is set, + // signal an error. + if cfg.RejectPush && msg.PushAmount > 0 { + f.failFundingFlow( + fmsg.peer, fmsg.msg.PendingChannelID, + lnwallet.ErrNonZeroPushAmount()) + return + } + fndgLog.Infof("Recv'd fundingRequest(amt=%v, push=%v, delay=%v, "+ "pendingId=%x) from peer(%x)", amt, msg.PushAmount, msg.CsvDelay, msg.PendingChannelID, diff --git a/lnwallet/errors.go b/lnwallet/errors.go index f36d0b99..0d208623 100644 --- a/lnwallet/errors.go +++ b/lnwallet/errors.go @@ -78,6 +78,13 @@ func ErrChanReserveTooLarge(reserve, } } +// ErrNonZeroPushAmount is returned by a remote peer that receives a +// FundingOpen request for a channel with non-zero push amount while +// they have 'rejectpush' enabled. +func ErrNonZeroPushAmount() ReservationError { + return ReservationError{errors.New("Non-zero push amounts are disabled")} +} + // ErrMinHtlcTooLarge returns an error indicating that the MinHTLC value the // remote required is too large to be accepted. func ErrMinHtlcTooLarge(minHtlc,