Skip to content

routerrpc: fix fee limit validation and calculation #9671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,13 @@ message FeeLimit {

// The fee limit expressed as a percentage of the payment amount.
int64 percent = 2;

// The behavior when both fixed and percent values are specified.
// 0: Use minimum of fixed and percent (default)
// 1: Use maximum of fixed and percent
// 2: Use fixed only
// 3: Use percent only
int32 behavior = 4;
}
}

Expand Down
14 changes: 14 additions & 0 deletions lnrpc/routerrpc/router.proto
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,20 @@ message SendPaymentRequest {
base64.
*/
map<uint64, bytes> first_hop_custom_records = 25;

oneof fee_limit {
// The fee limit expressed as a fixed amount of satoshis.
int64 fee_limit_sat = 10;

// The fee limit expressed as a fixed amount of millisatoshis.
int64 fee_limit_msat = 11;

// The fee limit expressed as a percentage of the payment amount.
int64 fee_limit_percent = 12;
}

// Behavior when multiple fee limits could apply (same as FeeLimit.behavior)
int32 fee_limit_behavior = 13;
}

message TrackPaymentRequest {
Expand Down
79 changes: 77 additions & 2 deletions lnrpc/routerrpc/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,50 @@
// gRPC service.
var _ RouterServer = (*Server)(nil)

// validateFeeLimit checks that the fee limit fields are properly set and not conflicting
func validateFeeLimit(feeLimit *lnrpc.FeeLimit) error {
// Check that fixed and fixed_msat are not both set
if feeLimit.GetFixed() != 0 && feeLimit.GetFixedMsat() != 0 {
return fmt.Errorf("cannot specify both fixed and fixed_msat fee limits")
}
return nil
}

// calculateFeeLimit calculates the actual fee limit based on the payment amount and fee limit settings
func calculateFeeLimit(amountMsat int64, feeLimit *lnrpc.FeeLimit) (int64, error) {
// Start with no fee limit
var limitSat int64
var limitMsat int64

// Take the lower of fixed or fixed_msat converted to satoshis
if feeLimit.GetFixed() != 0 {
limitSat = feeLimit.GetFixed()
}
if feeLimit.GetFixedMsat() != 0 {
limitMsat = feeLimit.GetFixedMsat()
limitFromMsat := limitMsat / 1000
if limitSat == 0 || limitFromMsat < limitSat {
limitSat = limitFromMsat
}
}

// Calculate percentage-based limit if specified
var percentLimitMsat int64
if feeLimit.GetPercent() != 0 {
percentLimitMsat = amountMsat * feeLimit.GetPercent() / 100
percentLimitSat := percentLimitMsat / 1000

// Take the lower of fixed and percentage limits by default
if limitSat == 0 || percentLimitSat < limitSat {
limitSat = percentLimitSat
limitMsat = percentLimitMsat
}
}

// Return both sat and msat values
return limitSat, limitMsat

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / macOS itest

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (neutrino, backend=neutrino cover=1)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind-notxindex, backend="bitcoind notxindex")

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling")

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (btcd, backend=btcd cover=1)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind, backend=bitcoind cover=1)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / windows itest

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-cover)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / check commits

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)

Check failure on line 248 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

cannot use limitMsat (variable of type int64) as error value in return statement: int64 does not implement error (missing method Error)
}

// New creates a new instance of the RouterServer given a configuration struct
// that contains all external dependencies. If the target macaroon exists, and
// we're unable to create it, then an error will be returned. We also return
Expand Down Expand Up @@ -354,8 +398,19 @@
stream Router_SendPaymentV2Server) error {

// Set payment request attempt timeout.
if req.TimeoutSeconds == 0 {
req.TimeoutSeconds = DefaultPaymentTimeout
if req.FeeLimitSat != 0 && req.FeeLimitMsat != 0 {
return status.Error(codes.InvalidArgument,
"cannot specify both fee_limit_sat and fee_limit_msat")
}

// Calculate fee limit based on amount and fee limit settings
var feeLimitMsat int64

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / macOS itest

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (neutrino, backend=neutrino cover=1)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind-notxindex, backend="bitcoind notxindex")

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling")

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (btcd, backend=btcd cover=1)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind, backend=bitcoind cover=1)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / windows itest

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-cover)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / check commits

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

declared and not used: feeLimitMsat

Check failure on line 407 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

declared and not used: feeLimitMsat
if req.FeeLimitSat != 0 {
feeLimitMsat = req.FeeLimitSat * 1000
} else if req.FeeLimitMsat != 0 {
feeLimitMsat = req.FeeLimitMsat
} else if req.FeeLimitPercent != 0 {

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / macOS itest

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (neutrino, backend=neutrino cover=1)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind-notxindex, backend="bitcoind notxindex")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (btcd, backend=btcd cover=1)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind, backend=bitcoind cover=1)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / windows itest

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-cover)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / check commits

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 412 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)
feeLimitMsat = req.AmtMsat * req.FeeLimitPercent / 100

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / macOS itest

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (neutrino, backend=neutrino cover=1)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind-notxindex, backend="bitcoind notxindex")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (btcd, backend=btcd cover=1)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind, backend=bitcoind cover=1)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / windows itest

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-cover)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / check commits

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)

Check failure on line 413 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

req.FeeLimitPercent undefined (type *SendPaymentRequest has no field or method FeeLimitPercent)
}

payment, err := s.cfg.RouterBackend.extractIntentFromSendRequest(req)
Expand Down Expand Up @@ -524,6 +579,20 @@
"greater than 0")
}

// Calculate fee limit for probe
var feeLimitMsat int64
if payReq.MilliSat != nil {
feeLimitMsat = int64(*payReq.MilliSat) * routeFeeLimitPercent / 100

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / macOS itest

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (neutrino, backend=neutrino cover=1)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind-notxindex, backend="bitcoind notxindex")

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling")

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (btcd, backend=btcd cover=1)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind, backend=bitcoind cover=1)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / windows itest

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-cover)

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / check commits

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

undefined: routeFeeLimitPercent

Check failure on line 585 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

undefined: routeFeeLimitPercent
if feeLimitMsat > routeFeeLimitSat*1000 {
feeLimitMsat = routeFeeLimitSat * 1000
}
}

probeRequest := &SendPaymentRequest{
// ... existing fields ...
FeeLimitMsat: feeLimitMsat,
}

// Generate random payment hash, so we can be sure that the target of
// the probe payment doesn't have the preimage to settle the htlc.
var paymentHash lntypes.Hash
Expand All @@ -534,7 +603,7 @@
}

amtMsat := int64(*payReq.MilliSat)
probeRequest := &SendPaymentRequest{

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / macOS itest

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite-nativesql, backend=bitcoind dbbackend=sqlite nativesql=true)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (neutrino, backend=neutrino cover=1)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind-notxindex, backend="bitcoind notxindex")

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres, backend=bitcoind dbbackend=postgres)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-rpcpolling, backend="bitcoind rpcpolling")

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-sqlite, backend=bitcoind dbbackend=sqlite)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (btcd, backend=btcd cover=1)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / basic itests (bitcoind, backend=bitcoind cover=1)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-postgres-nativesql, backend=bitcoind dbbackend=postgres nativesql=true)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / itests (bitcoind-etcd, backend=bitcoind dbbackend=etcd)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / windows itest

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-cover)

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / check commits

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_postgres")

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_sqlite")

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit tags="kvdb_etcd")

no new variables on left side of :=

Check failure on line 606 in lnrpc/routerrpc/router_server.go

View workflow job for this annotation

GitHub Actions / run unit tests (unit-race)

no new variables on left side of :=
TimeoutSeconds: int32(timeout),
Dest: payReq.Destination.SerializeCompressed(),
MaxParts: 1,
Expand Down Expand Up @@ -1476,6 +1545,12 @@
func (s *Server) BuildRoute(_ context.Context,
req *BuildRouteRequest) (*BuildRouteResponse, error) {

// Validate amount and fee limits
if req.AmtMsat < 0 {
return nil, status.Error(codes.InvalidArgument,
"amount must be positive")
}

if len(req.HopPubkeys) == 0 {
return nil, errors.New("no hops specified")
}
Expand Down
Loading