Optimism 백서

Optimism

원문

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

s than the current base fee cannot be included in the blockchain. The simplest way to select a base fee is to look at the latest available OP Mainnet block. Each OP Mainnet block includes the current base fee and the amount of gas used within that block. You can use this information to predict a reasonable maximum fee for your transaction. Note that, like Ethereum, the base fee is not explicitly defined within a transaction. Instead, the maximum base fee is determined as the difference between the `maxFeePerGas` and the `maxPriorityFeePerGas` fields of any given transaction. <Steps> <Step title="Retrieve the latest block"> Using the JSON-RPC API or your favorite Ethereum library, retrieve the latest block on OP Mainnet. </Step> <Step title="Retrieve the base fee and gas used"> From the block, retrieve the `baseFeePerGas` and `gasUsed` fields. </Step> <Step title="Predict the next base fee"> OP Mainnet adjusts the base fee based on the amount of gas used in the previous block. If the previous block used more than 5m gas (of the 30m gas limit), then the base fee will increase by up to 10%. If the previous block used less than 5m gas, then the base fee will decrease by up to 10%. Refer to the [OP Mainnet EIP-1559 Parameters](/op-stack/protocol/differences#eip-1559-parameters) section for more details. </Step> <Step title="Select a base fee per gas"> Using the current base fee per gas and the amount of gas used in the previous block, you can predict the next base fee per gas. If you are highly sensitive to the base fee, you may want to select a base fee per gas that is either 10% higher or 10% lower than the previous base fee. However, you may run the risk that your transaction will not be included in a block quickly. If you are less sensitive to the base fee, you may wish to simply use a large multiple of the previous base fee (e.g. 2x). </Step> </Steps> ## Selecting the priority fee The priority fee is an optional tip that can be paid to the Sequencer to incentivize them to include your transaction more quickly. The priority fee is paid in addition to the base fee. The simplest way to select a priority fee is to use the [`eth_maxPriorityFeePerGas`](https://docs.alchemy.com/reference/eth-maxpriorityfeepergas) JSON-RPC method to retrieve an estimate for an acceptable priority fee. Many Ethereum libraries will provide a function to call this JSON-RPC method. You can also use the [`eth_feeHistory`](https://docs.alchemy.com/reference/eth-feehistory) JSON-RPC method to retrieve historical priority fee data. You can then use this data to predict a reasonable priority fee for your transaction. Alternatively, you can rely on Tenderly's [`tenderly_gasPrice`](https://docs.tenderly.co/node/rpc-reference/optimism-mainnet/tenderly_gasPrice?mtm_campaign=ext-docs\&mtm_kwd=optimism) to get real-time gas predictions with 3 levels of likelihood for transaction inclusion. # Transaction statuses on OP Mainnet Source: https://docs.optimism.io/app-developers/guides/transactions/statuses Reference for the statuses a transaction can have on OP Mainnet. This page is a reference for the statuses a transaction can have on OP Mainnet, listed in the order a transaction moves through them. Each entry gives the status, how long it typically takes to reach, what the status guarantees, and the JSON-RPC call used to observe it. Consult it when you need to troubleshoot a transaction, decide how many confirmations your application should wait for, or display accurate status information to your users. For an explanation of *why* a transaction moves through these states, see [Transaction flow](/op-stack/transactions/transaction-flow). ## Pending **Instant after sending to the Sequencer** A transaction is considered "pending" when it has been sent to the Sequencer but has not yet been included in a block. This is the first status a transaction will have after being sent to the Sequencer. At this point the transaction is not part of the blockchain and there is no guarantee that the transaction will be included in the blockchain. The list of all pending transactions can be retrieved by calling the standard JSON-RPC method [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) with the parameter `pending` as the block number. ## Sequencer confirmed or unsafe **Typically within 2-4 seconds** A transaction is considered "sequencer confirmed" or "unsafe" when it has been included in a block by the Sequencer but that block has **not** yet been published to Ethereum. Although the transaction is included in a block, it is still possible for the transaction to be excluded from the final blockchain if the Sequencer fails to publish the block to Ethereum within the [Sequencing Window](/connect/resources/glossary#sequencing-window) (approximately 12 hours). Applications should make sure to consider this possibility when displaying information about transactions that are in this state. The latest "sequencer confirmed" block can be retrieved by calling the standard JSON-RPC method [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) with the parameter `safe` as the block number and comparing this to the result returned for the `latest` block. If the `safe` block is behind the `latest` block, then the earliest "sequencer confirmed" block is the `safe` block plus one. ## Published to Ethereum or safe **Typically within 5-10 minutes, up to 12 hours** A transaction is considered "safe" when it has been included in a block by the Sequencer and that block has been published to Ethereum but that block is not yet finalized. Once a block has been published to Ethereum there is a high likelihood that the block will be included in the final blockchain. However, it is still possible for the block to be excluded from the final blockchain if the Ethereum blockchain experiences a reorganization. The latest "safe" block can be retrieved by calling the standard JSON-RPC method [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) with the parameter `safe` as the block number. Transactions typically become "safe" within a few minutes of becoming "sequencer confirmed". ## Finalized **Typically within 15-30 minutes, up to 12 hours** A transaction is considered "finalized" when it has been included in a block by the Sequencer, that block has been published to Ethereum, and that block has been finalized. Once a block has been finalized it is guaranteed to be included in the OP Mainnet blockchain. Applications that require the highest level of certainty that a transaction will be included in the blockchain should wait until the transaction is "finalized" before considering the transaction to be successful. The latest "finalized" block can be retrieved by calling the standard JSON-RPC method [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) with the parameter `finalized` as the block number. # Subblocks and gas usage on OP Stack Source: https://docs.optimism.io/app-developers/guides/transactions/subblocks-and-gas-usage Explains how Subblocks affect block gas usage, transaction inclusion, and why large transactions can be rejected or stay pending. This document explains how **subblocks** affect block gas usage, transaction inclusion, large-transaction handling, and how to avoid unexpected transaction rejections. If you are unfamiliar with subblocks you can read more in the [Subblocks explainer](/op-stack/features/subblocks). *** ## Background: Block Gas Limit vs. Transaction Gas Limit On OP Mainnet, the **theoretical block gas limit** is currently **40M gas**. In a traditional EVM mental model, a single transaction can use up to the full block gas limit, as long as it does not exceed it. With **subblocks**, block construction is incremental and *effective transaction inclusion depends on the gas already consumed within the block*, not just the theoretical maximum. *** ## What Are Subblocks? Subblocks are an incremental block-building mechanism: instead of constructing the full block at once, the sequencer's execution client assembles it as a series of subblocks, each of which adds to the *cumulative gas budget* available for inclusion. For what subblocks are and how a block's subblock count is determined, see the [Subblocks explainer](/op-stack/features/subblocks). The consequence for gas usage is that earlier subblocks can only include smaller transactions, and larger transactions fit only later in the block, *if enough gas remains*. ### Example Assume: * Block gas limit **B = 40M** * Number of subblocks **N = 10**, the count a 2-second block time and a 200 ms interval imply Then the cumulative gas limit increases as follows: | Subblock | Max cumulative gas available | | - | - | | 1 | 4M | | 2 | 8M | | 3 | 12M | | 4 | 16M | | 5 | 20M | | 6 | 24M | | 7 | 28M | | 8 | 32M | | 9 | 36M | | 10 | 40M | A transaction with a **20M gas limit** can only be included starting from subblock 5, *and only if prior subblocks have not already consumed that gas*. The subblock count is not fixed. Heavy execution in one interval leaves less time for the ones after it, so a real block may contain fewer subblocks than the interval implies. *** ## Why a Transaction Can Get Stuck A transaction may be submitted with a gas limit lower than the total block gas limit (e.g. **38M \< 40M**) and still remain pending or, depending on the EL implementation, be rejected with the error: `exceeds block gas limit`. This happens because transaction acceptance and transaction inclusion are decided by different components. Generally: * Incoming transactions first enter the Execution Layer txpool. * The EL checks whether `tx.gasLimit` exceeds the **full block gas limit**. * If it does, it rejects with `exceeds block gas limit`. * Otherwise, it keeps the transaction in the **pending/queued mempool** and **P2P-gossips** it, eventually reaching the **sequencer**. * The **sequencer's execution client** applies the incremental **remaining block gas** check to decide whether to include the tx in a subblock or leave it pending. ### Real-World Example * Block gas limit: **40M** * Gas already used in earlier subblocks: **13M** * Remaining gas: **27M** * Incoming transaction gas limit: **38M** The **EL** checks if the transaction exceeds **40M**. Since **38M \< 40M**, the transaction is accepted into the pending/queued mempool and gossiped to the **sequencer**. The sequencer's execution client applies the incremental remaining-gas constraint. With only **27M** gas remaining and the tx requiring **38M**, the transaction cannot be included yet and stays pending. **Result:** the transaction is not rejected, but remains pending in the mempool until there is enough remaining gas to include it in a subblock. *** ## Client Behavior and Error Messages There are two distinct outcomes depending on the transaction size: * **Rejected immediately (txpool admission failure):**\ The EL (e.g. **op-reth**) rejects transactions only when the transaction gas limit exceeds the **full block gas limit**: * Condition: `tx.gasLimit > blockGasLimit` * Error returned to the user: `exceeds block gas limit` * **Accepted but pending inclusion:**\ If the transaction gas limit is **within** the block gas limit, but still too large to fit into the **remaining block gas** at that point in the block, it will not be included yet. * The transaction remains in the **pending/queued mempool**, waiting for enough remaining gas to become available in a later subblock. * From the user’s perspective, the transaction may appear **pending** until it gets enough gas available for inclusion. In practice, transactions are sent to Execution Layer RPC nodes (e.g. via proxyd), checked, and only if accepted into the EL txpool are eventually propagated to the sequencer for potential inclusion. Implementing mechanisms such as txpool rebroadcasting can mitigate this divergence automatically, so users do not notice retries. However, when an error is surfaced, it may originate from the ingress client’s gas checks. *** ## Practical Guidance for Application Developers and End Users ### Leave Headroom for Large Transactions If you submit large transactions, avoid targeting the full block gas limit. **Recommended approach:** * Leave **20–30% headroom** relative to the block gas limit * For a 40M block, aim for ≤ **28–32M gas** Or: * Proactively cap single-transaction gas usage to \~16.7M gas to align with the upcoming L2 Fusaka transaction limit This increases the chance that the transaction fits within Execution Layer gas checks under partial block utilization. More generally, designing applications to avoid extremely large single transactions is good long-term practice since, with upcoming protocol changes (Fusaka on L2), transactions will be capped at 16.7M gas anyway. *** ### Expect Variable Gas Availability During Congestion Under high demand: * Early subblocks are often full * Remaining gas later in the block may be limited * Very large transactions may be rejected or require retries This is expected behavior with subblocks and not necessarily an issue with the transaction itself. *** ### Transaction Resubmission Because block state evolves quickly: * Retrying submission in a later block may succeed * Large transactions are more likely to be included when earlier subblocks are less congested *** ## Key Takeaways * Subblocks build blocks incrementally, unlocking gas capacity over time rather than all at once\ *(e.g. in a 40M gas block with 10 subblocks, only 4M is available at the first subblock, then 8M, and so on)* * A transaction must be **within the full block gas limit** to be accepted into the EL txpool, but it must fit within the **remaining block gas** to be included by the sequencer in the next subblock *(e.g. if 13M gas out of 40M has already been used, a 38M gas transaction can be accepted by EL but cannot be included until enough remaining gas is available once it reaches the sequencer)* * As a result, large transactions may be **accepted but remain pending** even when their gas limit is below the nominal block limit\ *(e.g. a 38M gas transaction can be accepted in a 40M gas block but delayed during periods of high activity)* * Leaving meaningful headroom is the most reliable way to improve inclusion success for large transactions\ *(e.g. targeting 28–32M gas instead of the full 40M or proactively implementing the Fusaka limit of 16.7M gas)* # Troubleshooting transactions Source: https://docs.optimism.io/app-developers/guides/transactions/troubleshooting Learn how to troubleshoot common problems with transactions. ## Transactions stuck in the transaction pool OP Chain uses EIP-1559, but with different parameters than L1 Ethereum. As a result, while the base fee on L1 can grow by up to 12.5% in a twelve-second period (in the case of a single 30M gas block), the L2 base fee can grow by up to 77% (in the case of six 30M gas blocks). However, it still shrinks by only up to 12.5% in the same twelve-second period (if all the blocks are empty). If the maximum fee per gas specified by the transaction is less than the block base fee, it does not get included until the base fee drops to below the value in the transaction. When this happens, some users may see their transaction become stuck. No ETH is lost, but the transaction does not clear on its own. We have a workaround that users and wallet operators can implement immediately, and we expect a protocol-level fix to be live by the end of Q4. ### Recommendation Set the maximum fee per gas for transactions to a relatively high value, such as 0.1 gwei. This will *not* increase the transaction cost because the same base fee, determined by a formula, is charged to all the transactions in the block. To save on the cost of L2 gas you want to minimize the max priority fee. Also, if the [current base fee](https://optimistic.grafana.net/public-dashboards/c84a5a9924fe4e14b270a42a8651ceb8?orgId=1\&refresh=5m) is comparable to 0.1 gwei or higher, you might want to suggest to users a higher multiple of the base fee than you would on L1 Ethereum because it can grow faster in the time interval between transaction creation and transaction signing and submission. #### Recommendations for wallet developers Wallets are usually in charge of determining the default priority fee and max fee that a transaction would include, so the above recommendations can be applied directly. #### Recommendations for app developers As an app developer, you can usually override the default recommendation of the wallet (see, for example, [ethers](https://github.com/ethers-io/ethers.js/blob/v5.7/packages/contracts/lib/index.d.ts#L10-L11)). As long as not all wallets are upgraded according to our recommendations, it makes sense for apps to get the current base fee and recommend a value based on that. #### Recommendations for users As a user, you are the final authority on transaction fields. Sometimes when submitting a transaction, the gas fee is set too low, and it gets stuck in the transaction pool (a.k.a. mempool). If you want to push that transaction through, [you can cancel it by submitting another transaction with the same nonce](https://info.etherscan.com/how-to-cancel-ethereum-pending-transactions/). This method increases the fee and the sequencer will process it from the mempool quicker. ## Deposit transactions don't have a chainId on L2 [Deposit transactions](https://specs.optimism.io/protocol/deposits.html?utm_source=op-docs\&utm_medium=docs#the-deposited-transaction-type) are transactions added to the L2 blockchain as part of the block derivation process. These transactions come from a dummy address and don't have a signature. Because in Ethereum the chainID is encoded as part of the signature, this means there is no recoverable chainID for these transactions. This is not a problem because the only source of deposit transactions is the block derivation process. There shouldn't be a need to recover the chainID. # App developers Source: https://docs.optimism.io/app-developers/index Routes app developers to the quickstarts, guides, tutorials, tools, and reference for building on OP Mainnet and other OP Stack chains. You are building an app on OP Mainnet or another OP Stack chain. Pick the path that matches where you are: start from zero, solve a specific task, or look something up. <CardGroup> <Card title="Deploy your first app" href="/app-developers/quickstarts/get-started"> Go from zero to a working app on an OP Stack chain with the quickstart. </Card> <Card title="Solve a specific task" href="/app-developers/guides/building-apps"> Follow a guide for building and testing apps, bridging, interoperability, or transactions. </Card> <Card title="Learn by doing" href="/app-developers/tutorials/deploy-a-contract"> Work through step-by-step tutorials, from deploying a contract to cross-chain messaging with Supersim. </Card> <Card title="Pick your tools" href="/app-developers/tools-sdks/support-matrix"> Choose supported SDKs, faucets, block explorers, and data tools for your stack. </Card> <Card title="Look up the details" href="/app-developers/reference/rpc-providers"> Find RPC providers, Actions SDK definitions, token lists, and Supersim reference material. </Card> <Card title="Running a chain or a node instead?" href="/"> Route by role from the documentation home: chain operators, node operators, and protocol learners each have their own section. </Card> </CardGroup> # Integrating DeFi with Actions SDK Source: https://docs.optimism.io/app-developers/quickstarts/actions Perform DeFi actions with lightweight, composable, and type-safe modules. <Warning> Actions SDK is still under construction and not ready for producti
프로젝트로 돌아가기