From 26ae6cff9c453af93739df396149b15eab4ac05a Mon Sep 17 00:00:00 2001 From: Ross Savage Date: Thu, 16 Nov 2023 14:01:38 +0100 Subject: [PATCH] Fix potential max_allowed_to_receive_msats underflow --- libs/sdk-core/src/greenlight/node_api.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/sdk-core/src/greenlight/node_api.rs b/libs/sdk-core/src/greenlight/node_api.rs index 03fa929f3..f301271f3 100644 --- a/libs/sdk-core/src/greenlight/node_api.rs +++ b/libs/sdk-core/src/greenlight/node_api.rs @@ -1,4 +1,4 @@ -use std::cmp::{max, min, Reverse}; +use std::cmp::{min, Reverse}; use std::pin::Pin; use std::str::FromStr; use std::sync::Arc; @@ -702,7 +702,8 @@ impl NodeAPI for Greenlight { Ok(()) })?; - let max_allowed_to_receive_msats = max(MAX_INBOUND_LIQUIDITY_MSAT - channels_balance, 0); + let max_allowed_to_receive_msats = + MAX_INBOUND_LIQUIDITY_MSAT.saturating_sub(channels_balance); let node_pubkey = hex::encode(node_info.id); // construct the node state