Skip to content

feat: optimize bulk account cloning with collect-then-push strategy - #183

Merged
EtienneWallet merged 4 commits into
developfrom
feat/optimize_cloning
Mar 12, 2026
Merged

feat: optimize bulk account cloning with collect-then-push strategy#183
EtienneWallet merged 4 commits into
developfrom
feat/optimize_cloning

Conversation

@EtienneWallet

Copy link
Copy Markdown
Contributor

Summary

Introduces AccountBatchCloneStep to optimize cloning multiple accounts in a single operation. This reduces cloning ~650 Ashswap/X-Exchange pools from ~1 hour to an estimated ~2-5 minutes by eliminating redundant operations and smart-batching HTTP calls.

Changes

Core Implementation:

  • AccountBatchCloneStep: New step accepting a list of addresses with 4-phase collect-then-push strategy

    • Phase 1: Cache-aware data fetching for all addresses
    • Phase 2: Single ESDT module reconciliation (vs O(n) before)
    • Phase 3: Single Elasticsearch bulk insert (vs O(n) before)
    • Phase 4: Smart-batched account state pushing by payload size
  • set_states_batched(): Groups multiple accounts by estimated payload size (~2MB target per call) with automatic batching and retry resilience

  • _set_state_with_retry(): Exponential backoff wrapper (3 retries at 1s/2s/4s) for transient failures

  • _estimate_account_bytes(): Estimates account payload including metadata fields

  • Extracted 8 reusable functions from AccountCloneStep for code reuse

Configuration:

  • Chain simulator rate limits increased: API_RATE_LIMIT=100 (from 2), STORAGE_ITERATION_BATCH_SIZE=5000 (from 1000)

Documentation:

  • Added full user documentation for AccountBatchCloneStep
  • Updated changelog with new features and config changes
  • Updated step count in development guide

Testing

  • All existing unit tests pass (268 tests)
  • Code quality checks pass: ruff, pylint 9.84/10, bandit, flake8
  • Behavior of existing AccountCloneStep unchanged (backward compatible)

EtienneWallet and others added 4 commits March 12, 2026 08:57
Implements 4-phase collect-then-push strategy to reduce cloning ~650 accounts from ~1 hour to ~2-5 minutes by eliminating O(n²) ESDT module fetches, reducing Elasticsearch inserts from O(n) to O(1), and smart-batching set_state calls by payload size.

Changes:
- AccountBatchCloneStep: new step accepting list of addresses with cache-aware rate limiting, single ESDT reconciliation, and payload-aware batching
- Extracted 8 reusable functions from AccountCloneStep: _fetch_account_clone_data, _fetch_source_storage, _get_storage_clone_data, _find_missing_esdt_identifiers, _fetch_missing_esdt_entries, _get_esdt_module_clone_data, _fetch_with_backoff, _insert_tokens_in_elasticsearch
- set_states_batched: groups accounts by estimated payload size (target ~2MB per call) with retry resilience
- _set_state_with_retry: exponential backoff wrapper (3 retries at 1s/2s/4s)
- _estimate_account_bytes: payload estimation including metadata fields
- Chain simulator config: API_RATE_LIMIT=100 (from 2), STORAGE_ITERATION_BATCH_SIZE=5000 (from 1000)
Updates:
- docs/source/user_documentation/steps.md: Add full AccountBatchCloneStep section with YAML example, feature bullets, and 4-phase execution description
- docs/source/dev_documentation/changelog.md: Added AccountBatchCloneStep, set_states_batched, _set_state_with_retry to Unreleased Added section; added Changed section for config updates and extracted functions
- CLAUDE.md: Updated step count from 28 to 29, added AccountBatchClone to Setup list
Changes:
- .gitignore: Changed bare 'temp' to '/temp/' to only ignore top-level temp directory
- docs/dictionary/custom_wordlist.txt: Added 'AccountBatchCloneStep' to spell check dictionary
@EtienneWallet
EtienneWallet merged commit f512e55 into develop Mar 12, 2026
@EtienneWallet
EtienneWallet deleted the feat/optimize_cloning branch March 12, 2026 08:02
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