zpay32: move HopHint and DefaultFinalCLTVDelta

This commit is contained in:
Joost Jager committed 2019-03-15 10:08:32 +01:00
1 parent 652ebb1652
commit 2be1051fb6
11 files changed
+70 -66

No files matched your search

+2 -1
View File
@@ -8,6 +8,7 @@ import (
"github.com/coreos/bbolt"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/zpay32"
)
const (
@@ -152,7 +153,7 @@ func (m *missionControl) GraphPruneView() graphPruneView {
// view from Mission Control. An optional set of routing hints can be provided
// in order to populate additional edges to explore when finding a path to the
// payment's destination.
func (m *missionControl) NewPaymentSession(routeHints [][]HopHint,
func (m *missionControl) NewPaymentSession(routeHints [][]zpay32.HopHint,
target Vertex) (*paymentSession, error) {
viewSnapshot := m.GraphPruneView()
-22
View File
@@ -39,28 +39,6 @@ const (
RiskFactorBillionths = 15
)
// HopHint is a routing hint that contains the minimum information of a channel
// required for an intermediate hop in a route to forward the payment to the
// next. This should be ideally used for private channels, since they are not
// publicly advertised to the network for routing.
type HopHint struct {
// NodeID is the public key of the node at the start of the channel.
NodeID *btcec.PublicKey
// ChannelID is the unique identifier of the channel.
ChannelID uint64
// FeeBaseMSat is the base fee of the channel in millisatoshis.
FeeBaseMSat uint32
// FeeProportionalMillionths is the fee rate, in millionths of a
// satoshi, for every satoshi sent through the channel.
FeeProportionalMillionths uint32
// CLTVExpiryDelta is the time-lock delta of the channel.
CLTVExpiryDelta uint16
}
// Hop represents an intermediate or final node of the route. This naming
// is in line with the definition given in BOLT #4: Onion Routing Protocol.
// The struct houses the channel along which this hop can be reached and
+11 -10
View File
@@ -22,6 +22,7 @@ import (
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/zpay32"
)
const (
@@ -1746,11 +1747,11 @@ func TestPathFindSpecExample(t *testing.T) {
// The CLTV expiry should be the current height plus 9 (the expiry for
// the B -> C channel.
if firstRoute.TotalTimeLock !=
startingHeight+DefaultFinalCLTVDelta {
startingHeight+zpay32.DefaultFinalCLTVDelta {
t.Fatalf("wrong total time lock: got %v, expecting %v",
firstRoute.TotalTimeLock,
startingHeight+DefaultFinalCLTVDelta)
startingHeight+zpay32.DefaultFinalCLTVDelta)
}
// Next, we'll set A as the source node so we can assert that we create
@@ -1845,11 +1846,11 @@ func TestPathFindSpecExample(t *testing.T) {
// The outgoing CLTV value itself should be the current height plus 30
// to meet Carol's requirements.
if routes[0].Hops[0].OutgoingTimeLock !=
startingHeight+DefaultFinalCLTVDelta {
startingHeight+zpay32.DefaultFinalCLTVDelta {
t.Fatalf("wrong total time lock: got %v, expecting %v",
routes[0].Hops[0].OutgoingTimeLock,
startingHeight+DefaultFinalCLTVDelta)
startingHeight+zpay32.DefaultFinalCLTVDelta)
}
// For B -> C, we assert that the final hop also has the proper
@@ -1860,11 +1861,11 @@ func TestPathFindSpecExample(t *testing.T) {
lastHop.AmtToForward, amt)
}
if lastHop.OutgoingTimeLock !=
startingHeight+DefaultFinalCLTVDelta {
startingHeight+zpay32.DefaultFinalCLTVDelta {
t.Fatalf("wrong total time lock: got %v, expecting %v",
lastHop.OutgoingTimeLock,
startingHeight+DefaultFinalCLTVDelta)
startingHeight+zpay32.DefaultFinalCLTVDelta)
}
// We'll also make similar assertions for the second route from A to C
@@ -1875,7 +1876,7 @@ func TestPathFindSpecExample(t *testing.T) {
t.Fatalf("wrong amount: got %v, expected %v",
secondRoute.TotalAmount, expectedAmt)
}
expectedTimeLock := startingHeight + daveFinalCLTV + DefaultFinalCLTVDelta
expectedTimeLock := startingHeight + daveFinalCLTV + zpay32.DefaultFinalCLTVDelta
if secondRoute.TotalTimeLock != uint32(expectedTimeLock) {
t.Fatalf("wrong total time lock: got %v, expecting %v",
secondRoute.TotalTimeLock, expectedTimeLock)
@@ -1885,7 +1886,7 @@ func TestPathFindSpecExample(t *testing.T) {
t.Fatalf("wrong forward amount: got %v, expected %v",
onionPayload.AmtToForward, amt)
}
expectedTimeLock = startingHeight + DefaultFinalCLTVDelta
expectedTimeLock = startingHeight + zpay32.DefaultFinalCLTVDelta
if onionPayload.OutgoingTimeLock != uint32(expectedTimeLock) {
t.Fatalf("wrong outgoing time lock: got %v, expecting %v",
onionPayload.OutgoingTimeLock,
@@ -1899,11 +1900,11 @@ func TestPathFindSpecExample(t *testing.T) {
lastHop.AmtToForward, amt)
}
if lastHop.OutgoingTimeLock !=
startingHeight+DefaultFinalCLTVDelta {
startingHeight+zpay32.DefaultFinalCLTVDelta {
t.Fatalf("wrong total time lock: got %v, expecting %v",
lastHop.OutgoingTimeLock,
startingHeight+DefaultFinalCLTVDelta)
startingHeight+zpay32.DefaultFinalCLTVDelta)
}
}
+4 -7
View File
@@ -25,13 +25,10 @@ import (
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/multimutex"
"github.com/lightningnetwork/lnd/routing/chainview"
"github.com/lightningnetwork/lnd/zpay32"
)
const (
// DefaultFinalCLTVDelta is the default value to be used as the final
// CLTV delta for a route if one is unspecified.
DefaultFinalCLTVDelta = 9
// defaultPayAttemptTimeout is a duration that we'll use to determine
// if we should give up on a payment attempt. This will be used if a
// value isn't specified in the LightningNode struct.
@@ -1331,7 +1328,7 @@ func (r *ChannelRouter) FindRoutes(source, target Vertex,
var finalCLTVDelta uint16
if len(finalExpiry) == 0 {
finalCLTVDelta = DefaultFinalCLTVDelta
finalCLTVDelta = zpay32.DefaultFinalCLTVDelta
} else {
finalCLTVDelta = finalExpiry[0]
}
@@ -1551,7 +1548,7 @@ type LightningPayment struct {
// multiple routes, ensure the hop hints within each route are chained
// together and sorted in forward order in order to reach the
// destination successfully.
RouteHints [][]HopHint
RouteHints [][]zpay32.HopHint
// OutgoingChannelID is the channel that needs to be taken to the first
// hop. If nil, any channel may be used.
@@ -1628,7 +1625,7 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
var finalCLTVDelta uint16
if payment.FinalCLTVDelta == nil {
finalCLTVDelta = DefaultFinalCLTVDelta
finalCLTVDelta = zpay32.DefaultFinalCLTVDelta
} else {
finalCLTVDelta = *payment.FinalCLTVDelta
}
+5 -4
View File
@@ -19,6 +19,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/zpay32"
)
// defaultNumRoutes is the default value for the maximum number of routes to
@@ -186,7 +187,7 @@ func TestFindRoutesFeeSorting(t *testing.T) {
routes, err := ctx.router.FindRoutes(
ctx.router.selfNode.PubKeyBytes,
target, paymentAmt, noRestrictions, defaultNumRoutes,
DefaultFinalCLTVDelta,
zpay32.DefaultFinalCLTVDelta,
)
if err != nil {
t.Fatalf("unable to find any routes: %v", err)
@@ -248,7 +249,7 @@ func TestFindRoutesWithFeeLimit(t *testing.T) {
routes, err := ctx.router.FindRoutes(
ctx.router.selfNode.PubKeyBytes,
target, paymentAmt, restrictions, defaultNumRoutes,
DefaultFinalCLTVDelta,
zpay32.DefaultFinalCLTVDelta,
)
if err != nil {
t.Fatalf("unable to find any routes: %v", err)
@@ -1345,7 +1346,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
routes, err := ctx.router.FindRoutes(
ctx.router.selfNode.PubKeyBytes,
targetPubKeyBytes, paymentAmt, noRestrictions, defaultNumRoutes,
DefaultFinalCLTVDelta,
zpay32.DefaultFinalCLTVDelta,
)
if err != nil {
t.Fatalf("unable to find any routes: %v", err)
@@ -1391,7 +1392,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
routes, err = ctx.router.FindRoutes(
ctx.router.selfNode.PubKeyBytes,
targetPubKeyBytes, paymentAmt, noRestrictions, defaultNumRoutes,
DefaultFinalCLTVDelta,
zpay32.DefaultFinalCLTVDelta,
)
if err != nil {
t.Fatalf("unable to find any routes: %v", err)