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

chore!: enable multiple L1 nodes to be used #11945

Merged
merged 43 commits into from
Feb 26, 2025
Merged

chore!: enable multiple L1 nodes to be used #11945

merged 43 commits into from
Feb 26, 2025

Conversation

spypsy
Copy link
Member

@spypsy spypsy commented Feb 12, 2025

  • Updates ETHEREUM_HOST env var to ETHEREUM_HOSTS. Using a single host should still work as it did before
  • Single ViemWalletClient & ViemPublicClient

BREAKING CHANGE:

  • env var ETHEREUM_HOST -> ETHEREUM_HOSTS
  • CLI arg --l1-rpc-url -> --l1-rpc-urls
  • TypeScript configs with l1RpcUrl -> l1RpcUrls
  • aztec.js functions with l1RpcUrl -> l1RpcUrls
  • DeployL1Contracts (type) -> DeployL1ContractsReturnType

Fixes #11790

Follow-up #12254

@spypsy spypsy marked this pull request as ready for review February 12, 2025 14:26
Copy link
Contributor

Changes to public function bytecode sizes

Generated at commit: ad901e035ea4109b8e123a34da5b59ed9cae999d, compared to commit: 921d2cd9de54a9fd7cc49e4951c9fa65ab1526ef

🧾 Summary (100% most significant diffs)

Program Bytecode size in bytes (+/-) %
TokenBlacklist::public_dispatch +42 ❌ +0.18%

Full diff report 👇
Program Bytecode size in bytes (+/-) %
TokenBlacklist::public_dispatch 23,831 (+42) +0.18%

@spypsy spypsy requested a review from charlielye as a code owner February 20, 2025 14:05
@spypsy spypsy changed the title fix: enable multiple L1 nodes to be used chore!: enable multiple L1 nodes to be used Feb 20, 2025
Copy link
Contributor

@spalladino spalladino left a comment

Choose a reason for hiding this comment

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

Hell of a PR. Found a few instances that need attention, but aside from that, looks good.

@@ -64,7 +64,7 @@ services:
- p2p-boot-node
entrypoint: |
/bin/sh -c '
export ETHEREUM_HOST=$$(cat /var/run/secrets/ethereum-host)
export ETHEREUM_HOSTS=$$(cat /var/run/secrets/ethereum-host)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to pluralize the secret as well? (I'm fine if we don't, just checking we didn't chan ge the secret but forgot to change here)

Copy link
Member Author

Choose a reason for hiding this comment

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

only for consistency's sake, will do

Comment on lines 213 to 217
until curl -s -X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":67}' \
${ETHEREUM_HOST} | grep 0x; do
echo "Waiting for Ethereum node ${ETHEREUM_HOST}..."
${ETHEREUM_HOSTS} | grep 0x; do
echo "Waiting for Ethereum node ${ETHEREUM_HOSTS}..."
sleep 5
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will break if there's more than one value in ETHEREUM_HOSTS, we need to loop over all values and wait until all (or one?) is available.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think one? point of this is redundancy so we should consider just one as 'ready'

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense!

const publicClient = createPublicClient({
chain: chain.chainInfo,
transport: http(chain.rpcUrl),
transport: fallback(config.l1RpcUrls.map(url => http(url))),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

Comment on lines 44 to 53
this.walletClient = createWalletClient({
account: this.account,
chain: chain.chainInfo,
transport: ViemHttp(chain.rpcUrl),
transport: fallback([ViemHttp(chain.rpcUrls[0])]),
});

this.publicClient = createPublicClient({
chain: chain.chainInfo,
transport: ViemHttp(chain.rpcUrl),
transport: fallback([ViemHttp(chain.rpcUrls[0])]),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why rpcUrls[0] instead of mapping over all urls, as done in the archiver?

Copy link
Member Author

Choose a reason for hiding this comment

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

good question, I don't think I meant to do that. will update

Comment on lines +55 to +56
private publicClient: ViemPublicClient,
private walletClient: ViemWalletClient,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR, but we should stop using the two clients simultaneously, and just use the wallet.extend(publicActions) to have one client with the capabilities of both.

export L1_CHAIN_ID=$(curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' \
$ETHEREUM_HOST | grep -o '"result":"0x[^"]*"' | cut -d'"' -f4 | xargs printf "%d\n")
$ETHEREUM_HOSTS | grep -o '"result":"0x[^"]*"' | cut -d'"' -f4 | xargs printf "%d\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

# Automatically detect if we're using Anvil
if curl -s -H "Content-Type: application/json" -X POST --data '{"method":"web3_clientVersion","params":[],"id":49,"jsonrpc":"2.0"}' $ETHEREUM_HOST | jq .result | grep -q anvil; then
if curl -s -H "Content-Type: application/json" -X POST --data '{"method":"web3_clientVersion","params":[],"id":49,"jsonrpc":"2.0"}' $ETHEREUM_HOSTS | jq .result | grep -q anvil; then
Copy link
Contributor

Choose a reason for hiding this comment

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

And here

Copy link
Member Author

Choose a reason for hiding this comment

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

seems we don't actually use IS_ANVIL anymore, will remove

@@ -162,7 +162,7 @@ describe('End-to-end tests for devnet', () => {
claimSecret: { value: string };
messageLeafIndex: string;
}>('bridge-fee-juice', [amount, l2Account.getAddress()], {
'l1-rpc-url': ETHEREUM_HOST!,
'l1-rpc-url': ETHEREUM_HOSTS!,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'l1-rpc-url': ETHEREUM_HOSTS!,
'l1-rpc-urls': ETHEREUM_HOSTS!,

I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch indeed!

@@ -279,7 +279,7 @@ describe('End-to-end tests for devnet', () => {

async function getL1Balance(address: string, token?: EthAddress): Promise<bigint> {
const { balance } = await cli<{ balance: string }>('get-l1-balance', [address], {
'l1-rpc-url': ETHEREUM_HOST!,
'l1-rpc-url': ETHEREUM_HOSTS!,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Comment on lines 29 to 35
export type ViemClient = Client<
HttpTransport,
Chain,
PrivateKeyAccount,
[...PublicRpcSchema, ...WalletRpcSchema],
PublicActions<HttpTransport, Chain> & WalletActions<Chain, PrivateKeyAccount>
>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why we had to re-define and re-export this type from here

Copy link
Member Author

Choose a reason for hiding this comment

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

ah this was initially the only place I ran into it so only had it here. then realized it's used in more places and added in types, will update 👍

@spalladino
Copy link
Contributor

There are also a few mentions to ETHEREUM_HOST in the docs folder that will need update

@spalladino
Copy link
Contributor

And it'd be nice if we could tweak the cheat codes to also handle multiple rpc urls, it's the only component left that still forces one rpc url.

@spypsy spypsy requested a review from spalladino February 25, 2025 16:27
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":67}' \
${HOST} | grep -q 0x; then
echo "Ethereum node ${HOST} is ready!"
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the scope of this exit 0? IIUC this template gets pasted as-is where it is included, so any operations after this helper would not run due to the early exit. This would affect eg deploy-l1-contracts:

- name: deploy-l1-contracts
          {{- include "aztec-network.image" . | nindent 10 }}
          command:
            - /bin/bash
            - -c
            - |
              cp /scripts/deploy-l1-contracts.sh /tmp/deploy-l1-contracts.sh
              chmod +x /tmp/deploy-l1-contracts.sh
              source /shared/config/service-addresses
              source /shared/config/validator-addresses
              {{- include "aztec-network.waitForEthereum" . | nindent 14 }}
           /tmp/deploy-l1-contracts.sh "{{ .Values.aztec.l1Salt }}" "{{ .Values.ethereum.chainId }}" "$VALIDATOR_ADDRESSES"

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, reviewed this in an outdated commit and it was already fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still, I think the new version doesn't do what we expect. I understand it loops over every host, waiting for 5s inbetween them, and exits once the first one replies. But it doesn't go back to the first one to retry if all failed, it just goes through, right?

Comment on lines 30 to 40
found_node=0
for HOST in $(echo "${ETHEREUM_HOSTS}" | tr ',' '\n'); do
if curl -s -X POST -H 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
"$HOST" 2>/dev/null | grep -q 'result'; then
echo "Node $HOST is ready"
found_node=1
break
fi
sleep 1
done
Copy link
Contributor

Choose a reason for hiding this comment

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

Heads up this is not equivalent to the previous one: the new one will exit if the node is not immediately available, while the previous one will retry. Given this is called simultaneously to ETHEREUM_SCRIPT in scripts/run_native_testnet.sh, we should keep the behaviour of waiting for the node to be up.

@spypsy spypsy requested a review from spalladino February 26, 2025 12:14
"$HOST" 2>/dev/null | grep -q 'result'; then
echo "Node $HOST is ready"
found_node=1
break 2
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL!

@spypsy spypsy enabled auto-merge (squash) February 26, 2025 17:49
@spypsy spypsy merged commit fcf6278 into master Feb 26, 2025
9 checks passed
@spypsy spypsy deleted the spy/multi-rpc-urls branch February 26, 2025 19:23
TomAFrench added a commit that referenced this pull request Feb 26, 2025
* master: (31 commits)
  feat: Slack message to ci channel tagging owners on flakes. (#12284)
  fix: slack notify was broken by quoted commit titles
  revert: "chore: Fix and reenable fees-settings test (#12302)"
  fix: run arm64 on master (#12307)
  yolo fix
  chore: Fix and reenable fees-settings test (#12302)
  feat!: rename compute_nullifier_without_context (#12308)
  chore: Lazy loading artifacts everywhere (#12285)
  chore: Reenable dapp subscription test (#12304)
  chore: Run prover test with fake proofs when requested (#12305)
  chore: Do not set CI_FULL outside CI (#12300)
  chore: new mnemonic deployments on sepolia (#12076)
  chore!: enable multiple L1 nodes to be used (#11945)
  chore: remove no longer supported extension from vscode/extension.json (#12303)
  fix(e2e): p2p_reqresp (#12297)
  feat: Sync from noir (#12298)
  chore: enabling `e2e_contract_updates` in CI + nuking irrelevant test (#12293)
  feat: prepend based merge (#12093)
  feat: fetch addresses from registry (#12000)
  feat: live logs (#12271)
  ...
just-mitch pushed a commit that referenced this pull request Mar 3, 2025
Follow-up fixes from merging #11945 & #12076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

L1 Node redundancy
2 participants