Skip to content
Merged
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
80 changes: 42 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
build build-portal build-op-node build-op-geth \
logs op-node-logs op-geth-logs \
test-frag test-seal \
docs
docs \
build-key_to_address

%: build-key_to_address

# ──────────────────────────────────────────────
# Cross-platform networking shim
Expand Down Expand Up @@ -84,22 +87,30 @@ build-rabby-chrom: ## 🏗️ Build modified Rabby wallet for Google Chrome and
yarn build:pro:mv2


ifeq ($(filter start-gateway,$(MAKECMDGOALS)),start-gateway)
ifeq ($(strip $(PORTAL)),)
$(error PORTAL is undefined! \
Please invoke like `make start-gateway \
PORTAL=http://… GATEWAY_SEQUENCING_KEY=…`)
endif
ifeq ($(strip $(GATEWAY_SEQUENCING_KEY)),)
$(error GATEWAY_SEQUENCING_KEY is undefined! \
Please invoke like `make start-gateway \
PORTAL=http://… GATEWAY_SEQUENCING_KEY=…`)
endif
endif
L1_CHAIN_ID?=11155111
L2_CHAIN_ID?=$(shell \
RAW=$$(od -An -N2 -tu2 /dev/urandom | tr -d ' '); \
echo $$((RAW % 50000 + 1)); \
)
L2_CHAIN_ID_HEX := $(shell printf "0x%064x" $(L2_CHAIN_ID))

PORTAL?=http://18.185.199.51:8080
L1_RPC_URL?=http://34.194.193.217:8545
L1_BEACON_RPC_URL?=http://34.194.193.217:5052
# if GATEWAY_SEQUENCING_KEY is set, use that one, otherwise key_to_address will generate a new one
GATEWAY_SEQUENCING_KEY ?= $(shell \
[ -f .local_gateway_and_follower/.env ] && \
grep -m1 '^GATEWAY_SEQUENCING_KEY=' .local_gateway_and_follower/.env \
| cut -d= -f2 \
)
_GATEWAY_KEY_AND_WALLET:=$(shell docker run --rm -i key_to_address $(GATEWAY_SEQUENCING_KEY))
GATEWAY_SEQUENCING_KEY:=$(word 1,$(_GATEWAY_KEY_AND_WALLET))
GATEWAY_SEQUENCING_ADDRESS:=$(word 2,$(_GATEWAY_KEY_AND_WALLET))

BASED_GATEWAY_DATA_DIR?=.local_gateway_and_follower/data/gateway
BASED_OP_NODE_DATA_DIR?=.local_gateway_and_follower/data/node
BASED_OP_GETH_DATA_DIR?=.local_gateway_and_follower/data/geth
start-gateway: build-follower-op-node build-follower-op-geth build-gateway build-key_to_address build-overseer
start-gateway:
@if docker ps --format '{{.Names}}' | grep -wq based-op-gateway ; then \
echo "❌ Gateway already running."; \
exit 1; \
Expand All @@ -116,8 +127,11 @@ start-gateway: build-follower-op-node build-follower-op-geth build-gateway build
cp follower_node/env_example .local_gateway_and_follower/.env; \
cp follower_node/compose.yml .local_gateway_and_follower/compose.yml; \
echo "Initializing gateway and follower op-node in ./.local_gateway_and_follower ..."; \
echo "Gateway Sequencing Private Key: $(GATEWAY_SEQUENCING_KEY)"; \
echo "Gateway Sequencing Wallet: $(GATEWAY_SEQUENCING_ADDRESS)"; \
{ \
echo "PORTAL=$(PORTAL)"; \
echo "OP_NODE_GOSSIP_IP=$$(curl ifconfig.me)"; \
echo "GATEWAY_SEQUENCING_KEY=$(GATEWAY_SEQUENCING_KEY)"; \
echo "MAIN_OP_NODE_GOSSIP_STATIC=$$(curl -s -X POST -H 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","method":"portal_opNodeGossipStatic","params":[],"id":1}' \
Expand Down Expand Up @@ -172,7 +186,7 @@ start-gateway: build-follower-op-node build-follower-op-geth build-gateway build
mkdir -p $(BASED_GATEWAY_DATA_DIR); \
fi

@wallet=$$(docker run -i key_to_address $(GATEWAY_SEQUENCING_KEY)); \
@wallet=$$(docker run --rm -i key_to_address $(GATEWAY_SEQUENCING_KEY)); \
echo "...Done"; \
echo; \
echo "Starting with the following generated .env:"; \
Expand All @@ -182,12 +196,12 @@ start-gateway: build-follower-op-node build-follower-op-geth build-gateway build
GATEWAY_URL=http://$$(curl -s ifconfig.me):$$(grep -m1 '^GATEWAY_PORT[[:space:]]*=' .local_gateway_and_follower/.env | cut -d= -f2); \
GATEWAY_ADDRESS=$$wallet; \
JWT=$$(cat .local_gateway_and_follower/config/jwt); \
curl -X POST $$PORTAL \
curl -X POST "$(PORTAL)" \
-H "Content-Type: application/json" \
-d "{\"jsonrpc\":\"2.0\", \
\"method\":\"registry_registerGateway\", \
\"params\":[ \
[\"$$GATEWAY_URL\", \"$$GATEWAY_ADDRESS\", \"$$JWT\"] \
[\"$$GATEWAY_URL\", \"$(GATEWAY_SEQUENCING_ADDRESS)\", \"$$JWT\"] \
], \
\"id\":1}"; \
echo; echo
Expand All @@ -196,25 +210,9 @@ start-gateway: build-follower-op-node build-follower-op-geth build-gateway build
$(MAKE) start-overseer


ifeq ($(filter start-overseer,$(MAKECMDGOALS)),start-gateway)
ifeq ($(strip $(PORTAL)),)
$(error PORTAL is undefined! \
Please invoke like `make start-gateway \
PORTAL=http://… GATEWAY_SEQUENCING_KEY=…`)
endif
endif
start-overseer: build-overseer
start-overseer:
docker exec -it based-op-gateway overseer --portal-url $(PORTAL)

L1_CHAIN_ID?=11155111
L2_CHAIN_ID?=$(shell \
RAW=$$(od -An -N2 -tu2 /dev/urandom | tr -d ' '); \
echo $$((RAW % 50000 + 1)); \
)
L2_CHAIN_ID_HEX := $(shell printf "0x%064x" $(L2_CHAIN_ID))
L1_RPC_URL?=https://ethereum-sepolia-rpc.publicnode.com
L1_BEACON_RPC_URL?=https://ethereum-sepolia-beacon-api.publicnode.com


# ────────────────────────────────────────────────────────────────────────────────
# Only perform these parse-time checks if the user asked for deploy-chain
Expand Down Expand Up @@ -444,19 +442,25 @@ logs-follower-node:
fi
docker compose -f .local_gateway_and_follower/compose.yml logs --tail 100 -f

logs-portal: ## 📜 Show portal logs
logs-portal: ## 📜 Show portal logs (only for main sequencing node)
docker logs based-portal --tail 100 -f

logs-registry: ## 📜 Show registry logs
logs-registry: ## 📜 Show registry logs (only for main sequencing node)
docker logs based-registry --tail 100 -f

logs-gateway: ## 📜 Show gateway logs
docker logs based-op-gateway --tail 100 -f

logs-based-op-node: ## 📜 Show based op-node logs
docker logs based-op-node --tail 100 -f

logs-based-op-geth: ## 📜 Show based op-geth logs
docker logs based-op-node --tail 100 -f

logs-op-node: ## 📜 Show main op-node logs (when on main box)
logs-op-node: ## 📜 Show main op-node logs (only for main sequencing node)
docker logs op-node --tail 100 -f

logs-op-geth: ## 📜 Show main op-geth logs (when on main box)
logs-op-geth: ## 📜 Show main op-geth logs (only for main sequencing node)
docker logs op-geth --tail 100 -f

logs-batcher:
Expand Down
51 changes: 31 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,12 @@

## Local Development/Quick start

> [!IMPORTANT]
>
> **Prerequisites**
>
> Before you start, make sure you have the following installed on your machine:
>
> - [Go](https://golang.org/dl/)
> - [Rust](https://www.rust-lang.org/tools/install)
> - [Docker](https://docs.docker.com/get-docker/)
> - [Make](https://www.gnu.org/software/make/)
>
> Based-op is fully l1 pectra ready


### With existing OP chain
The following steps have been tested on Sepolia, with a previously deployed L2 chain (l2 non-pectra)
1. locate your `rollup.json`, `genesis.json` and `state.json` files
2. run `make config-main-node OP_NODE_DATA_DIR=<path/to/op-node/data> OP_GETH_DATA_DIR=<path/to/op-geth/data> ROLLUP_JSON=<path/to/rollup.json> GENESIS_JSON=<path/to/genesis.json> STATE_JSON=<path/to/state.json>`
3. there should be some files set up in `.local_main_node`
4. start sequencing the main chain with `make start-main-node OP_BATCHER_KEY=<op-batcher-private-key> OP_PROPOSER_KEY=<op-proposer-private-key> MAIN_KEY=<vault-key/main-sequencing key> L1_RPC_URL=<sepolia rpc url> L1_BEACON_RPC_URL=<sepolia beacon rpc url>`
4. start sequencing the main chain with `make start-main-node OP_BATCHER_KEY=<op-batcher-private-key> OP_PROPOSER_KEY=<op-proposer-private-key> MAIN_KEY=<vault-key/main-sequencing key>`
5. Normally you should see some logs starting
6. `blockscout` should be up and running at `http://0.0.0.0:4000`
7a. `make stop-main-node` to stop all the sequencing services
Expand All @@ -30,17 +16,41 @@ The following steps have been tested on Sepolia, with a previously deployed L2 c
### Deploy a new l2 chain on Sepolia
1. To deploy a new chain on l2, make sure to have an address on Sepolia with some funds. This will be used as the `MAIN`/`vault` address.
2. create 2 more accounts, deposit ~0.2 eth in them. One will be used for the `op-batcher` one for the `op-proposer.
3. run `make deploy-chain OP_BATCHER_KEY=<op-batcher private key> OP_PROPOSER_KEY=<op-proposer private key> MAIN_KEY=<vault key> L1_RPC_URL=<l1 sepolia rpc url> L1_BEACON_RPC_URL=<l1 sepolia beacon rpc url>`
3. run `make deploy-chain OP_BATCHER_KEY=<op-batcher private key> OP_PROPOSER_KEY=<op-proposer private key> MAIN_KEY=<vault key>`
4. start sequencing the main chain with `make start-main-node OP_BATCHER_KEY=<op-batcher-private-key> OP_PROPOSER_KEY=<op-proposer-private-key> MAIN_KEY=<vault-key/main-sequencing key> L1_RPC_URL=<sepolia rpc url> L1_BEACON_RPC_URL=<sepolia beacon rpc url>`
5. Normally you should see some logs starting
6. `blockscout` should be up and running at `http://0.0.0.0:4000`
7a. `make stop-main-node` to stop all the sequencing services
7b. `make logs-main-node` to output logs of all the main services

### Run a based-gateway
1. run `make start-gateway PORTAL=<portal rpc url> GATEWAY_SEQUENCING_KEY=<private key used to sequence with>`
2. to stop the based gateway run `make stop-gateway`
3. for logs `make logs-gateway`
### Run a Based Gateway

In the following, all defaults are set up to target the [`Based OP` testnet](https://based-explorer.gattaca.com), deployed on top of mainnet Sepolia.
With that default config, a new `private-key` and `wallet` combo will be generated which your `Gateway` will use to sign `Frags`.
The `wallet` is communicated back to the `Portal` to be gossiped around to the rest of the network for signature verification.

The following single command sets up everything and will start your `Gateway`, `Based OP-node`, `Based OP-geth`:
`git clone https://github.com/gattaca-com/based-op && cd based-op && make start-gateway`

If everything went well, you should see a terminal UI appear, called the `Overseer`:

![ ](https://github.com/gattaca-com/based-op/blob/main/docs/docs/based_op.gif)

This shows you the status of your local `Gateway` and a general overview of the chain.
You can press left and right keys to cycle between the different tabs and explore all the information!

The configuration that was generated can be found in `based-op/.local_gateway_and_follower`, mainly the `.env` and `compose.yml` files.

When you [spam some transactions with `based-bmf`](https://based-bmf.gattaca.com), you should see them appear in the `Transaction Pool` of your `Gateway`.

A couple of commands tend to come in handy (from the top `based-op` directory):
- `make stop-gateway`
- `make start-gateway`
- `make start-overseer`
- `make logs-gateway`
- `make logs-based-op-node`
- `make logs-based-op-geth`


### Add/Update based-gateways to Registry
When a based-gateway is started with `make start-gateway`, it will register itself to the Registry behind the `PORTAL`. For now, the Registry is kept in a simple json file in `.local_main_node/config/registry.json`. You can add/update/remove gateways there, the Registry and Portal will pick up on the changes every minute.
Expand All @@ -52,6 +62,7 @@ your url.
You can now test sending a transaction with `make test-tx`.
The transaction will be sent to the Portal, and forwarded to the gateway, which will sequence the transaction in a new Frag, and broacast it via p2p to follower nodes.


> [!IMPORTANT]
>
> **The following is experimental**
Expand Down
4 changes: 3 additions & 1 deletion based/bin/overseer/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ impl UIData {

let (t, cur_state) = data.current_state().unwrap_or_default();
if let Some((url, address)) = data.current_gateway.as_ref() {
let _ = writeln!(&mut tw, "Current Gateway:\t{url}\t signing wallet: {address}");
let _ = writeln!(&mut tw, "Current Gateway:\t{url}");
let _ = writeln!(&mut tw, "Signing wallet:\t{address}");
} else {
let _ = writeln!(&mut tw, "Current Gateway:");
let _ = writeln!(&mut tw);
}

let _ = writeln!(&mut tw, "Current Block:\t{}", data.block_number);
Expand Down
4 changes: 2 additions & 2 deletions based/bin/portal/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub struct PortalArgs {
#[arg(long = "port", default_value_t = 8080)]
pub portal_port: u16,

/// TEMP: the URL to the main op-node's RPC-API
#[arg(long = "op_node.url", default_value = "http://0.0.0.0:9545")]
/// TEMP: the URL to the based-op-node's RPC-API
#[arg(long = "op_node.url", default_value = "http://0.0.0.0:8547")]
pub op_node_url: Url,

/// TEMP: the URL to the fallback EthAPI
Expand Down
Loading
Loading