fundingmanager: use value the _remote_ require us to use in ChannelUpdate

This commit fixes a bug that would make us advertise the remote's
min_htlc value in our channel update.

The min_htlc value is set by a node Alice to limit its exposure to small
HTLCs, and the channel counter party should not forward HTLCs of value
smaller than this to Alice. This means that the value a node Bob should
advertise in its ChannelUpdate, is the min_htlc value the counter party
require all HTLCs to be above.

Instead of populating the ChannelUpdate with the MinHtlc value found in
the remote constraints, we now use the value from the local constraints.
This commit is contained in:
Johan T. Halseth 2018-08-22 09:32:43 +02:00
parent 0c65719613
commit e174fbd759
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -2072,16 +2072,17 @@ func (f *fundingManager) addToRouterGraph(completeChan *channeldb.OpenChannel,
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
// We'll obtain their min HTLC as we'll use this value within our
// ChannelUpdate. We use this value isn't of ours, as the remote party
// will be the one that's carrying the HTLC towards us.
remoteMinHTLC := completeChan.RemoteChanCfg.MinHTLC
// We'll obtain the min HTLC value we can forward in our direction, as
// we'll use this value within our ChannelUpdate. This constraint is
// originally set by the remote node, as it will be the one that will
// need to determine the smallest HTLC it deems economically relevant.
fwdMinHTLC := completeChan.LocalChanCfg.MinHTLC
ann, err := f.newChanAnnouncement(
f.cfg.IDKey, completeChan.IdentityPub,
completeChan.LocalChanCfg.MultiSigKey.PubKey,
completeChan.RemoteChanCfg.MultiSigKey.PubKey, *shortChanID,
chanID, remoteMinHTLC,
chanID, fwdMinHTLC,
)
if err != nil {
return fmt.Errorf("error generating channel "+
@ -2192,11 +2193,12 @@ func (f *fundingManager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
fndgLog.Infof("Announcing ChannelPoint(%v), short_chan_id=%v",
&fundingPoint, spew.Sdump(shortChanID))
// We'll obtain their min HTLC as we'll use this value within
// our ChannelUpdate. We use this value isn't of ours, as the
// remote party will be the one that's carrying the HTLC towards
// us.
remoteMinHTLC := completeChan.RemoteChanCfg.MinHTLC
// We'll obtain the min HTLC value we can forward in our
// direction, as we'll use this value within our ChannelUpdate.
// This constraint is originally set by the remote node, as it
// will be the one that will need to determine the smallest
// HTLC it deems economically relevant.
fwdMinHTLC := completeChan.LocalChanCfg.MinHTLC
// Create and broadcast the proofs required to make this channel
// public and usable for other nodes for routing.
@ -2204,7 +2206,7 @@ func (f *fundingManager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
f.cfg.IDKey, completeChan.IdentityPub,
completeChan.LocalChanCfg.MultiSigKey.PubKey,
completeChan.RemoteChanCfg.MultiSigKey.PubKey,
*shortChanID, chanID, remoteMinHTLC,
*shortChanID, chanID, fwdMinHTLC,
)
if err != nil {
return fmt.Errorf("channel announcement failed: %v", err)
@ -2371,10 +2373,10 @@ type chanAnnouncement struct {
// identity pub keys of both parties to the channel, and the second segment is
// authenticated only by us and contains our directional routing policy for the
// channel.
func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.PublicKey,
func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey,
localFundingKey, remoteFundingKey *btcec.PublicKey,
shortChanID lnwire.ShortChannelID, chanID lnwire.ChannelID,
remoteMinHTLC lnwire.MilliSatoshi) (*chanAnnouncement, error) {
fwdMinHTLC lnwire.MilliSatoshi) (*chanAnnouncement, error) {
chainHash := *f.cfg.Wallet.Cfg.NetParams.GenesisHash
@ -2428,9 +2430,10 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
Flags: chanFlags,
TimeLockDelta: uint16(f.cfg.DefaultRoutingPolicy.TimeLockDelta),
// We use the *remote* party's HtlcMinimumMsat, as they'll be
// the ones carrying the HTLC routed *towards* us.
HtlcMinimumMsat: remoteMinHTLC,
// We use the HtlcMinimumMsat that the remote party required us
// to use, as our ChannelUpdate will be used to carry HTLCs
// towards them.
HtlcMinimumMsat: fwdMinHTLC,
BaseFee: uint32(f.cfg.DefaultRoutingPolicy.BaseFee),
FeeRate: uint32(f.cfg.DefaultRoutingPolicy.FeeRate),
@ -2509,7 +2512,7 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
// finish, either successfully or with an error.
func (f *fundingManager) announceChannel(localIDKey, remoteIDKey, localFundingKey,
remoteFundingKey *btcec.PublicKey, shortChanID lnwire.ShortChannelID,
chanID lnwire.ChannelID, remoteMinHTLC lnwire.MilliSatoshi) error {
chanID lnwire.ChannelID, fwdMinHTLC lnwire.MilliSatoshi) error {
// First, we'll create the batch of announcements to be sent upon
// initial channel creation. This includes the channel announcement
@ -2517,7 +2520,7 @@ func (f *fundingManager) announceChannel(localIDKey, remoteIDKey, localFundingKe
// proof needed to fully authenticate the channel.
ann, err := f.newChanAnnouncement(localIDKey, remoteIDKey,
localFundingKey, remoteFundingKey, shortChanID, chanID,
remoteMinHTLC,
fwdMinHTLC,
)
if err != nil {
fndgLog.Errorf("can't generate channel announcement: %v", err)