Skip to content
Open
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
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ L2_CHAIN_ID?=$(shell \
)
L2_CHAIN_ID_HEX:=$(shell printf "0x%064x" $(L2_CHAIN_ID))
PORTAL?=http://0.0.0.0:8080
REGISTRY?=http://0.0.0.0:8082
TXPROXY?=http://0.0.0.0:8090
L1_RPC_URL?=https://ethereum-sepolia-rpc.publicnode.com
L1_BEACON_RPC_URL?=https://ethereum-sepolia-beacon-api.publicnode.com
Expand Down Expand Up @@ -129,6 +130,7 @@ start-based-gateway: create-network
echo "Gateway Sequencing Wallet: $(GATEWAY_SEQUENCING_ADDRESS)"; \
{ \
echo "PORTAL=$(PORTAL)"; \
echo "REGISTRY=$(REGISTRY)"; \
echo "OP_NODE_GOSSIP_IP=$(PUBLIC_IP)"; \
echo "GATEWAY_SEQUENCING_KEY=$(GATEWAY_SEQUENCING_KEY)"; \
echo "MAIN_OP_NODE_GOSSIP_STATIC=$$(curl -s -X POST -H 'Content-Type: application/json' \
Expand Down Expand Up @@ -193,13 +195,12 @@ start-based-gateway: create-network
echo "Calling registerGateway method via JSON-RPC:"; \
GATEWAY_URL=http://$(PUBLIC_IP):$$(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 "$(REGISTRY)" \
-H "Content-Type: application/json" \
-d "{\"jsonrpc\":\"2.0\", \
\"method\":\"registry_registerGateway\", \
\"params\":[ \
[\"$$GATEWAY_URL\", \"$(GATEWAY_SEQUENCING_ADDRESS)\", \"$$JWT\"] \
[\"$$GATEWAY_URL\", \"$(GATEWAY_SEQUENCING_ADDRESS)\"] \
], \
\"id\":1}"; \
echo; echo
Expand All @@ -209,7 +210,7 @@ start-based-gateway: create-network
$(MAKE) start-overseer

start-overseer:
docker exec -it based-gateway overseer --portal-url $(PORTAL) --rich-wallet-key $(DUMMY_RICH_WALLET_PRIVATE_KEY)
docker exec -it based-gateway overseer --portal-url $(PORTAL) --registry-url $(REGISTRY) --rich-wallet-key $(DUMMY_RICH_WALLET_PRIVATE_KEY)

# start spamoor as a foreground process
start-spamoor:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ A couple of commands tend to come in handy (from the top `based-op` directory):

### Add/Update based-gateways to Registry

When a based-gateway is started with `just follower-node start`, 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.
When a based-gateway is started with `just follower-node start`, it will register itself directly to the Registry (via `REGISTRY`, default `http://localhost:8082`). 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, and the Registry/Portal will pick up on the changes every minute.

If you have started both the main sequencing node and the gateway on the same machine, you might need to change the ip to `0.0.0.0`, by default `curl ifconfig.me` is used to populate
your url.
Expand Down
9 changes: 8 additions & 1 deletion based/bin/overseer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub struct OverseerArgs {
/// The url of the portal that is connected to the main sequencer node
#[arg(short, long)]
pub portal_url: Url,
/// The url of the registry for gateway `registration/listing`
#[arg(long)]
pub registry_url: Url,
/// The url of the based-op-node running next to the based-gateway
#[arg(long, default_value = "http://127.0.0.1:8547")]
pub based_op_node_url: Url,
Expand Down Expand Up @@ -114,6 +117,7 @@ struct OverseerConnections {
walkie_talkie: WalkieTalkie,
runtime: tokio::runtime::Runtime,
client_portal: HttpClient,
client_registry: HttpClient,
client_based_op_node: HttpClient,
client_based_op_geth: HttpClient,
rollup_config: RollupConfig,
Expand All @@ -127,6 +131,8 @@ impl OverseerConnections {
.expect("Couldn't initialize tokio runtime");
let client_portal =
HttpClient::builder().build(args.portal_url.clone()).expect("Couldn't initialize portal rpc client");
let client_registry =
HttpClient::builder().build(args.registry_url.clone()).expect("Couldn't initialize registry rpc client");
let client_based_op_node = HttpClient::builder()
.build(args.based_op_node_url.clone())
.expect("Couldn't initialize based-op-node rpc client");
Expand All @@ -142,6 +148,7 @@ impl OverseerConnections {
telemetry: telemetry_queue().into(),
runtime,
client_portal,
client_registry,
client_based_op_node,
client_based_op_geth,
rollup_config,
Expand All @@ -162,7 +169,7 @@ impl OverseerConnections {
}

pub fn current_gateway(&self) -> Result<(Url, Address), ClientError> {
self.runtime.block_on(self.client_portal.current_gateway()).map(|(_, url, address)| (url, address))
self.runtime.block_on(self.client_registry.current_gateway()).map(|(_, url, address)| (url, address))
}

pub fn peers_based_op_node(&self) -> Result<Vec<OpPeerInfo>, ClientError> {
Expand Down
7 changes: 0 additions & 7 deletions based/bin/portal/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::clients::{AuthRpcClient, RpcClient};
pub struct EngineApiProxy<S> {
pub inner: S,
pub geth_client: AuthRpcClient,
pub registry_client: RpcClient,
pub op_node_client: RpcClient,
pub metrics: Producer<MetricsUpdate>,
}
Expand All @@ -42,7 +41,6 @@ where
let inner = self.inner.clone();
let method = req.method_name().to_string();
let fallback_client = self.geth_client.clone();
let registry_client = self.registry_client.clone();
let op_node_client = self.op_node_client.clone();

let uuid = uuid();
Expand All @@ -67,11 +65,6 @@ where
inner.call(req).await;
res
}
Some(("registry", _)) => {
debug!(method = %method, "Received request in RegistryApiProxy");
MetricsUpdate::send_ref(uuid, Metric::IncrementCounter(Counter::RegistryApiRequests, 1), &metrics);
external_call(registry_client.clone(), &req).await
}
Some(("optimism", _)) | Some(("opp2p", _)) => {
debug!(method = %method, "Received request for OP node");
MetricsUpdate::send_ref(uuid, Metric::IncrementCounter(Counter::OpNodeApiRequests, 1), &metrics);
Expand Down
2 changes: 0 additions & 2 deletions based/bin/portal/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ impl PortalServer {

pub async fn run(self, addr: SocketAddr) -> eyre::Result<()> {
let geth_engine_client = self.geth_engine_client.clone();
let registry_client = self.gateway_manager.registry_client.clone();
let op_node_client = self.op_node_client.clone();
let metrics = self.metrics;

let rpc_middleware = RpcServiceBuilder::new().layer_fn(move |s| EngineApiProxy {
inner: s,
geth_client: geth_engine_client.clone(),
registry_client: registry_client.clone(),
op_node_client: op_node_client.clone(),
metrics,
});
Expand Down
7 changes: 4 additions & 3 deletions based/follower-node.just
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export FOLLOWER_NODE_DIR := join(justfile_directory(), "..", "follower_node")

# External environment configuration
export PORTAL := shell("echo ${PORTAL:-$(" + portal + " address)}")
export REGISTRY := shell("echo ${REGISTRY:-$(" + registry + " address)}")

# Force config creation
export FORCE := env("FORCE", "")
Expand All @@ -32,6 +33,7 @@ PORTAL_TIMEOUT := env("PORTAL_TIMEOUT", "30")
self := "just -f " + justfile()
parent := "just -f " + join(justfile_directory(), "..", "Justfile")
portal := "just -f " + join(justfile_directory(), "portal.just")
registry := "just -f " + join(justfile_directory(), "registry.just")
wallet := "just -f " + join(justfile_directory(), "scripts", "wallet.just")
link := "just -f " + join(justfile_directory(), "scripts", "link.just")

Expand All @@ -45,6 +47,7 @@ _generate-dotenv gossip enr enode $dotenv=join(FOLLOWER_NODE_DATA, ".env"):
l2_chain_id=$({{portal}} l2_chain_id)

echo "PORTAL=$PORTAL" >> $dotenv
echo "REGISTRY=$REGISTRY" >> $dotenv
echo "OP_NODE_GOSSIP_IP=$PUBLIC_IP" >> $dotenv
echo "GATEWAY_SEQUENCING_KEY=$GATEWAY_SEQUENCING_KEY" >> $dotenv
echo "MAIN_OP_NODE_GOSSIP_STATIC={{gossip}}" >> $dotenv
Expand Down Expand Up @@ -188,10 +191,8 @@ start-dev $dotenv=join(FOLLOWER_NODE_DATA, ".env") network="based_op_node": (doc
port=$(grep -m1 '^GATEWAY_PORT[[:space:]]*=' $dotenv | cut -d= -f2)

address=$({{wallet}} address {{WALLET_NAME}})
jwt=$(cat $FOLLOWER_NODE_DATA/config/jwt)

echo "Registering gateway"
{{portal}} register-gateway "http://$ip:$port" "$address" "$jwt"
{{registry}} register-gateway "http://$ip:$port" "$address"

# Start services
echo "Starting gateway and monitoring services..."
Expand Down
1 change: 1 addition & 0 deletions based/overseer.just
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ parent := "just -f " + join(justfile_directory(), "..", "Justfile")
@start:
docker exec -it based-gateway overseer \
--portal-url $({{parent}} portal address) \
--registry-url $({{parent}} registry address) \
--rich-wallet-key {{DUMMY_RICH_WALLET_PRIVATE_KEY}}
5 changes: 0 additions & 5 deletions based/portal.just
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ l2_chain_id: (_rpc "portal_l2ChainId")
rollup: (_rpc "portal_fileRollup")
genesis: (_rpc "portal_fileGenesis")

@register-gateway url address:
# The portal returns null on success so we remove the -e flag
JQ_ARGS="" {{self}} _rpc "registry_registerGateway" \
"[[\"{{url}}\", \"{{address}}\"]]"

# Start the portal service and view logs (for main sequencing node)
start:
#!/usr/bin/env bash
Expand Down
17 changes: 17 additions & 0 deletions based/registry.just
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ self := "just -f " + justfile()

service-name := "based-registry"

export REGISTRY_PORT := env("REGISTRY_PORT", "8082")
export REGISTRY := env("REGISTRY", "http://0.0.0.0:" + REGISTRY_PORT)
export JQ_ARGS := env("JQ_ARGS", "-e")

@address:
echo $REGISTRY

@_rpc method params="[]":
curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "method": "{{method}}", "params": {{params}}, "id": 1}' \
{{REGISTRY}} | jq -r $JQ_ARGS '.result'

@register-gateway url address:
# The registry returns null on success so we remove the -e flag
JQ_ARGS="" {{self}} _rpc "registry_registerGateway" \
"[[\"{{url}}\", \"{{address}}\"]]"

# Start the registry service and view logs (for main sequencing node)
start:
#!/usr/bin/env bash
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/getting_started/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ The following steps have been tested on Sepolia, with a previously deployed L2 c
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>`
1. run `make start-gateway PORTAL=<portal rpc url> REGISTRY=<registry 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`

#### 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.
When a based-gateway is started with `make start-gateway`, it will register itself directly to the Registry (via `REGISTRY`). 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, and the Registry/Portal will pick up on the changes every minute.

If you have started both the main sequencing node and the gateway on the same machine, you might need to change the ip to `0.0.0.0`, by default `curl ifconfig.me` is used to populate
your url.
Expand Down
2 changes: 1 addition & 1 deletion follower_node/compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ services:
- --safedb.path=/data/op-node/op-node-beacon-data
- --p2p.static=$MAIN_OP_NODE_GOSSIP_STATIC
- --rpc.enable-based
- --registry=$PORTAL
- --registry=$REGISTRY
- --p2p.bootnodes=$MAIN_OP_NODE_ENR
- --syncmode=execution-layer
- --metrics.enabled=true
Expand Down
2 changes: 1 addition & 1 deletion follower_node/compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ services:
- --safedb.path=/data/op-node/op-node-beacon-data
- --p2p.static=$MAIN_OP_NODE_GOSSIP_STATIC
- --rpc.enable-based
- --registry=$PORTAL
- --registry=$REGISTRY
- --p2p.bootnodes=$MAIN_OP_NODE_ENR
- --syncmode=execution-layer
- --metrics.enabled=true
Expand Down
2 changes: 2 additions & 0 deletions follower_node/env_example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ OP_GETH_WS_PORT=8646
GATEWAY_PORT=9997
GATEWAY_PORT_NO_AUTH=9994
TXPROXY=http://localhost:8090
PORTAL=http://localhost:8080
REGISTRY=http://localhost:8082
2 changes: 1 addition & 1 deletion follower_node_dockerized_network/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ services:
- --safedb.path=/data/op-node/op-node-beacon-data
- --p2p.static=$MAIN_OP_NODE_GOSSIP_STATIC
- --rpc.enable-based
- --registry=$PORTAL
- --registry=$REGISTRY
- --p2p.bootnodes=$MAIN_OP_NODE_ENR
- --syncmode=execution-layer
volumes:
Expand Down
2 changes: 2 additions & 0 deletions follower_node_dockerized_network/env_example
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ OP_GETH_ENGINE_RPC_PORT=8651
OP_GETH_RPC_PORT=8645
OP_GETH_WS_PORT=8646
GATEWAY_PORT=9997
PORTAL=http://host.docker.internal:8080
REGISTRY=http://host.docker.internal:8082
Loading