diff --git a/scripts/derive_galileo_gas_parameter/.env.example b/scripts/derive_galileo_gas_parameter/.env.example new file mode 100644 index 0000000000..238cee4367 --- /dev/null +++ b/scripts/derive_galileo_gas_parameter/.env.example @@ -0,0 +1,3 @@ +SCROLL_URL=https://rpc.scroll.io +MAINNET_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY +BEACON_URL=https://eth-mainnet-beacon.g.alchemy.com/v2/YOUR_API_KEY diff --git a/scripts/derive_galileo_gas_parameter/.gitignore b/scripts/derive_galileo_gas_parameter/.gitignore new file mode 100644 index 0000000000..9b0509c16d --- /dev/null +++ b/scripts/derive_galileo_gas_parameter/.gitignore @@ -0,0 +1,41 @@ +# Environment variables (contains API keys) +.env + +# Cached data files +*.pkl + +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# Virtual environments +.venv +venv/ +ENV/ + +# IDE +.idea/ +.vscode/ +*.swp +*.swo + +# Logs +*.log diff --git a/scripts/derive_galileo_gas_parameter/README.md b/scripts/derive_galileo_gas_parameter/README.md new file mode 100644 index 0000000000..121dfc48ec --- /dev/null +++ b/scripts/derive_galileo_gas_parameter/README.md @@ -0,0 +1,54 @@ +# Galileo Gas Parameter Derivation + +Derives L1 fee parameters (`commit_scalar`, `blob_scalar`, `penalty_multiplier`) for Scroll's Galileo upgrade by analyzing historical on-chain data. + +## Prerequisites + +- Python 3.10+ +- pipenv +- gcc and python3-devel + +```bash +# Ubuntu/Debian +sudo apt install python3-dev gcc +# Fedora/RHEL +sudo dnf install python3-devel gcc +``` + +## Installation + +```bash +cd scripts/derive_galileo_gas_parameter +pipenv install +``` + +## Running + +### 1. Create `.env` file + +```bash +SCROLL_URL=https://rpc.scroll.io +MAINNET_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY +BEACON_URL=https://eth-mainnet-beacon.g.alchemy.com/v2/YOUR_API_KEY +``` + +### 2. Usage + +```bash +# Collect data from 30 recent batches +pipenv run python -u derive_galileo_gas_parameter.py --mode collect --n-batches 30 + +# Load previously cached data +pipenv run python -u derive_galileo_gas_parameter.py --mode load --start-batch 494041 --end-batch 494070 +``` + +**Options:** +- `--mode {collect,load}` - Collect new data or load from cache (required) +- `--n-batches N` - Number of batches to collect (default: 30) +- `--start-batch N` / `--end-batch N` - Batch range for load mode +- `--target-penalty FLOAT` - Target penalty at P95 (default: 0.1 = 10%) +- `--penalty-multiplier FLOAT` - Use fixed penalty multiplier instead of calculating + +### 3. Cached Data + +Collected data is saved to `galileo_data_batch_{start}_{end}.pkl` for re-analysis without re-fetching from RPC. Use `--mode load` to reload. diff --git a/scripts/derive_galileo_gas_parameter/derive_galileo_gas_parameter.py b/scripts/derive_galileo_gas_parameter/derive_galileo_gas_parameter.py index 32e262effa..d82b24b7d6 100644 --- a/scripts/derive_galileo_gas_parameter/derive_galileo_gas_parameter.py +++ b/scripts/derive_galileo_gas_parameter/derive_galileo_gas_parameter.py @@ -32,12 +32,15 @@ # Read RPC endpoints from environment variables mainnet_url = os.getenv('MAINNET_URL', '') scroll_url = os.getenv('SCROLL_URL', 'https://rpc.scroll.io') +beacon_url = os.getenv('BEACON_URL', '') # Validate that environment variables are set if not mainnet_url: raise ValueError("MAINNET_URL environment variable is not set. Please set it to your Ethereum mainnet RPC endpoint.") if not scroll_url: raise ValueError("SCROLL_URL environment variable is not set. Please set it to your Scroll RPC endpoint.") +if not beacon_url: + raise ValueError("BEACON_URL environment variable is not set. Please set it to your Ethereum beacon chain RPC endpoint.") # EtherFi contract addresses (lowercase for comparison) ETHERFI_SPEND_ADDRESS = "0x7ca0b75e67e33c0014325b739a8d019c4fe445f0" @@ -465,7 +468,7 @@ def collect_batch_data(n_batches=30, width=5, start_time=None): print("=" * 60) # Get L1 head - mainnet_beacon_url = "https://eth-mainnetbeacon.g.alchemy.com/v2/Lzj9QLupql91nuRFYAosy" + mainnet_beacon_url = beacon_url l1_head = latest_finalized_event_block(width) beacon_head_slot = beacon_head(l1_head, mainnet_beacon_url)