Skip to content

executor: stop contract code that runs outside a method's time limit - #10

Merged
EnzinoBB merged 1 commit into
build/reproducible-1518from
fix/bound-contract-code
Oct 30, 2026
Merged

EnzinoBB merged 1 commit into
build/reproducible-1518from
fix/bound-contract-code

Conversation

@EnzinoBB

Copy link
Copy Markdown
Collaborator

Summary

Build 1518 runs some contract code on the Thrift thread with no time limit: the reserved token name check (the contract's getName()/getSymbol() at deploy) and the serialization and deserialization of the state around every call (the writeObject/readObject/hashCode of the contract's classes). Contract code that never returns there keeps a CPU busy for the life of the executor, once per transaction that reaches it, on every node that executes it; the call never gets an answer (the node gives up after executor_receive_timeout, 4 s by default).

ContractCodeLimit runs that code on a thread of its own:

  • what it returns or throws is passed on unchanged (the same exception object), so every call that ends gets the answer build 1518 gives;
  • code still running after max(execution time, 120 s) is stopped, and the answer is held back 10 min before a failure is returned: the node has stopped waiting long before, as it does with build 1518, which never answers. The node records the same result (TimeExpired) either way, so a network mixing this executor with 1518 agrees.

Wrapped: the name check (Deployer), the state serialization after deploy and after a call and the deserialization before a call (ContractExecutorServiceImpl), the deserialization per getter of executeByteCodeMultiple (LimitTimeThreadMethodExecutor), and getContractVariables. Code inside a contract method (already under the method's limit, running with the contract's permissions) is unchanged.

Limits: -Dcontract.executor.unbounded.code.limit.ms (default 120000), -Dcontract.executor.unbounded.code.hold.ms (default 600000).

Test plan

  • Node repo harness (ci/contracts/executor_harness.py, ci: token smart contract tests (executor harness and private testnet) node#127) on the release executor and this branch, every token scenario: identical status, return values, state hashes and emitted transactions on every step; the two scenarios with code that never returns (a token whose getName() loops, a state whose writeObject loops) get no answer from 1518 and a failure from this branch after limit + hold (5 s + 20 s in the run), with the looping thread stopped
  • Unit tests: the same 8 pre-existing failures of ContractExecutorTest as on the base branch, nothing new
  • CI

🤖 Generated with Claude Code

The reserved token name check calls the contract's getName()/getSymbol() at deploy, and
the state is deserialized and serialized around every call (the readObject/writeObject/
hashCode of the contract's classes), all on the Thrift thread and with no limit. Contract
code that never returns there keeps a CPU busy for the life of the executor, once per
transaction that reaches it.

That code now runs on a thread of its own. What it returns or throws is passed on
unchanged, so a call that ends gets the answer build 1518 gives. Code still running after
max(execution time, 120 s) is stopped and the answer is held back 10 min before a failure
is returned: the node has stopped waiting long before (executor_receive_timeout, 4 s by
default), as it does with build 1518, which never answers such a call.
@EnzinoBB
EnzinoBB merged commit 33e7f55 into build/reproducible-1518 Oct 30, 2026
4 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.

1 participant