Optimism 백서

Optimism

원문

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

--l2-chain-id` flag supports flexible chain identification using the `alloy_chains` crate: **Numeric Chain IDs:** ```bash theme={null} kona-node --l2-chain-id 10 node [args...] # Optimism mainnet kona-node --l2-chain-id 8453 node [args...] # Base mainnet kona-node --l2-chain-id 1 node [args...] # Ethereum mainnet ``` **String Chain Names:** ```bash theme={null} kona-node --l2-chain-id optimism node [args...] kona-node --l2-chain-id base node [args...] kona-node --l2-chain-id mainnet node [args...] ``` **Short Flag and Environment Variable:** ```bash theme={null} kona-node -c optimism node [args...] export KONA_NODE_L2_CHAIN_ID=optimism && kona-node node [args...] ``` Supported chain names include all those recognized by `alloy_chains` (e.g., `optimism`, `base`, `mainnet`). Unknown numeric chain IDs are accepted for custom networks. ## P2P Arguments | Flag | Env | Description | Default | | - | - | - | - | | `--p2p.no-discovery` | `KONA_NODE_P2P_NO_DISCOVERY` | Disable Discv5 (node discovery) | `false` | | `--p2p.priv.path <PATH>` | `KONA_NODE_P2P_PRIV_PATH` | Path to hex-encoded 32-byte private key for peer ID | - | | `--p2p.priv.raw <HEX>` | `KONA_NODE_P2P_PRIV_RAW` | Hex-encoded 32-byte private key for peer ID | - | | `--p2p.advertise.ip <IP>` | `KONA_NODE_P2P_ADVERTISE_IP` | IP to advertise to external peers | - | | `--p2p.advertise.tcp <PORT>` | `KONA_NODE_P2P_ADVERTISE_TCP_PORT` | TCP port to advertise | `0` | | `--p2p.advertise.udp <PORT>` | `KONA_NODE_P2P_ADVERTISE_UDP_PORT` | UDP port to advertise | `0` | | `--p2p.listen.ip <IP>` | `KONA_NODE_P2P_LISTEN_IP` | IP to bind LibP2P/Discv5 to | `0.0.0.0` | | `--p2p.listen.tcp <PORT>` | `KONA_NODE_P2P_LISTEN_TCP_PORT` | TCP port to bind LibP2P to | `9222` | | `--p2p.listen.udp <PORT>` | `KONA_NODE_P2P_LISTEN_UDP_PORT` | UDP port to bind Discv5 to | `9223` | | `--p2p.peers.lo <N>` | `KONA_NODE_P2P_PEERS_LO` | Low-tide peer count | `20` | | `--p2p.peers.hi <N>` | `KONA_NODE_P2P_PEERS_HI` | High-tide peer count | `30` | | `--p2p.peers.grace <SECONDS>` | `KONA_NODE_P2P_PEERS_GRACE` | Grace period for new peers | `30` | | `--p2p.gossip.mesh.d <N>` | `KONA_NODE_P2P_GOSSIP_MESH_D` | GossipSub mesh target count | `8` | | `--p2p.gossip.mesh.lo <N>` | `KONA_NODE_P2P_GOSSIP_MESH_DLO` | GossipSub mesh low watermark | `6` | | `--p2p.gossip.mesh.dhi <N>` | `KONA_NODE_P2P_GOSSIP_MESH_DHI` | GossipSub mesh high watermark | `12` | | `--p2p.gossip.mesh.dlazy <N>` | `KONA_NODE_P2P_GOSSIP_MESH_DLAZY` | GossipSub gossip target | `6` | | `--p2p.gossip.mesh.floodpublish` | `KONA_NODE_P2P_GOSSIP_FLOOD_PUBLISH` | Publish to all known peers | `false` | | `--p2p.scoring <none or light>` | `KONA_NODE_P2P_SCORING` | Peer scoring strategy | `light` | | `--p2p.ban.peers` | `KONA_NODE_P2P_BAN_PEERS` | Enable peer banning | `false` | | `--p2p.ban.threshold <N>` | `KONA_NODE_P2P_BAN_THRESHOLD` | Ban threshold | `-100` | | `--p2p.ban.duration <MINUTES>` | `KONA_NODE_P2P_BAN_DURATION` | Ban duration | `60` | | `--p2p.discovery.interval <SECONDS>` | `KONA_NODE_P2P_DISCOVERY_INTERVAL` | Peer discovery interval | `5` | | `--p2p.bootstore <PATH>` | `KONA_NODE_P2P_BOOTSTORE` | Directory to store the bootstore | - | | `--p2p.redial <N>` | `KONA_NODE_P2P_REDIAL` | Peer redialing threshold | `500` | | `--p2p.redial.period <MINUTES>` | `KONA_NODE_P2P_REDIAL_PERIOD` | Peer dial period | `60` | | `--p2p.bootnodes <ENR,...>` | `KONA_NODE_P2P_BOOTNODES` | List of bootnode ENRs | - | | `--p2p.topic-scoring` | `KONA_NODE_P2P_TOPIC_SCORING` | Enable topic scoring | `false` | | `--p2p.discovery.randomize <SECONDS>` | `KONA_NODE_P2P_DISCOVERY_RANDOMIZE` | Remove random peers from discovery | - | | `--p2p.sequencer.key <HEX>` | `KONA_NODE_P2P_SEQUENCER_KEY` | Hex-encoded private key that signs gossiped blocks. A sequencer needs this, `--p2p.sequencer.key.path`, or a remote signer | - | | `--p2p.sequencer.key.path <PATH>` | `KONA_NODE_P2P_SEQUENCER_KEY_PATH` | Path to a file with the hex-encoded private key that signs gossiped blocks | - | | `--p2p.signer.endpoint <URL>` | `KONA_NODE_P2P_SIGNER_ENDPOINT` | Remote op-signer that signs gossiped blocks. Requires `--p2p.signer.address` | - | | `--p2p.signer.address <ADDRESS>` | `KONA_NODE_P2P_SIGNER_ADDRESS` | Address of the remote signer's key | - | ## RPC Arguments | Flag | Env | Description | Default | | - | - | - | - | | `--rpc.disabled` | `KONA_NODE_RPC_DISABLED` | Disable the RPC server | `false` | | `--rpc.no-restart` | `KONA_NODE_RPC_NO_RESTART` | Prevent RPC server from restarting | `false` | | `--rpc.addr <IP>` | `KONA_NODE_RPC_ADDR` | RPC listening address | `0.0.0.0` | | `--port <PORT>` | `KONA_NODE_RPC_PORT` | RPC listening port | `9545` | | `--rpc.enable-admin` | `KONA_NODE_RPC_ENABLE_ADMIN` | Enable the admin API | `false` | | `--rpc.admin-state <PATH>` | `KONA_NODE_RPC_ADMIN_STATE` | File path for admin state persistence | - | | `--rpc.ws-enabled` | `KONA_NODE_RPC_WS_ENABLED` | Enable websocket RPC server | `false` | ## Sequencer Arguments | Flag | Env | Description | Default | | - | - | - | - | | `--sequencer.stopped` | `KONA_NODE_SEQUENCER_STOPPED` | Start sequencer in stopped state | `false` | | `--sequencer.max-safe-lag <N>` | `KONA_NODE_SEQUENCER_MAX_SAFE_LAG` | Max L2 safe/unsafe lag | `0` | | `--sequencer.l1-confs <N>` | `KONA_NODE_SEQUENCER_L1_CONFS` | L1 block confirmations for sequencer | `4` | | `--sequencer.recover` | `KONA_NODE_SEQUENCER_RECOVER` | Strictly prepare next L1 origin and create empty L2 blocks | `false` | | `--conductor.rpc <URL>` | `KONA_NODE_CONDUCTOR_RPC` | RPC endpoint URL of an external conductor service. Supplying it enables the conductor integration in sequencer mode; it has no effect in validator mode. | - | | `--conductor.rpc.timeout <SECONDS>` | `KONA_NODE_CONDUCTOR_RPC_TIMEOUT` | Conductor service RPC timeout | `1` | ## Interop Arguments | Flag | Env | Description | Default | | - | - | - | - | | `--interop.dependency-set <PATH>` | `KONA_NODE_INTEROP_DEPENDENCY_SET` | Path to the JSON file describing the interop dependency set for this chain. Required when the rollup config schedules the Lagoon hardfork. | - | `kona-node` does not run a supervisor RPC server, so there is no `--supervisor.*` flag group. `--interop.dependency-set` is the node's only interop flag. ## RPC Trust Flags The `--l1-trust-rpc` and `--l2-trust-rpc` flags control whether Kona verifies the block hashes of RPC responses. For guidance on when to disable trust and worked examples for trusted, untrusted, and mixed provider setups, see [configure RPC trust](/node-operators/kona-node/run/rpc-trust). ## Default Behavior Unless overridden by the flags above, a `kona-node node` run has the following defaults: * The P2P stack is spun up. The libp2p swarm listens on TCP `9222` to receive block gossip. The `discv5` discovery service runs on UDP port `9223`. Peer scoring is enabled. * An RPC server is exposed at `0.0.0.0:9545`. Websocket connections are disabled by default. * Prometheus metrics are disabled. Enable them with the `--metrics.enabled` flag; metrics are then served on `0.0.0.0:9090`, configurable via the `--metrics.port` and `--metrics.addr` flags. ## Rollup Configuration Loading If a file path to a rollup config is *not* specified via the `--l2-config-file` cli flag, the Rollup Config will be loaded via the [superchain registry][scr]. A custom rollup config can either be specified through the `--l2-config-file` flag, or specific values may be overridden using a set of override flags provided by the `kona-node`. Override flags (for example `--canyon-override`) can be viewed in the help menu by running `kona-node node --help`. The only overrides currently supported are hardfork timestamps in seconds. [scr]: https://github.com/ethereum-optimism/superchain-registry/tree/main # Derivation in Kona Node Source: https://docs.optimism.io/node-operators/kona-node/design/derivation The derivation system in kona-node is responsible for transforming L1 data into L2 payload attributes that can be executed to produce the canonical L2 blocks. This document covers how the [`kona-derive`][kd] crate is integrated and used within the kona-node architecture. ## Overview The derivation subsystem in kona-node is built around the **DerivationActor**, which manages the derivation pipeline lifecycle and coordinates with other node components. The actor uses the trait-abstracted [`kona-derive`][kd] pipeline to continuously process L1 data and produce L2 payload attributes. ### Key Components * **DerivationActor**: The main actor responsible for running the derivation pipeline * **OnlinePipeline**: A concrete implementation of the derivation pipeline using online providers * **DerivationStateMachine**: Manages when derivation is allowed to occur and tracks the confirmed safe head * **L2Finalizer**: Tracks derived L2 blocks awaiting finalization * **Signal System**: Handles pipeline resets, hardfork activations, and error conditions ## Architecture ### DerivationActor The `DerivationActor` is a [`NodeActor`][na] that runs as part of the node service. It receives requests from other actors over a single inbound channel and steps the derivation pipeline forward to produce new payload attributes. ```rust theme={null} pub struct DerivationActor<DerivationEngineClient_, PipelineSignalReceiver> where DerivationEngineClient_: DerivationEngineClient, PipelineSignalReceiver: Pipeline + SignalReceiver, { /// The channel on which all inbound requests are received by the actor. inbound_request_rx: mpsc::Receiver<DerivationActorRequest>, /// The Engine client used to interact with the engine. engine_client: DerivationEngineClient_, /// The derivation pipeline. pipeline: PipelineSignalReceiver, /// The state machine controlling when derivation can occur. derivation_state_machine: DerivationStateMachine, /// The L2Finalizer tracks derived L2 blocks awaiting finalization. finalizer: L2Finalizer, } ``` Inbound requests are expressed as the `DerivationActorRequest` enum: L1 head updates, finalized L1 block updates, engine safe head updates, engine sync completion, and pipeline signals from the engine (for example flush or reset). The actor coordinates with several other node components: * **Engine Actor**: Receives payload attributes for execution and sends back safe head updates and pipeline signals * **L1 Watcher Actor**: Sends L1 head and finalized block updates from the L1 chain ### Pipeline Construction The derivation pipeline is constructed by the `RollupNode` service when it wires up the derivation actor. The node builds caching L1/L2 providers and then creates an `OnlinePipeline`, which traverses L1 by polling its chain provider for the next block: ```rust theme={null} OnlinePipeline::new_polled( self.config.clone(), self.l1_config.chain_config.clone(), OnlineBlobProvider::init(self.l1_config.beacon_client.clone()).await, l1_derivation_provider, l2_derivation_provider, self.dependency_set.clone(), ) ``` ### Provider Configuration The node uses caching providers to optimize performance: * **AlloyChainProvider**: Provides L1 blockchain data with configurable cache size * **AlloyL2ChainProvider**: Provides L2 blockchain data and system configuration * **OnlineBlobProvider**: Retrieves blob data from the beacon chain for post-4844 transactions The cache size is set to 1024 entries by default: ```rust theme={null} const DERIVATION_PROVIDER_CACHE_SIZE: usize = 1024; ``` ## Pipeline Operation ### Main Processing Loop The derivation actor runs a continuous loop that handles various events: 1. **Shutdown signals**: Graceful shutdown when cancellation token is triggered 2. **L1 head updates**: Triggers derivation when new L1 blocks are available 3. **Safe head updates**: Triggers derivation when the L2 safe head advances 4. **Pipeline signals**: Handles resets, hardfork activations, and channel flushes ### Stepping Logic The core derivation logic is implemented in `produce_next_attributes()`: ```rust theme={null} async fn produce_next_attributes( &mut self, ) -> Result<OpAttributesWithParent, DerivationError> ``` This method continuously steps the pipeline until payload attributes are produced: 1. **Step the pipeline** with the last confirmed L2 safe head from the derivation state machine 2. **Handle step results**: * `PreparedAttributes`: Attributes are ready to be consumed * `AdvancedOrigin`: Pipeline advanced to next L1 block * `OriginAdvanceErr`/`StepFailed`: Handle various error conditions 3. **Return attributes** when available ### Error Handling The derivation actor handles three categories of pipeline errors: #### Temporary Errors * `PipelineError::NotEnoughData`: Continue stepping, more data may become available * `PipelineError::Eof`: Yield and wait for more L1 data #### Reset Errors * `ResetError::HoloceneActivation`: Send an `ActivationSignal` to the pipeline and keep stepping * Any other reset error, including `ResetError::ReorgDetected`: Send a reset request to the engine, then wait for the engine's signal before continuing. `ReorgDetected` additionally increments the `L1_REORG_COUNT` metric. #### Critical Errors * Unrecoverable errors that terminate the derivation process * Increment metrics counter and propagate error up ### Signal Handling The pipeline supports several signal types for coordination: * **ResetSignal**: Resets pipeline state with new L1 origin and system config * **ActivationSignal**: Handles hardfork activations (e.g., Holocene) * **FlushChannel**: Invalidates current channel data for deposit-only blocks Signals are sent from the engine actor when specific conditions are detected during payload execution. ## Configuration ### Rollup Configuration The derivation pipeline requires a [`RollupConfig`][rc] that defines: * Chain parameters (chain ID, block time, etc.) * Hardfork activation heights * System configuration addresses * Batch and channel parameters ### Runtime Configuration Runtime configuration includes: * Provider cache sizes * Polling intervals for L1 data * Metrics collection settings ## Integration Patterns ### With Engine Actor The derivation actor produces `OpAttributesWithParent` that are sent to the engine actor for execution through the `DerivationEngineClient` interface: ```rust theme={null} // Send payload attributes out for processing. self.engine_client .send_safe_l2_signal(payload_attributes.into()) .await ``` The engine actor executes these attributes and updates the L2 safe head, which triggers the next derivation cycle. ### With the L1 Watcher The derivation actor receives L1 head updates from the L1 watcher actor as `DerivationActorRequest::ProcessL1HeadUpdateRequest` messages on its inbound request channel, which indicate when new L1 data is available for processing. Finalized L1 blocks arrive the same way and drive the `L2Finalizer`. ### With RPC Layer The RPC layer can query derivation status and potentially trigger pipeline operations through the standard node RPC interface. ## Metrics and Observability The derivation actor exposes several metrics for monitoring: * `DERIVATION_L1_ORIGIN`: Current L1 origin block number * `DERIVATION_CRITICAL_ERROR`: Count of critical derivation errors * `L1_REORG_COUNT`: Count of detected L1 reorganizations These metrics help operators monitor the health and progress of the derivation process. ## Related Documentation For more details on the underlying derivation pipeline implementation, see: * The [`kona-derive` crate source](https://github.com/ethereum-optimism/optimism/tree/develop/rust/kona/crates/protocol/derive) * The [`kona-derive` API documentation](https://docs.rs/kona-derive/latest/kona_derive/) on docs.rs * The [derivation pipeline specification](https://specs.optimism.io/protocol/derivation.html) [kd]: https://crates.io/crates/kona-derive [na]: /node-operators/kona-node/design/intro#actors [rc]: https://docs.rs/kona-genesis/latest/kona_genesis/struct.RollupConfig.html # Execution Engine Source: https://docs.optimism.io/node-operators/kona-node/design/engine The `kona-engine` crate provides a modular execution engine implementation for the OP Stack rollup node. It serves as the bridge between the rollup protocol and the execution layer (EL), managing Engine API interactions through a sophisticated task queue system. ## Architecture Overview The execution engine is built around several key components: * **Engine Task Queue**: A priority-ordered queue that manages Engine API operations * **Trait Abstractions**: Extensible interfaces for tasks, errors, and state management * **Engine Client**: HTTP client for communicating with the execution layer * **Actor Integration**: Service layer integration through the `EngineActor` ## Core Trait Abstractions ### EngineTaskExt The `EngineTaskExt` trait defines the interface for all engine tasks: ```rust theme={null} #[async_trait] pub trait EngineTaskExt { type Output; type Error: EngineTaskError; async fn execute(&self, state: &mut EngineState) -> Result<Self::Output, Self::Error>; } ``` This trait enables: * **Atomic operations** over the `EngineState` * **Extensible task implementation** for custom operations * **Async execution** with proper error handling ### EngineTaskError The `EngineTaskError` trait provides sophisticated error handling with severity levels: ```rust theme={null} pub trait EngineTaskError { fn severity(&self) -> EngineTaskErrorSeverity; } pub enum EngineTaskErrorSeverity { Temporary, // Retry the task Critical, // Propagate to engine actor Reset, // Request derivation reset Flush, // Request derivation flush } ``` This allows tasks to signal different recovery strategies based on the error type. ## Task Queue System The engine uses a priority-based task queue (a binary heap ordered by the `EngineTask` `Ord` implementation) where tasks are ordered according to OP Stack synchronization requirements. Tasks are generic over an `EngineClient` implementation. ### Task Priority (Highest to Lowest) 1. **Seal** - Seals blocks that have finished building (sequencer mode) 2. **Build** - Builds new blocks (sequencer mode) 3. **Insert** - Inserts unsafe blocks from gossip 4. **Consolidate** - Advances safe chain via derivation 5. **Finalize** - Finalizes L2 blocks Forkchoice updates are not a standalone queue entry: the `SynchronizeTask` runs as part of the other tasks whenever the forkchoice state needs to move. ### Task Types #### SynchronizeTask Updates the execution layer's forkchoice state. It is invoked by the other tasks rather than queued directly: ```rust theme={null} pub struct SynchronizeTask<EngineClient_: EngineClient> { /// The engine client. pub client: Arc<EngineClient_>, /// The rollup config. pub rollup: Arc<RollupConfig>, /// The sync state update to apply to the engine state. pub state_update: EngineSyncStateUpdate, } ``` Handles: * Forkchoice synchronization via `engine_forkchoiceUpdated` * EL sync status management #### BuildTask Starts building a new block in sequencer mode, producing a payload ID: ```rust theme={null} pub struct BuildTask<EngineClient_: EngineClient> { /// The engine API client. pub engine: Arc<EngineClient_>, /// The RollupConfig. pub cfg: Arc<RollupConfig>, /// The OpAttributesWithParent to instruct the execution layer to build. pub attributes: OpAttributesWithParent, /// The optional sender through which the PayloadId will be sent /// after the block build has been started. pub payload_id_tx: Option<mpsc::Sender<PayloadId>>, } ``` Handles payload building initiation with `engine_forkchoiceUpdated`. #### SealTask Seals a block started by a `BuildTask`, retrieving the payload with version-specific `engine_getPayload` calls, inserting it, and canonicalizing it: ```rust theme={null} pub struct SealTask<EngineClient_: EngineClient> { /// The engine API client. pub engine: Arc<EngineClient_>, /// The RollupConfig. pub cfg: Ar
프로젝트로 돌아가기