routerrpc: inject clock for testable expiry validation

Refactors payment request expiry validation to use an injected clock
dependency instead of calling time.Now() directly.
This commit is contained in:
Erick Cestari
2025-06-10 11:35:16 -03:00
parent a27bd69b9c
commit c01a66783f
3 changed files with 18 additions and 4 deletions

View File

@@ -696,6 +696,7 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
routerBackend := &routerrpc.RouterBackend{
SelfNode: selfNode.PubKeyBytes,
Clock: clock.NewDefaultClock(),
FetchChannelCapacity: func(chanID uint64) (btcutil.Amount,
error) {
@@ -5609,7 +5610,9 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme
}
// Next, we'll ensure that this payreq hasn't already expired.
err = routerrpc.ValidatePayReqExpiry(payReq)
err = routerrpc.ValidatePayReqExpiry(
r.routerBackend.Clock, payReq,
)
if err != nil {
return payIntent, err
}