smartcontracts / simple-optimism-node

The easiest way to run an Optimism node
MIT License
337 stars 115 forks source link

feat: add L2 sync #26

Closed smartcontracts closed 2 years ago

PierrickGT commented 2 years ago

I've managed to get this branch running but I feel like the /scripts/dtl-start.sh script is not working as intended. It may be because I didn't start with a fresh install but I had to declare the following variables in my .env file to be able to sync from L2.

DATA_TRANSPORT_LAYER__DEFAULT_BACKEND=l2
DATA_TRANSPORT_LAYER__L1_GAS_PRICE_BACKEND=l2

DATA_TRANSPORT_LAYER__L1_RPC_ENDPOINT=https://mainnet.optimism.io
DATA_TRANSPORT_LAYER__L2_RPC_ENDPOINT=https://mainnet.optimism.io

Hope it helps.

smartcontracts commented 2 years ago

Thanks! Useful feedback. I still need to properly test this. Had to get on a plane half way through writing this PR.

markodayan commented 2 years ago

Gonna give this a run on a VM, will let you know how it pans out!

markodayan commented 2 years ago

So I am doing this on a fresh Ubuntu VM with Docker installed. To confirm what @PierrickGT mentioned in his comment, I also had to make those changes he recommended (after which the L2 sync works 👍 ). If you don't do that you would notice these kind of logs from the dtl service:

simple-optimism-node-dtl-1  | {"level":30,"time":1669154242700,"msg":"Service is starting..."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242700,"msg":"Service is initializing..."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242701,"msg":"Initializing L1 Data Transport Service..."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242710,"msg":"L2 chain ID is: 10"}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242710,"msg":"BSS HF1 will activate at: 2824317"}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242715,"msg":"Service is initializing..."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242718,"defaultBackend":"l1","l1GasPriceBackend":"l1","msg":"HTTP Server Options"}
simple-optimism-node-dtl-1  | {"level":40,"time":1669154242718,"msg":"HTTP Server L1 RPC Provider not initialized"}
simple-optimism-node-dtl-1  | {"level":40,"time":1669154242719,"msg":"HTTP Server L2 RPC Provider not initialized"}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242719,"msg":"Service has initialized."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242719,"msg":"Service is initializing..."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242719,"msg":"Service has initialized."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242719,"msg":"Service has initialized."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242719,"msg":"Service is starting..."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242719,"msg":"Service is starting..."}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242721,"host":"0.0.0.0","port":7878,"msg":"Server started and listening"}
simple-optimism-node-dtl-1  | {"level":30,"time":1669154242721,"msg":"Cannot connect to L2, retrying 1/20"}

So basically, just make these changes along with the PR updates and you should be good:

In the .env file:

markodayan commented 2 years ago

Think maybe adding this to the dtl-start.sh script would fix the issue:

if [ $SYNC_SOURCE == "l2" ]; then
  DATA_TRANSPORT_LAYER__SYNC_FROM_L1=false
  DATA_TRANSPORT_LAYER__SYNC_FROM_L2=true
  DATA_TRANSPORT_LAYER__DEFAULT_BACKEND=l2
  DATA_TRANSPORT_LAYER__L1_GAS_PRICE_BACKEND=l2
fi

Then you don't even need to remove the DTL default backend and gas price backend from the dtl.env file

Will try it out now

smartcontracts commented 2 years ago

Let me know if it works!

markodayan commented 2 years ago

@smartcontracts just ran it now on another machine and it works :) Basically what I did was: 1) Left the dtl.env untouched (didn't remove the fields as done in the PR) 2) Changed the dtl-start.sh file to look like this:

#!/bin/sh
set -eou

# Setting both endpoints doesn't hurt
DATA_TRANSPORT_LAYER__L1_RPC_ENDPOINT=$DATA_TRANSPORT_LAYER__RPC_ENDPOINT
DATA_TRANSPORT_LAYER__L2_RPC_ENDPOINT=$DATA_TRANSPORT_LAYER__RPC_ENDPOINT

# Also tell the DTL to sync from the right place
if [ $SYNC_SOURCE == "l2" ]; then
  DATA_TRANSPORT_LAYER__SYNC_FROM_L1=false
  DATA_TRANSPORT_LAYER__SYNC_FROM_L2=true
  DATA_TRANSPORT_LAYER__DEFAULT_BACKEND=l2
  DATA_TRANSPORT_LAYER__L1_GAS_PRICE_BACKEND=l2
fi

# Run the DTL
exec node \
  dist/src/services/run.js \
  $@

Just some extra .env info:

markodayan commented 2 years ago

@smartcontracts This may be out of scope here, but I had to change my L1_RPC endpoint from my Ethereum full node running on my machine to an Alchemy endpoint because I kept getting this error from l2geth -> Fatal: No genesis block configured.

smartcontracts commented 2 years ago

Looks like I just needed to add the export keyword

smartcontracts commented 2 years ago

Thanks for all the help here everyone! I think everything should be syncing ok now.

0xheycat commented 2 years ago

finnaly working thank you