Skip to content

comet-ing/comet-cronjob

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

comet_prod_cron.sh – Cron for Comet

Overview

comet_prod_cron.sh is a production cron script that drives activity on the Comet JAM dApp by automatically:

  • Creating jams on L2.
  • Appending entries to each jam from different accounts.
  • Withdrawing ETH from one participant.
  • Deposit‑minting a Comet NFT via the EtherPortal.

It inspects existing state before choosing new jam IDs, so it can be safely re‑run without colliding with previously created jams.


What the script does

  • Discovers the next jam ID

    • Calls the Cartesi inspect API (alljams) via INSPECT_URL (default: https://base-sepolia.rollups.cartesi.io/v2/inspect/comet).
    • Parses the response, finds the maximum existing id, and computes:
      • START_JAM_ID = maxId + 1 (or 0 if no jams exist).
    • This keeps newly created jams, their names, and append/mint IDs aligned with the backend.
  • Runs a time‑slotted schedule

    • Uses discrete time slots, one every CREATE_INTERVAL seconds.
    • Per jam:
      1. Create at slot S.
      2. First append at S + APPEND_SLOTS.
      3. Second append + withdraw + mint at S + 2 * APPEND_SLOTS.
    • JAM_COUNT controls how many jams are created in a run; the script exits after all scheduled actions complete.
  • Creates jams with fixed parameters

    • Name: Comet #<id>.
    • Description: Automated test Comet <id> (prod check).
    • mintPrice = 0.001 ETH.
    • maxEntries = 4.
    • A genesis entry is included at creation time.
  • Appends entries and mints

    • Each jam receives:
      • 1 genesis entry from the creator account.
      • 1 append from a second account.
      • 1 append from a third account.
    • After the second append, the script:
      • Sends an eth.withdraw request for 0.1 ETH from the first appender.
      • Sends an EtherPortal depositEther call with a jam.mint exec payload and value 0.2 ETH (or 0.0001 ETH in the JS cron).
  • Rotates three accounts

    • Uses ACCOUNT1_PK, ACCOUNT2_PK, ACCOUNT3_PK.
    • For each jam:
      • One account is the creator.
      • One is the first appender.
      • One is the second appender and minter.
    • The assignment rotates by jam index (slot % 3), spreading activity across the three addresses.

How it works internally

  • Configuration loading

    • Optionally sources cronjob.env from:
      • The same directory as comet_prod_cron.sh, or
      • One directory above.
    • This file is for local/dev runs only.
    • In production, all environment variables should be provided by the platform (e.g. Fly.io secrets); the script does not require cronjob.env to exist.
  • Required environment variables

    • The script enforces, at startup:
      • RPC_URL – L1 RPC endpoint (e.g. Base Sepolia).
      • INPUT_BOX_ADDRESS – Cartesi InputBox contract.
      • APPLICATION_ADDRESS – Comet application address.
      • ETHER_PORTAL_ADDRESS – EtherPortal contract.
      • ACCOUNT1_PK, ACCOUNT2_PK, ACCOUNT3_PK – three EOA private keys (with or without 0x, normalized by the script).
    • Optional / tunable:
      • JAM_COUNT (default 5).
      • CREATE_INTERVAL (default 900 seconds).
      • SLEEP_BETWEEN_STEPS (default 1800 seconds).
      • INSPECT_URL (default https://base-sepolia.rollups.cartesi.io/v2/inspect/comet).
  • Inspect‑based START_JAM_ID

    • If START_JAM_ID is not set in the environment:
      • The script calls get_next_jam_id, which:
        • POSTs "alljams" to INSPECT_URL.
        • Decodes the hex payload to JSON.
        • Computes nextJamId = max(jams[].id) + 1 (or 0 if there are no jams).
      • START_JAM_ID is then set to this value for the run.
    • If START_JAM_ID is set, the script logs that it is using the provided value and skips inspect.
  • Slot loop

    • Computes:
      • APPEND_SLOTS = SLEEP_BETWEEN_STEPS / CREATE_INTERVAL.
      • TOTAL_SLOTS = JAM_COUNT + 2 * APPEND_SLOTS.
    • For each slot from 0 to TOTAL_SLOTS - 1:
      • Logs the slot number and virtual time.
      • Performs create / append / withdraw / mint actions as their respective slot thresholds are reached.
      • Sleeps CREATE_INTERVAL seconds between slots (except after the final slot).

Usage

Local / development

  • Create a cronjob.env file:
    • Start from cronjob.env.example.
    • Fill in RPC URL, contract addresses, and test private keys.
  • Run the script from the repo root:
./comet_prod_cron.sh
  • The script will:
    • Source cronjob.env if present.
    • Validate required environment variables.
    • Inspect current jams to choose the next START_JAM_ID.
    • Create and manage JAM_COUNT jams on a timed schedule.

Production (e.g. Fly.io, other cloud cron)

  • Do not rely on cronjob.env in production.
  • Configure all required environment variables securely via your platform’s env/secret mechanism.
  • Schedule or trigger:
./comet_prod_cron.sh
  • Each run:
    • Reads configuration from the process environment.
    • Inspects the Comet machine to determine the next jam ID.
    • Executes the create/append/withdraw/mint lifecycle for JAM_COUNT jams, then exits.

Deploying to Fly.io

Image build (Dockerfile)

This repo includes a Dockerfile that:

  • Installs dependencies:
    • bash, curl, jq, xxd, ca-certificates
    • Foundry (cast) via foundryup
  • Copies the cron script into /app:
    • comet_prod_cron.sh
  • Sets the entrypoint to:
bash /app/comet_prod_cron.sh

The container runs the cron script once and exits after the scheduled JAM lifecycle completes.

Fly app configuration

A minimal fly.toml is provided:

  • App name: comet-cronjob (change if needed).
  • Primary region: iad by default (change to your preferred region).
  • Processes:
[processes]
cron = "bash /app/comet_prod_cron.sh"

There are no HTTP services defined; this app is intended to be run as a job/cron rather than a long-lived web service.

Required environment / secrets on Fly

Set the same required variables as the script expects, but via Fly secrets:

  • RPC_URL
  • INPUT_BOX_ADDRESS
  • APPLICATION_ADDRESS
  • ETHER_PORTAL_ADDRESS
  • ACCOUNT1_PK
  • ACCOUNT2_PK
  • ACCOUNT3_PK

Optional tunables:

  • JAM_COUNT
  • CREATE_INTERVAL
  • SLEEP_BETWEEN_STEPS
  • INSPECT_URL
  • START_JAM_ID (to override inspect-based derivation)

Example:

fly secrets set \
  RPC_URL="https://..." \
  INPUT_BOX_ADDRESS="0x..." \
  APPLICATION_ADDRESS="0x..." \
  ETHER_PORTAL_ADDRESS="0x..." \
  ACCOUNT1_PK="..." \
  ACCOUNT2_PK="..." \
  ACCOUNT3_PK="..."

Build and deploy

From the repo root:

fly deploy

This will:

  • Build the Docker image using Dockerfile.
  • Deploy it as the comet-cronjob app (or whatever app name you configure).

Scheduling with Fly cron (Machines)

Use Fly Machines cron to run the job on a schedule. For example, to run hourly:

fly cron schedule comet-prod-cron "0 * * * *" \
  --process "cron" \
  --command "bash /app/comet_prod_cron.sh"
  • comet-prod-cron is the cron schedule name (not the app name).
  • --process "cron" matches the cron process in fly.toml.
  • --command overrides the default entrypoint if desired (you can omit it since ENTRYPOINT already runs the script).

Each scheduled run:

  • Starts a Machine using the current image.
  • Executes the cron script once.
  • Exits when the script finishes the JAM lifecycle.

About

Bash script to automate Comet app testing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors