Skip to content

Commit

Permalink
Modify Node Syncing docs to show new node snapshots from R2 Cloudflare (
Browse files Browse the repository at this point in the history
#400)

Co-authored-by: Julian Rubino <[email protected]>
  • Loading branch information
julianrubino and Julian Rubino authored Aug 1, 2024
1 parent 4e53722 commit 80e178c
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 11 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"axios": "1.6.5",
"bech32": "2.0.0",
"clsx": "1.2.1",
"date-fns": "^3.6.0",
"cmdk": "1.0.0",
"dotenv": "16.3.1",
"ethers": "5.7.2",
Expand Down Expand Up @@ -88,6 +89,7 @@
"@emotion/babel-plugin": "11.11.0",
"@emotion/babel-plugin-jsx-pragmatic": "0.2.1",
"@next/eslint-plugin-next": "12.3.4",
"@types/date-fns": "^2.6.0",
"@types/eslint": "8.56.2",
"@types/lodash-es": "4.17.12",
"@types/node": "17.0.45",
Expand Down
134 changes: 134 additions & 0 deletions src/components/Docs/components/NodeSnapshots.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import axios from "axios";
import { format } from "date-fns";
import React, { useEffect, useMemo, useState } from "react";

import { LoadingTable, NetworkTypeTabs, networkTypeTabs } from "~/components/shared";

interface NodeSnapshotsProps {
apiUrl: string;
}

interface Snapshot {
environment: string;
type: string;
networkVersion?: string;
height?: number;
creationDate?: string;
link?: string;
}

const NodeSnapshots: React.FC<NodeSnapshotsProps> = ({ apiUrl }) => {
const [mainnetSnapshots, setMainnetSnapshots] = useState<Snapshot[]>([]);
const [testnetSnapshots, setTestnetSnapshots] = useState<Snapshot[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [activeTab, setActiveTab] = useState(networkTypeTabs[0]);

useEffect(() => {
const fetchData = async () => {
const endpoints = [
`${apiUrl}/testnet/fullnode/latest.json`,
`${apiUrl}/testnet/archive/latest.json`,
`${apiUrl}/mainnet/fullnode/latest.json`,
`${apiUrl}/mainnet/archive/latest.json`,
];

const fetchEndpoint = async (endpoint: string) => {
try {
const response = await axios.get(endpoint);
if (response.config.url) {
const urlParts = response.config.url.split("/");
const type = urlParts[urlParts.length - 2];
const environment = urlParts[urlParts.length - 3];
return response.data.snapshots.map((snapshot: any) => ({
...snapshot,
environment,
type,
}));
}
} catch (error) {
if (axios.isAxiosError(error) && error.response?.status === 404) {
const urlParts = endpoint.split("/");
const type = urlParts[urlParts.length - 2];
const environment = urlParts[urlParts.length - 3];
return [
{
environment,
type,
},
];
} else {
console.error("Error fetching data", error);
}
}
return [];
};

const allData = await Promise.all(endpoints.map((endpoint) => fetchEndpoint(endpoint)));
const combinedData = allData.flat();

setMainnetSnapshots(combinedData.filter((snapshot) => snapshot.environment === "mainnet"));
setTestnetSnapshots(combinedData.filter((snapshot) => snapshot.environment === "testnet"));
setIsLoading(false);
};

fetchData();
}, [apiUrl]);

const formatDate = (dateString?: string) => {
if (!dateString) {
return "";
}
const date = new Date(dateString);
if (Number.isNaN(date.getTime())) {
return "Invalid date";
}
return format(date, "PPPpp");
};

const snapshots = useMemo(() => {
return activeTab.networkType === "mainnet" ? mainnetSnapshots : testnetSnapshots;
}, [activeTab.networkType, mainnetSnapshots, testnetSnapshots]);

return (
<div className="mt-8 first:mt-0">
<NetworkTypeTabs activeTab={activeTab} setActiveTab={setActiveTab} layoutIdPrefix="node-snapshot-" />

{isLoading ? (
<LoadingTable rowCount={8} />
) : (
<div className="overflow-x-auto mt-8">
<table>
<thead>
<tr>
<th>Type</th>
<th>Network Version</th>
<th>Height</th>
<th>Creation Date</th>
<th>Download</th>
</tr>
</thead>
<tbody>
{snapshots.map((snapshot, index) => (
<tr key={index}>
<td>{snapshot.type}</td>
<td>{snapshot.networkVersion || ""}</td>
<td>{snapshot.height || ""}</td>
<td>{formatDate(snapshot.creationDate)}</td>
<td>
{snapshot.link ? (
<a href={snapshot.link} target="_blank" rel="noopener noreferrer">
<button>Download</button>
</a>
) : null}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
);
};

export default NodeSnapshots;
1 change: 1 addition & 0 deletions src/components/Docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./components/ForeignCoinsTable";
export * from "./components/GovParams";
export * from "./components/GovUpgradeProposals";
export * from "./components/NetworkDetails";
export { default as NodeSnapshots } from "./components/NodeSnapshots";
export * from "./components/ObserverList";
export * from "./components/ObserverParams";
export * from "./components/OpenAPIBrowser";
Expand Down
22 changes: 11 additions & 11 deletions src/pages/nodes/start-here/syncing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ title: Syncing a Node
---

import { Alert } from "~/components/shared";
import { NodeSnapshots } from "~/components/Docs";

<Alert variant="note">
This guide assumes you've completed the [Setting Up Your Node](/nodes/start-here/setup) step.
</Alert>

# Option 1: Snapshot method

Syncing with a snapshot downloads the data directory from an existing node.
Downloads the data directory backed up from an existing node.

Choose the network and the snapshot type, fetch the URL and follow instructions
returned in response.
Choose the network and snapshot type, download the snapshot and extract the snapshot
inside `~/.zetacored` directory.

| Network | Type | URL |
| ------- | ---------------- | ----------------------------------------------------------------------- |
| Mainnet | Snapshot | https://snapshots.zetachain.com/latest-snapshot?network=mainnet |
| Mainnet | Archive Snapshot | https://snapshots.zetachain.com/latest-archive-snapshot?network=mainnet |
| Testnet | Snapshot | https://snapshots.zetachain.com/latest-snapshot?network=athens3 |
| Testnet | Archive Snapshot | https://snapshots.zetachain.com/latest-archive-snapshot?network=athens3 |
<NodeSnapshots apiUrl="https://snapshots.rpc.zetachain.com" />

Untar the file inside `~/.zetacored` and start the node.
<Alert variant="warning">
Note: Our nodes database backend is `pebbledb`. Ensure that your node is configured to
use the same backend to utilize our snapshots.
</Alert>

#### Alternative snapshots

- https://polkachu.com/tendermint_snapshots/zetachain
- https://app.nodejumper.io/zetachain/sync
- https://app.nodejumper.io/zetachain-testnet/sync

# Option 2: KYVE's KSYNC method

Expand Down Expand Up @@ -71,7 +71,7 @@ https://github.com/BlockPILabs/cosmos-db.
### Sync the Node

```
ksync state-sync --binary="/path/to/zetacored" --chain-id=kaon-1 --snapshot-pool-id=11
ksync state-sync --binary="/path/to/zetacored" --chain-id=zetachain_7000-1 --snapshot-pool-id=11
```

# Checking Node Health
Expand Down

0 comments on commit 80e178c

Please sign in to comment.