Skip to content

Commit

Permalink
feat: support zks_L1ChainId (matter-labs#262)
Browse files Browse the repository at this point in the history
* support zks_L1ChainId

* bump

* update rust version

* lint
  • Loading branch information
nbaztec authored Feb 26, 2024
1 parent d6ad110 commit 207729d
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-08-21
toolchain: nightly-2024-01-01
components: rustfmt, clippy

- uses: actions/setup-node@v3
Expand All @@ -44,7 +44,7 @@ jobs:
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-08-21
toolchain: nightly-2024-01-01

- name: Build Code
run: make all
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-08-21
toolchain: nightly-2024-01-01
- name: Setup Pages
uses: actions/configure-pages@v3

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-08-21
toolchain: nightly-2024-01-01
- name: Install target
run: rustup target add ${{ matrix.arch }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-08-21
toolchain: nightly-2024-01-01

- name: Install cargo-nextest
run: cargo install cargo-nextest
Expand Down
25 changes: 24 additions & 1 deletion SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The `status` options are:
| [`ZKS`](#zks-namespace) | [`zks_getTokenPrice`](#zks_getTokenPrice) | `SUPPORTED` | Gets the USD price of a token <br />_(`ETH` is hard-coded to `1_500`, while some others are `1`)_ |
| [`ZKS`](#zks-namespace) | [`zks_getTransactionDetails`](#zks_gettransactiondetails) | `SUPPORTED` | Returns data from a specific transaction given by the transaction hash |
| `ZKS` | `zks_L1BatchNumber` | `NOT IMPLEMENTED` | Returns the latest L1 batch number |
| `ZKS` | `zks_L1ChainId` | `NOT IMPLEMENTED` | Returns the chain id of the underlying L1 |
| [`ZKS`](#zks-namespace) | [`zks_L1ChainId`](#zks_l1chainid) | `IMPLEMENTED` | Returns the chain id of the underlying L1 |

## `CONFIG NAMESPACE`

Expand Down Expand Up @@ -1979,3 +1979,26 @@ curl --request POST \
"params": ["0x364d6D0333432C3Ac016Ca832fb8594A8cE43Ca6"]
}'
```

### `zks_L1ChainId`

[source](src/node/zks.rs)

Returns the chain id of the underlying L1.

#### Arguments

+ _NONE_

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "zks_L1ChainId","params": []}'
```
2 changes: 1 addition & 1 deletion etc/system-contracts/bootloader/test_infra/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2023-08-21
nightly-2024-01-01
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-08-21"
channel = "nightly-2024-01-01"
components = ["rustfmt", "clippy"]
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("");
tracing::info!("Rich Accounts");
tracing::info!("=============");
for (_, wallet) in LEGACY_RICH_WALLETS.iter().enumerate() {
for wallet in LEGACY_RICH_WALLETS.iter() {
let address = wallet.0;
node.set_rich_account(H160::from_str(address).unwrap());
}
Expand Down
11 changes: 10 additions & 1 deletion src/node/zks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> ZksNamespa
}

fn l1_chain_id(&self) -> RpcResult<zksync_basic_types::U64> {
not_implemented("zks_L1ChainId")
use crate::namespaces::EthNamespaceT;
self.chain_id()
}

fn get_confirmed_tokens(
Expand Down Expand Up @@ -515,6 +516,7 @@ mod tests {

use crate::cache::CacheConfig;
use crate::fork::ForkDetails;
use crate::node::TEST_NODE_NETWORK_ID;
use crate::testing;
use crate::testing::{ForkBlockConfig, MockServer};
use crate::{http_fork_source::HttpForkSource, node::InMemoryNode};
Expand Down Expand Up @@ -1043,6 +1045,13 @@ mod tests {
assert_eq!(&balances[0].name, "Ether");
}

#[tokio::test]
async fn test_get_l1_chain_id() {
let node = InMemoryNode::<HttpForkSource>::default();
let chain_id = node.l1_chain_id().await.expect("get chain id").as_u32();
assert_eq!(TEST_NODE_NETWORK_ID, chain_id);
}

#[tokio::test]
async fn test_get_all_account_balances_forked() {
let cbeth_address = Address::from_str("0x75af292c1c9a37b3ea2e6041168b4e48875b9ed5")
Expand Down
11 changes: 11 additions & 0 deletions test_endpoints.http
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@ content-type: application/json
POST http://localhost:8011
content-type: application/json

{
"jsonrpc": "2.0",
"id": "1",
"method": "zks_L1ChainId",
"params": []
}

###
POST http://localhost:8011
content-type: application/json

{
"jsonrpc": "2.0",
"id": "1",
Expand Down

0 comments on commit 207729d

Please sign in to comment.