funding: when crafting our ChannelUpdate use the remote party's minHTLC

In this commit, we implement a recent spec change that require nodes to
advertise the minHTLC of the remote node within their ChannelUpdate. We
do this as it will be the remote node which carries the HTLC towards
us, therefore we should advertise *their* minHTLC value.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-30 22:52:28 -08:00
parent 55bdf25235
commit c081b386d2
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1650,11 +1650,18 @@ func (f *fundingManager) sendChannelAnnouncement(completeChan *channeldb.OpenCha
fndgLog.Infof("Announcing ChannelPoint(%v), short_chan_id=%v", fndgLog.Infof("Announcing ChannelPoint(%v), short_chan_id=%v",
&fundingPoint, spew.Sdump(shortChanID)) &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
// Register the new link with the L3 routing manager so this new // Register the new link with the L3 routing manager so this new
// channel can be utilized during path finding. // channel can be utilized during path finding.
err := f.announceChannel(f.cfg.IDKey, completeChan.IdentityPub, err := f.announceChannel(f.cfg.IDKey, completeChan.IdentityPub,
completeChan.LocalChanCfg.MultiSigKey, completeChan.LocalChanCfg.MultiSigKey,
completeChan.RemoteChanCfg.MultiSigKey, *shortChanID, chanID) completeChan.RemoteChanCfg.MultiSigKey, *shortChanID, chanID,
remoteMinHTLC,
)
if err != nil { if err != nil {
return fmt.Errorf("channel announcement failed: %v", err) return fmt.Errorf("channel announcement failed: %v", err)
} }
@ -1853,8 +1860,8 @@ type chanAnnouncement struct {
// channel. // channel.
func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.PublicKey, func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.PublicKey,
localFundingKey, remoteFundingKey *btcec.PublicKey, localFundingKey, remoteFundingKey *btcec.PublicKey,
shortChanID lnwire.ShortChannelID, shortChanID lnwire.ShortChannelID, chanID lnwire.ChannelID,
chanID lnwire.ChannelID) (*chanAnnouncement, error) { remoteMinHTLC lnwire.MilliSatoshi) (*chanAnnouncement, error) {
chainHash := *f.cfg.Wallet.Cfg.NetParams.GenesisHash chainHash := *f.cfg.Wallet.Cfg.NetParams.GenesisHash
@ -1871,7 +1878,7 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
// being updated within the ChannelUpdateAnnouncement announcement // being updated within the ChannelUpdateAnnouncement announcement
// below. A value of zero means it's the edge of the "first" node and 1 // below. A value of zero means it's the edge of the "first" node and 1
// being the other node. // being the other node.
var chanFlags uint16 var chanFlags lnwire.ChanUpdateFlag
// The lexicographical ordering of the two identity public keys of the // The lexicographical ordering of the two identity public keys of the
// nodes indicates which of the nodes is "first". If our serialized // nodes indicates which of the nodes is "first". If our serialized
@ -1900,14 +1907,18 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
} }
chanUpdateAnn := &lnwire.ChannelUpdate{ chanUpdateAnn := &lnwire.ChannelUpdate{
ShortChannelID: shortChanID, ShortChannelID: shortChanID,
ChainHash: chainHash, ChainHash: chainHash,
Timestamp: uint32(time.Now().Unix()), Timestamp: uint32(time.Now().Unix()),
Flags: chanFlags, Flags: chanFlags,
TimeLockDelta: uint16(f.cfg.DefaultRoutingPolicy.TimeLockDelta), TimeLockDelta: uint16(f.cfg.DefaultRoutingPolicy.TimeLockDelta),
HtlcMinimumMsat: f.cfg.DefaultRoutingPolicy.MinHTLC,
BaseFee: uint32(f.cfg.DefaultRoutingPolicy.BaseFee), // We use the *remote* party's HtlcMinimumMsat, as they'll be
FeeRate: uint32(f.cfg.DefaultRoutingPolicy.FeeRate), // the ones carrying the HTLC routed *towards* us.
HtlcMinimumMsat: remoteMinHTLC,
BaseFee: uint32(f.cfg.DefaultRoutingPolicy.BaseFee),
FeeRate: uint32(f.cfg.DefaultRoutingPolicy.FeeRate),
} }
// With the channel update announcement constructed, we'll generate a // With the channel update announcement constructed, we'll generate a
@ -1972,14 +1983,16 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
// finish, either successfully or with an error. // finish, either successfully or with an error.
func (f *fundingManager) announceChannel(localIDKey, remoteIDKey, localFundingKey, func (f *fundingManager) announceChannel(localIDKey, remoteIDKey, localFundingKey,
remoteFundingKey *btcec.PublicKey, shortChanID lnwire.ShortChannelID, remoteFundingKey *btcec.PublicKey, shortChanID lnwire.ShortChannelID,
chanID lnwire.ChannelID) error { chanID lnwire.ChannelID, remoteMinHTLC lnwire.MilliSatoshi) error {
// First, we'll create the batch of announcements to be sent upon // First, we'll create the batch of announcements to be sent upon
// initial channel creation. This includes the channel announcement // initial channel creation. This includes the channel announcement
// itself, the channel update announcement, and our half of the channel // itself, the channel update announcement, and our half of the channel
// proof needed to fully authenticate the channel. // proof needed to fully authenticate the channel.
ann, err := f.newChanAnnouncement(localIDKey, remoteIDKey, ann, err := f.newChanAnnouncement(localIDKey, remoteIDKey,
localFundingKey, remoteFundingKey, shortChanID, chanID) localFundingKey, remoteFundingKey, shortChanID, chanID,
remoteMinHTLC,
)
if err != nil { if err != nil {
fndgLog.Errorf("can't generate channel announcement: %v", err) fndgLog.Errorf("can't generate channel announcement: %v", err)
return err return err