Skip to content

Conversation

@acuarica
Copy link
Contributor

@acuarica acuarica commented Jul 11, 2025

Description:

This PR validates that the operator account OPERATOR_ID_MAIN has positive balance when starting up the Relay/WebSocket server in Read-Write mode. If the operator account has no balance (or does not exist), the Relay/WebSocket will fail on start up.

Related issue(s):

Fixes #3929.

Notes for reviewer:

Note

This PR introduces an async start up check. It needs to be async because it needs to make a request to the Mirror Node to get the operator's balance. This check needs to be placed directly in main (for both Relay and WebSocket) because the ConfigService loading process is sync (no Promises involved). It cannot be placed in the Relay's constructor either because this will lead to an async constructor.

Note

Initial discussion can be found here #3896 (comment).

Note

In packages/relay/tests/lib/eth/eth-helpers.ts, some @ts-ignore comments were removed because they were not exercised. We should use @ts-expect-error instead.

Note

In packages/relay/tests/lib/eth/eth_getBalance.spec.ts, code related to SDKClient was removed because it's not used anymore.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@acuarica acuarica linked an issue Jul 11, 2025 that may be closed by this pull request
@acuarica acuarica self-assigned this Jul 11, 2025
@acuarica acuarica added the enhancement New feature or request label Jul 11, 2025
@acuarica acuarica added this to the 0.70.0 milestone Jul 11, 2025
@github-actions
Copy link

github-actions bot commented Jul 11, 2025

Test Results

 20 files  ±0  277 suites  ±0   18m 2s ⏱️ +5s
702 tests  - 1  697 ✅ ±0  5 💤 ±0  0 ❌  - 1 
718 runs  ±0  713 ✅ +1  5 💤 ±0  0 ❌  - 1 

Results for commit c1224f4. ± Comparison against base commit f82f220.

This pull request removes 1 test.
"after all" hook in "@web-socket-batch-1 eth_call" ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-1 eth_call "after all" hook in "@web-socket-batch-1 eth_call"

♻️ This comment has been updated with latest results.

@acuarica acuarica marked this pull request as ready for review July 15, 2025 13:49
@acuarica acuarica requested review from a team as code owners July 15, 2025 13:49
acuarica added 4 commits July 15, 2025 17:06
Signed-off-by: Luis Mastrangelo <[email protected]>
Signed-off-by: Luis Mastrangelo <[email protected]>
Signed-off-by: Luis Mastrangelo <[email protected]>
@acuarica acuarica force-pushed the 3929-operator-has-balance-in-read-write-mode branch from 8fa49fb to c1224f4 Compare July 15, 2025 15:07
Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

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

LG left some thought

Copy link
Contributor

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

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

LGTM! Great work as always!

@acuarica acuarica modified the milestones: 0.70.0, 0.71.0 Jul 21, 2025
@acuarica
Copy link
Contributor Author

After an offline discussion with the team, we came to the conclusion that the start up validation shouldn't be in the

  • Precheck class, as it deals with "prechecks before sending a raw transaction",
  • validators module, as it deals with validating request payloads,
  • config-service package because the dependencies needed and the async check.

Moreover, there is already an async start up check in the Relay

this.populatePreconfiguredSpendingPlans().then();

private async populatePreconfiguredSpendingPlans(): Promise<void> {
return this.hbarSpendingPlanConfigService
.populatePreconfiguredSpendingPlans()
.then((plansUpdated) => {
if (plansUpdated > 0) {
this.logger.info('Pre-configured spending plans populated successfully');
}
})
.catch((e) => this.logger.warn(`Failed to load pre-configured spending plans: ${e.message}`));
}

so having ensureOperatorHasBalance in the Relay might not be such a bad idea after all.

@acuarica acuarica merged commit 7e4078f into main Jul 23, 2025
71 of 73 checks passed
@acuarica acuarica deleted the 3929-operator-has-balance-in-read-write-mode branch July 23, 2025 16:06
@codecov
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

@@            Coverage Diff             @@
##             main    #3930      +/-   ##
==========================================
- Coverage   86.86%   86.75%   -0.11%     
==========================================
  Files          87       87              
  Lines        5039     5045       +6     
  Branches     1020     1022       +2     
==========================================
  Hits         4377     4377              
- Misses        400      407       +7     
+ Partials      262      261       -1     
Flag Coverage Δ
config-service 95.78% <ø> (ø)
relay 81.32% <100.00%> (+0.05%) ⬆️
server 80.81% <100.00%> (ø)
ws-server 61.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/relay/src/lib/relay.ts 94.87% <100.00%> (+0.42%) ⬆️
packages/server/src/server.ts 67.88% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure the operator account has positive balance in Read-Write mode

4 participants