Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add l1 token address endpoint #1031

Merged

Conversation

jrchatruc
Copy link
Contributor

What ❔

This PR adds an RPC method that answers the chain's base token, or 0x0..01 if the base token is eth.

Why ❔

To make clients like block explorers or cli tools able to know which token the chain they point to is operating on, now that it could be one different from eth.

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted via zk fmt and zk lint.
  • Spellcheck has been run via zk spellcheck.
  • Linkcheck has been run via zk linkcheck.

Copy link
Member

@popzxc popzxc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look better now!

let base_token_addr = client
.get_base_token_l1_address()
.await
.context("Failed to fetch base token address")?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably wouldn't work if the new EN is released before the server version is updated (e.g. EN will attempt to call this method, but it doesn't exist yet on the older version of server) -- and this is likely to happen, because EN is almost always released first, since we have to test the new version on testnet for some time.
Probably what we want to do is to handle the error: if the request fails with "method does not exist" error, we fallback to the existing behavior (base token is ETH). We still can fail on other errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @popzxc!.

I've handled the case for the missing rpc method here.
I'm not quite sure if this is the proper way to match with jsonrpsee's Error type, let me know if there's another and proper way to do it.

Also, one thing that to note is that I've hardcoded ETH's base token value here, I'm guessing this should be properly set as a const value somewhere, but I haven't found where this should be done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 0x0000000000000000000000000000000000000001 an expected address?
We have L1 ETH address defined here and L2 ETH here as constants, you should be able to reuse them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now set from the env, but the previous hardcoded value of0x0000000000000000000000000000000000000001 was because the zk init set the env var CONTRACTS_BASE_TOKEN_ADDR=0x0000000000000000000000000000000000000001
when not specifiying a non-eth base token

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fkrause98 Not sure if I understand. We want to fallback to ETH if there is no dedicated config set for that (this may happen when we'll be rolling out this version of server on existing zkSync Era deployments). Why would we use 0x0000000000000000000000000000000000000001 in that case? We want to use ETH address, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, now the ETH token case - with or without shared bridge - returns 0x...00

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I've consulted @vladbochok on this topic and it appears that this is still WIP, but we indeed leaning towards having it as 0x00..01 everywhere, including public interfaces.

This unfortunately renders my proposal incorrect -- sorry for that.
Now I believe that the right thing would be to make the base token optional, e.g. the corresponding config variable would have an Option<Address> instead of Address and if it's None then in the API we'll return Err(Web3Error::NotImplemented), otherwise we return whatever is stored in the config.

On EN we'll have two fallbacks then: first on MethodNotFound and second on NotImplemented, both resulting in setting base token to None. Otherwise it'll be Some whatever returned by API.

This way we'll have no additional hackery to support base token until it's explicitly enabled in existing envs.

Does it make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it does make sense, I'll make those changes and let you know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@popzxc I've implemented and tested the 3 cases you stated above and works as expected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@popzxc can we resolve this?

Copy link
Member

@popzxc popzxc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. I guess to get CI passing, you need to merge recent main.

core/lib/env_config/src/contracts.rs Outdated Show resolved Hide resolved
core/bin/external_node/src/config/mod.rs Outdated Show resolved Hide resolved
core/lib/config/src/configs/contracts.rs Outdated Show resolved Hide resolved
core/lib/config/src/configs/contracts.rs Outdated Show resolved Hide resolved
core/lib/constants/src/contracts.rs Show resolved Hide resolved
core/lib/contracts/src/lib.rs Outdated Show resolved Hide resolved
core/lib/env_config/src/contracts.rs Show resolved Hide resolved
Copy link
Member

@popzxc popzxc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server-side implementation LGTM, one small fix for EN and that should be it.

core/bin/external_node/src/config/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@popzxc popzxc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR LGTM, but the CI seems to be failing.

@lferrigno
Copy link
Contributor

PR LGTM, but the CI seems to be failing.

CI is failing in the destination branch. @kelemeno is working on that separately

@lferrigno lferrigno merged commit a0868d5 into matter-labs:kl-factory Apr 8, 2024
2 checks passed
@fkrause98 fkrause98 deleted the base-token-addr-endpoint branch April 9, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants