-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b1e104
commit 5be9ae3
Showing
6 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "generate-readme" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
serde = { version = "1.0.188", default-features = false, features = ["derive"] } | ||
serde_json = { version = "1.0.106", default-features = false, features = ["alloc"] } | ||
|
||
[[bin]] | ||
name = "generate-readme" | ||
path = "generate_readme.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<p align="center"> | ||
<h1 align="center">starknet-snapshots</h1> | ||
</p> | ||
|
||
**Starknet full node snapshots maintained by the [zkLend](https://zklend.com) team** | ||
|
||
## Downloading the snapshots | ||
|
||
There are several ways to download the snapshots. You're recommended to use S3-compatible clients (e.g. `rclone`). It's also possible to just use a plain `curl` command, but it seems to be prone to failures based on reports from users. | ||
|
||
### Rclone | ||
|
||
Download and install [Rclone](https://rclone.org/). Then, add this section to your config file, typically located at `$HOME/.config/rclone/rclone.conf` (you may need to create the file on a fresh install): | ||
|
||
```conf | ||
[zklend-pathfinder-backup] | ||
type = s3 | ||
provider = Cloudflare | ||
region = auto | ||
endpoint = https://pathfinder-backup.zklend.com/ | ||
``` | ||
|
||
Then, download a snapshot to the current directory with: | ||
|
||
```console | ||
rclone copy -P zklend-pathfinder-backup:EXAMPLE_NETWORK/EXAMPLE_FILE_NAME . | ||
``` | ||
|
||
### `curl` | ||
|
||
Downloading with `curl` is not recommended but possible: | ||
|
||
```console | ||
curl -OL "https://pathfinder-backup.zklend.com/EXAMPLE_NETWORK/EXAMPLE_FILE_NAME" | ||
``` | ||
|
||
## Using the snapshots | ||
|
||
Simply decompress and extract the file downloaded with `tar`: | ||
|
||
```console | ||
tar Jxvf ./EXAMPLE_FILE_NAME | ||
``` | ||
|
||
LIST_OF_SNAPSHOTS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use std::{ | ||
fmt::{Display, Formatter, Write as FmtWrite}, | ||
io::Write, | ||
}; | ||
|
||
use serde::Deserialize; | ||
|
||
const JSON: &str = include_str!("./snapshots.json"); | ||
const TEMPLATE: &str = include_str!("./TEMPLATE.md"); | ||
|
||
#[derive(Deserialize)] | ||
struct Node { | ||
node: NodeType, | ||
networks: Vec<Network>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
#[serde(rename_all = "snake_case")] | ||
enum NodeType { | ||
Pathfinder, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct Network { | ||
network: NetworkType, | ||
snapshots: Vec<Snapshot>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
enum NetworkType { | ||
#[serde(rename = "mainnet")] | ||
Mainnet, | ||
#[serde(rename = "goerli-1")] | ||
Goerli1, | ||
#[serde(rename = "goerli-2")] | ||
Goerli2, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct Snapshot { | ||
block: u64, | ||
version: String, | ||
} | ||
|
||
impl NodeType { | ||
fn downloand_link_base(&self) -> &str { | ||
match self { | ||
Self::Pathfinder => "https://pathfinder-backup.zklend.com/", | ||
} | ||
} | ||
} | ||
|
||
impl Snapshot { | ||
fn file_name(&self, network: &NetworkType) -> String { | ||
format!("{}-v{}-{}.tar.xz", network, self.version, self.block) | ||
} | ||
} | ||
|
||
impl Display for NodeType { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Pathfinder => write!(f, "pathfinder"), | ||
} | ||
} | ||
} | ||
|
||
impl Display for NetworkType { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Mainnet => write!(f, "mainnet"), | ||
Self::Goerli1 => write!(f, "goerli-1"), | ||
Self::Goerli2 => write!(f, "goerli-2"), | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let nodes: Vec<Node> = serde_json::from_str(JSON).expect("unable to deserialize JSON"); | ||
|
||
let mut snapshot_list = String::new(); | ||
|
||
let mut example_network: Option<String> = None; | ||
let mut example_file_name: Option<String> = None; | ||
|
||
for node in nodes.iter() { | ||
writeln!(snapshot_list, "## `{}`", node.node).unwrap(); | ||
|
||
for network in node.networks.iter() { | ||
writeln!(snapshot_list).unwrap(); | ||
writeln!(snapshot_list, "### `{}`", network.network).unwrap(); | ||
writeln!(snapshot_list).unwrap(); | ||
|
||
writeln!( | ||
snapshot_list, | ||
"| Network | Version | Block | Download Link |" | ||
) | ||
.unwrap(); | ||
writeln!(snapshot_list, "| - | - | - | - |").unwrap(); | ||
|
||
for snapshot in network.snapshots.iter() { | ||
let network_name = format!("{}", network.network); | ||
let file_name = snapshot.file_name(&network.network); | ||
|
||
if example_network.is_none() { | ||
example_network = Some(network_name.clone()); | ||
} | ||
if example_file_name.is_none() { | ||
example_file_name = Some(file_name.clone()); | ||
} | ||
|
||
writeln!( | ||
snapshot_list, | ||
"| `{}` | `v{}` | `{}` | {}{}/{} |", | ||
network_name, | ||
snapshot.version, | ||
snapshot.block, | ||
node.node.downloand_link_base(), | ||
network_name, | ||
file_name | ||
) | ||
.unwrap(); | ||
} | ||
} | ||
} | ||
|
||
let example_network = example_network.expect("no example network generated"); | ||
let example_file_name = example_file_name.expect("no example file name generated"); | ||
|
||
let full_readme = TEMPLATE | ||
.replace("EXAMPLE_NETWORK", &example_network) | ||
.replace("EXAMPLE_FILE_NAME", &example_file_name) | ||
.replace("LIST_OF_SNAPSHOTS", &snapshot_list); | ||
|
||
let mut file = std::fs::File::create("./README.md").expect("unable to create file"); | ||
|
||
file.write_all(full_readme.as_bytes()) | ||
.expect("unable to write to file"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[ | ||
{ | ||
"node": "pathfinder", | ||
"networks": [ | ||
{ | ||
"network": "mainnet", | ||
"snapshots": [ | ||
{ | ||
"block": 213169, | ||
"version": "0.8.1" | ||
}, | ||
{ | ||
"block": 141083, | ||
"version": "0.7.0" | ||
} | ||
] | ||
}, | ||
{ | ||
"network": "goerli-1", | ||
"snapshots": [ | ||
{ | ||
"block": 860674, | ||
"version": "0.8.1" | ||
}, | ||
{ | ||
"block": 841817, | ||
"version": "0.7.0" | ||
} | ||
] | ||
}, | ||
{ | ||
"network": "goerli-2", | ||
"snapshots": [ | ||
{ | ||
"block": 141801, | ||
"version": "0.8.1" | ||
}, | ||
{ | ||
"block": 136651, | ||
"version": "0.7.0" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |