Skip to content

Conversation

@acuarica
Copy link
Contributor

@acuarica acuarica commented Jul 3, 2025

Description:

This PR introduces a Read-Only execution mode for the JSON-RPC Relay. In Read-Only mode, RPC methods that need the operator settings, i.e., OPERATOR_ID_MAIN and OPERATOR_KEY_MAIN, are disabled (returning Unsupported operation error).

You can enable Read-Only mode by setting the configuration variable READ_ONLY to true. Note that in Read-Only mode, both configuration variables OPERATOR_ID_MAIN and OPERATOR_KEY_MAIN will not be used and should not be set.

Related issue(s):

Fixes #3878.

Notes for reviewer:

Note

eth_call might call the CN if either ETH_CALL_CONSENSUS_SELECTORS applies or ETH_CALL_DEFAULT_TO_CONSENSUS_NODE is set. However, these variables are in the process to be removed

Therefore, these variables are not taken into account when Read-Only mode is activated.

Note

Initially, the logic to check for the READ_ONLY flag was placed in SDKClient.executeTransaction. However, there was an issue when USE_ASYNC_TX_PROCESSING was set. In this case, the transaction hash would be returned in Read-Only mode. This is not the desired outcome, as we want the user to get Unsupported operation error. That's why the logic was placed in TransactionService.sendRawTransaction.

Note

Usages of @ts-ignore were replaced by @ts-expect-error in the updated tests. We should prefer @ts-expect-error so we can detect unused directives. Also, TypeScript error messages were included to be more explicit about the ignored error.

Checklist

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

Signed-off-by: Luis Mastrangelo <[email protected]>
@acuarica acuarica linked an issue Jul 3, 2025 that may be closed by this pull request
acuarica added 2 commits July 3, 2025 22:10
Signed-off-by: Luis Mastrangelo <[email protected]>
Signed-off-by: Luis Mastrangelo <[email protected]>
@acuarica acuarica self-assigned this Jul 3, 2025
@acuarica acuarica added the enhancement New feature or request label Jul 3, 2025
@acuarica acuarica added this to the 0.70.0 milestone Jul 3, 2025
@github-actions
Copy link

github-actions bot commented Jul 3, 2025

Test Results

 20 files  +  4  278 suites  +56   17m 55s ⏱️ + 3m 3s
704 tests +153  699 ✅ +151  5 💤 +2  0 ❌ ±0 
720 runs  +153  715 ✅ +151  5 💤 +2  0 ❌ ±0 

Results for commit 8b3ea3d. ± Comparison against base commit 3684f3c.

This pull request removes 1 and adds 154 tests. Note that renamed tests count towards both.
should fail with INVALID_PARAMETER when using PrestateTracer ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @debug API Acceptance Tests debug_traceTransaction Edge Cases - Parameter Validation should fail with INVALID_PARAMETER when using PrestateTracer
"eth_call" for non-existing contract address returns 0x ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call "eth_call" for non-existing contract address returns 0x
001 Should call pureMultiply ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With evm address 001 Should call pureMultiply
001 Should call pureMultiply ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With long-zero address 001 Should call pureMultiply
002 Should call msgSender ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With evm address 002 Should call msgSender
002 Should call msgSender ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With long-zero address 002 Should call msgSender
003 Should call txOrigin ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With evm address 003 Should call txOrigin
003 Should call txOrigin ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With long-zero address 003 Should call txOrigin
004 Should call msgSig ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With evm address 004 Should call msgSig
004 Should call msgSig ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With long-zero address 004 Should call msgSig
005 Should call addressBalance ‑ RPC Server Acceptance Tests Acceptance tests @api-conformity @api-batch-3 RPC Server Acceptance Tests eth_call Caller contract With evm address 005 Should call addressBalance
…

♻️ This comment has been updated with latest results.

acuarica added 6 commits July 3, 2025 23:09
Signed-off-by: Luis Mastrangelo <[email protected]>
Signed-off-by: Luis Mastrangelo <[email protected]>
Signed-off-by: Luis Mastrangelo <[email protected]>
Signed-off-by: Luis Mastrangelo <[email protected]>
@acuarica acuarica marked this pull request as ready for review July 9, 2025 13:00
@acuarica acuarica requested review from a team as code owners July 9, 2025 13:00
@acuarica acuarica requested a review from quiet-node July 9, 2025 13:00
Signed-off-by: Luis Mastrangelo <[email protected]>
@konstantinabl
Copy link
Contributor

@acuarica should we wait for the removal of ETH_CALL_DEFAULT_TO_CONSENSUS_NODE before merging this (#3918), since I don't see it in the PR, but users should also be warned about it, in case they've set it but they are in READ ONLY

@acuarica
Copy link
Contributor Author

Hi @konstantinabl, it should be ok to merge this now. I wouldn't wait until we merge PR #3918.

@acuarica
Copy link
Contributor Author

We are considering to include one additional requirement as part of this PR. That is, to ensure the operator has positive balance before starting the JSON-RPC Relay/WebSocket. This requirement can be seen as new validation, which is independent of the Read-Only mode feature.

This simply change, however, has some implications. Currently, the start of the Relay is sync, i.e., there are no promises running until Koa server starts listening. This means that the validation logic needs to be placed in both Relay and WebSocket's main. But we don't currently have tests at main level. Only at server.ts and webSocketServer.ts levels respectively.

Therefore, we can either

  • 1. drop this requirement altogether, or
  • 2. we can implement this in a following PR given the amount of changes that this may require.

@acuarica acuarica merged commit 34ce7f7 into main Jul 11, 2025
85 of 94 checks passed
@acuarica acuarica deleted the 3878-json-rpc-relay-read-only-or-read-write-mode branch July 11, 2025 17:13
@codecov
Copy link

codecov bot commented Jul 11, 2025

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/config-service/src/services/index.ts 88.88% 1 Missing and 1 partial ⚠️
@@           Coverage Diff           @@
##             main    #3896   +/-   ##
=======================================
  Coverage        ?   87.00%           
=======================================
  Files           ?       87           
  Lines           ?     5094           
  Branches        ?     1042           
=======================================
  Hits            ?     4432           
  Misses          ?      387           
  Partials        ?      275           
Flag Coverage Δ
config-service 95.78% <88.88%> (?)
relay 81.21% <100.00%> (?)
server 80.81% <ø> (?)
ws-server 61.00% <ø> (?)

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

Files with missing lines Coverage Δ
...ckages/config-service/src/services/globalConfig.ts 100.00% <ø> (ø)
packages/relay/src/lib/clients/sdkClient.ts 73.33% <ø> (ø)
...thService/transactionService/TransactionService.ts 89.78% <100.00%> (ø)
packages/relay/src/utils.ts 94.11% <100.00%> (ø)
packages/config-service/src/services/index.ts 95.55% <88.88%> (ø)
🚀 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.

Json RPC Relay READ ONLY OR READ-WRITE mode

5 participants