-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fastnode_support
- Loading branch information
Showing
39 changed files
with
342 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
||
|
@@ -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') | ||
|
@@ -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, | ||
|
@@ -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() | ||
|
||
|
@@ -179,34 +190,21 @@ def devnet_l1_genesis(paths): | |
log.info('Generating L1 genesis state') | ||
init_devnet_l1_deploy_config(paths) | ||
|
||
geth = subprocess.Popen([ | ||
'geth', '--dev', '--http', '--http.api', 'eth,debug', | ||
'--verbosity', '4', '--gcmode', 'archive', '--dev.gaslimit', '30000000', | ||
'--rpc.allow-unprotected-txs' | ||
]) | ||
|
||
try: | ||
forge = ChildProcess(deploy_contracts, paths) | ||
forge.start() | ||
forge.join() | ||
err = forge.get_error() | ||
if err: | ||
raise Exception(f"Exception occurred in child process: {err}") | ||
fqn = 'scripts/Deploy.s.sol:Deploy' | ||
run_command([ | ||
'forge', 'script', '--chain-id', '900', fqn, "--sig", "runWithStateDump()" | ||
], env={}, cwd=paths.contracts_bedrock_dir) | ||
|
||
res = debug_dumpBlock('127.0.0.1:8545') | ||
response = json.loads(res) | ||
allocs = response['result'] | ||
forge_dump = read_json(paths.forge_dump_path) | ||
write_json(paths.allocs_path, { "accounts": forge_dump }) | ||
os.remove(paths.forge_dump_path) | ||
|
||
write_json(paths.allocs_path, allocs) | ||
finally: | ||
geth.terminate() | ||
shutil.copy(paths.l1_deployments_path, paths.addresses_json_path) | ||
|
||
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) | ||
|
@@ -247,15 +245,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) | ||
|
@@ -267,6 +266,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) | ||
|
@@ -286,17 +286,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: | ||
|
@@ -310,6 +310,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.') | ||
|
@@ -351,6 +352,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/[email protected]'], 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":[]}' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.