refactor: remove redundant lamports_per_write parameter from calculate_top_up_lamports#2086
Conversation
…e_top_up_lamports The function now reads lamports_per_write from self instead of requiring it as a parameter, since it's already stored in the CompressionInfo struct.
WalkthroughThe PR refactors the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10–15 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (2)
program-tests/utils/src/assert_ctoken_transfer.rsis excluded by none and included by noneprogram-tests/utils/src/assert_mint_action.rsis excluded by none and included by none
📒 Files selected for processing (4)
program-libs/compressible/src/compression_info.rs(1 hunks)program-libs/compressible/tests/compression_info.rs(0 hunks)programs/compressed-token/program/src/ctoken_transfer.rs(0 hunks)programs/compressed-token/program/src/transfer2/compression/ctoken/compress_or_decompress_ctokens.rs(0 hunks)
💤 Files with no reviewable changes (3)
- programs/compressed-token/program/src/transfer2/compression/ctoken/compress_or_decompress_ctokens.rs
- programs/compressed-token/program/src/ctoken_transfer.rs
- program-libs/compressible/tests/compression_info.rs
🧰 Additional context used
📓 Path-based instructions (2)
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/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/src/compression_info.rs
🧠 Learnings (15)
📓 Common learnings
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
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.
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.
📚 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:
program-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:
program-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:
program-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:
program-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_rent_and_balance` function to determine if a CToken account is compressible
Applied to files:
program-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:
program-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:
program-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 compression cost and incentive values as constants: COMPRESSION_COST = 10,000 lamports, COMPRESSION_INCENTIVE = 1,000 lamports.
Applied to files:
program-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 rent curve algorithms (`rent_curve_per_epoch`) from RentConfig for calculating compressibility thresholds
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: 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:
program-libs/compressible/src/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/close_token_account.rs : Close Token Account instruction must return rent exemption to rent recipient if compressible, and return remaining lamports to destination account
Applied to files:
program-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_exemption_lamports` function to return Solana's rent-exempt balance for a given account size, with error handling for unavailable rent sysvar.
Applied to files:
program-libs/compressible/src/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/program-libs/compressible/src/config.rs : RentConfig struct must use fixed-size fields: base_rent (u16, 2 bytes), compression_cost (u16, 2 bytes), lamports_per_byte_per_epoch (u8, 1 byte), and _place_holder_bytes ([u8; 3], 3 bytes padding) for proper 8-byte alignment
Applied to files:
program-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 constants with values: BASE_RENT = 1,220 lamports, RENT_PER_BYTE = 10 lamports, SLOTS_PER_EPOCH = 432,000.
Applied to files:
program-libs/compressible/src/compression_info.rs
⏰ 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). (13)
- GitHub Check: Forester e2e test
- GitHub Check: Test program-libs-fast
- GitHub Check: system-programs (native, ["cargo-test-sbf -p sdk-native-test", "cargo-test-sbf -p sdk-v1-native-t...
- GitHub Check: stateless-js-v2
- GitHub Check: Test batched-merkle-tree-simulate
- GitHub Check: programs (system-cpi-test-v2-functional-account-infos, ["cargo-test-sbf -p system-cpi-v2-test -- ...
- GitHub Check: Test program-libs-slow
- GitHub Check: programs (account-compression-and-registry, ["cargo-test-sbf -p account-compression-test", "cargo...
- GitHub Check: programs (system-cpi-test-v2-functional-read-only, ["cargo-test-sbf -p system-cpi-v2-test -- func...
- GitHub Check: programs (compressed-token-and-e2e, ["cargo-test-sbf -p compressed-token-test --test v1", "cargo-...
- GitHub Check: programs (compressed-token-batched-tree, ["cargo-test-sbf -p compressed-token-test -- test_transf...
- GitHub Check: programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test", "cargo test -p light-system-prog...
- GitHub Check: lint
🔇 Additional comments (1)
program-libs/compressible/src/compression_info.rs (1)
92-98: Excellent refactor - removes redundant parameter.The removal of the
lamports_per_writeparameter simplifies the API since this value is already available as a struct field. This makes the function signature cleaner and eliminates the possibility of passing a value that conflicts with the stored configuration.
The function now reads lamports_per_write from self instead of requiring it as a parameter, since it's already stored in the CompressionInfo struct.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.