routing/route+multi: remove redundant TotalFees field

Instead get it on demand using method TotalFees().
This commit is contained in:
Johan T. Halseth 2019-05-15 14:37:58 +02:00
parent 27ae22fa6c
commit 15bed506b1
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
8 changed files with 17 additions and 18 deletions

@ -361,7 +361,7 @@ func deserializeHop(r io.Reader) (*route.Hop, error) {
func serializeRoute(w io.Writer, r route.Route) error {
if err := WriteElements(w,
r.TotalTimeLock, r.TotalFees, r.TotalAmount, r.SourcePubKey[:],
r.TotalTimeLock, r.TotalAmount, r.SourcePubKey[:],
); err != nil {
return err
}
@ -382,7 +382,7 @@ func serializeRoute(w io.Writer, r route.Route) error {
func deserializeRoute(r io.Reader) (route.Route, error) {
rt := route.Route{}
if err := ReadElements(r,
&rt.TotalTimeLock, &rt.TotalFees, &rt.TotalAmount,
&rt.TotalTimeLock, &rt.TotalAmount,
); err != nil {
return rt, err
}

@ -27,7 +27,6 @@ var (
testRoute = route.Route{
TotalTimeLock: 123,
TotalFees: 999,
TotalAmount: 1234567,
SourcePubKey: route.NewVertex(pub),
Hops: []*route.Hop{

@ -185,8 +185,8 @@ func calculateFeeLimit(feeLimit *lnrpc.FeeLimit,
func (r *RouterBackend) MarshallRoute(route *route.Route) *lnrpc.Route {
resp := &lnrpc.Route{
TotalTimeLock: route.TotalTimeLock,
TotalFees: int64(route.TotalFees.ToSatoshis()),
TotalFeesMsat: int64(route.TotalFees),
TotalFees: int64(route.TotalFees().ToSatoshis()),
TotalFeesMsat: int64(route.TotalFees()),
TotalAmt: int64(route.TotalAmount.ToSatoshis()),
TotalAmtMsat: int64(route.TotalAmount),
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,
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
finalExpiry ...uint16) (*route.Route, error) {
@ -95,7 +93,8 @@ func TestQueryRoutes(t *testing.T) {
t.Fatal("unexpected ignored node")
}
return rt, nil
hops := []*route.Hop{&route.Hop{}}
return route.NewRouteFromHops(amt, 144, source, hops)
}
backend := &RouterBackend{

@ -269,7 +269,7 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
}
return &RouteFeeResponse{
RoutingFeeMsat: int64(route.TotalFees),
RoutingFeeMsat: int64(route.TotalFees()),
TimeLockDelay: int64(route.TotalTimeLock),
}, nil
}

@ -69,11 +69,6 @@ type Route struct {
// the payment preimage to complete the payment.
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
// 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
@ -104,6 +99,13 @@ func (r *Route) HopFee(hopIndex int) lnwire.MilliSatoshi {
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
// information to perform the payment. It infers fee amounts and populates the
// node, chan and prev/next hop maps.
@ -124,7 +126,6 @@ func NewRouteFromHops(amtToSend lnwire.MilliSatoshi, timeLock uint32,
Hops: hops,
TotalTimeLock: timeLock,
TotalAmount: amtToSend,
TotalFees: amtToSend - hops[len(hops)-1].AmtToForward,
}
return route, nil

@ -199,7 +199,7 @@ func TestFindRoutesWithFeeLimit(t *testing.T) {
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))
}

@ -2753,7 +2753,7 @@ func (r *rpcServer) savePayment(route *route.Route,
CreationDate: time.Now(),
},
Path: paymentPath,
Fee: route.TotalFees,
Fee: route.TotalFees(),
TimeLockLength: route.TotalTimeLock,
}
copy(payment.PaymentPreimage[:], preImage)
@ -3123,7 +3123,7 @@ func (r *rpcServer) dispatchPaymentIntent(
}
// 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
// purposes.