Skip to content

Commit

Permalink
chore(protocol): enhancements to simulation setup and execution docum…
Browse files Browse the repository at this point in the history
…entation (#16068)

Co-authored-by: Daniel Wang <[email protected]>
Co-authored-by: D <[email protected]>
  • Loading branch information
3 people authored Feb 27, 2024
1 parent 06a774e commit b206047
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test": "forge test -vvv --match-path test/*.t.sol",
"test:coverage": "mkdir -p coverage && forge coverage --report lcov && lcov --remove ./lcov.info -o ./coverage/lcov.info 'test/' 'script/' 'contracts/thirdparty/' && genhtml coverage/lcov.info --branch-coverage --output-dir coverage --ignore-errors category && open coverage/index.html",
"test:genesis": "pnpm compile && FOUNDRY_PROFILE=genesis ./genesis/generate_genesis.test.sh",
"export:simconf": "forge test --match-test 'test_simulation' -vv > simulation/out/simconf_$(date +%s).txt"
"export:simconf": "mkdir -p simulation/out && forge test --match-test 'test_L2_NoFeeCheck_simulation' -vv > simulation/out/simconf_$(date +%s).txt"
},
"keywords": [
"ZKP",
Expand Down
55 changes: 50 additions & 5 deletions packages/protocol/simulation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,57 @@

Assuming you are in this directory.

1. Install required packages: `python3 -m pip install -r requirements.txt`
### Setup

1. Make the output directory: `mkdir -p out`
1. **Update Foundry**

1. Run `pnpm run export:simconf` to export a new the config used in test `test_eip1559_math` to a file in `out/`, the file name will be automatically generated, for example `simconf_1697809145.txt`
Before installing any packages, ensure your Foundry environment is up to date by running:

1. Run `python3 simulate.py out/simconf_1697809145.txt`
```
foundryup
```

This command updates Foundry tools to their latest versions.

2. **Install Required Packages**

Install the necessary Python packages using pip:

```
python3 -m pip install -r requirements.txt
```

### Exporting Configuration

4. **Export Simulation Configuration**

Run the following command to export the configuration used in the `test_eip1559_math` test to a file in the `out/` directory. A unique file name based on the current timestamp will be generated automatically (e.g., `simconf_<timestamp>.txt`):

```
pnpm run export:simconf
```

**Note:** Replace `<timestamp>` with the actual timestamp from the generated file name.

### Running Simulation

5. **Run Simulation**

After exporting the configuration, locate the newly created file in the `out/` directory. Run the simulation using the command below, replacing `simconf_<timestamp>.txt` with the name of your specific file:

```
python3 simulate.py out/simconf_<timestamp>.txt
```

For example, if your file is named `simconf_1697809145.txt`, the command would be:

```
python3 simulate.py out/simconf_1697809145.txt
```

**Important:** The filename `simconf_<timestamp>.txt` is provided as an example. Your file will have a different timestamp. Please adjust the command according to the actual file name generated by the export process.

### Understanding the Outcome

The parameters set in the `test_eip1559_math` test simulate approximations of possible mainnet scenarios (e.g., 10x the Ethereum gas target). Run the commands as described above to become familiar with the simulation outcome and generated plots.

Currently, every parameter set in the `test_eip1559_math` is an approximation of a possible mainnet scenario (like 10x the ethereum gas target), so you can just run the commands below to get familiar with the outcome and plots.

1 comment on commit b206047

@malutki880
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up

Please sign in to comment.