fix: correct epochs_funded_ahead calculation for lagging claims#2087
fix: correct epochs_funded_ahead calculation for lagging claims#2087ananas-block merged 2 commits intomainfrom
Conversation
WalkthroughReplaces inline funded-epochs arithmetic with a new AccountRentState::epochs_funded_ahead(...) method and updates callers/tests to use it. Tests were renamed/adjusted to reflect revised top-up expectations and added coverage for arrears (lagging claims). Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (4)
🧰 Additional context used📓 Path-based instructions (3)program-libs/compressible/**/*.rs📄 CodeRabbit inference engine (program-libs/compressible/CLAUDE.md)
Files:
program-libs/**/*.rs📄 CodeRabbit inference engine (CLAUDE.md)
Files:
sdk-libs/**/*.rs📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (36)📓 Common learnings📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:48.449ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:01:14.087ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:48.449ZApplied to files:
📚 Learning: 2025-11-24T18:00:48.449ZApplied to files:
📚 Learning: 2025-11-24T18:01:42.343ZApplied to files:
📚 Learning: 2025-11-24T18:01:14.087ZApplied to files:
📚 Learning: 2025-11-24T18:01:42.343ZApplied to files:
📚 Learning: 2025-11-24T18:01:14.087ZApplied to files:
📚 Learning: 2025-11-24T18:01:30.012ZApplied to files:
📚 Learning: 2025-11-24T18:01:14.087ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:48.449ZApplied to files:
📚 Learning: 2025-11-24T18:00:48.449ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:01:42.343ZApplied to files:
📚 Learning: 2025-11-24T18:01:14.087ZApplied to files:
📚 Learning: 2025-11-24T18:00:13.178ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:13.178ZApplied to files:
📚 Learning: 2025-11-24T18:01:14.087ZApplied to files:
📚 Learning: 2025-11-24T18:00:13.178ZApplied to files:
📚 Learning: 2025-11-24T18:01:14.087ZApplied to files:
📚 Learning: 2025-11-24T18:00:21.501ZApplied to files:
📚 Learning: 2025-11-24T18:00:13.178ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
📚 Learning: 2025-11-24T18:00:36.663ZApplied to files:
🧬 Code graph analysis (2)sdk-libs/sdk/src/compressible/compression_info.rs (1)
program-libs/compressible/src/compression_info.rs (1)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
program-libs/compressible/tests/compression_info.rs (1)
412-419: Stale epochs_funded_ahead value in test description (semantic nit)In
TestCase { name: "exact boundary - lagging claim requires top-up", ... }the description saysepochs_funded_ahead=1 < max=2, but with the updated program logic and its comment (“if last_funded_epoch_number == current_epoch ... has 0 epochs funded ahead”), this scenario (last_claimed_slot = 0, 2 epochs of rent,current_slot = SLOTS_PER_EPOCH) actually hasepochs_funded_ahead = 0. The expected behavior (expected_top_up = lamports_per_write) is still correct; only the explanatory text is out of date. I’d update the description to reflectepochs_funded_ahead = 0(or drop the explicit value) so it stays consistent with the new definition used in code and the LAGGING CLAIMS tests.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
program-libs/compressible/src/compression_info.rs(1 hunks)program-libs/compressible/tests/compression_info.rs(3 hunks)sdk-libs/sdk/src/compressible/compression_info.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
sdk-libs/**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
Unit tests in sdk-libs must not depend on light-test-utils; any test requiring light-test-utils must be in sdk-tests
Files:
sdk-libs/sdk/src/compressible/compression_info.rs
program-libs/compressible/**/*.rs
📄 CodeRabbit inference engine (program-libs/compressible/CLAUDE.md)
program-libs/compressible/**/*.rs: Use Anchor serialization for CompressibleConfig account structures in Rust programs
Implement state validation methods (validate_active,validate_not_inactive) for CompressibleConfig account state verification
Derive PDA addresses usingderive_pdaandderive_v1_config_pdafunctions for CToken account configuration
Use rent curve algorithms (rent_curve_per_epoch) from RentConfig for calculating compressibility thresholds
Calculate claimable rent usingclaimable_lamportsfunction before closing CToken accounts
Error types must use numeric codes in the 19xxx range for rent/config module errors
Support multiple serialization formats (Anchor, Pinocchio, Borsh) for cross-program compatibility
Usecalculate_rent_and_balancefunction to determine if a CToken account is compressible
Usecalculate_close_lamportsfunction to determine lamport distribution when closing CToken accounts
Files:
program-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
program-libs/**/*.rs
📄 CodeRabbit inference engine (CLAUDE.md)
Unit tests in program-libs must not depend on light-test-utils; any test requiring light-test-utils must be in program-tests
Files:
program-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
🧠 Learnings (27)
📓 Common learnings
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `get_last_funded_epoch` function to determine the last epoch number covered by rent payments.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Use epoch-based accounting (432,000 slots ≈ 2.5 days) instead of continuous time for Light Protocol rent collection
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `calculate_close_lamports` function to return (u64, u64) tuple splitting lamports between rent recipient and user, with rent recipient receiving completed epochs and user receiving partial epoch remainder.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Implement account compressibility states in the following order: Funded (rent for current + 1 epoch) → Compressible (lacks rent for current + 1 epoch) → Claimable (funded but past epochs unclaimed)
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: Applies to program-libs/compressible/**/*.rs : Calculate claimable rent using `claimable_lamports` function before closing CToken accounts
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Account closure must distribute lamports according to: Solana rent exemption → returned to user, completed epoch rent → rent recipient, partial epoch rent → user, compression incentive → forester node
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Light Protocol rent is calculated per epoch as: 1220 minimum + (data_bytes * 10) lamports per epoch
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `calculate_rent_and_balance` function to determine compressibility by checking if account balance covers required rent for epochs since last claim, returning (bool, u64) tuple.
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Rent is calculated per epoch (432,000 slots). Accounts must maintain sufficient balance for all epochs since last claim.
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `get_last_funded_epoch` function to determine the last epoch number covered by rent payments.
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `calculate_close_lamports` function to return (u64, u64) tuple splitting lamports between rent recipient and user, with rent recipient receiving completed epochs and user receiving partial epoch remainder.
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `calculate_rent_and_balance` function to determine compressibility by checking if account balance covers required rent for epochs since last claim, returning (bool, u64) tuple.
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `calculate_rent_inner` as a generic helper function with INCLUDE_CURRENT const parameter to calculate rent components, returning (required_epochs, rent_per_epoch, epochs_paid, unutilized_lamports).
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Implement account compressibility states in the following order: Funded (rent for current + 1 epoch) → Compressible (lacks rent for current + 1 epoch) → Claimable (funded but past epochs unclaimed)
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:01:14.087Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: Applies to program-libs/compressible/**/*.rs : Calculate claimable rent using `claimable_lamports` function before closing CToken accounts
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:01:14.087Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: Applies to program-libs/compressible/**/*.rs : Use `calculate_close_lamports` function to determine lamport distribution when closing CToken accounts
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Light Protocol rent is calculated per epoch as: 1220 minimum + (data_bytes * 10) lamports per epoch
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `claimable_lamports` function to return None if account is compressible, otherwise return Some(amount) for completed epochs only (excluding current ongoing epoch).
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Account closure must distribute lamports according to: Solana rent exemption → returned to user, completed epoch rent → rent recipient, partial epoch rent → user, compression incentive → forester node
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Rent is calculated per epoch (432,000 slots). Accounts must maintain sufficient balance for all epochs since last claim.
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `get_rent` function to calculate total rent across multiple epochs using: rent_curve_per_epoch * epochs.
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement `rent_curve_per_epoch` function with formula: base_rent + (num_bytes * lamports_per_byte_per_epoch).
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rsprogram-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Use `rent_curve_per_epoch(base_rent, lamports_per_byte_per_epoch, num_bytes)` function for base rent calculations in all rent operations.
Applied to files:
sdk-libs/sdk/src/compressible/compression_info.rs
📚 Learning: 2025-11-24T18:01:30.012Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-tests/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:30.012Z
Learning: Run Light system program compression tests using `cargo test-sbf -p system-test -- test_with_compression` and `cargo test-sbf -p system-test --test test_re_init_cpi_account` to test compressed account operations
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/{claim,transfer2}/**/*.rs : Rent authority can only compress accounts when is_compressible() returns true; lamport distribution on close is: rent → rent_sponsor, unutilized → destination
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:01:14.087Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:14.087Z
Learning: Applies to program-libs/compressible/**/*.rs : Implement state validation methods (`validate_active`, `validate_not_inactive`) for CompressibleConfig account state verification
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:00:13.178Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/CONFIG_ACCOUNT.md:0-0
Timestamp: 2025-11-24T18:00:13.178Z
Learning: Applies to program-libs/compressible/docs/**/config.rs : Set CompressibleConfig default values for CToken V1: base_rent = 1220, compression_cost = 11000, lamports_per_byte_per_epoch = 10, and address_space[0] = `amt2kaJA14v3urZbZvnc5v2np8jqvc4Z8zDep5wbtzx`
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement compression cost and incentive values as constants: COMPRESSION_COST = 10,000 lamports, COMPRESSION_INCENTIVE = 1,000 lamports.
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:00:36.663Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/RENT.md:0-0
Timestamp: 2025-11-24T18:00:36.663Z
Learning: Applies to program-libs/compressible/docs/**/*rent*.rs : Implement rent constants with values: BASE_RENT = 1,220 lamports, RENT_PER_BYTE = 10 lamports, SLOTS_PER_EPOCH = 432,000.
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : In test environments, mock Solana rent exemption instead of calling the actual Rent sysvar, using a hardcoded value like 2_282_880 lamports
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Applies to program-libs/compressible/docs/**/*.rs : Light Protocol accounts must satisfy both Solana rent exemption and Light Protocol rent requirements, plus an 11,000 lamport compression incentive during creation
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T18:01:42.343Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: programs/compressed-token/program/CLAUDE.md:0-0
Timestamp: 2025-11-24T18:01:42.343Z
Learning: Applies to programs/compressed-token/program/src/{claim,withdraw_funding_pool}*.rs : Claim and Withdraw Funding Pool instructions require config validation that allows Not Inactive state (active or deprecated OK)
Applied to files:
program-libs/compressible/tests/compression_info.rs
📚 Learning: 2025-11-24T17:56:50.011Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/batched-merkle-tree/docs/INITIALIZE_STATE_TREE.md:0-0
Timestamp: 2025-11-24T17:56:50.011Z
Learning: Applies to program-libs/batched-merkle-tree/docs/src/initialize_state_tree.rs : Return error `AccountError::AccountNotRentExempt` (error code 12011) when account balance is insufficient for rent exemption at calculated size
Applied to files:
program-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T17:58:50.237Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/account-checks/docs/ACCOUNT_CHECKS.md:0-0
Timestamp: 2025-11-24T17:58:50.237Z
Learning: Applies to program-libs/account-checks/docs/program-libs/account-checks/src/checks.rs : Implement `check_account_balance_is_rent_exempt` function to verify account size matches expected_size and account balance meets rent exemption requirement, returning rent exemption amount or errors `InvalidAccountSize` (20004), `InvalidAccountBalance` (20007), or `FailedBorrowRentSysvar` (20008)
Applied to files:
program-libs/compressible/src/compression_info.rs
📚 Learning: 2025-11-24T18:00:48.449Z
Learnt from: CR
Repo: Lightprotocol/light-protocol PR: 0
File: program-libs/compressible/docs/SOLANA_RENT.md:0-0
Timestamp: 2025-11-24T18:00:48.449Z
Learning: Use epoch-based accounting (432,000 slots ≈ 2.5 days) instead of continuous time for Light Protocol rent collection
Applied to files:
program-libs/compressible/src/compression_info.rs
🧬 Code graph analysis (1)
program-libs/compressible/src/compression_info.rs (1)
program-libs/compressible/src/rent/account_rent.rs (1)
slot_to_epoch(174-176)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Test program-libs-fast
- GitHub Check: Test program-libs-slow
- GitHub Check: Test batched-merkle-tree-simulate
- GitHub Check: stateless-js-v2
🔇 Additional comments (2)
program-libs/compressible/src/compression_info.rs (1)
118-123: Epochs-funded-ahead off‑by‑one fix matches rent docs and bug scenarioSwitching to
last_funded_epoch_number.saturating_sub(current_epoch)correctly counts only epochs after the current one, so withlast_funded_epoch_number = 4andcurrent_epoch = 3you now getepochs_funded_ahead = 1instead of 2, which aligns with the PR description and prevents arrears from being treated as “ahead” funding. The added comment (“funded through the current epoch but has 0 epochs funded ahead”) is consistent withget_last_funded_epoch’s documented meaning of “epoch through which rent has been prepaid”. Usingsaturating_subis a good defensive guard if state ever drifts such thatcurrent_epoch > last_funded_epoch_number. Based on learnings from RENT.md aboutget_last_funded_epoch.program-libs/compressible/tests/compression_info.rs (1)
535-563: Lagging-claims tests accurately cover the fixed bug scenarioThe new LAGGING CLAIMS cases (5/6/4 epochs funded with
last_claimed_slot = 0andcurrent_slot = 3 * SLOTS_PER_EPOCH) exactly exercise the scenario where arrears used to be miscounted as “ahead” funding. They assert that:
- 5 epochs prepaid yields
epochs_funded_ahead = 1and still triggers a top‑up.- 6 epochs prepaid yields
epochs_funded_ahead = 2and skips the top‑up.- 4 epochs prepaid only just cover arrears + current, giving
epochs_funded_ahead = 0and requiring a top‑up.This matches the new “AFTER the current epoch” semantics in the program’s
calculate_top_up_lamportsimplementation and locks in the intended behavior for lagginglast_claimed_slot. Based on learnings from SOLANA_RENT.md about epoch-based rent accounting.
When last_claimed_slot lagged behind current_slot, the epochs_funded_ahead calculation incorrectly counted arrears as "ahead" epochs. This caused top-ups to be skipped when they should have triggered. Example of the bug: - last_claimed_epoch=0, current_epoch=3, available_balance=5*rent_per_epoch - Old: epochs_funded_ahead = (4+1) - 3 = 2 >= max=2 → skip top-up - Fixed: epochs_funded_ahead = 4 - 3 = 1 < max=2 → trigger top-up Changes: - program-libs/compressible: Remove +1 from epochs_funded_ahead calculation - sdk-libs/sdk: Subtract required_epochs from total_epochs_fundable - Add test cases for lagging claim scenarios
15acd45 to
fa37fc8
Compare
fa37fc8 to
1cfedfb
Compare
When last_claimed_slot lagged behind current_slot, the epochs_funded_ahead calculation incorrectly counted arrears as "ahead" epochs. This caused top-ups to be skipped when they should have triggered.
Example of the bug:
Changes:
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.