routing: add clock to router config
This commit is contained in:
parent
c357511051
commit
8558534417
@ -17,6 +17,7 @@ import (
|
||||
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
@ -302,6 +303,9 @@ type Config struct {
|
||||
|
||||
// PathFindingConfig defines global path finding parameters.
|
||||
PathFindingConfig PathFindingConfig
|
||||
|
||||
// Clock is mockable time provider.
|
||||
Clock clock.Clock
|
||||
}
|
||||
|
||||
// EdgeLocator is a struct used to identify a specific edge.
|
||||
@ -1680,7 +1684,7 @@ func (r *ChannelRouter) preparePayment(payment *LightningPayment) (
|
||||
info := &channeldb.PaymentCreationInfo{
|
||||
PaymentHash: payment.PaymentHash,
|
||||
Value: payment.Amount,
|
||||
CreationTime: time.Now(),
|
||||
CreationTime: r.cfg.Clock.Now(),
|
||||
PaymentRequest: payment.PaymentRequest,
|
||||
}
|
||||
|
||||
@ -1709,7 +1713,7 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) (
|
||||
info := &channeldb.PaymentCreationInfo{
|
||||
PaymentHash: hash,
|
||||
Value: amt,
|
||||
CreationTime: time.Now(),
|
||||
CreationTime: r.cfg.Clock.Now(),
|
||||
PaymentRequest: nil,
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -131,6 +132,7 @@ func createTestCtxFromGraphInstance(startingHeight uint32, graphInstance *testGr
|
||||
return next, nil
|
||||
},
|
||||
PathFindingConfig: pathFindingConfig,
|
||||
Clock: clock.NewTestClock(time.Unix(1, 0)),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to create router %v", err)
|
||||
@ -2967,6 +2969,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
|
||||
next := atomic.AddUint64(&uniquePaymentID, 1)
|
||||
return next, nil
|
||||
},
|
||||
Clock: clock.NewTestClock(time.Unix(1, 0)),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create router %v", err)
|
||||
|
@ -740,6 +740,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
AssumeChannelValid: cfg.Routing.UseAssumeChannelValid(),
|
||||
NextPaymentID: sequencer.NextID,
|
||||
PathFindingConfig: pathFindingConfig,
|
||||
Clock: clock.NewDefaultClock(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't create router: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user