Skip to content

api: invoke_contract fails fast when there's no node connection (#1695) - #2139

Closed
vsnation wants to merge 1 commit into
BeamMW:masterfrom
vsnation:fix/1695-invoke-contract-no-node
Closed

vsnation wants to merge 1 commit into
BeamMW:masterfrom
vsnation:fix/1695-invoke-contract-no-node

Conversation

@vsnation

@vsnation vsnation commented Oct 6, 2026

Copy link
Copy Markdown

Fix: invoke_contract answers immediately with -32019 "No connection to the node" when wallet-api has no node connection, instead of never answering and blocking later calls.

Why: the shader only starts once the wallet is synced (Wallet::DoInSyncedWallet). Without a node that never happens, so the request never completes. Later calls then queue behind it (default API), or fail with "Previous shader call is still in progress" (v6.0). Neither handler (v6.0, v6.1) checked the connection.

How to see the bug (master, no node needed)

beam-wallet restore --pass=p --wallet_path=w.db --seed_phrase="abandon;abandon;abandon;abandon;abandon;abandon;abandon;abandon;abandon;abandon;abandon;about;"
wallet-api --pass=p --wallet_path=w.db -n 127.0.0.1:1 -p 10000 --use_http=1 &      # no node on :1
curl --max-time 8 http://127.0.0.1:10000/api/wallet -d '{"jsonrpc":"2.0","id":1,"method":"invoke_contract","params":{"contract_file":"bvm/Shaders/vault/app.wasm","args":"role=manager,action=view","create_tx":false}}'
# master: no response (hangs); a second identical call hangs too

Improvement

master this PR
call 1 no response (8 s timeout) {"error":{"code":-32019,"data":"No connection to the node",…}} immediately
call 2 no response same error, immediately (not blocked)
with a reachable node works unchanged

How: V6Api keeps the nodeNetwork and checks it in both invoke_contract handlers before anything is queued, so no busy state is left behind. Without a nodeNetwork (e.g. wasm), nothing changes. It reuses ContractError, so there are no new error codes.

Testing: the table above (master vs this branch). New TestInvokeContractNoNodeConnection in wallet_test (an offline wallet with a real ShadersManager: each call must throw ContractError and leave the manager not busy). Without the fix it fails 2 checks; with it, it passes. Fork CI (running): https://github.com/vsnation/beam/actions/runs/37479393148

Fixes #1695

…MW#1695)

Without a node connection the shader never starts: ShadersManager waits
for a synced wallet (DoInSyncedWallet) that never comes, so
invoke_contract never answered, and later calls either queued behind it
(default API) or failed with "Previous shader call is still in progress"
(v6.0). Check the node connection before queueing the call and answer
ContractError "No connection to the node". Without a nodeNetwork (e.g.
wasm) nothing changes.

wallet_test: TestInvokeContractNoNodeConnection (fails without the fix).
@vsnation

Copy link
Copy Markdown
Author

Closing in favour of #2142, which fixes #1695 more completely (it fails calls only after a reconnect really fails, and releases queued calls too). Tested side by side, see my comment there.

@vsnation vsnation closed this Oct 12, 2026
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.

invoke_contract & no nnet

1 participant