funding: extract defaultForwardingPolicy

This commit is contained in:
Oliver Gugger committed 2023-08-18 09:44:06 +02:00
1 parent 665179ece2
commit 5b9aa63cec
1 file changed
+19 -18
+19 -18
View File
@@ -1747,13 +1747,10 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
minHtlc = acceptorResp.MinHtlcIn minHtlc = acceptorResp.MinHtlcIn
} }
// If we are handling a FundingOpen request then we need to // If we are handling a FundingOpen request then we need to specify the
// specify the default channel fees since they are not provided // default channel fees since they are not provided by the responder
// by the responder interactively. // interactively.
forwardingPolicy := htlcswitch.ForwardingPolicy{ forwardingPolicy := f.defaultForwardingPolicy()
BaseFee: f.cfg.DefaultRoutingPolicy.BaseFee,
FeeRate: f.cfg.DefaultRoutingPolicy.FeeRate,
}
// Once the reservation has been created successfully, we add it to // Once the reservation has been created successfully, we add it to
// this peer's map of pending reservations to track this particular // this peer's map of pending reservations to track this particular
@@ -1765,7 +1762,7 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
resCtx := &reservationWithCtx{ resCtx := &reservationWithCtx{
reservation: reservation, reservation: reservation,
chanAmt: amt, chanAmt: amt,
forwardingPolicy: forwardingPolicy, forwardingPolicy: *forwardingPolicy,
remoteCsvDelay: remoteCsvDelay, remoteCsvDelay: remoteCsvDelay,
remoteMinHtlc: minHtlc, remoteMinHtlc: minHtlc,
remoteMaxValue: remoteMaxValue, remoteMaxValue: remoteMaxValue,
@@ -4282,14 +4279,10 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
maxHtlcs = f.cfg.RequiredRemoteMaxHTLCs(capacity) maxHtlcs = f.cfg.RequiredRemoteMaxHTLCs(capacity)
} }
// Prepare the optional channel fee values from the initFundingMsg. // Prepare the optional channel fee values from the initFundingMsg. If
// If useBaseFee or useFeeRate are false the client did not // useBaseFee or useFeeRate are false the client did not provide fee
// provide fee values hence we assume default fee settings from // values hence we assume default fee settings from the config.
// the config. forwardingPolicy := f.defaultForwardingPolicy()
forwardingPolicy := htlcswitch.ForwardingPolicy{
BaseFee: f.cfg.DefaultRoutingPolicy.BaseFee,
FeeRate: f.cfg.DefaultRoutingPolicy.FeeRate,
}
if baseFee != nil { if baseFee != nil {
forwardingPolicy.BaseFee = lnwire.MilliSatoshi(*baseFee) forwardingPolicy.BaseFee = lnwire.MilliSatoshi(*baseFee)
} }
@@ -4327,7 +4320,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
resCtx := &reservationWithCtx{ resCtx := &reservationWithCtx{
chanAmt: capacity, chanAmt: capacity,
forwardingPolicy: forwardingPolicy, forwardingPolicy: *forwardingPolicy,
remoteCsvDelay: remoteCsvDelay, remoteCsvDelay: remoteCsvDelay,
remoteMinHtlc: minHtlcIn, remoteMinHtlc: minHtlcIn,
remoteMaxValue: maxValue, remoteMaxValue: maxValue,
@@ -4621,7 +4614,15 @@ func copyPubKey(pub *btcec.PublicKey) *btcec.PublicKey {
return btcec.NewPublicKey(&tmp.X, &tmp.Y) return btcec.NewPublicKey(&tmp.X, &tmp.Y)
} }
// saveInitialFwdingPolicy saves the forwarding policy for the provided // defaultForwardingPolicy returns the default forwarding policy.
func (f *Manager) defaultForwardingPolicy() *htlcswitch.ForwardingPolicy {
return &htlcswitch.ForwardingPolicy{
BaseFee: f.cfg.DefaultRoutingPolicy.BaseFee,
FeeRate: f.cfg.DefaultRoutingPolicy.FeeRate,
}
}
// saveInitialForwardingPolicy saves the forwarding policy for the provided
// chanPoint in the channelOpeningStateBucket. // chanPoint in the channelOpeningStateBucket.
func (f *Manager) saveInitialFwdingPolicy(permChanID lnwire.ChannelID, func (f *Manager) saveInitialFwdingPolicy(permChanID lnwire.ChannelID,
forwardingPolicy *htlcswitch.ForwardingPolicy) error { forwardingPolicy *htlcswitch.ForwardingPolicy) error {