Skip to content

Commit

Permalink
Add support for finalized tag. (#728)
Browse files Browse the repository at this point in the history
* Add support for finalized tag.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* Update docs/developers/reference/api/linea-estimategas.mdx

safe not supported

* Update docs/developers/reference/api/linea-getproof.mdx

safe not supported

---------

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
Co-authored-by: m4sterbunny <harrie.bickle@consensys.net>
  • Loading branch information
bgravenorst and m4sterbunny committed Sep 12, 2024
1 parent ea74756 commit b4d7a6b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
34 changes: 22 additions & 12 deletions docs/developers/guides/finalized-block.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,34 @@ image: /img/socialCards/retrieve-finalized-l2-blocks.jpg
A finalized L2 block is a block on an L2 blockchain (Linea) that has been confirmed and validated
by the L1 blockchain (Ethereum), ensuring its immutability and security.

Linea doesn't currently support the Ethereum-standard `finalized` block parameter tag, meaning you
cannot use the tag in JSON-RPC API calls to retrieve blocks that have been confirmed by the L1
network. This includes, for example, methods where you can specify a block parameter, such as
[`linea_estimateGas`](../reference/api/linea-estimategas.mdx).
There are two methods to obtain the current finalized block:

:::note
Support for the `finalized` block parameter is planned in a future Linea release.
:::
- [Use the `finalized` block parameter tag](#use-the-finalized-tag) in JSON-RPC API calls.
- [Query the Linea L1 rollup contract](#query-the-rollup-contract).

This limitation requires you to query the [Linea L1 rollup contract](https://etherscan.io/address/0xd19d4b5d358258f05d7b411e21a1460d11b0876f#readProxyContract)
to retrieve the value of the current finalized L2 block number stored in the `currentL2BlockNumber`
variable.
## Use the `finalized` tag

## Prerequisites
Use the `finalized` tag in API calls to specify a block that has been confirmed by the L1
network. For example, here the `eth_getBlockByNumber` method returns information about the current
finalized block:

```bash
curl https://rpc.linea.build \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["finalized",false],"id":1}'
```

## Query the rollup contract

Query the [Linea L1 rollup contract](https://etherscan.io/address/0xd19d4b5d358258f05d7b411e21a1460d11b0876f#readProxyContract)
to retrieve the value of the current finalized L2 block number stored in the `currentL2BlockNumber` variable.

### Prerequisites

- [Download and install Node.js](https://nodejs.org/en)

## Create the script
### Create the script

1. In your project folder, initialize the project and install the `web3` package:

Expand Down
9 changes: 6 additions & 3 deletions docs/developers/reference/api/linea-estimategas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ using `linea_estimateGas` for more accurate results.
- `value`: _\[optional]_ Hexadecimal value of the value sent with this transaction.
- `data`: _\[optional]_ Hash of the method signature and encoded parameters. See the
[Ethereum contract ABI specification](https://docs.soliditylang.org/en/latest/abi-spec.html).
- `block number`: _\[optional]_ A string representing a block number, or one of the string tags `latest`, `earliest`, or
`pending`. See the [default block parameter](https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block).
You can [query the L1 rollup contract](../../guides/finalized-block.mdx) to retrieve the current finalized block.
- `block number`: _\[optional]_ A string representing a block number, or one of the string tags `latest`, `earliest`,
`pending`, or `finalized`.

:::note
A `finalized` block is a block on an L2 blockchain (Linea) that has been confirmed and validated by
the L1 blockchain (Ethereum).
:::

## Returns

Expand Down
18 changes: 7 additions & 11 deletions docs/developers/reference/api/linea-getproof.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@ The supplied block parameter must be an L2 block that has been finalized on L1.

In the [example response](#response) the account exists but the slot does not.

:::info important

Linea currently does not support the block parameter `finalized`, meaning that to get the current
finalised block on the L1, users must [retrieve the value from the `currentL2BlockNumber`](../../guides/finalized-block.mdx)
variable in the [LineaRollup L1 contract](https://etherscan.io/address/0xd19d4b5d358258f05d7b411e21a1460d11b0876f#readProxyContract).

:::

## Parameters

- `address`: A string representing the address (20 bytes) for which the proof is requested.
- `storageKeys`: An array of 32-byte storage keys to be proofed and included.
- `blockParameter`: A hexadecimal block number, or one of the string tags `latest`, `earliest`, or
`pending`. See the [default block parameter](https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block).
You can [query the L1 rollup contract](../../guides/finalized-block.mdx) to retrieve the current finalized block.
- `blockParameter`: A hexadecimal block number, or one of the string tags `latest`, `earliest`,
`pending`, or `finalized`.

:::note
A `finalized` block is a block on an L2 blockchain (Linea) that has been confirmed and validated by
the L1 blockchain (Ethereum).
:::

## Returns

Expand Down

0 comments on commit b4d7a6b

Please sign in to comment.