Skip to content

refactor: remove redundant lamports_per_write parameter from calculate_top_up_lamports#2086

Merged
SwenSchaeferjohann merged 1 commit intomainfrom
jorrit/chore-remove-redundant-lamports-input
Dec 2, 2025
Merged

refactor: remove redundant lamports_per_write parameter from calculate_top_up_lamports#2086
SwenSchaeferjohann merged 1 commit intomainfrom
jorrit/chore-remove-redundant-lamports-input

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Dec 2, 2025

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

  • Refactor
    • Simplified compression rent calculation by refactoring internal parameter handling to improve code maintainability while preserving existing functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

…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.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

Walkthrough

The PR refactors the calculate_top_up_lamports method in CompressionInfo by removing the lamports_per_write parameter and computing it internally from self.lamports_per_write. All call sites are updated to reflect the new method signature.

Changes

Cohort / File(s) Summary
CompressionInfo method definition
program-libs/compressible/src/compression_info.rs
Method signature simplified: calculate_top_up_lamports no longer accepts lamports_per_write parameter; now derives it internally from self.lamports_per_write via type conversion.
Method tests
program-libs/compressible/tests/compression_info.rs
Test call updated to match new signature; lamports_per_write argument removed from calculate_top_up_lamports invocation.
Call sites
programs/compressed-token/program/src/ctoken_transfer.rs, programs/compressed-token/program/src/transfer2/compression/ctoken/compress_or_decompress_ctokens.rs
Both call sites updated to remove lamports_per_write argument passed to calculate_top_up_lamports.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Homogeneous parameter removal across multiple call sites reduces cognitive overhead
  • Logic within the method is unchanged; only where the parameter originates differs
  • Straightforward verification: confirm all call sites updated and no new dependencies introduced

Possibly related PRs

  • fix: calculate_top_up_lamports #2060: Also modifies calculate_top_up_lamports in the same file; may affect epoch-based top-up logic and error propagation—review for potential conflicts or complementary changes.

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

✨ A parameter takes its leave,

Now nestled in the self it grieves,

Internal truths need not be passed—

Cleaner calls, at long last! 🎯

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing a redundant parameter from a method signature to read it from self instead.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jorrit/chore-remove-redundant-lamports-input

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c90d54 and 7d40449.

⛔ Files ignored due to path filters (2)
  • program-tests/utils/src/assert_ctoken_transfer.rs is excluded by none and included by none
  • program-tests/utils/src/assert_mint_action.rs is 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 using derive_pda and derive_v1_config_pda functions for CToken account configuration
Use rent curve algorithms (rent_curve_per_epoch) from RentConfig for calculating compressibility thresholds
Calculate claimable rent using claimable_lamports function 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
Use calculate_rent_and_balance function to determine if a CToken account is compressible
Use calculate_close_lamports function 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_write parameter 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.

@SwenSchaeferjohann SwenSchaeferjohann merged commit 8328855 into main Dec 2, 2025
32 checks passed
@SwenSchaeferjohann SwenSchaeferjohann deleted the jorrit/chore-remove-redundant-lamports-input branch December 2, 2025 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants