Skip to content

Conversation

louisinger
Copy link
Collaborator

@louisinger louisinger commented Oct 8, 2025

This PR adds unit tests to our outpointLocker struct.

@altafan please review

Summary by CodeRabbit

  • Refactor

    • Simplified key-derivation interface and streamlined key-management flow to reduce internal complexity.
  • Tests

    • Added comprehensive unit tests for outpoint locking covering expiry, re-locking, and concurrent access.
  • Bug Fixes

    • Skip lock processing for empty inputs to improve performance.
    • Detect and surface duplicate-lock attempts to prevent conflicting locks.

Copy link
Contributor

coderabbitai bot commented Oct 8, 2025

Walkthrough

Removed the network parameter from deriveForfeitPrvkey and updated its call site. OutpointLocker.Lock now early-returns on empty input, errors if any outpoint is already locked, and uses placeholder context parameters; added fmt import. Added comprehensive OutpointLocker unit tests covering expiry and concurrency.

Changes

Cohort / File(s) Summary of Changes
Key management API change
pkg/arkd-wallet/core/application/wallet/key_manager.go
Dropped network parameter from deriveForfeitPrvkey signature and updated newKeyManager to call the single-argument form. No other logic changes reported.
Outpoint locker implementation
pkg/arkd-wallet/core/application/wallet/outpoint_locker.go
Added fmt import; renamed context parameter to placeholder _; Lock returns immediately for empty input and errors if any provided outpoint is already locked; otherwise assigns/refreshes lock expiry entries.
Outpoint locker tests
pkg/arkd-wallet/core/application/wallet/outpoint_locker_test.go
Added unit tests: initialization, single/multiple locking, expiry-based eviction, re-lock expiry refresh, concurrency with goroutines, and a deterministic random32Bytes helper.

Sequence Diagram(s)

sequenceDiagram
  participant KM as KeyManager
  participant HD as hdkeychain.ExtendedKey

  rect rgba(233,246,255,0.6)
  note over KM: newKeyManager()
  KM->>HD: deriveForfeitPrvkey(xpub)
  note over KM,HD: network parameter removed
  HD-->>KM: btcec.PrivateKey / error
  end
Loading
sequenceDiagram
  participant C as Caller
  participant OL as OutpointLocker

  rect rgba(240,255,240,0.6)
  note over C: Lock(outpoints)
  C->>OL: Lock(_, outpoints, expiry)
  alt outpoints empty
    OL-->>C: nil
  else
    alt any outpoint already locked
      OL-->>C: error (duplicate lock)
    else
      loop for each outpoint
        OL->>OL: add/refresh lock entry with expiry
      end
      OL-->>C: nil
    end
  end
  end

  note over C,OL: Get returns only non-expired entries
  C->>OL: Get(_)
  OL-->>C: set of active locked outpoints
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • altafan

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly identifies the primary change—adding unit tests for the OutpointLocker component in the arkd-wallet module—and is concise and directly related to the pull request’s content.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 755d051 and 30b1641.

📒 Files selected for processing (3)
  • pkg/arkd-wallet/core/application/wallet/key_manager.go (2 hunks)
  • pkg/arkd-wallet/core/application/wallet/outpoint_locker.go (2 hunks)
  • pkg/arkd-wallet/core/application/wallet/outpoint_locker_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: unit tests
  • GitHub Check: integration tests

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: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30b1641 and 0c624db.

📒 Files selected for processing (2)
  • pkg/arkd-wallet/core/application/wallet/outpoint_locker.go (2 hunks)
  • pkg/arkd-wallet/core/application/wallet/outpoint_locker_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/arkd-wallet/core/application/wallet/outpoint_locker_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: integration tests
  • GitHub Check: unit tests
🔇 Additional comments (3)
pkg/arkd-wallet/core/application/wallet/outpoint_locker.go (3)

5-5: LGTM: fmt import added.

The fmt package import is necessary for the error message formatting on line 39.


26-29: LGTM: Good defensive programming.

The signature change using _ for the unused context parameter is idiomatic Go, and the early return for empty input is an efficient guard clause that avoids unnecessary mutex acquisition.


48-48: LGTM: Consistent unused-parameter pattern.

The underscore for the unused context parameter matches the pattern established in the lock method and is idiomatic Go.

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: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53d2b0f and 786d738.

📒 Files selected for processing (1)
  • pkg/arkd-wallet/core/application/wallet/outpoint_locker.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: integration tests
  • GitHub Check: unit tests
🔇 Additional comments (3)
pkg/arkd-wallet/core/application/wallet/outpoint_locker.go (3)

5-5: LGTM!

The fmt import is correctly added for the error message formatting.


27-29: LGTM!

The early return for empty input is a sensible optimization that avoids unnecessary lock acquisition.


55-55: LGTM!

Using _ for the unused context parameter is appropriate and follows Go conventions.

@altafan altafan merged commit 3c966e7 into arkade-os:master Oct 8, 2025
5 checks passed
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