Skip to content

Commit

Permalink
pkg: Add batch submitter (ethereum-optimism#12)
Browse files Browse the repository at this point in the history
* pkg: Add batch submitter

* chore(batch-submitter): fix configs

* chore(batch-submitter): use latest smock

* fix: use latest typescript

* chore: disable prettier in incompat lines

Long term fixed by switching to eslint

* perf: only test packages that have changed since master

https://github.com/lerna/lerna/tree/main/core/filter-options\#--since-ref

Co-authored-by: Georgios Konstantopoulos <[email protected]>
  • Loading branch information
smartcontracts and gakonst authored Mar 29, 2021
1 parent aa8baef commit 550a2f6
Show file tree
Hide file tree
Showing 43 changed files with 3,807 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Fetch history
run: git fetch

- name: Setup node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"lerna": "^4.0.0"
},
"scripts": {
"clean": "yarn workspaces run clean",
"build": "yarn workspaces run build",
"test": "yarn lerna run test --parallel",
"lint": "yarn lerna run lint --parallel",
"lint:fix": "yarn workspaces run lint:fix"
"clean": "yarn lerna run clean",
"build": "yarn lerna run build",
"test": "yarn lerna run test --parallel --since origin/master",
"lint": "yarn lerna run lint --parallel --since origin/master",
"lint:fix": "yarn lerna run lint:fix"
}
}
26 changes: 26 additions & 0 deletions packages/batch-submitter/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logging
DEBUG=info*,error*,warn*,debug*

L1_NODE_WEB3_URL=http://localhost:9545
L2_NODE_WEB3_URL=http://localhost:8545

MAX_TX_SIZE=90000
MIN_TX_SIZE=0
MAX_BATCH_SIZE=50
MAX_BATCH_SUBMISSION_TIME=0
POLL_INTERVAL=15000
NUM_CONFIRMATIONS=0
RESUBMISSION_TIMEOUT=300 # in seconds
FINALITY_CONFIRMATIONS=0
RUN_TX_BATCH_SUBMITTER=true
RUN_STATE_BATCH_SUBMITTER=true
SAFE_MINIMUM_ETHER_BALANCE=0
CLEAR_PENDING_TXS=false
ADDRESS_MANAGER_ADDRESS=

# Optional gas settings
MAX_GAS_PRICE_IN_GWEI=200
GAS_RETRY_INCREMENT=5
GAS_THRESHOLD_IN_GWEI=100

SEQUENCER_PRIVATE_KEY=0xd2ab07f7c10ac88d5f86f1b4c1035d5195e81f27dbe62ad65e59cbf88205629b
8 changes: 8 additions & 0 deletions packages/batch-submitter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build
dist
node_modules
.env
cache/*

# vim
*.swp
22 changes: 22 additions & 0 deletions packages/batch-submitter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog

## v0.1.3

- Add tx resubmission logic
- Log when the batch submitter runs low on ETH

## v0.1.2

Adds mnemonic config parsing

## v0.1.1

Final fixes before minnet release.

- Add batch submission timeout
- Log sequencer address
- remove ssh

## v0.1.0

The inital release
40 changes: 40 additions & 0 deletions packages/batch-submitter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Batch Submitter

Contains an executable batch submitter service which watches L1 and a local L2 node and submits batches to the
`CanonicalTransactionChain` & `StateCommitmentChain` based on its local information.

## Configuration
All configuration is done via environment variables. See all variables at [.env.example](.env.example); copy into a `.env` file before running.

## Building & Running
1. Make sure dependencies are installed just run `yarn` in the base directory
2. Build `yarn build`
3. Run `yarn start`

## Controlling log output verbosity
Before running, set the `DEBUG` environment variable to specify the verbosity level. It must be made up of comma-separated values of patterns to match in debug logs. Here's a few common options:
* `debug*` - Will match all debug statements -- very verbose
* `info*` - Will match all info statements -- less verbose, useful in most cases
* `warn*` - Will match all warnings -- recommended at a minimum
* `error*` - Will match all errors -- would not omit this

Examples:
* Everything but debug: `export DEBUG=info*,error*,warn*`
* Most verbose: `export DEBUG=info*,error*,warn*,debug*`

## Testing & linting

### Local

- Run unit tests with `yarn test`
- See lint errors with `yarn lint`; auto-fix with `yarn lint --fix`

### Submission

You may test a submission locally against a local Hardhat fork.

1. Follow the instructions [here](https://github.com/ethereum-optimism/hardhat) to run a Hardhat node.
2. Change the Batch Submitter `.env` field `L1_NODE_WEB3_URL` to the local Hardhat url. Depending on which network you are using, update `ADDRESS_MANAGER_ADDRESS` according to the [Regenesis repo](https://github.com/ethereum-optimism/regenesis).
3. Also check `L2_NODE_WEB3_URL` is correctly set and has transactions to submit.
3. Run `yarn build` to build your changes.
4. Start Batch Submitter with `yarn start`. It will automatically start submitting pending transactions from L2.
5 changes: 5 additions & 0 deletions packages/batch-submitter/exec/run-batch-submitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

const batchSubmitter = require("../build/src/exec/run-batch-submitter")

batchSubmitter.run()
35 changes: 35 additions & 0 deletions packages/batch-submitter/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import '@nomiclabs/hardhat-waffle'
import { HardhatUserConfig } from 'hardhat/config'

import {
DEFAULT_ACCOUNTS_HARDHAT,
RUN_OVM_TEST_GAS,
} from './test/helpers/constants'

const config: HardhatUserConfig = {
networks: {
hardhat: {
accounts: DEFAULT_ACCOUNTS_HARDHAT,
blockGasLimit: RUN_OVM_TEST_GAS * 2,
},
},
mocha: {
timeout: 50000,
},
solidity: {
version: '0.7.0',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
'*': {
'*': ['storageLayout'],
},
},
},
},
}

export default config
3 changes: 3 additions & 0 deletions packages/batch-submitter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const rootPath = __dirname

export { rootPath }
72 changes: 72 additions & 0 deletions packages/batch-submitter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "@eth-optimism/batch-submitter",
"version": "0.1.5",
"description": "[Optimism] Batch submission for sequencer & aggregators",
"main": "dist/index",
"types": "dist/index",
"files": [
"dist/index"
],
"scripts": {
"start": "node ./exec/run-batch-submitter.js",
"build": "tsc -p ./tsconfig.build.json",
"clean": "rimraf dist/ ./tsconfig.build.tsbuildinfo",
"lint": "yarn lint:fix && yarn lint:check",
"lint:check": "tslint --format stylish --project .",
"lint:fix": "prettier --config prettier-config.json --write \"hardhat.config.ts\" \"{src,exec,test}/**/*.ts\"",
"test": "hardhat test --show-stack-traces"
},
"keywords": [
"optimism",
"ethereum",
"sequencer",
"aggregator"
],
"homepage": "https://github.com/ethereum-optimism/optimism-monorepo/tree/master/packages/batch-submitter#readme",
"license": "MIT",
"author": "Optimism",
"repository": {
"type": "git",
"url": "https://github.com/ethereum-optimism/optimism-monorepo.git"
},
"dependencies": {
"@eth-optimism/contracts": "^0.0.2-alpha.7",
"@eth-optimism/core-utils": "^0.1.10",
"@eth-optimism/provider": "^0.0.1-alpha.13",
"@eth-optimism/ynatm": "^0.2.2",
"@ethersproject/abstract-provider": "^5.0.5",
"@ethersproject/providers": "^5.0.14",
"bluebird": "^3.7.2",
"dotenv": "^8.2.0",
"ethers": "5.0.0",
"new-contracts": "npm:@eth-optimism/[email protected]"
},
"devDependencies": {
"@eth-optimism/smock": "1.0.0-alpha.3",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@types/chai": "^4.1.7",
"@types/chai-as-promised": "^7.1.0",
"@types/mocha": "^5.2.6",
"@types/node": "^11.11.3",
"@types/sinon": "^9.0.10",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"ethereum-waffle": "3.0.0",
"ganache-core": "^2.13.2",
"hardhat": "^2.1.1",
"mocha": "^6.1.4",
"prettier": "^1.16.4",
"rimraf": "^2.6.3",
"sinon": "^9.2.4",
"sinon-chai": "^3.5.0",
"ts-node": "^8.2.0",
"typescript": "^4.2.3"
},
"resolutions": {
"ganache-core": "^2.13.2"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions packages/batch-submitter/prettier-config.json
Loading

0 comments on commit 550a2f6

Please sign in to comment.