chaindiff 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chaindiff-0.1.0/LICENSE +21 -0
- chaindiff-0.1.0/PKG-INFO +146 -0
- chaindiff-0.1.0/README.md +121 -0
- chaindiff-0.1.0/pyproject.toml +45 -0
- chaindiff-0.1.0/setup.cfg +4 -0
- chaindiff-0.1.0/src/chaindiff/__init__.py +3 -0
- chaindiff-0.1.0/src/chaindiff/__main__.py +4 -0
- chaindiff-0.1.0/src/chaindiff/catalog.py +179 -0
- chaindiff-0.1.0/src/chaindiff/cli.py +156 -0
- chaindiff-0.1.0/src/chaindiff/data/clients.json +68 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/besu.json +1227 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/erigon.json +1045 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/geth.json +1647 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/lighthouse.json +898 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/nethermind.json +2319 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/nimbus.json +793 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/prysm.json +1248 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/reth.json +709 -0
- chaindiff-0.1.0/src/chaindiff/data/releases/teku.json +926 -0
- chaindiff-0.1.0/src/chaindiff/evaluate.py +229 -0
- chaindiff-0.1.0/src/chaindiff/models.py +69 -0
- chaindiff-0.1.0/src/chaindiff/refresh.py +155 -0
- chaindiff-0.1.0/src/chaindiff/report.py +166 -0
- chaindiff-0.1.0/src/chaindiff/versions.py +131 -0
- chaindiff-0.1.0/src/chaindiff.egg-info/PKG-INFO +146 -0
- chaindiff-0.1.0/src/chaindiff.egg-info/SOURCES.txt +33 -0
- chaindiff-0.1.0/src/chaindiff.egg-info/dependency_links.txt +1 -0
- chaindiff-0.1.0/src/chaindiff.egg-info/entry_points.txt +2 -0
- chaindiff-0.1.0/src/chaindiff.egg-info/requires.txt +3 -0
- chaindiff-0.1.0/src/chaindiff.egg-info/top_level.txt +1 -0
- chaindiff-0.1.0/tests/test_catalog.py +120 -0
- chaindiff-0.1.0/tests/test_cli.py +94 -0
- chaindiff-0.1.0/tests/test_evaluate.py +214 -0
- chaindiff-0.1.0/tests/test_refresh.py +57 -0
- chaindiff-0.1.0/tests/test_versions.py +29 -0
chaindiff-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ChainDiff contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
chaindiff-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chaindiff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Decide whether an Ethereum node client upgrade is safe.
|
|
5
|
+
Author: ehsanhajian
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/ehsanhajian/chaindiff
|
|
8
|
+
Project-URL: Repository, https://github.com/ehsanhajian/chaindiff
|
|
9
|
+
Project-URL: Issues, https://github.com/ehsanhajian/chaindiff/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/ehsanhajian/chaindiff/releases
|
|
11
|
+
Keywords: ethereum,blockchain,geth,node,upgrade,cli
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: System :: Systems Administration
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# ChainDiff
|
|
27
|
+
|
|
28
|
+
Decide whether an Ethereum node client upgrade is safe.
|
|
29
|
+
|
|
30
|
+
ChainDiff compares the client you run with the release you want. It answers **safe** only when every release in between has a sourced review and none of those reviews is breaking. Otherwise the answer is **review required** or **not safe**.
|
|
31
|
+
|
|
32
|
+
It does not restart a node, edit config, or apply an upgrade.
|
|
33
|
+
|
|
34
|
+
## Scope
|
|
35
|
+
|
|
36
|
+
Supported clients:
|
|
37
|
+
|
|
38
|
+
| Client | Role | Release source |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| Geth | execution | ethereum/go-ethereum |
|
|
41
|
+
| Nethermind | execution | NethermindEth/nethermind |
|
|
42
|
+
| Erigon | execution | erigontech/erigon |
|
|
43
|
+
| Besu | execution | besu-eth/besu |
|
|
44
|
+
| Reth | execution | paradigmxyz/reth |
|
|
45
|
+
| Lighthouse | consensus | sigp/lighthouse |
|
|
46
|
+
| Prysm | consensus | OffchainLabs/prysm |
|
|
47
|
+
| Teku | consensus | Consensys-Incorporated/teku |
|
|
48
|
+
| Nimbus | consensus | status-im/nimbus-eth2 |
|
|
49
|
+
|
|
50
|
+
Reth and Nimbus are in the catalog because operators run them. Besu and Teku are read from their current GitHub repositories.
|
|
51
|
+
|
|
52
|
+
The shipping catalog is Ethereum mainnet. The tool also covers these networks, one task each. A check has to use the clients that network actually runs, and that chain's upgrade, not only the latest tag of an upstream Ethereum client.
|
|
53
|
+
|
|
54
|
+
- Ethereum mainnet
|
|
55
|
+
- Gnosis
|
|
56
|
+
- BNB Smart Chain
|
|
57
|
+
- Avalanche
|
|
58
|
+
- OP Mainnet
|
|
59
|
+
- Base
|
|
60
|
+
- Arbitrum One
|
|
61
|
+
- Polygon PoS
|
|
62
|
+
- Linea
|
|
63
|
+
- Scroll
|
|
64
|
+
- zkSync Era
|
|
65
|
+
- Starknet
|
|
66
|
+
|
|
67
|
+
Not in this cut: Lodestar, Grandine, applying the upgrade, node metrics, peer or disk checks, and RPC benchmarks. Configuration scanning and execution/consensus pairing are tracked as later work. They need sourced rules, not guesses.
|
|
68
|
+
|
|
69
|
+
Calendar-versioned clients (Besu, Teku, Nimbus) do not treat a new year in the version as a breaking change by itself. Semver clients do: an unreviewed major bump is **not safe**.
|
|
70
|
+
|
|
71
|
+
## Install
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install chaindiff
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
That package is published from a GitHub release. Until the first release is on PyPI:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install git+https://github.com/ehsanhajian/chaindiff.git
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Commands
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
chaindiff versions
|
|
87
|
+
chaindiff check --client geth --from <installed>
|
|
88
|
+
chaindiff check --client lighthouse --from <installed> --to v8.2.3
|
|
89
|
+
chaindiff plan --client nethermind --from <installed>
|
|
90
|
+
chaindiff refresh
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`check` and `plan` use the local catalog. `refresh` is the only command that talks to GitHub. Set `GH_TOKEN` or `GITHUB_TOKEN` if you hit the unauthenticated rate limit.
|
|
94
|
+
|
|
95
|
+
### Verdicts
|
|
96
|
+
|
|
97
|
+
- **ALREADY CURRENT** (exit 0) — you are on the target release.
|
|
98
|
+
- **SAFE** (exit 0) — every release in the range has a sourced review, and none is breaking.
|
|
99
|
+
- **REVIEW REQUIRED** (exit 1) — ChainDiff will not call it safe. Releases are missing a review, something is deprecated, or the catalog is too old to trust "latest".
|
|
100
|
+
- **NOT SAFE** (exit 2) — a reviewed breaking change, or an unreviewed semver major bump.
|
|
101
|
+
- **PRERELEASE** (exit 2) — the target is a prerelease. Don't run it on a mainnet node.
|
|
102
|
+
- **DOWNGRADE** (exit 2) — the target is older than what you run.
|
|
103
|
+
|
|
104
|
+
A stale catalog (older than 5 days) cannot produce **safe** or **already current** for `latest`. Comparing two explicit versions still works; the report warns that the catalog is old.
|
|
105
|
+
|
|
106
|
+
The checklist always includes the operator steps that are worth doing on any upgrade: read the notes, back up, keep the old binary, upgrade one client at a time, and roll back if the node fails. Client-specific steps appear only when an advisory says what to change.
|
|
107
|
+
|
|
108
|
+
## Release catalog
|
|
109
|
+
|
|
110
|
+
GitHub Actions refreshes the catalog twice a week, Monday and Thursday at 06:15 UTC, and commits it when the run succeeds. Run `chaindiff refresh` yourself any time.
|
|
111
|
+
|
|
112
|
+
Erigon tags from the old date scheme, such as `v2022.10.01`, are left out. They are not comparable with the 2.x and 3.x line, and treating them as newer versions would hide the current release.
|
|
113
|
+
|
|
114
|
+
The stored catalog is tags, dates, titles, and URLs. It does not copy release-note bodies. A release title that mentions a security fix is reported as a warning. That warning does not by itself make the upgrade safe or unsafe.
|
|
115
|
+
|
|
116
|
+
## Advisories
|
|
117
|
+
|
|
118
|
+
Safe and not-safe both require a review. Put reviews in `src/chaindiff/data/advisories/<client>.json`:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"schema_version": 1,
|
|
123
|
+
"advisories": [
|
|
124
|
+
{
|
|
125
|
+
"version": "2.0.0",
|
|
126
|
+
"severity": "breaking",
|
|
127
|
+
"summary": "What breaks.",
|
|
128
|
+
"action": "What the operator changes.",
|
|
129
|
+
"source": "https://github.com/org/repo/releases/tag/2.0.0"
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`severity` is `breaking`, `deprecated`, `note`, or `none`. `none` means the release was reviewed and there is nothing to do. `breaking` and `deprecated` need an `action`. Every advisory needs an `http` or `https` source. Do not mark a release reviewed without reading it.
|
|
136
|
+
|
|
137
|
+
## Development
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
python3 -m venv .venv
|
|
141
|
+
source .venv/bin/activate
|
|
142
|
+
pip install -e ".[dev]"
|
|
143
|
+
pytest
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Tests that need a private catalog can set `CHAINDIFF_DATA` to a directory with the same `clients.json`, `releases/`, and `advisories/` layout.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# ChainDiff
|
|
2
|
+
|
|
3
|
+
Decide whether an Ethereum node client upgrade is safe.
|
|
4
|
+
|
|
5
|
+
ChainDiff compares the client you run with the release you want. It answers **safe** only when every release in between has a sourced review and none of those reviews is breaking. Otherwise the answer is **review required** or **not safe**.
|
|
6
|
+
|
|
7
|
+
It does not restart a node, edit config, or apply an upgrade.
|
|
8
|
+
|
|
9
|
+
## Scope
|
|
10
|
+
|
|
11
|
+
Supported clients:
|
|
12
|
+
|
|
13
|
+
| Client | Role | Release source |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| Geth | execution | ethereum/go-ethereum |
|
|
16
|
+
| Nethermind | execution | NethermindEth/nethermind |
|
|
17
|
+
| Erigon | execution | erigontech/erigon |
|
|
18
|
+
| Besu | execution | besu-eth/besu |
|
|
19
|
+
| Reth | execution | paradigmxyz/reth |
|
|
20
|
+
| Lighthouse | consensus | sigp/lighthouse |
|
|
21
|
+
| Prysm | consensus | OffchainLabs/prysm |
|
|
22
|
+
| Teku | consensus | Consensys-Incorporated/teku |
|
|
23
|
+
| Nimbus | consensus | status-im/nimbus-eth2 |
|
|
24
|
+
|
|
25
|
+
Reth and Nimbus are in the catalog because operators run them. Besu and Teku are read from their current GitHub repositories.
|
|
26
|
+
|
|
27
|
+
The shipping catalog is Ethereum mainnet. The tool also covers these networks, one task each. A check has to use the clients that network actually runs, and that chain's upgrade, not only the latest tag of an upstream Ethereum client.
|
|
28
|
+
|
|
29
|
+
- Ethereum mainnet
|
|
30
|
+
- Gnosis
|
|
31
|
+
- BNB Smart Chain
|
|
32
|
+
- Avalanche
|
|
33
|
+
- OP Mainnet
|
|
34
|
+
- Base
|
|
35
|
+
- Arbitrum One
|
|
36
|
+
- Polygon PoS
|
|
37
|
+
- Linea
|
|
38
|
+
- Scroll
|
|
39
|
+
- zkSync Era
|
|
40
|
+
- Starknet
|
|
41
|
+
|
|
42
|
+
Not in this cut: Lodestar, Grandine, applying the upgrade, node metrics, peer or disk checks, and RPC benchmarks. Configuration scanning and execution/consensus pairing are tracked as later work. They need sourced rules, not guesses.
|
|
43
|
+
|
|
44
|
+
Calendar-versioned clients (Besu, Teku, Nimbus) do not treat a new year in the version as a breaking change by itself. Semver clients do: an unreviewed major bump is **not safe**.
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install chaindiff
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
That package is published from a GitHub release. Until the first release is on PyPI:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install git+https://github.com/ehsanhajian/chaindiff.git
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Commands
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
chaindiff versions
|
|
62
|
+
chaindiff check --client geth --from <installed>
|
|
63
|
+
chaindiff check --client lighthouse --from <installed> --to v8.2.3
|
|
64
|
+
chaindiff plan --client nethermind --from <installed>
|
|
65
|
+
chaindiff refresh
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`check` and `plan` use the local catalog. `refresh` is the only command that talks to GitHub. Set `GH_TOKEN` or `GITHUB_TOKEN` if you hit the unauthenticated rate limit.
|
|
69
|
+
|
|
70
|
+
### Verdicts
|
|
71
|
+
|
|
72
|
+
- **ALREADY CURRENT** (exit 0) — you are on the target release.
|
|
73
|
+
- **SAFE** (exit 0) — every release in the range has a sourced review, and none is breaking.
|
|
74
|
+
- **REVIEW REQUIRED** (exit 1) — ChainDiff will not call it safe. Releases are missing a review, something is deprecated, or the catalog is too old to trust "latest".
|
|
75
|
+
- **NOT SAFE** (exit 2) — a reviewed breaking change, or an unreviewed semver major bump.
|
|
76
|
+
- **PRERELEASE** (exit 2) — the target is a prerelease. Don't run it on a mainnet node.
|
|
77
|
+
- **DOWNGRADE** (exit 2) — the target is older than what you run.
|
|
78
|
+
|
|
79
|
+
A stale catalog (older than 5 days) cannot produce **safe** or **already current** for `latest`. Comparing two explicit versions still works; the report warns that the catalog is old.
|
|
80
|
+
|
|
81
|
+
The checklist always includes the operator steps that are worth doing on any upgrade: read the notes, back up, keep the old binary, upgrade one client at a time, and roll back if the node fails. Client-specific steps appear only when an advisory says what to change.
|
|
82
|
+
|
|
83
|
+
## Release catalog
|
|
84
|
+
|
|
85
|
+
GitHub Actions refreshes the catalog twice a week, Monday and Thursday at 06:15 UTC, and commits it when the run succeeds. Run `chaindiff refresh` yourself any time.
|
|
86
|
+
|
|
87
|
+
Erigon tags from the old date scheme, such as `v2022.10.01`, are left out. They are not comparable with the 2.x and 3.x line, and treating them as newer versions would hide the current release.
|
|
88
|
+
|
|
89
|
+
The stored catalog is tags, dates, titles, and URLs. It does not copy release-note bodies. A release title that mentions a security fix is reported as a warning. That warning does not by itself make the upgrade safe or unsafe.
|
|
90
|
+
|
|
91
|
+
## Advisories
|
|
92
|
+
|
|
93
|
+
Safe and not-safe both require a review. Put reviews in `src/chaindiff/data/advisories/<client>.json`:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"schema_version": 1,
|
|
98
|
+
"advisories": [
|
|
99
|
+
{
|
|
100
|
+
"version": "2.0.0",
|
|
101
|
+
"severity": "breaking",
|
|
102
|
+
"summary": "What breaks.",
|
|
103
|
+
"action": "What the operator changes.",
|
|
104
|
+
"source": "https://github.com/org/repo/releases/tag/2.0.0"
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`severity` is `breaking`, `deprecated`, `note`, or `none`. `none` means the release was reviewed and there is nothing to do. `breaking` and `deprecated` need an `action`. Every advisory needs an `http` or `https` source. Do not mark a release reviewed without reading it.
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
python3 -m venv .venv
|
|
116
|
+
source .venv/bin/activate
|
|
117
|
+
pip install -e ".[dev]"
|
|
118
|
+
pytest
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Tests that need a private catalog can set `CHAINDIFF_DATA` to a directory with the same `clients.json`, `releases/`, and `advisories/` layout.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "chaindiff"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Decide whether an Ethereum node client upgrade is safe."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
keywords = ["ethereum", "blockchain", "geth", "node", "upgrade", "cli"]
|
|
10
|
+
authors = [{ name = "ehsanhajian" }]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Environment :: Console",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
"Topic :: System :: Systems Administration",
|
|
19
|
+
]
|
|
20
|
+
dependencies = []
|
|
21
|
+
|
|
22
|
+
[project.optional-dependencies]
|
|
23
|
+
dev = ["pytest>=8"]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/ehsanhajian/chaindiff"
|
|
27
|
+
Repository = "https://github.com/ehsanhajian/chaindiff"
|
|
28
|
+
Issues = "https://github.com/ehsanhajian/chaindiff/issues"
|
|
29
|
+
Changelog = "https://github.com/ehsanhajian/chaindiff/releases"
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
chaindiff = "chaindiff.cli:main"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["setuptools>=77"]
|
|
36
|
+
build-backend = "setuptools.build_meta"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.package-data]
|
|
42
|
+
chaindiff = ["data/*.json", "data/releases/*.json", "data/advisories/*.json"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""Load and store the client registry, release catalog, and advisories."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from chaindiff.models import SEVERITIES, Advisory, Client, Release
|
|
11
|
+
from chaindiff.versions import parse_version
|
|
12
|
+
|
|
13
|
+
SCHEMA_VERSION = 1
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def data_dir() -> Path:
|
|
17
|
+
override = os.environ.get("CHAINDIFF_DATA")
|
|
18
|
+
if override:
|
|
19
|
+
return Path(override)
|
|
20
|
+
return Path(__file__).resolve().parent / "data"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def format_time(moment: datetime) -> str:
|
|
24
|
+
return moment.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def parse_time(value: str) -> datetime:
|
|
28
|
+
return datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _read_json(path: Path) -> dict:
|
|
32
|
+
try:
|
|
33
|
+
payload = json.loads(path.read_text())
|
|
34
|
+
except json.JSONDecodeError as exc:
|
|
35
|
+
raise ValueError(f"{path} is not valid JSON") from exc
|
|
36
|
+
if not isinstance(payload, dict):
|
|
37
|
+
raise ValueError(f"{path} must contain a JSON object")
|
|
38
|
+
if payload.get("schema_version") != SCHEMA_VERSION:
|
|
39
|
+
raise ValueError(f"{path} has an unsupported schema_version")
|
|
40
|
+
return payload
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def load_clients() -> list[Client]:
|
|
44
|
+
path = data_dir() / "clients.json"
|
|
45
|
+
payload = _read_json(path)
|
|
46
|
+
clients: list[Client] = []
|
|
47
|
+
seen: set[str] = set()
|
|
48
|
+
for raw in payload.get("clients", []):
|
|
49
|
+
client_id = str(raw.get("id", "")).strip()
|
|
50
|
+
role = raw.get("role")
|
|
51
|
+
versioning = raw.get("versioning")
|
|
52
|
+
github = str(raw.get("github", "")).strip()
|
|
53
|
+
name = str(raw.get("name", "")).strip()
|
|
54
|
+
if not client_id or not name or not github:
|
|
55
|
+
raise ValueError(f"{path} has a client missing id, name, or github")
|
|
56
|
+
if role not in ("execution", "consensus"):
|
|
57
|
+
raise ValueError(f"{client_id} has an unknown role")
|
|
58
|
+
if versioning not in ("semver", "calver"):
|
|
59
|
+
raise ValueError(f"{client_id} has an unknown versioning scheme")
|
|
60
|
+
if client_id in seen:
|
|
61
|
+
raise ValueError(f"{client_id} is listed twice")
|
|
62
|
+
seen.add(client_id)
|
|
63
|
+
clients.append(
|
|
64
|
+
Client(
|
|
65
|
+
id=client_id,
|
|
66
|
+
name=name,
|
|
67
|
+
role=role,
|
|
68
|
+
github=github,
|
|
69
|
+
versioning=versioning,
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
if not clients:
|
|
73
|
+
raise ValueError(f"{path} does not list any clients")
|
|
74
|
+
return clients
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def client_by_id(clients: list[Client], client_id: str) -> Client | None:
|
|
78
|
+
key = client_id.strip().lower()
|
|
79
|
+
for client in clients:
|
|
80
|
+
if client.id == key:
|
|
81
|
+
return client
|
|
82
|
+
return None
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def releases_path(client_id: str) -> Path:
|
|
86
|
+
return data_dir() / "releases" / f"{client_id}.json"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def load_releases(client_id: str) -> tuple[datetime, list[Release]] | None:
|
|
90
|
+
path = releases_path(client_id)
|
|
91
|
+
if not path.exists():
|
|
92
|
+
return None
|
|
93
|
+
payload = _read_json(path)
|
|
94
|
+
fetched_at = parse_time(str(payload["fetched_at"]))
|
|
95
|
+
releases: list[Release] = []
|
|
96
|
+
for raw in payload.get("releases", []):
|
|
97
|
+
tag = str(raw.get("tag", ""))
|
|
98
|
+
version = parse_version(tag)
|
|
99
|
+
if version is None:
|
|
100
|
+
continue
|
|
101
|
+
releases.append(
|
|
102
|
+
Release(
|
|
103
|
+
tag=tag,
|
|
104
|
+
name=str(raw.get("name") or tag),
|
|
105
|
+
published_at=str(raw.get("published_at") or ""),
|
|
106
|
+
prerelease=bool(raw.get("prerelease")),
|
|
107
|
+
url=str(raw.get("url") or ""),
|
|
108
|
+
version=version,
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
return fetched_at, releases
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def save_releases(
|
|
115
|
+
client: Client,
|
|
116
|
+
releases: list[Release],
|
|
117
|
+
ignored_tag_count: int,
|
|
118
|
+
fetched_at: datetime,
|
|
119
|
+
) -> None:
|
|
120
|
+
path = releases_path(client.id)
|
|
121
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
122
|
+
ordered = sorted(releases, key=lambda item: (item.version, item.published_at, item.tag), reverse=True)
|
|
123
|
+
payload = {
|
|
124
|
+
"schema_version": SCHEMA_VERSION,
|
|
125
|
+
"client": client.id,
|
|
126
|
+
"github": client.github,
|
|
127
|
+
"fetched_at": format_time(fetched_at),
|
|
128
|
+
"ignored_tag_count": ignored_tag_count,
|
|
129
|
+
"releases": [
|
|
130
|
+
{
|
|
131
|
+
"tag": item.tag,
|
|
132
|
+
"name": item.name,
|
|
133
|
+
"published_at": item.published_at,
|
|
134
|
+
"prerelease": item.prerelease,
|
|
135
|
+
"url": item.url,
|
|
136
|
+
}
|
|
137
|
+
for item in ordered
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
text = json.dumps(payload, indent=2) + "\n"
|
|
141
|
+
temporary = path.with_suffix(".json.tmp")
|
|
142
|
+
temporary.write_text(text)
|
|
143
|
+
temporary.replace(path)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def load_advisories(client_id: str) -> list[Advisory]:
|
|
147
|
+
path = data_dir() / "advisories" / f"{client_id}.json"
|
|
148
|
+
if not path.exists():
|
|
149
|
+
return []
|
|
150
|
+
payload = _read_json(path)
|
|
151
|
+
advisories: list[Advisory] = []
|
|
152
|
+
for index, raw in enumerate(payload.get("advisories", []), start=1):
|
|
153
|
+
version_text = str(raw.get("version", "")).strip()
|
|
154
|
+
version = parse_version(version_text)
|
|
155
|
+
severity = str(raw.get("severity", "")).strip()
|
|
156
|
+
summary = str(raw.get("summary", "")).strip()
|
|
157
|
+
action = str(raw.get("action", "")).strip()
|
|
158
|
+
source = str(raw.get("source", "")).strip()
|
|
159
|
+
where = f"{path} advisory {index} ({version_text or 'missing version'})"
|
|
160
|
+
if version is None:
|
|
161
|
+
raise ValueError(f"{where} has a version ChainDiff cannot parse")
|
|
162
|
+
if severity not in SEVERITIES:
|
|
163
|
+
raise ValueError(f"{where} has an unknown severity")
|
|
164
|
+
if not summary:
|
|
165
|
+
raise ValueError(f"{where} needs a summary")
|
|
166
|
+
if severity in ("breaking", "deprecated") and not action:
|
|
167
|
+
raise ValueError(f"{where} needs an action")
|
|
168
|
+
if not source.startswith(("https://", "http://")):
|
|
169
|
+
raise ValueError(f"{where} needs an http(s) source URL")
|
|
170
|
+
advisories.append(
|
|
171
|
+
Advisory(
|
|
172
|
+
version=version,
|
|
173
|
+
severity=severity,
|
|
174
|
+
summary=summary,
|
|
175
|
+
action=action,
|
|
176
|
+
source=source,
|
|
177
|
+
)
|
|
178
|
+
)
|
|
179
|
+
return advisories
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""Command line for ChainDiff."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from datetime import datetime, timezone
|
|
9
|
+
|
|
10
|
+
from chaindiff import __version__
|
|
11
|
+
from chaindiff.catalog import client_by_id, load_advisories, load_clients, load_releases
|
|
12
|
+
from chaindiff.evaluate import evaluate, latest_stable
|
|
13
|
+
from chaindiff.models import CURRENT, DOWNGRADE, PRERELEASE, REVIEW, SAFE, UNSAFE
|
|
14
|
+
from chaindiff.refresh import refresh_catalog
|
|
15
|
+
from chaindiff.report import check_json, format_check, format_versions, versions_json
|
|
16
|
+
from chaindiff.versions import explain_unparsed, parse_version
|
|
17
|
+
|
|
18
|
+
_EXIT = {
|
|
19
|
+
CURRENT: 0,
|
|
20
|
+
SAFE: 0,
|
|
21
|
+
REVIEW: 1,
|
|
22
|
+
UNSAFE: 2,
|
|
23
|
+
DOWNGRADE: 2,
|
|
24
|
+
PRERELEASE: 2,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _parser() -> argparse.ArgumentParser:
|
|
29
|
+
parser = argparse.ArgumentParser(
|
|
30
|
+
prog="chaindiff",
|
|
31
|
+
description="Decide whether an Ethereum node client upgrade is safe.",
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument("--version", action="version", version=f"chaindiff {__version__}")
|
|
34
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
35
|
+
|
|
36
|
+
versions = commands.add_parser("versions", help="Show the latest stable release of each client")
|
|
37
|
+
versions.add_argument("--client", action="append", dest="clients", help="Limit to one client id")
|
|
38
|
+
versions.add_argument("--json", action="store_true")
|
|
39
|
+
|
|
40
|
+
check = commands.add_parser("check", help="Compare an installed version with a target release")
|
|
41
|
+
plan = commands.add_parser("plan", help="Checklist for the same comparison as check")
|
|
42
|
+
for command in (check, plan):
|
|
43
|
+
command.add_argument("--client", required=True, help="Client id, for example geth")
|
|
44
|
+
command.add_argument("--from", dest="current", required=True, help="Installed version")
|
|
45
|
+
command.add_argument("--to", dest="target", default="latest", help="Target version, or latest")
|
|
46
|
+
command.add_argument("--json", action="store_true")
|
|
47
|
+
|
|
48
|
+
refresh = commands.add_parser("refresh", help="Download the release catalog from GitHub")
|
|
49
|
+
refresh.add_argument("--client", action="append", dest="clients", help="Refresh one client id")
|
|
50
|
+
return parser
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _selected_clients(raw_ids: list[str] | None):
|
|
54
|
+
try:
|
|
55
|
+
clients = load_clients()
|
|
56
|
+
except ValueError as exc:
|
|
57
|
+
print(str(exc), file=sys.stderr)
|
|
58
|
+
return None
|
|
59
|
+
if not raw_ids:
|
|
60
|
+
return clients
|
|
61
|
+
selected = []
|
|
62
|
+
for raw in raw_ids:
|
|
63
|
+
client = client_by_id(clients, raw)
|
|
64
|
+
if client is None:
|
|
65
|
+
known = ", ".join(item.id for item in clients)
|
|
66
|
+
print(f"Unknown client '{raw}'. Known clients: {known}", file=sys.stderr)
|
|
67
|
+
return None
|
|
68
|
+
selected.append(client)
|
|
69
|
+
return selected
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _versions(args: argparse.Namespace) -> int:
|
|
73
|
+
clients = _selected_clients(args.clients)
|
|
74
|
+
if clients is None:
|
|
75
|
+
return 3
|
|
76
|
+
rows = []
|
|
77
|
+
missing = False
|
|
78
|
+
for client in clients:
|
|
79
|
+
try:
|
|
80
|
+
loaded = load_releases(client.id)
|
|
81
|
+
except ValueError as exc:
|
|
82
|
+
print(str(exc), file=sys.stderr)
|
|
83
|
+
return 3
|
|
84
|
+
if loaded is None:
|
|
85
|
+
missing = True
|
|
86
|
+
rows.append((client, None, None))
|
|
87
|
+
continue
|
|
88
|
+
fetched_at, releases = loaded
|
|
89
|
+
rows.append((client, fetched_at, releases))
|
|
90
|
+
now = datetime.now(timezone.utc)
|
|
91
|
+
if args.json:
|
|
92
|
+
print(json.dumps(versions_json(rows, now=now), indent=2))
|
|
93
|
+
else:
|
|
94
|
+
print(format_versions(rows, now=now), end="")
|
|
95
|
+
if missing:
|
|
96
|
+
print("Run `chaindiff refresh` to fill a missing catalog.", file=sys.stderr)
|
|
97
|
+
return 0
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _check(args: argparse.Namespace, *, plan_only: bool) -> int:
|
|
101
|
+
clients = _selected_clients([args.client])
|
|
102
|
+
if clients is None:
|
|
103
|
+
return 3
|
|
104
|
+
client = clients[0]
|
|
105
|
+
current = parse_version(args.current)
|
|
106
|
+
if current is None:
|
|
107
|
+
print(explain_unparsed(args.current), file=sys.stderr)
|
|
108
|
+
return 3
|
|
109
|
+
try:
|
|
110
|
+
loaded = load_releases(client.id)
|
|
111
|
+
advisories = load_advisories(client.id)
|
|
112
|
+
except ValueError as exc:
|
|
113
|
+
print(str(exc), file=sys.stderr)
|
|
114
|
+
return 3
|
|
115
|
+
if loaded is None:
|
|
116
|
+
print(f"No release catalog for {client.id}. Run: chaindiff refresh", file=sys.stderr)
|
|
117
|
+
return 3
|
|
118
|
+
fetched_at, releases = loaded
|
|
119
|
+
target_is_latest = args.target.lower() in ("latest", "stable")
|
|
120
|
+
if target_is_latest:
|
|
121
|
+
stable = latest_stable(releases)
|
|
122
|
+
if stable is None:
|
|
123
|
+
print(f"{client.id} has no stable release in the catalog.", file=sys.stderr)
|
|
124
|
+
return 3
|
|
125
|
+
target = stable.version
|
|
126
|
+
else:
|
|
127
|
+
target = parse_version(args.target)
|
|
128
|
+
if target is None:
|
|
129
|
+
print(explain_unparsed(args.target), file=sys.stderr)
|
|
130
|
+
return 3
|
|
131
|
+
result = evaluate(
|
|
132
|
+
client=client,
|
|
133
|
+
releases=releases,
|
|
134
|
+
advisories=advisories,
|
|
135
|
+
current=current,
|
|
136
|
+
target=target,
|
|
137
|
+
target_is_latest=target_is_latest,
|
|
138
|
+
fetched_at=fetched_at,
|
|
139
|
+
now=datetime.now(timezone.utc),
|
|
140
|
+
)
|
|
141
|
+
if args.json:
|
|
142
|
+
print(json.dumps(check_json(result), indent=2))
|
|
143
|
+
else:
|
|
144
|
+
print(format_check(result, plan_only=plan_only), end="")
|
|
145
|
+
return _EXIT[result.verdict]
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def main(argv: list[str] | None = None) -> int:
|
|
149
|
+
args = _parser().parse_args(argv)
|
|
150
|
+
if args.command == "versions":
|
|
151
|
+
return _versions(args)
|
|
152
|
+
if args.command == "refresh":
|
|
153
|
+
return refresh_catalog(args.clients)
|
|
154
|
+
if args.command == "plan":
|
|
155
|
+
return _check(args, plan_only=True)
|
|
156
|
+
return _check(args, plan_only=False)
|