Optimism 백서

Optimism

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 64쪽

we'll use `base`, but any other OP Stack chain will do. ``` op-reth node \ --chain base \ --rollup.sequencer-http https://mainnet-sequencer.base.org \ --http \ --ws \ --authrpc.port 9551 \ --authrpc.jwtsecret /path/to/jwt.hex ``` Kona has a `generate-jwt` justfile target that can be used to create the `jwt.hex` file. Run `just generate-jwt`. <Info> The JWT token file path passed into `--authrpc.jwtsecret` **MUST** be the same as the one passed into the `kona-node`. This JWT token is how the `op-reth` client authenticates requests made by the `kona-node` to the engine rpc. By default, the `kona-node` will attempt to read a JWT token from a `jwt.hex` file in the local directory. If it cannot find one, it will create a JWT token in a new `jwt.hex` file. To specify the path to the file that contains the JWT token, pass the file path into the `--l2.jwt-secret` CLI flag or use the `KONA_NODE_L2_ENGINE_AUTH` environment variable. </Info> Then, run the `kona-node` using Base's chain id - `8453`. ``` kona-node node \ --chain 8453 \ --l1-eth-rpc <L1_RPC_URL> \ --l1-beacon <L1_BEACON_URL> \ --l2-engine-rpc http://127.0.0.1:9551 \ ``` That's it! Your node should connect to P2P and start syncing quickly. <Note> By default, `kona-node` trusts its RPC providers and doesn't perform additional verification, which is suitable for local nodes. When pointing the node at public RPC endpoints, follow [configure RPC trust](/node-operators/kona-node/run/rpc-trust) to enable block hash verification. </Note> #### What to Expect Now, when the `kona-node` starts up, it should immediately spin up the P2P stack. It will begin discovering valid peers on the network with the same chain id (base - `8453`) and OP Stack enr key "opstack". When valid peers are discovered, they are sent to the libp2p swarm which attempts to connect to them and listen for block gossip. Depending on the chain, and the P2P network topology, it may take longer for the `kona-node` to establish a strong set of peers and begin receiving block gossip. For larger, more mature chains like OP Mainnet and Base, peer discovery should happen quickly via the chain's P2P bootnodes. Once the first unsafe L2 payload attributes (block) is received from peers in the libp2p swarm, it is sent off to the `kona-node`'s engine actor which will kick off execution layer sync on the `op-reth` execution client. When this happens, the `op-reth` logs will start to show that it is fetching past L2 blocks to sync the chain to tip. Once EL sync is finished, `kona-node`'s derivation actor will kick off the derivation pipeline and begin deriving the L2 chain. All the while, the P2P stack is separately receiving unsafe L2 blocks from the chain's sequencer, and sending them off to the engine actor to insert into the chain. #### Next Steps * The node's default ports, default behavior, and every available CLI flag - including the sequencer and interop flag sets - are catalogued in the [Kona node CLI reference](/node-operators/kona-node/configuration). * To adjust log verbosity or set up metrics dashboards, see [Monitoring](/node-operators/kona-node/monitoring). * To learn more about running a `kona-node` using docker, check out the [docker guide](/node-operators/kona-node/run/docker). [scr]: https://github.com/ethereum-optimism/superchain-registry/tree/main [op-reth-docs]: https://reth.rs/run/opstack [op-reth]: https://github.com/paradigmxyz/reth/blob/main/crates/optimism/bin/src/main.rs [buildx]: https://github.com/ethereum-optimism/optimism/tree/develop/rust/kona/docker [packages]: https://github.com/orgs/op-rs/packages?repo_name=kona [pdocs]: https://github.com/ethereum-optimism/optimism/pkgs/container/kona%2Fkona-node/446969659?tag=latest # Docker Guide Source: https://docs.optimism.io/node-operators/kona-node/run/docker Run kona-node with op-reth using Kona's pre-packaged docker-compose setup, including Grafana dashboards and Prometheus. <Info> This guide uses Kona's pre-packaged docker config. For detailed usage of the `kona-node` binary, head over to [the binary guide](/node-operators/kona-node/run/binary). To run an op-node + op-reth stack with Docker instead, see [Running a Node With Docker](/node-operators/tutorials/node-from-docker). </Info> Kona provides a [`kona-node` docker recipe][recipe] with detailed instructions for running a complete node setup. ## Quick Start The easiest way to run `kona-node` with Docker is using the provided recipe: 1. **Navigate to the recipe directory:** ```bash theme={null} cd docker/recipes/kona-node ``` 2. **Configure environment variables:** Edit `cfg.env` to set your L1 RPC endpoints: ```bash theme={null} L1_PROVIDER_RPC=https://your-l1-rpc-endpoint L1_BEACON_API=https://your-l1-beacon-endpoint ``` 3. **Start the services:** ```bash theme={null} just up ``` This will start: * `kona-node` - The OP Stack node implementation * `op-reth` - Execution layer client * `prometheus` - Metrics collection * `grafana` - Monitoring dashboards (accessible at [http://localhost:3000](http://localhost:3000)) ## Docker Compose In the [provided docker compose][compose], there are a few services aside from the `kona-node` and `op-reth`. These are `prometheus` and `grafana` which automatically come provisioned with dashboards for monitoring and insight into the `kona-node` and `op-reth` services. For more detail into how Prometheus and Grafana work, head over to the [Monitoring][monitoring] docs. The `docker-compose.yaml` uses published images from GitHub Container Registry: * **`op-reth`**: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-reth:develop * **`kona-node`**: us-docker.pkg.dev/oplabs-tools-artifacts/images/kona-node:develop ### Service Configuration #### kona-node Service The `kona-node` service is configured with the following key settings: * **Ports**: * `5060` - RPC endpoint * `9223` - P2P discovery (TCP/UDP) * `9002` - Metrics * **Environment**: L1 RPC and Beacon API endpoints are required * **Volumes**: Persistent data storage and JWT token for engine API authentication #### op-reth Service The `op-reth` service provides the execution layer: * **Ports**: * `8545` - HTTP RPC * `8551` - Engine API (authenticated) * `30303` - P2P discovery * `9001` - Metrics * **Configuration**: Pre-configured for OP Sepolia testnet ## Configuration ### Network Selection By default, the recipe is configured for **OP Sepolia**. To sync a different OP Stack chain: 1. Set appropriate L1 endpoints for your target network in `cfg.env` 2. Modify the docker-compose.yaml: * Update `op-reth --chain` parameter * Update `op-reth --rollup.sequencer-http` endpoint * Update `kona-node --chain` parameter ### RPC Trust Configuration By default, `kona-node` trusts RPC providers (both L1 and L2). When using public or untrusted RPC endpoints, you should disable trust to enable block hash verification: ```bash theme={null} # In cfg.env or as environment variables: KONA_NODE_L1_TRUST_RPC=false KONA_NODE_L2_TRUST_RPC=false ``` Or modify the docker-compose.yaml command: ```yaml theme={null} kona-node: command: | node --chain op-sepolia --l1-eth-rpc ${L1_PROVIDER_RPC} --l1-beacon ${L1_BEACON_API} --l1-trust-rpc false # Add this for untrusted L1 RPCs --l2-engine-rpc ws://op-reth:8551 --l2-trust-rpc false # Add this for untrusted L2 RPCs ``` See [configure RPC trust](/node-operators/kona-node/run/rpc-trust) for more details on RPC trust settings. ### Port Configuration All host ports can be customized via environment variables in `cfg.env`: ```bash theme={null} # Kona Node ports KONA_NODE_RPC_PORT=5060 KONA_NODE_DISCOVERY_PORT=9223 KONA_NODE_METRICS_PORT=9002 # OP Reth ports OP_RETH_RPC_PORT=8545 OP_RETH_ENGINE_PORT=8551 OP_RETH_METRICS_PORT=9001 OP_RETH_DISCOVERY_PORT=30303 # Monitoring PROMETHEUS_PORT=9090 ``` ### Logging Adjust log levels by setting the `RUST_LOG` environment variable: ```bash theme={null} export RUST_LOG=engine_builder=trace,runtime=debug ``` ## Management Commands The recipe includes convenient Just commands: ```bash theme={null} # Start all services just up # Stop all services just down # Restart all services just restart # Generate JWT token (if needed) ./generate-jwt.sh ``` ## Getting the kona-node Image The recipe pulls published `kona-node` and `op-reth` images automatically. Use this section when you want to pull or build the `kona-node` image yourself, for example to pin a release version or test local changes. ### Pulling a published image Kona docker images are published with every release on GitHub Container Registry. You can obtain the latest `kona-node` image with: ```bash theme={null} docker pull us-docker.pkg.dev/oplabs-tools-artifacts/images/kona-node ``` <Note> Specify a specific version (e.g. v0.1.0) like so. ```bash theme={null} docker pull us-docker.pkg.dev/oplabs-tools-artifacts/images/kona-node:v0.1.0 ``` </Note> You can test the image with: ```bash theme={null} docker run --rm us-docker.pkg.dev/oplabs-tools-artifacts/images/kona-node --version ``` If you can see the [latest release](https://github.com/ethereum-optimism/optimism/releases) version, then you've successfully installed Kona via Docker. ### Building the Docker image To build the image from source, navigate to the root of the [kona directory](https://github.com/ethereum-optimism/optimism/tree/develop/rust/kona) in the monorepo and run: ```bash theme={null} just build-local kona-node ``` <Note> This will create an image with the tag `kona:local`. To specify a custom tag, just pass it in after `kona-node` in the command above, like so: ```bash theme={null} just build-local kona-node my-custom-tag ``` </Note> The build will likely take several minutes. Once it's built, test it with: ```bash theme={null} docker run kona:local --version ``` To use the locally built image with the recipe, update `docker-compose.yaml` to use `kona:local` instead of the published image. [monitoring]: ../monitoring.mdx [recipe]: https://github.com/ethereum-optimism/optimism/blob/develop/rust/kona/docker/recipes/kona-node/README.md [compose]: https://github.com/ethereum-optimism/optimism/blob/develop/rust/kona/docker/recipes/kona-node/docker-compose.yaml # How it Works Source: https://docs.optimism.io/node-operators/kona-node/run/mechanics Kona brings together a powerful suite of `no-std` and `std` Rust components, purpose-built for the OP Stack. At the heart of this ecosystem is the `kona-node` — a modern, modular rollup node (L2 consensus node) that can be used as a drop-in binary or as a foundation for custom services. The `kona-node` is a fully compliant implementation of the ["Rollup Node" Specifications][rollup-node] and is released as a [binary][package] in the [kona repository][kona]. Whether you're running a production network, building new rollup features, or experimenting with the OP Stack, `kona-node` is built to be both robust and extensible. ### Background A rollup node is responsible for deriving the canonical L2 chain from L1 blocks and their receipts. It validates these blocks using the [Engine API][engine-api], passing them to the execution layer for processing. Paired with an execution engine like op-reth or op-geth, `kona-node` tracks the unsafe, safe, and finalized tips of the L2 OP Stack chain, ensuring the node is always in sync with the latest state. <Note> Rollup nodes hold minimal state. Unsafe and safe payloads alike are sent away to the execution engine client which holds the chain's db. This way, the rollup node holds a view of the tip of the chain - unsafe, safe, and finalized block info. All data otherwise needed is held in memory. </Note> There are a few core architectural pieces of the `kona-node`. * **Derivation Pipeline:** Constructs L2 payload attributes from L1 blocks, forming the backbone of rollup logic. * **Execution Engine Integration:** Executes L2 payload attributes via the [Engine API][engine-api], abstracting away different EL clients. * **P2P Networking:** Enables block gossip and peer discovery. For an in-depth breakdown of these three pillars and a detailed design of the `kona-node`, visit the [Node Design section](/node-operators/kona-node/design/intro). Additionally, an RPC server exposes essential methods, including the [L2 Output RPC method][l2o-rpc]. ### Syncing The `kona-node` syncs the L2 chain in two main phases: 1. **Execution Layer (EL) Sync:** When starting, the node initially has an empty engine task queue. Once an unsafe block is received from P2P gossip, an `InsertTask` is executed. That task inserts the payload and sends a forkchoice update through the engine api. Since the engine state is lazily initialized (the safe and finalized heads are zero), the forkchoice update kicks off EL sync on the execution layer (EL) client (such as op-reth or op-geth). EL sync instructs the execution client to fetch and sync L2 blocks directly from peers. During this phase, the `kona-node` effectively waits for the EL client to reach the chain tip, when it returns that it is `synced`. No L2 blocks are derived from L1 during this period. 2. **Consensus Layer (CL) Sync:** Once the EL client is fully synced to the tip, the node transitions to consensus layer (CL) sync. In this phase, `kona-node` begins deriving new L2 payload attributes from the L1 chain, following the rollup derivation process. `OpAttributesWithParent` values derived this way are executed as an engine task which submits the payloads to the execution engine for validation and execution. <Note> * `kona-node` does **not** support historical CL sync or backfilling L2 blocks from L1 for past chain history. It relies on the EL client to perform the initial sync of the L2 chain. * Only after the EL is fully synced does the node begin deriving and following new L2 blocks from L1. </Note> ### Extensibility The `kona-node` is designed as a modular, actor-based node SDK, making it possible to extend or customize node behavior by adding new actors or swapping out existing ones. This extensibility is currently in **beta**, but the architecture is intentionally built to support advanced use cases and custom integrations. #### Actor Model At the core of `kona-node` is the concept of **actors**: independent, async services that communicate over channels. Each actor implements the [`NodeActor` trait][node-actor], a minimal interface with a single `step` method that the service drives in a loop until the actor reports a fatal error or the node shuts down. The [`RollupNode` service][node] builds and spawns a fixed set of actors covering derivation, the execution engine and its read-only engine RPC, the L1 watcher, P2P networking, the node's RPC server, and, in sequencer mode, block building. The [Node Design section](/node-operators/kona-node/design/intro) is the canonical description of that actor set and of what each actor does. #### Extending with Custom Actors You can write your own actor by implementing the `NodeActor` trait. This allows you to introduce new background services, event processors, or integrations with external systems. The trait has one associated type and one method. Each call to `step` handles a single inbound request, event, or scheduled tick. Returning `Ok(())` means the actor is ready to be stepped again; returning an error is fatal and stops the actor. Cancellation is handled by the caller that drives the loop, so the actor itself does not own a cancellation token. **Example: Defining a Custom Actor** ```rust theme={null} use async_trait::async_trait; use kona_node_service::NodeActor; struct MyCustomActor; #[async_trait] impl NodeActor for MyCustomActor { type Error = std::io::Error; async fn step(&mut self) -> Result<(), Self::Error> { // Your actor logic for one step here. Ok(()) } } ``` #### Running Custom Actors There is no trait-based extension point for swapping actors into the standard node today. [`RollupNode`][node] is a concrete type rather than a trait, its actor set is fixed in that type's `start` method, and the helper that spawns and supervises those actors is internal to the `kona-node-service` crate. Running a custom actor therefore means composing the node yourself. The built-in actors are public API of the `kona-node-service` crate. The request and payload types they exchange over channels are public too, spread across `kona-node-service`, sibling kona crates such as `kona-rpc` and `kona-gossip`, and the shared alloy engine types. A custom binary can therefore construct the actors it needs, wire them together over channels, add its own `NodeActor` implementations, and drive each actor's `step` method in its own task. #### Programmatic Node Construction The [`RollupNodeBuilder`][builder] provides a convenient way to construct a standard node, but for advanced use cases, you can build your own node by composing actors directly, or by implementing your own builder pattern. #### Current Limitations * The actor and service APIs are **beta** and may change. * The standard `RollupNode` exposes no hook for overriding an individual actor or pipeline, so extending the node means composing actors in your own binary rather than wrapping `RollupNode`. * Documentation and examples for advanced extensibility are still evolving—contributions and feedback are welcome! #### Learn More * See the [`NodeActor` trait documentation][node-actor] for details on implementing actors. * Explore the [kona-node-service crate][service] for source code and more examples. [cli-docs]: ../configuration.mdx [subcommands]: ../subcommands.mdx [service]: https://github.com/ethereum-optimism/optimism/tree/develop/rust/kona/crates/node/service [node-actor]: https://docs.rs/kona-node-service/latest/kona_node_service/trait.NodeActor.html [node]: https://github.com/ethereum-optimism/optimism/blob/develop/rust/kona/crates/node/service/src/service/node.rs [builder]: https://github.com/ethereum-optimism/optimism/blob/develop/rust/kona/crates/node/service/src/service/builder.rs [kona]: https://github.com/ethereum-optimism/optimism/tree/develop/rust/kona [packages]: https://github.com/orgs/op-rs/packages?repo_name=kona [rollup-node]: https://specs.optimism.io/protocol/rollup-node.html [package]: https://github.com/ethereum-optimism/optimism/pkgs/container/kona%2Fkona-node [pdocs]: https://github.com/ethereum-optimism/optimism/pkgs/container/kona%2Fkona-node/446969659?tag=latest [buildx]: https://github.com/ethereum-optimism/optimism/tree/develop/rust/kona/docker [engine-api]: https://github.com/ethereum/execution-apis/blob/main/src/engine/common.md [l2o-rpc]: https://specs.optimism.io/protocol/rollup-node.html#l2-output-rpc-method # Run a Node Source: https://docs.optimism.io/node-operators/kona-node/run/overview Now that you have [installed the `kona-node`](/node-operators/kona-node/install/overview), it's time to run it. In this section, we'll guide you through running the kona-node on various networks and with different configurations. ## Supported Networks Kona uses the [superchain-registry][scr] to dynamically load chain configurations for the specified network. As such, Kona can only support networks that are defined this way. [scr]: https://github.com/ethereum-optimism/superchain-registry To view available networks, the `kona-node` binary provides a `registry` subcommand that lists all available networks: ```bash theme={null} kona-node registry ``` <Tip> Want to add support for a new network? Feel free to [add a chain](https://github.com/ethereum-optimism/superchain-registry/blob/main/docs/ops.md#adding-a-chain) to the superchain-registry! </Tip> ## Configuration & Monitoring Learn how to configure and monitor your node: * **[Configuration](/node-operators/kona-node/configuration)** - Configure your node * **[Monitoring](/node-operators/kona-node/monitoring)** - Set up lo
프로젝트로 돌아가기