Skip to content

feat(billing): adds a unique rpc proxy header per instance of a batch signing client#2152

Merged
ygrishajev merged 1 commit intomainfrom
feature/billing
Nov 4, 2025
Merged

feat(billing): adds a unique rpc proxy header per instance of a batch signing client#2152
ygrishajev merged 1 commit intomainfrom
feature/billing

Conversation

@ygrishajev
Copy link
Contributor

@ygrishajev ygrishajev commented Nov 4, 2025

Summary by CodeRabbit

  • Refactor
    • Reworked signing client wiring to use a modular factory approach for creating HTTP-backed signing clients with unique request identifiers, and removed an older synchronous client wrapper.
  • Tests
    • Added and updated unit tests to cover the new signing-client factory and updated client usage.

@ygrishajev ygrishajev requested a review from a team as a code owner November 4, 2025 11:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2025

Walkthrough

Replaces the old SyncSigningStargateClient class with a factory-based SigningStargateClient creation flow. Adds a new signing-stargate-client factory (and tests), updates consumers to use the factory, and removes the SyncSigningStargateClient implementation and its exports.

Changes

Cohort / File(s) Summary
Factory Implementation
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts
New module exporting CreateSigningStargateClient, createSigningStargateClientFactory, and createSigningStargateClient. Composes HttpClient, Comet38Client, and SigningStargateClient.createWithSigner, adding a UUID X-Proxy-Key header.
Factory Tests
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts
New unit test verifying the factory constructs HttpClient with endpoint and header, creates Comet38Client, invokes signer factory, and returns the mocked SigningStargateClient.
Batch Signing Client
apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts, apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.spec.ts
Replaced SyncSigningStargateClient usage with SigningStargateClient and updated constructor/factory parameter types to CreateSigningStargateClient. Tests updated accordingly.
Removed Class
apps/api/src/billing/lib/sync-signing-stargate-client/sync-signing-stargate-client.ts
Deleted file that defined SyncSigningStargateClient and re-exported BroadcastTxSyncResponse.
Provider & Service Call Sites
apps/api/src/billing/providers/signing-client.provider.ts, apps/api/src/billing/services/dedupe-signing-client/dedupe-signing-client.service.ts
Replaced SyncSigningStargateClient.createWithEndpoint.bind(...) usage with the new createSigningStargateClient factory across registrations and call sites.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Provider as signing-client.provider
    participant Factory as createSigningStargateClient
    participant HttpC as HttpClient
    participant Comet as Comet38Client
    participant SSC as SigningStargateClient

    Provider->>Factory: createSigningStargateClient(endpoint, wallet, options?)
    Factory->>HttpC: new HttpClient(endpoint, { X-Proxy-Key: UUID })
    HttpC-->>Factory: httpClient
    Factory->>Comet: Comet38Client.create(httpClient)
    Comet-->>Factory: rpcClient
    Factory->>SSC: SigningStargateClient.createWithSigner(rpcClient, wallet, options?)
    SSC-->>Factory: signingClient
    Factory-->>Provider: SigningStargateClient instance
Loading
sequenceDiagram
    autonumber
    participant Provider as Provider
    participant Old as SyncSigningStargateClient
    participant New as createSigningStargateClient
    participant BSC as BatchSigningClientService

    rect rgb(220,220,255)
    Note over Old,BSC: Before (class-based)
    Provider->>Old: SyncSigningStargateClient.createWithEndpoint.bind(...)
    Old-->>Provider: bound factory
    Provider->>BSC: constructor(..., boundFactory)
    end

    rect rgb(220,255,220)
    Note over New,BSC: After (factory-based)
    Provider->>New: createSigningStargateClient
    New-->>Provider: signing client factory
    Provider->>BSC: constructor(..., createSigningStargateClient)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas needing extra attention:
    • Verify the factory's CreateSigningStargateClient signature matches all call sites.
    • Confirm UUID header generation and HttpClient construction are as intended and test-covered.
    • Ensure deletion of sync-signing-stargate-client.ts has no remaining references elsewhere.

Possibly related PRs

Suggested reviewers

  • stalniy
  • baktun14

Poem

🐇 I swapped the old sync hop for a factory spree,

UUIDs on headers, Comet and HTTP glee,
Clients now born from functions, neat and spry,
The old class waved goodbye with a twitch of its eye,
A little rabbit cheers: compose, don't bind — that's the key!

Pre-merge checks and finishing touches

✅ 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 accurately describes the main change: replacing SyncSigningStargateClient with a new factory-based approach that adds a unique proxy header per batch signing client instance.
✨ 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 feature/billing

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f8a15d and d7f019c.

📒 Files selected for processing (7)
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.spec.ts (2 hunks)
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts (4 hunks)
  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts (1 hunks)
  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts (1 hunks)
  • apps/api/src/billing/lib/sync-signing-stargate-client/sync-signing-stargate-client.ts (0 hunks)
  • apps/api/src/billing/providers/signing-client.provider.ts (4 hunks)
  • apps/api/src/billing/services/dedupe-signing-client/dedupe-signing-client.service.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/api/src/billing/lib/sync-signing-stargate-client/sync-signing-stargate-client.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.spec.ts
  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts
  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts
  • apps/api/src/billing/services/dedupe-signing-client/dedupe-signing-client.service.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/billing/providers/signing-client.provider.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/billing/providers/signing-client.provider.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: baktun14
Repo: akash-network/console PR: 1725
File: apps/api/src/utils/constants.ts:5-5
Timestamp: 2025-07-24T17:00:52.361Z
Learning: In the Akash Network Console project, when cross-cutting concerns or broader refactoring issues are identified during PR review, the preferred approach is to create a separate GitHub issue to track the work rather than expanding the scope of the current PR. This maintains focus and allows for proper planning of architectural improvements.
📚 Learning: 2025-08-21T04:03:23.490Z
Learnt from: stalniy
Repo: akash-network/console PR: 1827
File: apps/api/src/console.ts:146-154
Timestamp: 2025-08-21T04:03:23.490Z
Learning: In the Akash Network console project, services like JobQueueService implement dispose() methods for resource cleanup, and the tsyringe container has been extended with a dispose() method that iterates over all registered instances and calls their dispose() methods, enabling proper shutdown orchestration.

Applied to files:

  • apps/api/src/billing/providers/signing-client.provider.ts
🧬 Code graph analysis (1)
apps/api/src/billing/providers/signing-client.provider.ts (1)
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts (1)
  • createSigningStargateClient (57-61)
⏰ 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: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (2)
apps/api/src/billing/providers/signing-client.provider.ts (2)

4-4: LGTM! Clean refactoring to factory-based approach.

The import change from SyncSigningStargateClient to createSigningStargateClient aligns well with the factory pattern refactoring.


12-54: Factory-based signing client registration verified as correct.

The factory function signature matches the BatchSigningClientService constructor expectations exactly:

  • CreateSigningStargateClient type: (endpoint: string, wallet: Wallet, options?: { registry?: Registry }) => SigningStargateClient
  • Constructor call in provider: new BatchSigningClientService(..., createSigningStargateClient, ..., UNIQUE_IDENTIFIER)
  • Factory invocation in constructor: createClientWithSigner(RPC_ENDPOINT, wallet, { registry })

All three signing client registrations follow the same pattern consistently and are correctly implemented.


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

@ygrishajev ygrishajev changed the title feat(billing): adds a unique rpc proxy header per instance of a batch… feat(billing): adds a unique rpc proxy header per instance of a batch signing client Nov 4, 2025
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: 2

Caution

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

⚠️ Outside diff range comments (1)
apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts (1)

152-162: Await the async signing client creation.

SigningStargateClient.createWithSigner (and the preceding Comet38Client.create) both return promises, so createSigningStargateClient now yields a Promise<SigningStargateClient>. Assigning that promise to this.client means every subsequent call (e.g., this.client.getChainId(), this.client.sign(...)) will throw at runtime because this.client is not the resolved client instance. Please await the factory before storing/using the client—e.g., keep a clientPromise and await it at each use site, or change the factory/type to resolve the async creation internally.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e0e7bb and 6f8a15d.

📒 Files selected for processing (7)
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.spec.ts (2 hunks)
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts (4 hunks)
  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts (1 hunks)
  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts (1 hunks)
  • apps/api/src/billing/lib/sync-signing-stargate-client/sync-signing-stargate-client.ts (0 hunks)
  • apps/api/src/billing/providers/signing-client.provider.ts (4 hunks)
  • apps/api/src/billing/services/dedupe-signing-client/dedupe-signing-client.service.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/api/src/billing/lib/sync-signing-stargate-client/sync-signing-stargate-client.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.spec.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts
  • apps/api/src/billing/services/dedupe-signing-client/dedupe-signing-client.service.ts
  • apps/api/src/billing/providers/signing-client.provider.ts
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts
  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.spec.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts
  • apps/api/src/billing/services/dedupe-signing-client/dedupe-signing-client.service.ts
  • apps/api/src/billing/providers/signing-client.provider.ts
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts
  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts
  • apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.spec.ts
🧠 Learnings (2)
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it

Applied to files:

  • apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts
📚 Learning: 2025-08-21T04:03:23.490Z
Learnt from: stalniy
Repo: akash-network/console PR: 1827
File: apps/api/src/console.ts:146-154
Timestamp: 2025-08-21T04:03:23.490Z
Learning: In the Akash Network console project, services like JobQueueService implement dispose() methods for resource cleanup, and the tsyringe container has been extended with a dispose() method that iterates over all registered instances and calls their dispose() methods, enabling proper shutdown orchestration.

Applied to files:

  • apps/api/src/billing/providers/signing-client.provider.ts
🧬 Code graph analysis (5)
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.spec.ts (2)
apps/api/src/billing/lib/wallet/wallet.ts (1)
  • Wallet (7-65)
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts (1)
  • createSigningStargateClientFactory (37-52)
apps/api/src/billing/services/dedupe-signing-client/dedupe-signing-client.service.ts (1)
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts (1)
  • createSigningStargateClient (60-64)
apps/api/src/billing/providers/signing-client.provider.ts (1)
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts (1)
  • createSigningStargateClient (60-64)
apps/api/src/billing/lib/batch-signing-client/batch-signing-client.service.ts (1)
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts (1)
  • CreateSigningStargateClient (23-23)
apps/api/src/billing/lib/signing-stargate-client-factory/signing-stargate-client.factory.ts (1)
apps/api/src/billing/lib/wallet/wallet.ts (1)
  • Wallet (7-65)
⏰ 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: validate / validate-app
  • GitHub Check: test-build

@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.48%. Comparing base (8e0e7bb) to head (d7f019c).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2152      +/-   ##
==========================================
- Coverage   46.83%   46.48%   -0.36%     
==========================================
  Files        1015     1005      -10     
  Lines       28734    28385     -349     
  Branches     7442     7419      -23     
==========================================
- Hits        13458    13195     -263     
- Misses      14882    14885       +3     
+ Partials      394      305      -89     
Flag Coverage Δ *Carryforward flag
api 82.07% <100.00%> (ø)
deploy-web 25.25% <ø> (ø) Carriedforward from 8e0e7bb
log-collector ?
notifications 88.11% <ø> (ø) Carriedforward from 8e0e7bb
provider-console 81.48% <ø> (ø) Carriedforward from 8e0e7bb
provider-proxy 85.28% <ø> (ø) Carriedforward from 8e0e7bb

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...tch-signing-client/batch-signing-client.service.ts 90.38% <ø> (ø)
...-client-factory/signing-stargate-client.factory.ts 100.00% <100.00%> (ø)
...i/src/billing/providers/signing-client.provider.ts 88.23% <100.00%> (ø)
...pe-signing-client/dedupe-signing-client.service.ts 100.00% <100.00%> (ø)

... and 41 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@baktun14 baktun14 left a comment

Choose a reason for hiding this comment

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

Nice!

@ygrishajev ygrishajev merged commit 8122697 into main Nov 4, 2025
64 of 66 checks passed
@ygrishajev ygrishajev deleted the feature/billing branch November 4, 2025 16:08
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

Comments