Commit f2ca4ba9 authored by Joshua Gutow's avatar Joshua Gutow Committed by GitHub

Merge pull request #8517 from ethereum-optimism/feat/anvil-devnet-allocs

devnet: Convert devnet-allocs to Anvil
parents 658d4df5 720c6116
...@@ -1019,7 +1019,7 @@ jobs: ...@@ -1019,7 +1019,7 @@ jobs:
steps: steps:
- checkout - checkout
- check-changed: - check-changed:
patterns: op-(.+),packages,ops-bedrock patterns: op-(.+),packages,ops-bedrock,bedrock-devnet
- run: - run:
name: Install latest golang name: Install latest golang
command: | command: |
......
...@@ -9,6 +9,7 @@ import datetime ...@@ -9,6 +9,7 @@ import datetime
import time import time
import shutil import shutil
import http.client import http.client
import gzip
from multiprocessing import Process, Queue from multiprocessing import Process, Queue
import concurrent.futures import concurrent.futures
from collections import namedtuple from collections import namedtuple
...@@ -130,7 +131,7 @@ def deploy_contracts(paths): ...@@ -130,7 +131,7 @@ def deploy_contracts(paths):
run_command([ run_command([
'cast', 'send', '--from', account, 'cast', 'send', '--from', account,
'--rpc-url', 'http://127.0.0.1:8545', '--rpc-url', 'http://127.0.0.1:8545',
'--unlocked', '--value', '1ether', '0x3fAB184622Dc19b6109349B94811493BF2a45362' '--unlocked', '--value', '5ether', '0x3fAB184622Dc19b6109349B94811493BF2a45362'
], env={}, cwd=paths.contracts_bedrock_dir) ], env={}, cwd=paths.contracts_bedrock_dir)
# deploy the create2 deployer # deploy the create2 deployer
...@@ -143,7 +144,7 @@ def deploy_contracts(paths): ...@@ -143,7 +144,7 @@ def deploy_contracts(paths):
run_command([ run_command([
'forge', 'script', fqn, '--sender', account, 'forge', 'script', fqn, '--sender', account,
'--rpc-url', 'http://127.0.0.1:8545', '--broadcast', '--rpc-url', 'http://127.0.0.1:8545', '--broadcast',
'--unlocked' '--unlocked', '--with-gas-price', '100000000000'
], env={}, cwd=paths.contracts_bedrock_dir) ], env={}, cwd=paths.contracts_bedrock_dir)
shutil.copy(paths.l1_deployments_path, paths.addresses_json_path) shutil.copy(paths.l1_deployments_path, paths.addresses_json_path)
...@@ -165,9 +166,8 @@ def devnet_l1_genesis(paths): ...@@ -165,9 +166,8 @@ def devnet_l1_genesis(paths):
init_devnet_l1_deploy_config(paths) init_devnet_l1_deploy_config(paths)
geth = subprocess.Popen([ geth = subprocess.Popen([
'geth', '--dev', '--http', '--http.api', 'eth,debug', 'anvil', '-a', '10', '--port', '8545', '--chain-id', '1337', '--disable-block-gas-limit',
'--verbosity', '4', '--gcmode', 'archive', '--dev.gaslimit', '30000000', '--gas-price', '0', '--base-fee', '1', '--block-time', '1'
'--rpc.allow-unprotected-txs'
]) ])
try: try:
...@@ -178,10 +178,8 @@ def devnet_l1_genesis(paths): ...@@ -178,10 +178,8 @@ def devnet_l1_genesis(paths):
if err: if err:
raise Exception(f"Exception occurred in child process: {err}") raise Exception(f"Exception occurred in child process: {err}")
res = debug_dumpBlock('127.0.0.1:8545') res = anvil_dumpState('127.0.0.1:8545')
response = json.loads(res) allocs = convert_anvil_dump(res)
allocs = response['result']
write_json(paths.allocs_path, allocs) write_json(paths.allocs_path, allocs)
finally: finally:
geth.terminate() geth.terminate()
...@@ -272,17 +270,38 @@ def eth_accounts(url): ...@@ -272,17 +270,38 @@ def eth_accounts(url):
return data return data
def debug_dumpBlock(url): def anvil_dumpState(url):
log.info(f'Fetch debug_dumpBlock {url}') log.info(f'Fetch debug_dumpBlock {url}')
conn = http.client.HTTPConnection(url) conn = http.client.HTTPConnection(url)
headers = {'Content-type': 'application/json'} headers = {'Content-type': 'application/json'}
body = '{"id":3, "jsonrpc":"2.0", "method": "debug_dumpBlock", "params":["latest"]}' body = '{"id":3, "jsonrpc":"2.0", "method": "anvil_dumpState", "params":[]}'
conn.request('POST', '/', body, headers) conn.request('POST', '/', body, headers)
response = conn.getresponse() data = conn.getresponse().read()
data = response.read().decode() # Anvil returns a JSON-RPC response with a hex-encoded "result" field
conn.close() result = json.loads(data.decode('utf-8'))['result']
return data result_bytes = bytes.fromhex(result[2:])
uncompressed = gzip.decompress(result_bytes).decode()
return json.loads(uncompressed)
def convert_anvil_dump(dump):
accounts = dump['accounts']
for account in accounts.values():
bal = account['balance']
account['balance'] = str(int(bal, 16))
if 'storage' in account:
storage = account['storage']
storage_keys = list(storage.keys())
for key in storage_keys:
value = storage[key]
del storage[key]
storage[pad_hex(key)] = pad_hex(value)
return dump
def pad_hex(input):
return '0x' + input.replace('0x', '').zfill(64)
def wait_for_rpc_server(url): def wait_for_rpc_server(url):
log.info(f'Waiting for RPC server at {url}') log.info(f'Waiting for RPC server at {url}')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment