Merge pull request #3081 from halseth/route-remove-totalfees
routing/route+multi: remove redundant TotalFees field
This commit is contained in:
commit
2c1c29e060
@ -361,7 +361,7 @@ func deserializeHop(r io.Reader) (*route.Hop, error) {
|
|||||||
|
|
||||||
func serializeRoute(w io.Writer, r route.Route) error {
|
func serializeRoute(w io.Writer, r route.Route) error {
|
||||||
if err := WriteElements(w,
|
if err := WriteElements(w,
|
||||||
r.TotalTimeLock, r.TotalFees, r.TotalAmount, r.SourcePubKey[:],
|
r.TotalTimeLock, r.TotalAmount, r.SourcePubKey[:],
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -382,7 +382,7 @@ func serializeRoute(w io.Writer, r route.Route) error {
|
|||||||
func deserializeRoute(r io.Reader) (route.Route, error) {
|
func deserializeRoute(r io.Reader) (route.Route, error) {
|
||||||
rt := route.Route{}
|
rt := route.Route{}
|
||||||
if err := ReadElements(r,
|
if err := ReadElements(r,
|
||||||
&rt.TotalTimeLock, &rt.TotalFees, &rt.TotalAmount,
|
&rt.TotalTimeLock, &rt.TotalAmount,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return rt, err
|
return rt, err
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ var (
|
|||||||
|
|
||||||
testRoute = route.Route{
|
testRoute = route.Route{
|
||||||
TotalTimeLock: 123,
|
TotalTimeLock: 123,
|
||||||
TotalFees: 999,
|
|
||||||
TotalAmount: 1234567,
|
TotalAmount: 1234567,
|
||||||
SourcePubKey: route.NewVertex(pub),
|
SourcePubKey: route.NewVertex(pub),
|
||||||
Hops: []*route.Hop{
|
Hops: []*route.Hop{
|
||||||
|
@ -185,8 +185,8 @@ func calculateFeeLimit(feeLimit *lnrpc.FeeLimit,
|
|||||||
func (r *RouterBackend) MarshallRoute(route *route.Route) *lnrpc.Route {
|
func (r *RouterBackend) MarshallRoute(route *route.Route) *lnrpc.Route {
|
||||||
resp := &lnrpc.Route{
|
resp := &lnrpc.Route{
|
||||||
TotalTimeLock: route.TotalTimeLock,
|
TotalTimeLock: route.TotalTimeLock,
|
||||||
TotalFees: int64(route.TotalFees.ToSatoshis()),
|
TotalFees: int64(route.TotalFees().ToSatoshis()),
|
||||||
TotalFeesMsat: int64(route.TotalFees),
|
TotalFeesMsat: int64(route.TotalFees()),
|
||||||
TotalAmt: int64(route.TotalAmount.ToSatoshis()),
|
TotalAmt: int64(route.TotalAmount.ToSatoshis()),
|
||||||
TotalAmtMsat: int64(route.TotalAmount),
|
TotalAmtMsat: int64(route.TotalAmount),
|
||||||
Hops: make([]*lnrpc.Hop, len(route.Hops)),
|
Hops: make([]*lnrpc.Hop, len(route.Hops)),
|
||||||
|
@ -55,8 +55,6 @@ func TestQueryRoutes(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
rt := &route.Route{}
|
|
||||||
|
|
||||||
findRoute := func(source, target route.Vertex,
|
findRoute := func(source, target route.Vertex,
|
||||||
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
|
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
|
||||||
finalExpiry ...uint16) (*route.Route, error) {
|
finalExpiry ...uint16) (*route.Route, error) {
|
||||||
@ -95,7 +93,8 @@ func TestQueryRoutes(t *testing.T) {
|
|||||||
t.Fatal("unexpected ignored node")
|
t.Fatal("unexpected ignored node")
|
||||||
}
|
}
|
||||||
|
|
||||||
return rt, nil
|
hops := []*route.Hop{&route.Hop{}}
|
||||||
|
return route.NewRouteFromHops(amt, 144, source, hops)
|
||||||
}
|
}
|
||||||
|
|
||||||
backend := &RouterBackend{
|
backend := &RouterBackend{
|
||||||
|
@ -269,7 +269,7 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &RouteFeeResponse{
|
return &RouteFeeResponse{
|
||||||
RoutingFeeMsat: int64(route.TotalFees),
|
RoutingFeeMsat: int64(route.TotalFees()),
|
||||||
TimeLockDelay: int64(route.TotalTimeLock),
|
TimeLockDelay: int64(route.TotalTimeLock),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -69,11 +69,6 @@ type Route struct {
|
|||||||
// the payment preimage to complete the payment.
|
// the payment preimage to complete the payment.
|
||||||
TotalTimeLock uint32
|
TotalTimeLock uint32
|
||||||
|
|
||||||
// TotalFees is the sum of the fees paid at each hop within the final
|
|
||||||
// route. In the case of a one-hop payment, this value will be zero as
|
|
||||||
// we don't need to pay a fee to ourself.
|
|
||||||
TotalFees lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// TotalAmount is the total amount of funds required to complete a
|
// TotalAmount is the total amount of funds required to complete a
|
||||||
// payment over this route. This value includes the cumulative fees at
|
// payment over this route. This value includes the cumulative fees at
|
||||||
// each hop. As a result, the HTLC extended to the first-hop in the
|
// each hop. As a result, the HTLC extended to the first-hop in the
|
||||||
@ -104,6 +99,13 @@ func (r *Route) HopFee(hopIndex int) lnwire.MilliSatoshi {
|
|||||||
return incomingAmt - r.Hops[hopIndex].AmtToForward
|
return incomingAmt - r.Hops[hopIndex].AmtToForward
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TotalFees is the sum of the fees paid at each hop within the final route. In
|
||||||
|
// the case of a one-hop payment, this value will be zero as we don't need to
|
||||||
|
// pay a fee to ourself.
|
||||||
|
func (r *Route) TotalFees() lnwire.MilliSatoshi {
|
||||||
|
return r.TotalAmount - r.Hops[len(r.Hops)-1].AmtToForward
|
||||||
|
}
|
||||||
|
|
||||||
// NewRouteFromHops creates a new Route structure from the minimally required
|
// NewRouteFromHops creates a new Route structure from the minimally required
|
||||||
// information to perform the payment. It infers fee amounts and populates the
|
// information to perform the payment. It infers fee amounts and populates the
|
||||||
// node, chan and prev/next hop maps.
|
// node, chan and prev/next hop maps.
|
||||||
@ -124,7 +126,6 @@ func NewRouteFromHops(amtToSend lnwire.MilliSatoshi, timeLock uint32,
|
|||||||
Hops: hops,
|
Hops: hops,
|
||||||
TotalTimeLock: timeLock,
|
TotalTimeLock: timeLock,
|
||||||
TotalAmount: amtToSend,
|
TotalAmount: amtToSend,
|
||||||
TotalFees: amtToSend - hops[len(hops)-1].AmtToForward,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return route, nil
|
return route, nil
|
||||||
|
@ -198,7 +198,7 @@ func TestFindRoutesWithFeeLimit(t *testing.T) {
|
|||||||
t.Fatalf("unable to find any routes: %v", err)
|
t.Fatalf("unable to find any routes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if route.TotalFees > restrictions.FeeLimit {
|
if route.TotalFees() > restrictions.FeeLimit {
|
||||||
t.Fatalf("route exceeded fee limit: %v", spew.Sdump(route))
|
t.Fatalf("route exceeded fee limit: %v", spew.Sdump(route))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2753,7 +2753,7 @@ func (r *rpcServer) savePayment(route *route.Route,
|
|||||||
CreationDate: time.Now(),
|
CreationDate: time.Now(),
|
||||||
},
|
},
|
||||||
Path: paymentPath,
|
Path: paymentPath,
|
||||||
Fee: route.TotalFees,
|
Fee: route.TotalFees(),
|
||||||
TimeLockLength: route.TotalTimeLock,
|
TimeLockLength: route.TotalTimeLock,
|
||||||
}
|
}
|
||||||
copy(payment.PaymentPreimage[:], preImage)
|
copy(payment.PaymentPreimage[:], preImage)
|
||||||
@ -3123,7 +3123,7 @@ func (r *rpcServer) dispatchPaymentIntent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate amount paid to receiver.
|
// Calculate amount paid to receiver.
|
||||||
amt := route.TotalAmount - route.TotalFees
|
amt := route.TotalAmount - route.TotalFees()
|
||||||
|
|
||||||
// Save the completed payment to the database for record keeping
|
// Save the completed payment to the database for record keeping
|
||||||
// purposes.
|
// purposes.
|
||||||
|
Loading…
Reference in New Issue
Block a user