Skip to content

Commit

Permalink
Merge branch 'develop' into fastnode_support
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-reorg authored May 27, 2024
2 parents 27624a0 + 777fd9b commit 52a209d
Show file tree
Hide file tree
Showing 39 changed files with 342 additions and 217 deletions.
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
101 changes: 70 additions & 31 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 @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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.')
Expand Down Expand Up @@ -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":[]}'
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum v1.13.8 => github.com/bnb-chain/op-geth v0.4.0-alpha
replace github.com/ethereum/go-ethereum v1.13.8 => github.com/bnb-chain/op-geth v0.4.1-0.20240514082730-f8d1c9e18803

replace github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr3LCn5/XlcgDWr8=
github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk=
github.com/bnb-chain/op-geth v0.4.0-alpha h1:xvbVFmhTCS4HglOD/J0Vg81m+UUVzNawPoVfmEgTas4=
github.com/bnb-chain/op-geth v0.4.0-alpha/go.mod h1:dkpInaOz3WeP/5lgdL0BOA6mjexUj30tPQU81H1yEHQ=
github.com/bnb-chain/op-geth v0.4.1-0.20240514082730-f8d1c9e18803 h1:DBJAzHTOzLoRQ04tr22dHjSLW/QclnGsOzp1wo6WoBs=
github.com/bnb-chain/op-geth v0.4.1-0.20240514082730-f8d1c9e18803/go.mod h1:dkpInaOz3WeP/5lgdL0BOA6mjexUj30tPQU81H1yEHQ=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
Expand Down
6 changes: 3 additions & 3 deletions op-batcher/batcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type BatcherConfig struct {
// BatcherService represents a full batch-submitter instance and its resources,
// and conforms to the op-service CLI Lifecycle interface.
type BatcherService struct {
Log log.Logger
Metrics metrics.Metricer
L1Client client.Client
Log log.Logger
Metrics metrics.Metricer
L1Client client.Client

EndpointProvider dial.L2EndpointProvider
TxManager txmgr.TxManager
Expand Down
4 changes: 2 additions & 2 deletions op-batcher/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func NewMetrics(procName string) *Metrics {
blobUsedBytes: factory.NewHistogram(prometheus.HistogramOpts{
Namespace: ns,
Name: "blob_used_bytes",
Help: "Blob size in bytes being submitted.",
Buckets: prometheus.LinearBuckets(0.0, eth.MaxBlobDataSize/13, 13),
Help: "Blob size in bytes (of last blob only for multi-blob txs).",
Buckets: prometheus.LinearBuckets(0.0, eth.MaxBlobDataSize/13, 14),
}),

batcherTxEvs: opmetrics.NewEventVec(factory, ns, "", "batcher_tx", "BatcherTx", []string{"stage"}),
Expand Down
2 changes: 2 additions & 0 deletions op-batcher/metrics/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ func (*noopMetrics) RecordBlobUsedBytes(int) {}
func (*noopMetrics) StartBalanceMetrics(log.Logger, ethereum.ChainStateReader, common.Address) io.Closer {
return nil
}
func (*noopMetrics) RecordBlobsNumber(number int) {}

func (m *noopMetrics) RecordL1UrlSwitchEvt(url string) {
}
15 changes: 15 additions & 0 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ type DeployConfig struct {
FundDevAccounts bool `json:"fundDevAccounts"`
// opBNB fermat hard fork
Fermat *big.Int `json:"fermat,omitempty"`
// SnowTimeOffset is the number of seconds after genesis block that snow hard fork activates.
// Set it to 0 to activate at genesis. Nil to disable snow fork.
SnowTimeOffset *hexutil.Uint64 `json:"snowTimeOffset,omitempty"`
// RequiredProtocolVersion indicates the protocol version that
// nodes are required to adopt, to stay in sync with the network.
RequiredProtocolVersion params.ProtocolVersion `json:"requiredProtocolVersion"`
Expand Down Expand Up @@ -553,6 +556,17 @@ func (d *DeployConfig) InteropTime(genesisTime uint64) *uint64 {
return &v
}

func (d *DeployConfig) SnowTime(genesisTime uint64) *uint64 {
if d.SnowTimeOffset == nil {
return nil
}
v := uint64(0)
if offset := *d.SnowTimeOffset; offset > 0 {
v = genesisTime + uint64(offset)
}
return &v
}

// RollupConfig converts a DeployConfig to a rollup.Config
func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHash common.Hash, l2GenesisBlockNumber uint64) (*rollup.Config, error) {
if d.OptimismPortalProxy == (common.Address{}) {
Expand Down Expand Up @@ -600,6 +614,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHas
DAChallengeWindow: d.DAChallengeWindow,
DAResolveWindow: d.DAResolveWindow,
Fermat: d.Fermat,
SnowTime: d.SnowTime(l1StartBlock.Time()),
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion op-challenger/cmd/list_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ func ListClaims(ctx *cli.Context) error {
}
defer l1Client.Close()

caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
caller := batching.NewMultiCaller(l1Client.(*ethclient.Client).Client(), batching.DefaultBatchSize)
contract, err := contracts.NewFaultDisputeGameContract(gameAddr, caller)
if err != nil {
return fmt.Errorf("failed to create dispute game bindings: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion op-challenger/cmd/list_games.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli/v2"
)

Expand All @@ -37,7 +38,7 @@ func ListGames(ctx *cli.Context) error {
}
defer l1Client.Close()

caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
caller := batching.NewMultiCaller(l1Client.(*ethclient.Client).Client(), batching.DefaultBatchSize)
contract, err := contracts.NewDisputeGameFactoryContract(factoryAddr, caller)
if err != nil {
return fmt.Errorf("failed to create dispute game bindings: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion op-challenger/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -65,7 +66,7 @@ func newClientsFromCLI(ctx *cli.Context) (*batching.MultiCaller, txmgr.TxManager
}
defer l1Client.Close()

caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
caller := batching.NewMultiCaller(l1Client.(*ethclient.Client).Client(), batching.DefaultBatchSize)
txMgrConfig := txmgr.ReadCLIConfig(ctx)
txMgr, err := txmgr.NewSimpleTxManager("challenger", logger, &metrics.NoopTxMetrics{}, txMgrConfig)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s *Service) initL1Client(ctx context.Context, cfg *config.Config) error {
if err != nil {
return fmt.Errorf("failed to dial L1: %w", err)
}
s.l1Client = l1Client
s.l1Client = l1Client.(*ethclient.Client)
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions op-challenger/metrics/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type NoopMetricsImpl struct {
txmetrics.NoopTxMetrics
}

func (i *NoopMetricsImpl) RecordBlobsNumber(_ int) {}

func (i *NoopMetricsImpl) StartBalanceMetrics(l log.Logger, client *ethclient.Client, account common.Address) io.Closer {
return nil
}
Expand Down
Loading

0 comments on commit 52a209d

Please sign in to comment.