Skip to content

feat(chain-simulator): make block generation configurable with AUTO_GENERATE_BLOCKS - #186

Merged
EtienneWallet merged 11 commits into
developfrom
feat/auto_generate_block_option
Jun 4, 2026
Merged

feat(chain-simulator): make block generation configurable with AUTO_GENERATE_BLOCKS#186
EtienneWallet merged 11 commits into
developfrom
feat/auto_generate_block_option

Conversation

@EtienneWallet

@EtienneWallet EtienneWallet commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduce an AUTO_GENERATE_BLOCKS config option to control whether MxOps drives chain-simulator block production. Users can now point MxOps at a simulator started with auto-generate-blocks enabled by setting AUTO_GENERATE_BLOCKS=false, where MxOps behaves like on other networks: it polls/waits for blocks instead of forcing them. Default is true, preserving today's behavior.

Changes

  • Add AUTO_GENERATE_BLOCKS config option (default true) to the [CHAIN_SIMULATOR] section, validated so malformed values raise an explicit error instead of silently disabling block generation
  • Implement should_generate_blocks() helper in providers.py that gates block production on the network + flag
  • Gate all block-generation call sites on the helper:
    • Transaction wait (send_and_wait_for_result): drives blocks until completion only when enabled; otherwise polls at a clamped refresh rate to avoid busy-polling
    • WaitStep(for_blocks=N): generates blocks or waits for them depending on the flag
    • ChainSimulatorSetTokenBalanceStep Phase 5: commits state via block generation when enabled, otherwise waits on every user shard and the metachain so the balance writes are committed where they live

Testing

All 306 unit tests pass:

  • bash scripts/launch_unit_tests.sh
  • Static checks pass: bash scripts/check_python_code.sh (bandit, flake8, ruff, pylint ≥ 9.5) ✅

Test coverage includes should_generate_blocks() across all branches (other network, default-on, explicitly-off, missing option, malformed value), both send_and_wait_for_result paths (generates vs. polls with clamp), WaitStep in auto mode, and ChainSimulatorSetTokenBalanceStep Phase 5 multi-shard waits.

Configuration:

[CHAIN_SIMULATOR]
AUTO_GENERATE_BLOCKS=true   # default: MxOps drives block production (today's behavior)

To use with an auto-producing simulator:

[CHAIN_SIMULATOR]
AUTO_GENERATE_BLOCKS=false  # MxOps waits for the simulator's own blocks

Backward Compatibility

Fully backward compatible. Default true preserves existing behavior. User configs without the option default to true, so no action is required for existing users.

EtienneWallet and others added 11 commits June 4, 2026 16:22
Add InvalidConfigValue error class and validation in should_generate_blocks to catch typos like 'ture' instead of silently disabling blocks. Unrecognized values now raise an explicit error. Add import-cycle clarification comment explaining why the helper lives in providers.py rather than config.py.
When AUTO_GENERATE_BLOCKS=false, the polling loop was busy-polling at 0.001s (chain-simulator refresh period). This was safe when generate_blocks_until_tx_completion ran first, but skipping that creates thousands of proxy requests per transaction. Introduce MIN_TX_REFRESH_PERIOD=0.2 and clamp the refresh period in the non-generating path to avoid tight busy-polling against the simulator.
When AUTO_GENERATE_BLOCKS=false, Phase 5 of ChainSimulatorSetTokenBalanceStep was waiting only for the metachain to advance. However, ESDT balances are stored on the receiver's user shard, and metachain/user-shard production are not synchronized. A single metachain block does not prove the receiver's shard has committed the written state, risking stale reads. Now wait for all user shards (0..num_shards-1) plus the metachain so the set_address_state writes are committed everywhere before returning.
The startup path unconditionally calls generate_blocks_until_epoch(2), even though block generation is otherwise gated by AUTO_GENERATE_BLOCKS. Clarify that this is intentional: the bundled simulator is always started in manual mode, this bootstrap runs before any user scene, and the auto-generate case targets an external simulator not started via this command.
Add tests for both branches of send_and_wait_for_result: the default generates-blocks-then-returns path, and the new polls-with-clamped-period path when AUTO_GENERATE_BLOCKS=false. Verifies that generate_blocks_until_tx_completion is called in the first case and not in the second, and that the refresh period is clamped to MIN_TX_REFRESH_PERIOD to prevent busy-polling.
…TE_BLOCKS

Test that should_generate_blocks raises InvalidConfigValue on unrecognized config values (e.g. typos like 'ture'). Also update existing tests to restore the prior config value instead of hardcoding 'true', improving test isolation.
Patch get_network_status at its usage site (mxops.execution.utils) instead of the base class, making the mock less fragile. Restore the prior AUTO_GENERATE_BLOCKS value in teardown instead of hardcoding 'true', improving test isolation and eliminating cross-test config contamination.
Update test_step_auto_generate_blocks_disabled_waits to verify that Phase 5 waits on all user shards (0, 1, 2) plus the metachain when not generating blocks, ensuring the set_address_state writes are committed everywhere. Restore prior config value in teardown for proper test isolation.
Document in the Changed section that chain-simulator block production is now gated by AUTO_GENERATE_BLOCKS flag. Transaction waits, WaitStep, and set-token-balance only drive blocks when enabled (the default); when disabled, MxOps waits for the auto-producing simulator instead with a clamped polling rate.
Allow users to control whether MxOps drives chain-simulator block production. Set AUTO_GENERATE_BLOCKS=false to point MxOps at a simulator started with auto-generate-blocks enabled, where MxOps waits for blocks instead of forcing them. Default is true, preserving today's behavior. Adds should_generate_blocks helper in providers.py that gates block generation calls, and documents the feature in chain_simulator.md.
@EtienneWallet
EtienneWallet merged commit ef3251c into develop Jun 4, 2026
@EtienneWallet
EtienneWallet deleted the feat/auto_generate_block_option branch June 4, 2026 15:49
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