Skip to content

Commit bfffa7c

Browse files
Add EVM Gateway node ops section and main page (#1035)
* Add EVm Gateway node ops section and mainpage * Add optional docker run args * Typo * Added missing guidance on how to get private key for COA_KEY * Move binary to executable location for systemctl config * Drop duplicate mention of private key extraction * Fix title size * Tweak navbar position and title * Fix naming of the wrong network * Add troubleshooting items * Add missing bare metal startup guidance * Fix title case * Fix broken tab * Made comment consistent * Minor tidyup * Tidy up troublshooting * Minor fixes * remove redundant line * Make tab titles less confusing * Add tab to use Docker image from container registry * Add comment to run docker images that was pulled for registry * Link to container registry * Update docs/networks/node-ops/access-onchain-data/evm-gateway/evm-gateway-setup.md Co-authored-by: Vishal <1117327+vishalchangrani@users.noreply.github.com> * Update wording in opening description * Add guidance to obtain flow cli * Restore missing shell clause closure * Minor nits * Add notice about using old versions of data dir * Fix mainnet height * Add rate limits * Add new config param * Fix naming of config for KMS key --------- Co-authored-by: Vishal <1117327+vishalchangrani@users.noreply.github.com>
1 parent 4e6e208 commit bfffa7c

File tree

4 files changed

+354
-6
lines changed

4 files changed

+354
-6
lines changed

docs/evm/using.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ To use the Flow Wallet Chrome extension:
9696
| [eth_getBlockByNumber] ||
9797
| [eth_getBlockTransactionCountByHash] ||
9898
| [eth_getBlockTransactionCountByNumber] ||
99-
| eth_getBlockReceipts ||
99+
| [eth_getBlockReceipts] ||
100100
| [eth_getCode] ||
101101
| [eth_getFilterChanges] ||
102102
| [eth_getFilterLogs] ||
@@ -121,11 +121,11 @@ To use the Flow Wallet Chrome extension:
121121
| [eth_signTransaction] | 🚧 | Unsupported |
122122
| [eth_syncing] ||
123123
| [eth_uninstallFilter] ||
124-
| eth_maxPriorityFeePerGas ||
125-
| eth_feeHistory ||
126-
| debug_traceTransaction ||
127-
| debug_traceBlockByNumber ||
128-
| debug_traceBlockByHash ||
124+
| [eth_maxPriorityFeePerGas] ||
125+
| [eth_feeHistory] ||
126+
| [debug_traceTransaction] ||
127+
| [debug_traceBlockByNumber] ||
128+
| [debug_traceBlockByHash] ||
129129

130130
**Legend**: ❌ = not supported. 🚧 = work in progress. ✅ = supported.
131131

docs/networks/flow-networks/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ sidebar_position: 1
55

66
## About Flow Networks
77

8+
:::note
9+
10+
This page provides information on Flow network RPCs. EVM on Flow network RPCs can be found [here](../evm/networks)
11+
12+
:::
13+
814
In addition to Mainnet, developers have access to the Testnet environment, which serves as an essential testing ground for applications and smart contracts prior to their deployment on Mainnet. This ensures that any potential issues can be identified and resolved in a controlled setting, mitigating risks associated with live deployment.
915

1016
Furthermore, during network upgrades, Testnet receives updates ahead of Mainnet. This preemptive update process allows developers to comprehensively test their apps against the latest versions of the nodes, enhancements to the Cadence programming language, and core contract upgrades. This strategy guarantees that when these updates are eventually applied to Mainnet, applications and smart contracts will operate seamlessly, enhancing overall network stability and user experience.
@@ -30,6 +36,10 @@ There are two primary ways to access on-chain data within the Flow network; Acce
3036
- [Testnet](./accessing-testnet.md): `access.devnet.nodes.onflow.org:9000`
3137
- [Status Page](https://status.onflow.org/) - Network status page
3238

39+
### Rate limits
40+
41+
Rate limits for Flow Public Access nodes hosted by QuickNode are detailed [here](https://www.quicknode.com/docs/flow#endpoint-rate-limits).
42+
3343
### Running Your Own Node
3444

3545
If you’re getting started you don’t need to run your own node and you can use the above public nodes. The public access nodes are rate-limited, so as your product matures you might want to run your own node. There are multiple options available:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
label: EVM Gateway
Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
---
2+
title: Setting up an EVM Gateway node
3+
sidebar_label: EVM Gateway Setup
4+
sidebar_position: 3
5+
---
6+
7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
10+
This guide is for running the [EVM Gateway](https://github.com/onflow/flow-evm-gateway) node on Flow. The EVM Gateway implements the
11+
[Ethereum JSON-RPC specification](https://ethereum.org/en/developers/docs/apis/json-rpc/) and is the only node type which accepts EVM
12+
client connections.
13+
14+
The EVM Gateway consumes Flow protocol state from the configured Flow Access Node and persists the indexed EVM state locally to service EVM client requests. It submits EVM transactions it receives into the Flow network, wrapped in a Cadence transaction, and mutating EVM state when executed. Non-mutating RPC methods only query the local state index of the gateway and are never forwarded to Access Nodes. It does not participate in the block production process and requires no stake.
15+
16+
## Who Should Run an EVM Gateway
17+
18+
The EVM Gateway can serve as both a dedicated private RPC endpoint and a performance scaling solution, offering similar capabilities
19+
to centralized middleware providers like Infura, Alchemy, etc at a fraction of the cost. This is because EVM Gateway nodes connect
20+
directly to the Flow network with no middle layer in between.
21+
22+
Applications which generate high call volumes to the JSON-RPC and which may have hit rate limits can benefit from running their
23+
own gateway. Self-hosted gateways are dedicated to the operator, enabling the removal of rate limits. Self-hosted gateways
24+
connect directly to your chosen Access Node, which you can also run if desired.
25+
26+
## Hardware specifications
27+
28+
TBD
29+
30+
# How To Run EVM Gateway
31+
32+
## Step 1 - Account Creation
33+
34+
The EVM Gateway's role in mediating EVM transactions over to Cadence is how it accrues fees from handling client transactions. Since
35+
the gateway submits Cadence transactions wrapping EVM transaction payloads to the Flow Access Node the transaction fee for that must
36+
be paid by the EVM Gateway.
37+
38+
The account used for funding gateway Cadence transactions must be a COA, not an EOA. `--coa-address` is configured with the Cadence address
39+
of the COA account and the `--coa-key` must belong to the same account. The `--coinbase` account accrues EVM Gateway fees from EVM client
40+
transactions and can be either an EVM EOA or COA address.
41+
42+
It is acceptable to create a single Cadence account for the COA and use the EVM address associated with that for the COINBASE address.
43+
44+
### Create Flow account to use for COA
45+
46+
If you don't already have a Flow account you will need to create one.
47+
48+
<Tabs>
49+
<TabItem value="mainnet" label="Mainnet">
50+
51+
1. Install [Flow Wallet](https://wallet.flow.com/)
52+
2. Once installed you will be able to copy the wallet address, similar to _0x1844efeb3fef2242_
53+
3. Obtain account private key from
54+
<pre>Settings -> Account List -> Choose Main account -> Private Key -> [Password prompt]</pre>
55+
4. Ensure the wallet is funded from a CEX or other wallet
56+
57+
</TabItem>
58+
<TabItem value="testnet" label="Testnet">
59+
60+
Install [Flow CLI](https://developers.flow.com/tools/flow-cli/install) if not already installed.
61+
62+
```bash
63+
flow keys generate
64+
```
65+
This will output something similar to:
66+
`
67+
```bash
68+
🔴️ Store private key safely and don't share with anyone!
69+
Private Key 3cf8334d.....95c3c54a28e4ad1
70+
Public Key 33a13ade6....85f1b49a197747
71+
Mnemonic often scare peanut ... boil corn change
72+
Derivation Path m/44'/539'/0'/0/0
73+
Signature Algorithm ECDSA_P256
74+
```
75+
76+
Visit https://faucet.flow.com/, and use the generated `Public Key`, to create and fund your Flow testnet account.
77+
78+
</TabItem>
79+
</Tabs>
80+
81+
## Step 2 - Build the gateway
82+
83+
To run EVM Gateway on bare metal or in a VM without the use of docker, select the '_Build from source_' tab otherwise refer to the
84+
'_Build using Docker_' tab.
85+
86+
<Tabs>
87+
<TabItem value="source-build" label="Build from source">
88+
89+
This will build the EVM gateway binary from source.
90+
91+
```bash
92+
git clone https://github.com/onflow/flow-evm-gateway.git
93+
94+
cd flow-evm-gateway
95+
git checkout $(curl -s https://api.github.com/repos/onflow/flow-evm-gateway/releases/latest | jq -r .tag_name)
96+
CGO_ENABLED=1 go build -o evm-gateway cmd/main/main.go
97+
chmod a+x evm-gateway
98+
mv evm-gateway /usr/bin
99+
```
100+
101+
</TabItem>
102+
<TabItem value="docker-build" label="Build using Docker">
103+
104+
```bash
105+
git clone https://github.com/onflow/flow-evm-gateway.git
106+
107+
cd flow-evm-gateway
108+
git checkout $(curl -s https://api.github.com/repos/onflow/flow-evm-gateway/releases/latest | jq -r .tag_name)
109+
make docker-build
110+
```
111+
112+
</TabItem>
113+
<TabItem value="docker-install" label="Use Docker registry image">
114+
115+
Registry versions available for download can be found [here](https://console.cloud.google.com/artifacts/docker/dl-flow-devex-production/us-west1/development/flow-evm-gateway).
116+
```bash
117+
docker pull us-west1-docker.pkg.dev/dl-flow-devex-production/development/flow-evm-gateway:${VERSION}
118+
```
119+
120+
</TabItem>
121+
</Tabs>
122+
123+
## Step 3 - Start Your Node
124+
125+
Operators will need to refer to the gateway [configuration flags](https://github.com/onflow/flow-evm-gateway?tab=readme-ov-file#configuration-flags) and make adjustments that align with the desired
126+
deployment topology.
127+
128+
### EVM Coinbase address
129+
130+
If this is your first time setting up the gateway we need to ensure that an EVM COA or EOA address is available to configure the `COINBASE`. This account
131+
can be an account created using Metamask or other web3.js wallet, or otherwise can be the EVM address corresponding to the Flow Wallet COA account created above.
132+
133+
If you haven't already got an EVM address and you have the COA account created by Flow Wallet above then follow the steps below:
134+
135+
* Click top left burger icon to show current profile
136+
* Click 'Enable the path to EVM on Flow' button
137+
* Your EVM account will now be available to use in the left nav account view
138+
* When you switch to that account you can obtain its EVM address
139+
140+
### COA Address and Key
141+
142+
COA address and private key is configured for `--coa-address` & `--coa-key` configuration flags. If running multiple EVM Gateway hosts it is standard to
143+
share the same COA address and key across _n_ hosts.
144+
145+
### Run the gateway
146+
147+
Ensure that the following ENV variables have been set. Add/update as required if your configuration differs from those listed.
148+
149+
```bash
150+
# Set required environment variables
151+
export ACCESS_NODE_GRPC_HOST="access.mainnet.nodes.onflow.org:9000" # or access.devnet.nodes.onflow.org:9000 for testnet
152+
export FLOW_NETWORK_ID="flow-mainnet" # or flow-testnet
153+
export INIT_CADENCE_HEIGHT="85981135" # 211176670 for testnet
154+
export COINBASE="${EVM_ADDRESS_WITHOUT_0x}"
155+
export COA_ADDRESS="${CADENCE_ACCOUNT_ADDRESS_WITHOUT_0x}"
156+
export COA_KEY="${CADENCE_ACCOUNT_PRIVATE_KEY_WITHOUT_0x}"
157+
export GAS_PRICE="100"
158+
```
159+
160+
<Tabs>
161+
<TabItem value="source-build" label="Run from binary">
162+
163+
**Create EVM Gateway service**
164+
165+
```bash
166+
sudo tee <<EOF >/dev/null /etc/systemd/system/gateway.service
167+
[Unit]
168+
Description=Gateway daemon
169+
After=network-online.target
170+
171+
[Service]
172+
User=$USER
173+
ExecStart=/usr/bin/evm-gateway \
174+
--access-node-grpc-host=$ACCESS_NODE_GRPC_HOST \
175+
--flow-network-id=$FLOW_NETWORK_ID \
176+
--init-cadence-height=$INIT_CADENCE_HEIGHT \
177+
--ws-enabled=true \
178+
--coinbase=$COINBASE \
179+
--coa-address=$COA_ADDRESS \
180+
--coa-key=$COA_KEY \
181+
--rate-limit=9999999 \
182+
--rpc-host=0.0.0.0 \
183+
--gas-price=$GAS_PRICE \
184+
--tx-state-validation=local-index
185+
Restart=always
186+
RestartSec=3
187+
LimitNOFILE=4096
188+
189+
[Install]
190+
WantedBy=multi-user.target
191+
EOF
192+
193+
cat /etc/systemd/system/gateway.service
194+
sudo systemctl enable gateway
195+
```
196+
197+
**Start all services**
198+
199+
```bash
200+
sudo systemctl daemon-reload
201+
sudo systemctl restart access-node
202+
sudo systemctl restart gateway
203+
```
204+
205+
**Check logs**
206+
207+
```bash
208+
# change log settings to persistent if not already
209+
sed -i 's/#Storage=auto/Storage=persistent/g' /etc/systemd/journald.conf
210+
sudo systemctl restart systemd-journald
211+
212+
journalctl -u gateway.service -f -n 100
213+
```
214+
215+
</TabItem>
216+
<TabItem value="docker-build" label="Run with Docker">
217+
218+
It may be necessary to make local changes to the `docker-run` target to add params which are needed for your requirements. If you pulled a
219+
specific image from the gateway container registry ensure that the `$VERSION` environment variable is set to the same as the image version
220+
you pulled.
221+
222+
```bash
223+
cd flow-evm-gateway
224+
make docker-run
225+
```
226+
Additional options are available as follows
227+
228+
```bash
229+
DOCKER_RUN_DETACHED=true
230+
DOCKER_HOST_MOUNT=[host mount directory]
231+
DOCKER_HOST_PORT=[desired port to expose on host]
232+
233+
# Example usage
234+
235+
make DOCKER_RUN_DETACHED=true DOCKER_HOST_PORT=1234 DOCKER_HOST_MOUNT=/my/host/dir docker-run
236+
```
237+
238+
</TabItem>
239+
</Tabs>
240+
241+
### Startup bootstrap indexing
242+
243+
Once your EVM Gateway is up and running you will see it indexing the Flow network which was configured. At the present time this
244+
is a lengthy process (possibly 1-3 days, depending on CPU core count) during which time the gateway will not respond to queries.
245+
Once the data is fully indexed the gateway can serve requests to clients.
246+
247+
To speed up gateway setup we recommend backing up the `/${GATEWAY_HOME_DIR}/data` directory to use when creating additional nodes
248+
using the same release version. We are currently working on an export/import feature that will enable gateway operators to
249+
store state snapshots to bootstrap newly created nodes without the delay.
250+
251+
:::note
252+
253+
If you are upgrading the gateway from pre-v1.0.0 release versions the indexed data directory will need to be reindexed from genesis.
254+
You will not be able to re-use the DB data dir from the previous versions.
255+
256+
:::
257+
258+
### Account and Key Management
259+
260+
EVM Gateway allows for Google and AWS Key Management Service (KMS) setup, which is the recommended way of setting up the gateway
261+
for live networks. We recommend creating multiple KMS keys for the same Flow account (ideally 10 or more), how many depends on
262+
the desired transaction throughput, since the keys are used in rotation when submitting the transactions. If too few keys
263+
are configured it may result in sequence number collisions if the same key is used concurrently by multiple EVM client requests.
264+
265+
### KMS Configuration
266+
```
267+
--coa-cloud-kms-project-id=your-project-kms-id \
268+
--coa-cloud-kms-location-id=global \
269+
--coa-cloud-kms-key-ring-id=your-project-kms-key-ring-id \
270+
--coa-cloud-kms-key=example-gcp-kms1@1,example-gcp-kms2@1 \
271+
```
272+
273+
### Monitoring and Metrics
274+
275+
The EVM Gateway reports Prometheus metrics which are a way to monitor the gateway's availability and progress. The database folder
276+
size may also need to be monitored to prevent disk full issues.
277+
278+
**Metric labels**
279+
```bash
280+
evm_gateway_api_errors_total # Total count of API errors for period
281+
evm_gateway_api_request_duration_seconds_bucket # Histogram metric buckets for API request durations
282+
evm_gateway_api_request_duration_seconds_count # Histogram metric API request count for period
283+
evm_gateway_api_request_duration_seconds_sum # Histogram metric API request sum of values for period
284+
evm_gateway_api_server_panics_total # Total count of server panics for period
285+
evm_gateway_blocks_indexed_total # Total count of EVM blocks indexed
286+
evm_gateway_cadence_block_height # Cadence block height
287+
evm_gateway_evm_account_interactions_total # Count of unique accounts observed for period
288+
evm_gateway_evm_block_height # EVM block height
289+
evm_gateway_operator_balance # Gateway node COA operator account balance
290+
evm_gateway_trace_download_errors_total # Total count of trace download errors
291+
evm_gateway_txs_indexed_total # Total count of indexed transactions
292+
```
293+
294+
Alerts are recommended to be configured on server panics, low operator balance, and disk usage metrics.
295+
296+
**Metrics port**
297+
298+
```
299+
--metrics-port 8080 \
300+
```
301+
### Node Status
302+
303+
For basic node status or keepalive monitoring we recommend automated checks on the following monotonically increasing counter:
304+
```
305+
curl -s -XPOST 'your-evm-gw-host:8545' --header 'Content-Type: application/json' --data-raw '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' | jq -r '.result' | xargs printf "%d\n"
306+
10020239
307+
```
308+
309+
## Troubleshooting
310+
311+
Join our [Discord](https://discord.com/invite/J6fFnh2xx6) and use the `#flow-evm` channel to ask any questions you may have about
312+
EVM Gateway.
313+
314+
### State stream configuration
315+
316+
If you are running an Access Node on the same logical host as the EVM Gateway you may see ehe following log entries.
317+
318+
```bash
319+
failure in event subscription at height ${INIT-CADENCE-HEIGHT}, with: recoverable: disconnected: error receiving event: rpc error: code = Unimplemented desc = unknown service flow.executiondata.ExecutionDataAPI”
320+
```
321+
```bash
322+
component execution data indexer initialization failed: could not verify checkpoint file: could not find expected root hash e6d4f4c755666c21d7456441b4d33d3521e5e030b3eae391295577e9130fd715 in checkpoint file which contains: [e10d3c53608a1f195b7969fbc06763285281f64595be491630a1e1bdfbe69161]
323+
```
324+
325+
To resolve this configure `--state-stream-addr` to use the same address/port combination which is set for Access Node `--rpc-addr`.
326+
This is required by the gateway to allow both the streaming and non-streaming APIs to query using the same connection.
327+
328+
### Access Node not fully synced
329+
330+
The following log entry will occur when the EVM Gateway attempts to sync with the Access Node but it has not yet synced up to latest block
331+
```bash
332+
failure in event subscription at height ${INIT-CADENCE-HEIGHT}, with: recoverable: disconnected: error receiving event: rpc error: code = FailedPrecondition desc = could not get start height: failed to get lowest indexed height: index not initialized
333+
```
334+
335+
## FAQs
336+
337+
TBD

0 commit comments

Comments
 (0)