Skip to content
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
2 changes: 1 addition & 1 deletion rust/lit-node/lit-node/src/payment/payment_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sdd::AtomicShared;
use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering};

#[derive(Default, Copy, Clone)]
#[derive(Default, Copy, Clone, Debug)]
pub struct NodeCapacityConfig {
pub pkp_sign_max_concurrency: u64,
pub enc_sign_max_concurrency: u64,
Expand Down
15 changes: 14 additions & 1 deletion rust/lit-node/lit-node/src/tasks/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,20 @@ pub async fn usage_processor(
.as_u64(),
global_max_capacity: config.global_max_capacity.as_u64(),
};
payment_tracker_for_capacity.update_node_capacity_config(node_capacity_config);
if node_capacity_config.global_max_capacity > 0
&& node_capacity_config.pkp_sign_max_concurrency > 0
&& node_capacity_config.enc_sign_max_concurrency > 0
&& node_capacity_config.lit_action_max_concurrency > 0
&& node_capacity_config.sign_session_key_max_concurrency > 0
{
payment_tracker_for_capacity
.update_node_capacity_config(node_capacity_config);
} else {
warn!(
"Invalid node capacity config ( will not update payment tracker ): {:?}",
node_capacity_config
);
Comment on lines +157 to +169

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation prevents updating the payment tracker with zero values, which is good for preventing the immediate update. However, this creates a critical problem: if the payment tracker was initialized with default values (all zeros) and this validation prevents the first valid update from being applied, the payment tracker will remain in an invalid state with zeros. This will cause division by zero panics when:

  1. get_op_capacity() divides global_max_capacity by any of the concurrency values (lines 29-36 in payment_tracker.rs)
  2. get_usage_percentage() divides by global_max_capacity (line 74 in payment_tracker.rs)

These methods are called during normal operation when registering/deregistering usage. Consider either:

  1. Initializing PaymentTracker with valid non-zero default values using NodeCapacityConfig::new() instead of Default::default(), or
  2. Adding checks in the PaymentTracker methods to handle zero values gracefully, or
  3. Making the validation more sophisticated to allow updates if the current config is all zeros (first initialization)
Suggested change
if node_capacity_config.global_max_capacity > 0
&& node_capacity_config.pkp_sign_max_concurrency > 0
&& node_capacity_config.enc_sign_max_concurrency > 0
&& node_capacity_config.lit_action_max_concurrency > 0
&& node_capacity_config.sign_session_key_max_concurrency > 0
{
payment_tracker_for_capacity
.update_node_capacity_config(node_capacity_config);
} else {
warn!(
"Invalid node capacity config ( will not update payment tracker ): {:?}",
node_capacity_config
);
let all_zero = node_capacity_config.global_max_capacity == 0
&& node_capacity_config.pkp_sign_max_concurrency == 0
&& node_capacity_config.enc_sign_max_concurrency == 0
&& node_capacity_config.lit_action_max_concurrency == 0
&& node_capacity_config.sign_session_key_max_concurrency == 0;
if all_zero {
warn!(
"Invalid node capacity config (all zeros; will not update payment tracker): {:?}",
node_capacity_config
);
} else {
payment_tracker_for_capacity
.update_node_capacity_config(node_capacity_config);

Copilot uses AI. Check for mistakes.
}
Comment on lines +157 to +170

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validation logic lacks test coverage. Given that this is a critical safety check to prevent invalid capacity configurations from being applied (which could cause division by zero panics), it would be valuable to add tests that verify:

  1. Valid configurations are accepted and applied
  2. Configurations with any zero values are rejected and logged
  3. The payment tracker state remains unchanged when invalid configurations are rejected

The codebase has comprehensive test coverage for other payment-related functionality (see rust/lit-node/lit-node/src/payment/batches.rs:139), so this new validation should follow the same pattern.

Copilot uses AI. Check for mistakes.
}
Err(e) => {
error!("Failed to get node capacity config: {:?}", e);
Expand Down