Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix devnet after 1.7.2 upstream merge #194

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,21 @@ devnet-up: pre-devnet
PYTHONPATH=./bedrock-devnet $(PYTHON) ./bedrock-devnet/main.py --monorepo-dir=.
.PHONY: devnet-up

devnet-init: pre-devnet
PYTHONPATH=./bedrock-devnet $(PYTHON) ./bedrock-devnet/main.py --monorepo-dir=. --init
.PHONY: devnet-init

devnet-test: pre-devnet
PYTHONPATH=./bedrock-devnet $(PYTHON) ./bedrock-devnet/main.py --monorepo-dir=. --test
.PHONY: devnet-test

devnet-down:
@(cd ./ops-bedrock && GENESIS_TIMESTAMP=$(shell date +%s) docker compose stop)
if [ -f "./.devnet/node-deploy/start_cluster.sh" ]; then ./.devnet/node-deploy/start_cluster.sh stop; fi
.PHONY: devnet-down

devnet-clean:
if [ -f "./.devnet/node-deploy/start_cluster.sh" ]; then ./.devnet/node-deploy/start_cluster.sh stop; fi
rm -rf ./packages/contracts-bedrock/deployments/devnetL1
rm -rf ./.devnet
cd ./ops-bedrock && docker compose down
Expand Down
5 changes: 4 additions & 1 deletion bedrock-devnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ It allows us to quickly start the devnet locally (with L1 network as BSC network

# requirement

docker, nodejs 16+, yarn, foundry, python2, python3, pnpm
docker, nodejs 16+, yarn, foundry, python3, pnpm, poetry, go, jq

Tips:

Install Foundry by following [the instructions located here](https://getfoundry.sh/).

Please make sure your Foundry version matches the one described in versions.json.
If they do not match, please use a command such as `foundryup -C xxxxxx` to modify it.

# usage
First, execute `pnpm install` and `pnpm build` commands in the root directory.

Expand Down
74 changes: 62 additions & 12 deletions bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
parser.add_argument('--monorepo-dir', help='Directory of the monorepo', default=os.getcwd())
parser.add_argument('--allocs', help='Only create the allocs and exit', type=bool, action=argparse.BooleanOptionalAction)
parser.add_argument('--test', help='Tests the deployment, must already be deployed', type=bool, action=argparse.BooleanOptionalAction)
parser.add_argument('--init', help='init BSC L1 devnet chain', type=bool, action=argparse.BooleanOptionalAction)

log = logging.getLogger()

Expand Down Expand Up @@ -63,6 +64,9 @@ def main():

monorepo_dir = os.path.abspath(args.monorepo_dir)
devnet_dir = pjoin(monorepo_dir, '.devnet')
bsc_dir = pjoin(devnet_dir, 'bsc')
node_deploy_dir = pjoin(devnet_dir, 'node-deploy')
node_deploy_genesis_dir = pjoin(node_deploy_dir, 'genesis')
contracts_bedrock_dir = pjoin(monorepo_dir, 'packages', 'contracts-bedrock')
deployment_dir = pjoin(contracts_bedrock_dir, 'deployments', 'devnetL1')
forge_dump_path = pjoin(contracts_bedrock_dir, 'Deploy-900.json')
Expand All @@ -77,6 +81,9 @@ def main():
paths = Bunch(
mono_repo_dir=monorepo_dir,
devnet_dir=devnet_dir,
bsc_dir=bsc_dir,
node_deploy_dir=node_deploy_dir,
node_deploy_genesis_dir=node_deploy_genesis_dir,
contracts_bedrock_dir=contracts_bedrock_dir,
deployment_dir=deployment_dir,
forge_dump_path=forge_dump_path,
Expand Down Expand Up @@ -107,6 +114,10 @@ def main():
devnet_l1_genesis(paths)
return

if args.init:
bsc_l1_init(paths)
return

git_commit = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True, text=True).stdout.strip()
git_date = subprocess.run(['git', 'show', '-s', "--format=%ct"], capture_output=True, text=True).stdout.strip()

Expand Down Expand Up @@ -204,9 +215,7 @@ def devnet_l1_genesis(paths):
def deployL1ContractsForDeploy(paths):
log.info('Starting L1.')

run_command(['docker-compose', 'up', '-d', 'l1'], cwd=paths.ops_bedrock_dir, env={
'PWD': paths.ops_bedrock_dir
})
run_command(['./start_cluster.sh','start'], cwd=paths.node_deploy_dir)
wait_up(8545)
wait_for_rpc_server('http://127.0.0.1:8545')
time.sleep(3)
Expand Down Expand Up @@ -247,15 +256,16 @@ def deployL1ContractsForDeploy(paths):

shutil.copy(paths.l1_deployments_path, paths.addresses_json_path)

log.info('Syncing contracts.')
run_command([
'forge', 'script', fqn, '--sig', 'sync()',
'--rpc-url', 'http://127.0.0.1:8545'
], env={}, cwd=paths.contracts_bedrock_dir)
# log.info('Syncing contracts.')
# run_command([
# 'forge', 'script', fqn, '--sig', 'sync()',
# '--rpc-url', 'http://127.0.0.1:8545'
# ], env={}, cwd=paths.contracts_bedrock_dir)
log.info('Deployed L1 contracts.')

# Bring up the devnet where the contracts are deployed to L1
def devnet_deploy(paths):
bsc_l1_init(paths)
init_devnet_l1_deploy_config(paths)
l1env = dotenv_values('./ops-bedrock/l1.env')
log.info(l1env)
Expand All @@ -267,6 +277,7 @@ def devnet_deploy(paths):
log.info('Generating network config.')
devnet_cfg_orig = pjoin(paths.contracts_bedrock_dir, 'deploy-config', 'devnetL1.json')
devnet_cfg_backup = pjoin(paths.devnet_dir, 'devnetL1.json.bak')
devnet_cfg_final = pjoin(paths.devnet_dir, 'devnetL1.json')
shutil.copy(devnet_cfg_orig, devnet_cfg_backup)
deploy_config = read_json(devnet_cfg_orig)
deploy_config['l1ChainID'] = int(bscChainId,10)
Expand All @@ -286,17 +297,17 @@ def devnet_deploy(paths):
deploy_config['sequencerFeeVaultRecipient'] = l1_init_holder
deploy_config['proxyAdminOwner'] = l1_init_holder
deploy_config['finalSystemOwner'] = l1_init_holder
deploy_config['portalGuardian'] = l1_init_holder
deploy_config['governanceTokenOwner'] = l1_init_holder
deploy_config['l2GenesisDeltaTimeOffset'] = "0x1"
deploy_config['fermat'] = 0
deploy_config['L2GenesisEcotoneTimeOffset'] = "0x2"
write_json(devnet_cfg_orig, deploy_config)

if os.path.exists(paths.addresses_json_path):
log.info('L1 contracts already deployed.')
log.info('Starting L1.')

run_command(['docker-compose', 'up', '-d', 'l1'], cwd=paths.ops_bedrock_dir, env={
'PWD': paths.ops_bedrock_dir
})
run_command(['./start_cluster.sh','start'], cwd=paths.node_deploy_dir)
wait_up(8545)
wait_for_rpc_server('http://127.0.0.1:8545')
else:
Expand All @@ -310,6 +321,7 @@ def devnet_deploy(paths):
deploy_config['l1GenesisBlockTimestamp'] = l1BlockTimestamp
deploy_config['l1StartingBlockTag'] = l1BlockTag
write_json(devnet_cfg_orig, deploy_config)
write_json(devnet_cfg_final, deploy_config)

if os.path.exists(paths.genesis_l2_path):
log.info('L2 genesis and rollup configs already generated.')
Expand Down Expand Up @@ -351,6 +363,44 @@ def devnet_deploy(paths):

log.info('Devnet ready.')

def bsc_l1_init(paths):
l1env = dotenv_values('./ops-bedrock/l1.env')
log.info(l1env)
l1_init_holder = l1env['INIT_HOLDER']
l1_init_holder_prv = l1env['INIT_HOLDER_PRV']
if os.path.exists(paths.bsc_dir):
log.info('bsc path exists, skip git clone')
else:
run_command(['git','clone','https://github.com/bnb-chain/bsc.git'], cwd=paths.devnet_dir)
run_command(['git','checkout','v1.4.5'], cwd=paths.bsc_dir)
run_command(['make','geth'], cwd=paths.bsc_dir)
run_command(['go','build','-o', './build/bin/bootnode', './cmd/bootnode'], cwd=paths.bsc_dir)
if os.path.exists(paths.node_deploy_dir):
log.info('node-deploy path exists, skip git clone')
else:
run_command(['git','clone','https://github.com/bnb-chain/node-deploy.git'], cwd=paths.devnet_dir)
run_command(['git','checkout','27e7ca669a27c8fd259eeb88ba33ef5a1b4ac182'], cwd=paths.node_deploy_dir)
run_command(['git','submodule','update','--init','--recursive'], cwd=paths.node_deploy_dir)
run_command(['pip3','install','-r','requirements.txt'], cwd=paths.node_deploy_dir)
run_command(['npm','install'], cwd=paths.node_deploy_genesis_dir)
run_command(['forge','install','--no-git','--no-commit','foundry-rs/forge-std@v1.7.3'], cwd=paths.node_deploy_genesis_dir)
run_command(['poetry','install'], cwd=paths.node_deploy_genesis_dir)
with open(pjoin(paths.node_deploy_dir,'.env'), 'r') as file:
file_content = file.read()
file_content = file_content.replace('0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186', l1_init_holder)
file_content = file_content.replace('59ba8068eb256d520179e903f43dacf6d8d57d72bd306e1bd603fdb8c8da10e8', l1_init_holder_prv)
with open(pjoin(paths.node_deploy_dir,'.env'), 'w') as file:
file.write(file_content)

shutil.copy(pjoin(paths.bsc_dir,'build','bin','geth'), pjoin(paths.node_deploy_dir,'bin','geth'))
shutil.copy(pjoin(paths.bsc_dir,'build','bin','bootnode'), pjoin(paths.node_deploy_dir,'bin','bootnode'))
if os.path.exists(pjoin(paths.node_deploy_dir,'.local')):
log.info('already init .local config file, skip init script')
else:
run_command(['chmod','+x','start_cluster.sh'], cwd=paths.node_deploy_dir)
run_command(['./start_cluster.sh','reset'], cwd=paths.node_deploy_dir)
run_command(['./start_cluster.sh','stop'], cwd=paths.node_deploy_dir)

def wait_for_rpc_server(url):
log.info(f'Waiting for RPC server at {url}')
body = '{"id":1, "jsonrpc":"2.0", "method": "eth_chainId", "params":[]}'
Expand Down
12 changes: 4 additions & 8 deletions ops-bedrock/Dockerfile.l1
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
FROM golang:1.19-alpine3.18 as build
FROM golang:1.21-alpine3.18 as build
RUN apk add --no-cache git make cmake gcc musl-dev linux-headers build-base libc-dev gcompat
RUN git clone https://github.com/bnb-chain/bsc.git
RUN cd bsc && git checkout v1.2.12 && make geth && go build -o ./build/bin/bootnode ./cmd/bootnode
RUN git clone https://github.com/bnb-chain/node.git
RUN cd node && git checkout v0.10.16 && make build
RUN cd bsc && git checkout v1.4.5 && make geth && go build -o ./build/bin/bootnode ./cmd/bootnode

FROM golang:1.19-alpine3.18
FROM golang:1.21-alpine3.18

RUN apk add --no-cache bash expect wget nodejs npm git jq make cmake gcc musl-dev linux-headers build-base libc-dev gcompat python3

RUN mkdir /db
RUN cd /db && git clone https://github.com/bnb-chain/node-deploy.git
RUN cd /db/node-deploy && git checkout 7492b04275c6e802acc90868e29b6a0a34b8849b && make tool
RUN cd /db/node-deploy && git checkout 27e7ca669a27c8fd259eeb88ba33ef5a1b4ac182
COPY --from=build /go/bsc/build/bin/geth /db/node-deploy/bin/geth
COPY --from=build /go/bsc/build/bin/bootnode /db/node-deploy/bin/bootnode
COPY --from=build /go/node/build/tbnbcli /db/node-deploy/bin/tbnbcli
COPY --from=build /go/node/build/bnbchaind /db/node-deploy/bin/bnbchaind

ENTRYPOINT ["/bin/sh", "/l1-entrypoint.sh"]
50 changes: 13 additions & 37 deletions ops-bedrock/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version: '3.4'
# service.

volumes:
l1_data:
l2_data:
op_log:

Expand All @@ -21,21 +20,6 @@ services:
image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-stack-go:devnet
entrypoint: ["echo", "build complete"]

l1:
build:
context: .
dockerfile: Dockerfile.l1
ports:
- "8545:8545"
- "7060:6060"
env_file:
- ./l1.env
user: root
volumes:
- "l1_data:/db"
- "./l1-entrypoint.sh:/l1-entrypoint.sh"
entrypoint: /l1-entrypoint.sh

l2:
build:
context: .
Expand All @@ -57,7 +41,6 @@ services:
op-node:
depends_on:
- op_stack_go_builder
- l1
- l2
build:
context: ../
Expand All @@ -68,7 +51,7 @@ services:
command: >
op-node
--l1.trustrpc
--l1=http://l1:8545
--l1=http://host.docker.internal:8545
--l2=http://l2:8551
--l2.jwt-secret=/config/test-jwt-secret.txt
--sequencer.enabled
Expand All @@ -91,8 +74,11 @@ services:
--pprof.enabled
--rpc.enable-admin
--log.level=debug
--sequencer.priority
--l1.max-concurrency=20
ports:
- "7545:8545"
- "8545:9545"
- "7300:7300"
- "6060:6060"
volumes:
Expand All @@ -105,7 +91,6 @@ services:
op-proposer:
depends_on:
- op_stack_go_builder
- l1
- l2
- op-node
build:
Expand All @@ -119,7 +104,7 @@ services:
- "7302:7300"
- "6546:8545"
environment:
OP_PROPOSER_L1_ETH_RPC: http://l1:8545
OP_PROPOSER_L1_ETH_RPC: http://host.docker.internal:8545
OP_PROPOSER_ROLLUP_RPC: http://op-node:8545
OP_PROPOSER_POLL_INTERVAL: 1s
OP_PROPOSER_NUM_CONFIRMATIONS: 4
Expand All @@ -140,7 +125,6 @@ services:
op-batcher:
depends_on:
- op_stack_go_builder
- l1
- l2
- op-node
build:
Expand All @@ -154,15 +138,15 @@ services:
- "7301:7300"
- "6545:8545"
environment:
OP_BATCHER_L1_ETH_RPC: http://l1:8545
OP_BATCHER_L1_ETH_RPC: http://host.docker.internal:8545
OP_BATCHER_L2_ETH_RPC: http://l2:8545
OP_BATCHER_ROLLUP_RPC: http://op-node:8545
OP_BATCHER_MAX_L1_TX_SIZE_BYTES: 120000
OP_BATCHER_TARGET_L1_TX_SIZE_BYTES: 100000
OP_BATCHER_TARGET_NUM_FRAMES: 30
OP_BATCHER_TARGET_NUM_FRAMES: 6
OP_BATCHER_APPROX_COMPR_RATIO: "0.4"
OP_BATCHER_MAX_CHANNEL_DURATION: 20
OP_BATCHER_POLL_INTERVAL: 1s
OP_BATCHER_POLL_INTERVAL: 5s
OP_BATCHER_SAFE_ABORT_NONCE_TOO_LOW_COUNT: 3
OP_BATCHER_NUM_CONFIRMATIONS: 4
OP_BATCHER_TXMGR_RECEIPT_QUERY_INTERVAL: 1s
Expand All @@ -172,15 +156,17 @@ services:
OP_BATCHER_PPROF_ENABLED: "true"
OP_BATCHER_METRICS_ENABLED: "true"
OP_BATCHER_RPC_ENABLE_ADMIN: "true"
OP_BATCHER_BATCH_TYPE: 0
OP_BATCHER_BATCH_TYPE: 1
OP_BATCHER_LOG_TERMINAL: "true"
OP_BATCHER_SUB_SAFETY_MARGIN: 30 # SWS is 15, ChannelTimeout is 40
OP_BATCHER_MAX_PENDING_TX: 100
OP_BATCHER_MAX_PENDING_TX: 40
OP_BATCHER_TXMGR_MIN_TIP_CAP: 0
OP_BATCHER_TXMGR_MIN_BASEFEE: 0
OP_BATCHER_DATA_AVAILABILITY_TYPE: "blobs"

op-challenger:
depends_on:
- op_stack_go_builder
- l1
- l2
- op-node
build:
Expand Down Expand Up @@ -210,13 +196,3 @@ services:
OP_CHALLENGER_HD_PATH: "m/44'/60'/0'/0/4"
OP_CHALLENGER_NUM_CONFIRMATIONS: 1

artifact-server:
depends_on:
- l1
image: nginx:1.25-alpine
ports:
- "8080:80"
volumes:
- "${PWD}/../.devnet/:/usr/share/nginx/html/:ro"
security_opt:
- "no-new-privileges:true"
36 changes: 3 additions & 33 deletions ops-bedrock/l1-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,9 @@
#!/usr/bin/env bash
set -eou
cd /db
if [ ! -f solc-linux-amd64-v0.6.4+commit.1dca32f3 ]; then
wget https://github.com/ethereum/solc-bin/raw/gh-pages/linux-amd64/solc-linux-amd64-v0.6.4%2Bcommit.1dca32f3
cp solc-linux-amd64-v0.6.4+commit.1dca32f3 /usr/bin/solc
chmod +x /usr/bin/solc
else
echo "solc already exists"
fi

cd node-deploy
git submodule update --init --recursive
cd genesis
npm install
cd ..

sed -i -e "s/INIT_HOLDER=\"0x04d63aBCd2b9b1baa327f2Dda0f873F197ccd186\"/INIT_HOLDER=\"$INIT_HOLDER\"/g" .env
sed -i -e "s/INIT_HOLDER_PRV=\"59ba8068eb256d520179e903f43dacf6d8d57d72bd306e1bd603fdb8c8da10e8\"/INIT_HOLDER_PRV=\"$INIT_HOLDER_PRV\"/g" .env

if [ ! -f init_file_bc ]; then
bash +x ./setup_bc_node.sh native_init
echo "finish" > init_file_bc
else
echo "bc init already finish"
fi
bash +x ./setup_bc_node.sh native_start

if [ ! -f init_file_bsc ]; then
bash +x ./setup_bsc_node.sh native_init
echo "finish" > init_file_bsc
else
echo "bsc init already finish"
fi
bash +x ./setup_bsc_node.sh native_start
cd /db/node-deploy

echo "starting..."
bash -x ./start_cluster.sh start

while true; do
sleep 1000
Expand Down
Loading
Loading