Skip to content

refactor(launchpad): remove unused currentHeight params and fix naming#1238

Open
notJoon wants to merge 5 commits intomainfrom
refactor/launchpad-remove-current-height
Open

refactor(launchpad): remove unused currentHeight params and fix naming#1238
notJoon wants to merge 5 commits intomainfrom
refactor/launchpad-remove-current-height

Conversation

@notJoon
Copy link
Copy Markdown
Member

@notJoon notJoon commented Apr 7, 2026

Summary

Continue the cleanup started in #1236 by removing remaining unused currentHeight parameters and fixing misleading naming in launchpad contract tests.

Changes

Removed parameters (dead code)

Function File Reason
collectDepositReward(deposit, currentHeight, currentTime) launchpad_reward.gno currentHeight was accepted but never referenced in the function body
Test struct fields (currentHeight) in UpdateRewardPerDepositX128, CollectReward, newRewardManager reward_manager_test.gno Defined in test structs but never accessed via tt.currentHeight

Kept parameters (structurally required)

Function / Struct File Reason
createProjectParams.currentHeight launchpad_project.gno Passed to NewProject() which uses it for MakeProjectID(tokenPath, createdHeight) — project ID generation depends on it
NewDeposit(..., createdHeight, ...) launchpad_deposit.gno Stored as Deposit.createdHeight for audit tracking
withdrawDeposit(d, currentHeight, currentTime) deposit.gno Passed to Deposit.SetWithdrawn() which sets withdrawnHeight, used by IsWithdrawn()
withdrawDeposit(deposit, currentHeight, currentTime) method launchpad_withdraw.gno Passes height through to the helper; caller provides runtime.ChainHeight()

Propagation fix

runtime.ChainHeight() is now called at the top-level entry point (CollectDepositGns) and passed down as a parameter, instead of being called redundantly in nested functions. This makes the call chain consistent: entry points capture height/time, inner functions receive them as arguments.

Renamed test fields (currentHeightcurrentTime)

Several test struct fields were named currentHeight but their values were passed to time-based functions (isRewardStateClaimable, IsActivated, IsEnded), which accept currentTime int64. Renamed for accuracy:

  • reward_state_test.gno — field + test descriptions
  • project_tier_test.gno — field name

Summary by CodeRabbit

  • Bug Fixes

    • Reward collection and withdrawals now use timestamps only (current time) instead of blockchain height for consistent accrual and outcomes.
  • Breaking Changes

    • Height-based deposit getters and deposit height fields removed; deposit state and public APIs now expose/track time-only values.
  • Tests

    • Test suite updated to validate timestamp-driven reward collection, withdrawal flows, and adjusted deposit constructors.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: df9f463d-7daf-4821-ab51-791efc298459

📥 Commits

Reviewing files that changed from the base of the PR and between b3180ad and 779fc6c.

⛔ Files ignored due to path filters (1)
  • contract/r/scenario/getter/launchpad_getter_filetest.gno is excluded by !**/*filetest.gno
📒 Files selected for processing (2)
  • contract/r/gnoswap/launchpad/v1/launchpad_deposit.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_deposit.gno
💤 Files with no reviewable changes (2)
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_deposit.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_deposit.gno

Walkthrough

Removed blockchain-height usage from launchpad deposits, reward collection, withdrawals, getters, and tests; flows now use Unix timestamps (currentTime) and deposit created/withdrawn heights and related getters were removed.

Changes

Cohort / File(s) Summary
Core deposit model
contract/r/gnoswap/launchpad/deposit.gno, contract/r/scenario/upgrade/implements/v3_valid/launchpad/deposit.gno
Removed createdHeight/withdrawnHeight fields and accessors; SetWithdrawn now accepts only withdrawnTime; NewDeposit no longer takes created height.
Withdraw helper & call sites
contract/r/gnoswap/launchpad/v1/deposit.gno, contract/r/scenario/upgrade/implements/v3_valid/launchpad/deposit.gno
withdrawDeposit signature changed to take only currentTime int64; callers updated to stop passing chain height; withdrawal metadata updated via time-only API.
Reward collection
contract/r/gnoswap/launchpad/v1/launchpad_reward.gno, contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_reward.gno, contract/r/gnoswap/launchpad/v1/launchpad_reward_test.gno
Removed currentHeight param from collectDepositReward and call sites; reward updates and collection driven solely by currentTime.
Withdrawal flow
contract/r/gnoswap/launchpad/v1/launchpad_withdraw.gno, contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_withdraw.gno, contract/r/gnoswap/launchpad/v1/launchpad_withdraw_test.gno
CollectDepositGns and withdrawal callers compute/pass a single currentTime; withdrawDeposit calls adjusted accordingly; tests updated to capture/reuse currentTime.
Getter/API removals
contract/r/gnoswap/launchpad/getter.gno, contract/r/scenario/upgrade/implements/v3_valid/launchpad/getter.gno, contract/r/gnoswap/launchpad/types.gno, contract/r/gnoswap/launchpad/v1/getter.gno
Removed public getters and interface methods for deposit created/withdrawn heights.
Mocks & tests
contract/r/gnoswap/launchpad/_mock_test.gno, .../v1/*_test.gno, reward_manager_test.gno, reward_state_test.gno, deposit_test.gno, getter_test.gno, project_tier_test.gno, store_test.gno, counter_test.gno, project_condition_test.gno
Removed/renamed height fields in tests and mocks, updated constructors and helpers to time-only arguments, removed tests for deleted getters, and adjusted imports/aliases.
Deposit creation call sites
contract/r/gnoswap/launchpad/v1/launchpad_deposit.gno, contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_deposit.gno
Stopped capturing/passing runtime.ChainHeight() into NewDeposit; deposit creation now uses currentTime and other parameters only.

Sequence Diagram(s)

sequenceDiagram
  participant Caller as Caller
  participant LP as Launchpad
  participant Runtime as Runtime
  participant RM as RewardManager
  participant Store as Store

  Caller->>LP: CollectDepositGns(depositID)
  LP->>Runtime: time.Now().Unix()
  Runtime-->>LP: currentTime
  LP->>RM: collectDepositReward(deposit, currentTime)
  RM->>RM: updateRewardPerDepositX128(currentTime)
  RM->>RM: collectReward(deposit, currentTime)
  RM-->>LP: rewardAmount
  alt rewardAmount > 0
    LP->>Store: persist reward totals
    Store-->>LP: ack
  end
  LP->>LP: withdrawDeposit(deposit, currentTime)
  LP->>deposit: SetWithdrawn(currentTime)
  LP->>Store: save updated deposit
  Store-->>LP: ack
  LP-->>Caller: returned withdrawal amount
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ 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 directly and accurately summarizes the main change: removing unused currentHeight parameters from launchpad code and correcting test field naming (currentHeight → currentTime).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/launchpad-remove-current-height

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
Copy Markdown

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
contract/r/gnoswap/launchpad/v1/launchpad_withdraw_test.gno (1)

617-622: ⚠️ Potential issue | 🟡 Minor

Stale currentHeight used for withdrawal - potential test inconsistency.

The currentHeight used at line 621 was captured at line 567 during project creation, but testing.SkipHeights(tt.skipHeight) is called at line 608 before the withdrawal. This means the withdrawal receives a height that's significantly older than the actual chain state.

This is inconsistent with TestLaunchpadWithdraw_RewardStateRemoval (lines 512-514) where currentHeight is correctly captured after SkipHeights.

Suggested fix
 			// Withdraw specific deposit
 			withdrawDepositID := depositIDs[tt.withdrawDepositIndex]
 			deposit, _ := getDeposit(withdrawDepositID)
 			currentTime = time.Now().Unix()
+			currentHeight = runtime.ChainHeight()
 			_, _, err := lp.withdrawDeposit(deposit, currentHeight, currentTime)
 			uassert.NoError(t, err)
🧹 Nitpick comments (3)
contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_withdraw.gno (1)

63-127: Unused currentHeight parameter - consider removal or consistent usage.

The currentHeight parameter passed to lp.withdrawDeposit (line 63) is never used within the function. At line 115, runtime.ChainHeight() is called directly instead of using the passed currentHeight:

// Line 115: ignores the currentHeight parameter
withdrawalAmount := withdrawDeposit(deposit, runtime.ChainHeight(), currentTime)

This creates dead code since the caller captures runtime.ChainHeight() at line 39 but it's ignored. Either:

  1. Remove currentHeight from the signature (consistent with the collectDepositReward change in this PR)
  2. Use the passed currentHeight parameter at line 115

Given the PR's objective to remove unused height parameters, option 1 would be more consistent.

♻️ Suggested fix - use the passed parameter or remove it

Option A: Use the passed parameter

 	// Finalize withdrawal
-	withdrawalAmount := withdrawDeposit(deposit, runtime.ChainHeight(), currentTime)
+	withdrawalAmount := withdrawDeposit(deposit, currentHeight, currentTime)

Option B: Remove the unused parameter (preferred for consistency with this PR)

-func (lp *launchpadV1) withdrawDeposit(deposit *launchpad.Deposit, currentHeight, currentTime int64) (address, int64, error) {
+func (lp *launchpadV1) withdrawDeposit(deposit *launchpad.Deposit, currentTime int64) (address, int64, error) {
contract/r/gnoswap/launchpad/v1/launchpad_withdraw.gno (1)

84-148: Inconsistent use of currentHeight parameter.

The currentHeight parameter is passed to lp.withdrawDeposit but then ignored. At line 131, runtime.ChainHeight() is called again instead of using the passed value:

// Line 84: currentHeight parameter received
func (lp *launchpadV1) withdrawDeposit(deposit *launchpad.Deposit, currentHeight, currentTime int64) ...

// Line 131: parameter ignored, runtime.ChainHeight() called instead
withdrawalAmount := withdrawDeposit(deposit, runtime.ChainHeight(), currentTime)

Per the context snippet from deposit.gno, this height is recorded as withdrawnHeight on the deposit. While the difference is negligible in practice (same block), this creates:

  1. Unnecessary duplicate runtime.ChainHeight() call
  2. The currentHeight parameter becomes dead code within this function

The PR description states this parameter is "retained because it forwards height to Deposit.SetWithdrawn()", but it doesn't actually forward the caller-supplied value.

♻️ Suggested fix - use the passed parameter
 	// Finalize withdrawal
-	withdrawalAmount := withdrawDeposit(deposit, runtime.ChainHeight(), currentTime)
+	withdrawalAmount := withdrawDeposit(deposit, currentHeight, currentTime)
contract/r/gnoswap/launchpad/v1/deposit_test.gno (1)

384-388: Consider asserting WithdrawnHeight() to maintain test coverage.

The hardcoded 123 is a magic number, and the test no longer validates that deposit.WithdrawnHeight() is correctly set after withdrawal. Since the Deposit struct still tracks withdrawnHeight for audit purposes (as shown in deposit.gno), consider adding an assertion to verify this field:

 			amount := withdrawDeposit(deposit, 123, tt.currentTime)
 			uassert.Equal(t, tt.expectedAmount, amount)
 			uassert.Equal(t, tt.currentTime, deposit.WithdrawnTime())
+			uassert.Equal(t, int64(123), deposit.WithdrawnHeight())
 			uassert.Equal(t, tt.expectedRemaining, deposit.DepositAmount())
 			uassert.Equal(t, tt.expectedWithdrawn, deposit.IsWithdrawn())

Alternatively, define a named constant for the test height value to improve readability.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a56857a1-012a-4dae-abcd-4c2a36fc07d0

📥 Commits

Reviewing files that changed from the base of the PR and between 3e051b0 and 2cf80b9.

📒 Files selected for processing (10)
  • contract/r/gnoswap/launchpad/v1/deposit_test.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_reward.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_reward_test.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_withdraw.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_withdraw_test.gno
  • contract/r/gnoswap/launchpad/v1/project_tier_test.gno
  • contract/r/gnoswap/launchpad/v1/reward_manager_test.gno
  • contract/r/gnoswap/launchpad/v1/reward_state_test.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_reward.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_withdraw.gno

Comment thread contract/r/gnoswap/launchpad/v1/launchpad_withdraw.gno Outdated
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
contract/r/gnoswap/launchpad/deposit.gno (1)

105-111: Consider consolidating duplicate setters for withdrawnTime.

Both SetWithdrawnTime() (line 81-83) and SetWithdrawn() (line 109-111) perform identical operations on the same field. This could lead to confusion about which method to use.

♻️ Option 1: Delegate SetWithdrawn to SetWithdrawnTime
 func (d *Deposit) SetWithdrawn(withdrawnTime int64) {
-	d.withdrawnTime = withdrawnTime
+	d.SetWithdrawnTime(withdrawnTime)
 }
♻️ Option 2: Remove SetWithdrawn and use SetWithdrawnTime directly

If SetWithdrawn was primarily used to set both height and time (now simplified), consider removing it and having callers use SetWithdrawnTime() directly. This reduces API surface area.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f518df06-cf69-45da-b695-600a5fcc63bc

📥 Commits

Reviewing files that changed from the base of the PR and between 1c68dc9 and b3180ad.

📒 Files selected for processing (20)
  • contract/r/gnoswap/launchpad/_mock_test.gno
  • contract/r/gnoswap/launchpad/counter_test.gno
  • contract/r/gnoswap/launchpad/deposit.gno
  • contract/r/gnoswap/launchpad/getter.gno
  • contract/r/gnoswap/launchpad/getter_test.gno
  • contract/r/gnoswap/launchpad/project_condition_test.gno
  • contract/r/gnoswap/launchpad/store_test.gno
  • contract/r/gnoswap/launchpad/types.gno
  • contract/r/gnoswap/launchpad/v1/assert_test.gno
  • contract/r/gnoswap/launchpad/v1/deposit.gno
  • contract/r/gnoswap/launchpad/v1/deposit_test.gno
  • contract/r/gnoswap/launchpad/v1/getter.gno
  • contract/r/gnoswap/launchpad/v1/getter_test.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_deposit.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_reward_test.gno
  • contract/r/gnoswap/launchpad/v1/project_tier_test.gno
  • contract/r/gnoswap/launchpad/v1/reward_manager_test.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/deposit.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/getter.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_deposit.gno
💤 Files with no reviewable changes (9)
  • contract/r/gnoswap/launchpad/v1/assert_test.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/launchpad_deposit.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_deposit.gno
  • contract/r/gnoswap/launchpad/getter.gno
  • contract/r/gnoswap/launchpad/types.gno
  • contract/r/gnoswap/launchpad/_mock_test.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/getter.gno
  • contract/r/gnoswap/launchpad/v1/getter_test.gno
  • contract/r/gnoswap/launchpad/v1/getter.gno
✅ Files skipped from review due to trivial changes (3)
  • contract/r/gnoswap/launchpad/store_test.gno
  • contract/r/gnoswap/launchpad/project_condition_test.gno
  • contract/r/gnoswap/launchpad/v1/deposit_test.gno
🚧 Files skipped from review as they are similar to previous changes (4)
  • contract/r/gnoswap/launchpad/v1/project_tier_test.gno
  • contract/r/gnoswap/launchpad/v1/launchpad_reward_test.gno
  • contract/r/gnoswap/launchpad/v1/deposit.gno
  • contract/r/scenario/upgrade/implements/v3_valid/launchpad/deposit.gno

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@jinoosss jinoosss left a comment

Choose a reason for hiding this comment

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

We should consider whether removing the height information from the deposit is the right approach.
From the perspective of contract users, this data may be necessary.
Additionally, since launchpad deposits are reversible, we should consider implementing this change.

@jinoosss jinoosss added the DO NOT MERGE do not merge this PR label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DO NOT MERGE do not merge this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants