Skip to content

Commit 2cd7c6b

Browse files
committed
Merge bitcoin/bitcoin#30147: contrib: Fixup verify-binaries OS platform parsing
3ab2520 contrib: Fixup verify-binaries OS platform parsing (Ben Westgate) Pull request description: Closes #30145. This PR solves two major issues in the `parse_version_string` function of verify-binaries: 1. `-aarch64` binaries cannot be specifically downloaded. The -platform string gets interpreted as a release candidate that doesn't exist due to containing sub-string "rc". 2. Specifying a platform with a "-" in the name causes the parser to ignore both "-platform" AND "-rcN" and download the potentially wrong (non-rc) version for every platform. This also prevented specifying just one platform binary the user wished to download. It also updates the accompanying `test.py` to cover problem two and adds two examples that were formerly broken to `README.md` to show what is now possible. Including the most useful case of downloading only 1 specific platform's binary. This improves the Bitcoin verify-binaries tools user experience by not: 1. Failing to download for inexplicable reasons, 2. Downloading more files than what the user told it to, or in the worst case 3. Downloading only the wrong files. * A test was added to cover the command `verify-binaries/verify.py pub 22.0-x86_64-linux-gnu.tar.gz` which checks that _bitcoin-22.0-x86_64-linux-gnu.tar.gz_ downloads successfully AND ONLY _bitcoin-22.0-x86_64-linux-gnu.tar.gz_ downloads. * The steps to reproduce each bug are in the referenced issue #30145. Explanation of the potential issue as well as reasoning for the way the bug was fixed are in my commit descriptions. * This delivers the promised feature of "only download the binaries for a certain platform", by allowing strings with '-' to be accepted, allowing for single file downloads for any specific platform which was not always possible before. * Removes 6 lines of code from the offending `parse_version_string` function, while fixing the bugs/errors, and extending the functionality to be practical for users with slow connections. * Makes the error message more helpful when no file matches the provided platform string, now prints "Did you mean: `closest-match`" to help correct typos. Thanks for reading my PR. I look forward to getting this helpful tool in its best shape yet. Log of this branch passing the new test.py: ``` python3 test.py ✓ 'Nonexistent version should fail' passed ✓ 'Malformed version should fail' passed ✓ '--min-good-sigs 20 should fail' passed - testing verification (22.0-x86_64-linux-gnu.tar.gz) ✓ '22.0-x86_64-linux-gnu.tar.gz should succeed' passed - testing verification (22.0) ✓ '22.0 should succeed' passed ``` Log of master failing the new test.py: ``` python3 test.py ✓ 'Nonexistent version should fail' passed ✓ 'Malformed version should fail' passed ✓ '--min-good-sigs 20 should fail' passed - testing verification (22.0-x86_64-linux-gnu.tar.gz) ✓ '22.0-x86_64-linux-gnu.tar.gz should succeed' passed Traceback (most recent call last): File "/home/ben/Documents/GitHub/bitcoin/contrib/verify-binaries/test.py", line 74, in <module> main() File "/home/ben/Documents/GitHub/bitcoin/contrib/verify-binaries/test.py", line 27, in main assert len(v) == 1 ^^^^^^^^^^^ AssertionError ``` ACKs for top commit: stickies-v: re-ACK 3ab2520 willcl-ark: re-ACK 3ab2520 Tree-SHA512: 6093228bb876cd0ac84d1cd2630074e17a3f09c4b23325b9419d859a5721a802f928844575233b135df52b882287dd18d6fadf4419d88ec0a2cdf82db315329e
2 parents be4df59 + 3ab2520 commit 2cd7c6b

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

contrib/verify-binaries/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,23 @@ Get JSON output and don't prompt for user input (no auto key import):
5050

5151
```sh
5252
./contrib/verify-binaries/verify.py --json pub 22.0-x86
53+
./contrib/verify-binaries/verify.py --json pub 23.0-rc5-linux-gnu
5354
```
5455

5556
Rely only on local GPG state and manually specified keys, while requiring a
5657
threshold of at least 10 trusted signatures:
5758
```sh
5859
./contrib/verify-binaries/verify.py \
5960
--trusted-keys 74E2DEF5D77260B98BC19438099BAD163C70FBFA,9D3CC86A72F8494342EA5FD10A41BDC3F4FAFF1C \
60-
--min-good-sigs 10 pub 22.0-x86
61+
--min-good-sigs 10 pub 22.0-linux
6162
```
6263

63-
If you only want to download the binaries for a certain platform, add the corresponding suffix, e.g.:
64+
If you only want to download the binaries for a certain architecture and/or platform, add the corresponding suffix, e.g.:
6465

6566
```sh
66-
./contrib/verify-binaries/verify.py pub 24.0.1-darwin
67-
./contrib/verify-binaries/verify.py pub 23.1-rc1-win64
67+
./contrib/verify-binaries/verify.py pub 25.2-x86_64-linux
68+
./contrib/verify-binaries/verify.py pub 24.1-rc1-darwin
69+
./contrib/verify-binaries/verify.py pub 27.0-win64-setup.exe
6870
```
6971

7072
If you do not want to keep the downloaded binaries, specify the cleanup option.

contrib/verify-binaries/test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ def main():
1212
expect_code(run_verify("", "pub", '0.32.awefa.12f9h'), 11, "Malformed version should fail")
1313
expect_code(run_verify('--min-good-sigs 20', "pub", "22.0"), 9, "--min-good-sigs 20 should fail")
1414

15+
print("- testing verification (22.0-x86_64-linux-gnu.tar.gz)", flush=True)
16+
_220_x86_64_linux_gnu = run_verify("--json", "pub", "22.0-x86_64-linux-gnu.tar.gz")
17+
try:
18+
result = json.loads(_220_x86_64_linux_gnu.stdout.decode())
19+
except Exception:
20+
print("failed on 22.0-x86_64-linux-gnu.tar.gz --json:")
21+
print_process_failure(_220_x86_64_linux_gnu)
22+
raise
23+
24+
expect_code(_220_x86_64_linux_gnu, 0, "22.0-x86_64-linux-gnu.tar.gz should succeed")
25+
v = result['verified_binaries']
26+
assert result['good_trusted_sigs']
27+
assert len(v) == 1
28+
assert v['bitcoin-22.0-x86_64-linux-gnu.tar.gz'] == '59ebd25dd82a51638b7a6bb914586201e67db67b919b2a1ff08925a7936d1b16'
29+
1530
print("- testing verification (22.0)", flush=True)
1631
_220 = run_verify("--json", "pub", "22.0")
1732
try:

contrib/verify-binaries/verify.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,17 @@ def bool_from_env(key, default=False) -> bool:
9797

9898

9999
VERSION_FORMAT = "<major>.<minor>[.<patch>][-rc[0-9]][-platform]"
100-
VERSION_EXAMPLE = "22.0-x86_64 or 23.1-rc1-darwin"
100+
VERSION_EXAMPLE = "22.0 or 23.1-rc1-darwin.dmg or 27.0-x86_64-linux-gnu"
101101

102102
def parse_version_string(version_str):
103-
parts = version_str.split('-')
104-
version_base = parts[0]
105-
version_rc = ""
106-
version_os = ""
107-
if len(parts) == 2: # "<version>-rcN" or "version-platform"
108-
if "rc" in parts[1]:
109-
version_rc = parts[1]
110-
else:
111-
version_os = parts[1]
112-
elif len(parts) == 3: # "<version>-rcN-platform"
113-
version_rc = parts[1]
114-
version_os = parts[2]
103+
# "<version>[-rcN][-platform]"
104+
version_base, _, platform = version_str.partition('-')
105+
rc = ""
106+
if platform.startswith("rc"): # "<version>-rcN[-platform]"
107+
rc, _, platform = platform.partition('-')
108+
# else "<version>" or "<version>-platform"
115109

116-
return version_base, version_rc, version_os
110+
return version_base, rc, platform
117111

118112

119113
def download_with_wget(remote_file, local_file):
@@ -514,7 +508,9 @@ def cleanup():
514508
# Extract hashes and filenames
515509
hashes_to_verify = parse_sums_file(SUMS_FILENAME, [os_filter])
516510
if not hashes_to_verify:
517-
log.error("no files matched the platform specified")
511+
available_versions = ["-".join(line[1].split("-")[2:]) for line in parse_sums_file(SUMS_FILENAME, [])]
512+
closest_match = difflib.get_close_matches(os_filter, available_versions, cutoff=0, n=1)[0]
513+
log.error(f"No files matched the platform specified. Did you mean: {closest_match}")
518514
return ReturnCode.NO_BINARIES_MATCH
519515

520516
# remove binaries that are known not to be hosted by bitcoincore.org

0 commit comments

Comments
 (0)