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

ops-bedrock:modify the script to support fast start devnet #14

Closed
wants to merge 8 commits into from
Closed
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ nuke: clean devnet-clean
.PHONY: nuke

devnet-up:
@bash ./ops-bedrock/devnet-up.sh
pip3 install python-dotenv requests
PYTHONPATH=./bedrock-devnet python3 ./bedrock-devnet/main.py --monorepo-dir=.
.PHONY: devnet-up

devnet-up-deploy:
Expand Down
96 changes: 82 additions & 14 deletions bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import socket

import time

import requests
import shutil

import devnet.log_setup
from devnet.genesis import GENESIS_TMPL
from dotenv import dotenv_values

parser = argparse.ArgumentParser(description='Bedrock devnet launcher')
parser.add_argument('--monorepo-dir', help='Directory of the monorepo', default=os.getcwd())
Expand All @@ -34,6 +35,11 @@ def main():
sdk_addresses_json_path = pjoin(devnet_dir, 'sdk-addresses.json')
rollup_config_path = pjoin(devnet_dir, 'rollup.json')
os.makedirs(devnet_dir, exist_ok=True)
l1env = dotenv_values('./ops-bedrock/l1.env')
log.info(l1env)
bscChainId = l1env['BSC_CHAIN_ID']
l1_init_holder = l1env['INIT_HOLDER']
l1_init_holder_prv = l1env['INIT_HOLDER_PRV']

if os.path.exists(genesis_l1_path):
log.info('L2 genesis already generated.')
Expand All @@ -45,26 +51,18 @@ def main():
run_command(['docker-compose', 'up', '-d', 'l1'], cwd=ops_bedrock_dir, env={
'PWD': ops_bedrock_dir
})
wait_up(8545)

log.info('Generating network config.')
wait_up_url("http://127.0.0.1:8545/",'{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":74}',"wait L1 up...")
devnet_cfg_orig = pjoin(contracts_bedrock_dir, 'deploy-config', 'devnetL1.json')
devnet_cfg_backup = pjoin(devnet_dir, 'devnetL1.json.bak')
shutil.copy(devnet_cfg_orig, devnet_cfg_backup)
deploy_config = read_json(devnet_cfg_orig)
deploy_config['l1GenesisBlockTimestamp'] = GENESIS_TMPL['timestamp']
deploy_config['l1StartingBlockTag'] = 'earliest'
write_json(devnet_cfg_orig, deploy_config)

if os.path.exists(addresses_json_path):
log.info('Contracts already deployed.')
addresses = read_json(addresses_json_path)
else:
log.info('Deploying contracts.')
run_command(['yarn', 'hardhat', '--network', 'devnetL1', 'deploy', '--tags', 'l1'], env={
'CHAIN_ID': '900',
'CHAIN_ID': bscChainId,
'L1_RPC': 'http://localhost:8545',
'PRIVATE_KEY_DEPLOYER': 'ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
'PRIVATE_KEY_DEPLOYER': l1_init_holder_prv
}, cwd=contracts_bedrock_dir)
contracts = os.listdir(deployment_dir)
addresses = {}
Expand All @@ -90,6 +88,27 @@ def main():
if os.path.exists(genesis_l2_path):
log.info('L2 genesis and rollup configs already generated.')
else:
log.info('Generating network config.')
shutil.copy(devnet_cfg_orig, devnet_cfg_backup)
deploy_config = read_json(devnet_cfg_orig)
l1BlockTag = l1BlockTagGet()["result"]
log.info(l1BlockTag)
l1BlockTimestamp = l1BlockTimestampGet(l1BlockTag)["result"]["timestamp"]
log.info(l1BlockTimestamp)
deploy_config['l1GenesisBlockTimestamp'] = l1BlockTimestamp
deploy_config['l1StartingBlockTag'] = l1BlockTag
deploy_config['l1ChainID'] = int(bscChainId,10)
deploy_config['batchSenderAddress'] = l1_init_holder
deploy_config['l2OutputOracleProposer'] = l1_init_holder
deploy_config['baseFeeVaultRecipient'] = l1_init_holder
deploy_config['l1FeeVaultRecipient'] = l1_init_holder
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['controller'] = l1_init_holder
deploy_config['governanceTokenOwner'] = l1_init_holder
write_json(devnet_cfg_orig, deploy_config)
log.info('Generating L2 genesis and rollup configs.')
run_command([
'go', 'run', 'cmd/main.go', 'genesis', 'l2',
Expand All @@ -109,13 +128,15 @@ def main():
run_command(['docker-compose', 'up', '-d', 'l2'], cwd=ops_bedrock_dir, env={
'PWD': ops_bedrock_dir
})
wait_up(9545)
wait_up_url("http://127.0.0.1:9545/",'{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":74}',"wait L2 geth up...")

log.info('Bringing up everything else.')
run_command(['docker-compose', 'up', '-d', 'op-node', 'op-proposer', 'op-batcher'], cwd=ops_bedrock_dir, env={
'PWD': ops_bedrock_dir,
'L2OO_ADDRESS': addresses['L2OutputOracleProxy'],
'SEQUENCER_BATCH_INBOX_ADDRESS': rollup_config['batch_inbox_address']
'SEQUENCER_BATCH_INBOX_ADDRESS': rollup_config['batch_inbox_address'],
'OP_BATCHER_SEQUENCER_BATCH_INBOX_ADDRESS': rollup_config['batch_inbox_address'],
'INIT_HOLDER_PRV': l1_init_holder_prv
})

log.info('Devnet ready.')
Expand Down Expand Up @@ -149,6 +170,53 @@ def wait_up(port, retries=10, wait_secs=1):

raise Exception(f'Timed out waiting for port {port}.')

def wait_up_url(url,body,wait_msg):
status = True
log.info(wait_msg)
while status:
try:
headers = {
"Content-Type": "application/json"
}

response = requests.post(url, headers=headers, data=body)
if response.status_code != 200:
time.sleep(5)
else:
log.info("Status code is 200, continue next step")
status = False
except requests.exceptions.ConnectionError:
time.sleep(5)

def l1BlockTagGet():
headers = {
"Content-Type": "application/json"
}
try:
response = requests.post("http://127.0.0.1:8545",headers=headers,data='{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":74}')
if response.status_code != 200:
log.info(f'l1BlockTagGet resp status code is not 200, is {response.status_code}')
raise Exception("l1BlockTagGet status not 200!")
else:
result=response.json()
log.info(result)
return result
except requests.exceptions.ConnectionError:
raise Exception("l1BlockTagGet connection fail")

def l1BlockTimestampGet(block_tag):
headers = {
"Content-Type": "application/json"
}
try:
response = requests.post("http://127.0.0.1:8545",headers=headers,data=f'{{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["{block_tag}", false],"id":74}}')
if response.status_code != 200:
log.info(f'l1BlockTimestampGet resp status code is not 200, is {response.status_code}')
raise Exception("l1BlockTimestampGet status not 200!")
else:
return response.json()
except requests.exceptions.ConnectionError:
raise Exception("l1BlockTimestampGet connection fail")

def write_json(path, data):
with open(path, 'w+') as f:
Expand Down
2 changes: 1 addition & 1 deletion ops-bedrock/Dockerfile.l2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:optimism
FROM --platform=linux/amd64 ghcr.io/bnb-chain/op-geth:latest

RUN apk add --no-cache jq

Expand Down
66 changes: 66 additions & 0 deletions ops-bedrock/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[Eth]
NetworkId = 900
SyncMode = "full"
NoPruning = false
NoPrefetch = false
LightPeers = 100
UltraLightFraction = 75
DatabaseCache = 512
DatabaseFreezer = ""
TrieCleanCache = 256
TrieDirtyCache = 256
TrieTimeout = 3600000000000
EnablePreimageRecording = false
EWASMInterpreter = ""
EVMInterpreter = ""

[Eth.Miner]
GasFloor = 30000000
GasCeil = 40000000
GasPrice = 10000000000
Recommit = 10000000000
Noverify = false

[Eth.TxPool]
Locals = []
NoLocals = true
Journal = "transactions.rlp"
Rejournal = 3600000000000
PriceLimit = 10000000000
PriceBump = 10
AccountSlots = 16
GlobalSlots = 4096
AccountQueue = 64
GlobalQueue = 1024
Lifetime = 10800000000000


[Node]
IPCPath = "geth.ipc"
HTTPHost = "0.0.0.0"
NoUSB = true
InsecureUnlockAllowed = true
HTTPPort = 8545
HTTPVirtualHosts = ["*"]
HTTPModules = ["eth", "net", "web3", "txpool", "parlia"]
WSHost = "0.0.0.0"
WSPort = 8545

[Node.P2P]
MaxPeers = 50
NoDiscovery = true
StaticNodes = []
TrustedNodes = []
ListenAddr = ":30311"
EnableMsgEvents = false

[Node.HTTPTimeouts]
ReadTimeout = 30000000000
WriteTimeout = 30000000000
IdleTimeout = 120000000000

[Node.LogConfig]
FilePath = "bsc.log"
MaxBytesSize = 10485760
Level = "info"
FileRoot = ""
17 changes: 17 additions & 0 deletions ops-bedrock/create_bls_key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/expect
# 6 num wanted
set wallet_password 12345678
# 10 characters at least wanted
set account_password 1234567890

set timeout 5
spawn geth bls account new --datadir [lindex $argv 0]
expect "*assword:*"
send "$wallet_password\r"
expect "*assword:*"
send "$wallet_password\r"
expect "*assword:*"
send "$account_password\r"
expect "*assword:*"
send "$account_password\r"
expect EOF
Loading