ethereum-optimism/optimism-tutorial をやってみる
セットアップ
https://github.com/ethereum-optimism/optimism-tutorial/tree/main/hardhat の方をやっていく
公式のセットアップの手順が npm install -g
を求めてくるので、程よく無視しつつやる
$ ghq get https://github.com/ethereum-optimism/optimism-tutorial
$ ghq get https://github.com/ethereum-optimism/optimism
optimism-tutorial のセットアップ
$ cd /path/to/optimism-tutorial/hardhat/dapp
$ npm ci
optimism のセットアップ
Build the Optimistic Ethereum software.
$ cd /path/to/optimism
$ yarn install
$ yarn build
Build the Docker containers
$ cd ops
$ export COMPOSE_DOCKER_CLI_BUILD=1
$ export DOCKER_BUILDKIT=1
$ docker-compose build && echo Build complete
docker-compose
でエラーになる
=> ERROR [stage-3 10/12] RUN yarn build 73.3s
------
> [stage-3 10/12] RUN yarn build:
#33 1.237 yarn run v1.22.5
#33 1.323 $ yarn lerna run build
#33 1.813 $ /optimism/node_modules/.bin/lerna run build
#33 2.876 lerna notice cli v4.0.0
#33 2.882 lerna info versioning independent
#33 2.975 lerna info Executing command in 8 packages: "yarn run build"
#33 9.370 lerna info run Ran npm script 'build' in '@eth-optimism/common-ts' in 6.4s:
#33 9.371 $ tsc -p tsconfig.build.json
#33 9.388 lerna info run Ran npm script 'build' in '@eth-optimism/hardhat-ovm' in 6.4s:
#33 9.388 $ tsc -p tsconfig.build.json
#33 9.662 lerna info run Ran npm script 'build' in '@eth-optimism/core-utils' in 6.7s:
#33 9.662 $ tsc -p tsconfig.build.json
#33 15.66 lerna info run Ran npm script 'build' in '@eth-optimism/smock' in 6.0s:
#33 15.66 $ tsc -p tsconfig.build.json
#33 68.67 lerna ERR! yarn run build exited 137 in '@eth-optimism/contracts'
#33 68.67 lerna ERR! yarn run build stdout:
#33 68.67 $ ./scripts/build.sh
#33 68.67 $ hardhat compile --show-stack-traces
#33 68.67 $ tsc -p ./tsconfig.build.json
#33 68.67 Compiling 113 files with 0.7.6
#33 68.67 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
#33 68.67 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
#33 68.67 lerna ERR! yarn run build stderr:
#33 68.67 contracts/chugsplash/L1ChugSplashProxy.sol:17:1: Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
#33 68.67 contract L1ChugSplashProxy {
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67 contracts/chugsplash/L1ChugSplashProxy.sol:113:5: The payable fallback function is defined here.
#33 68.67 fallback()
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 contracts/chugsplash/L1ChugSplashProxy.sol:211:13: Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
#33 68.67 address
#33 68.67 ^-----^
#33 68.67
#33 68.67 contracts/chugsplash/L1ChugSplashProxy.sol:226:13: Warning: Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable.
#33 68.67 address
#33 68.67 ^-----^
#33 68.67
#33 68.67 contracts/optimistic-ethereum/OVM/predeploys/OVM_ETH.sol:19:1: Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
#33 68.67 contract OVM_ETH is L2StandardERC20, IWETH9 {
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67 contracts/optimistic-ethereum/OVM/predeploys/OVM_ETH.sol:38:5: The payable fallback function is defined here.
#33 68.67 fallback() external payable {
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 contracts/optimistic-ethereum/OVM/predeploys/OVM_ECDSAContractAccount.sol:30:1: Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
#33 68.67 contract OVM_ECDSAContractAccount is iOVM_ECDSAContractAccount {
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67 contracts/optimistic-ethereum/OVM/predeploys/OVM_ECDSAContractAccount.sol:55:5: The payable fallback function is defined here.
#33 68.67 fallback()
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 contracts/optimistic-ethereum/OVM/predeploys/OVM_ProxyEOA.sol:19:1: Warning: This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
#33 68.67 contract OVM_ProxyEOA {
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67 contracts/optimistic-ethereum/OVM/predeploys/OVM_ProxyEOA.sol:40:5: The payable fallback function is defined here.
#33 68.67 fallback()
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 @openzeppelin/contracts/access/Ownable.sol:26:5: Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
#33 68.67 constructor () internal {
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 @openzeppelin/contracts/token/ERC20/ERC20.sol:55:5: Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
#33 68.67 constructor (string memory name_, string memory symbol_) public {
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 @openzeppelin/contracts/utils/ReentrancyGuard.sol:38:5: Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
#33 68.67 constructor () internal {
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 contracts/optimistic-ethereum/OVM/predeploys/OVM_DeployerWhitelist.sol:131:5: Warning: Function state mutability can be restricted to view
#33 68.67 function isDeployerAllowed(
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 contracts/optimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol:406:5: Warning: Function state mutability can be restricted to view
#33 68.67 function ovmREVERT(
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 contracts/optimistic-ethereum/OVM/execution/OVM_ExecutionManager.sol:1828:5: Warning: Function state mutability can be restricted to view
#33 68.67 function _revertWithFlag(
#33 68.67 ^ (Relevant source part starts here and spans across multiple lines).
#33 68.67
#33 68.67 Killed
#33 68.67 error Command failed with exit code 137.
#33 68.67 error Command failed with exit code 137.
#33 68.67 lerna ERR! yarn run build exited 137 in '@eth-optimism/contracts'
#33 70.70 error Command failed with exit code 137.
#33 70.70 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
#33 72.65 error Command failed with exit code 137.
#33 72.66 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
executor failed running [/bin/sh -c yarn build]: exit code: 137
ERROR: Service 'builder' failed to build : Build failed
exit code の 137 は OOM が原因らしい
直前に MacBook Pro のディスク容量が残ってませんって警告が出ていたので、Swap を確保できずメモリが足りず OOM になったのかも
スクラッチで GitHub Actions でテストを動かす optimism の環境を作るのがいいかも
ディスク容量を空けて docker-compose build
を再実行した
error Command failed with exit code 137
が再現した
MacBook Pro で build できないってやばくない?
てか build 済みのコンテナ配布してほしいけど
そういや Docker for Mac は limitation があるんだった
メモリを4GB、Swap を2GBに変更して再実行してみる
→成功した
写経完了
このチュートリアルは L2 をローカルに立てて、そこに対してコントラクトの実行やそのテストを実行する内容だった
Best Practices for Running Tests
As you may have noticed, in this tutorial we ran all the tests first on the HardHat EVM and only then on Optimistic Ethereum. This is important, because it lets you isolate contract problems from problems that are the result of using Optimistic Ethereum rather than vanilla Ethereum.
は抑えておいたほうが良さそう
試しに CI でどちらのテストも実行するようにしてみた
個人的に気になるのは ERC20/ERC721 などのトークンを L2 で作ってこれを L1 に持っていく、もしくは逆のやり方なので別のドキュメントを探す必要がありそう
L2 のコンテナの build に10分ぐらいかかるのどうにかならないのかな
build 済みの image を Docker Hub とかで提供してほしい