Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
78123f0
refactor: Prepare for sync-v2
msbrogli Jul 12, 2023
ba13778
refactor: do not use built-in random and add proper linter check
jansegre Jul 12, 2023
6a2891f
Merge pull request #698 from HathorNetwork/refactor/no-builtin-random
jansegre Jul 12, 2023
b0672bc
refactor: remove deprecated typing uses and add custom linter script
jansegre Jul 12, 2023
ab215c4
Merge pull request #699 from HathorNetwork/refactor/no-deprecated-typing
jansegre Jul 12, 2023
32ae482
chore(extras): script to generate list of PRs that master is ahead of rc
jansegre Jul 12, 2023
d920df5
Merge pull request #701 from HathorNetwork/chore/gen-rc-prs-script
jansegre Jul 12, 2023
779494c
fix(event-queue): fix event simulator scenario parsing (#706)
glevco Jul 18, 2023
7bee591
feat(feature-activation): fix criteria validation (#708)
glevco Jul 19, 2023
c770612
feat(feature-activation): implement bit signaling service (#702)
glevco Jul 19, 2023
b826588
feat(feature-activation): block features endpoint (#690)
glevco Jul 20, 2023
5c04547
chore: update default Python version to 3.10
jansegre Jul 21, 2023
02d3bf7
Merge pull request #712 from HathorNetwork/chore/update-default-python
jansegre Jul 24, 2023
73a8a68
chore: update autobahn package
jansegre Jul 21, 2023
175f40a
Merge pull request #713 from HathorNetwork/chore/update-autobahn
jansegre Jul 25, 2023
f63f3b8
feat(sync-v2): sync-v2 implemented, sync-v1 still default
jansegre Sep 10, 2021
bdfc5fc
Merge pull request #275 from HathorNetwork/feat/sync-v2-mvp2
jansegre Jul 25, 2023
ad194da
fix(test): regression after sync-v2 command was removed
jansegre Jul 26, 2023
e9235e6
Merge pull request #730 from HathorNetwork/fix/sync-v2-regression
jansegre Jul 26, 2023
1d48776
refactor(p2p): rename sync *manager* to sync *agent*
jansegre Jul 26, 2023
405ab6a
Merge pull request #729 from HathorNetwork/refactor/sync-agent
jansegre Jul 26, 2023
b602039
refactor(sync-v2): improve deferreds handling
glevco Jul 26, 2023
7aaf57c
feat(indexes): add get_n_height_tips method to height index
jansegre Jul 27, 2023
91590c7
Merge pull request #734 from HathorNetwork/feat/new-height-index-method
jansegre Jul 27, 2023
e710e6d
feat(p2p): add setting to enable/disable peer whitelist for sync-v2
jansegre Jul 27, 2023
338b3ef
Merge pull request #735 from HathorNetwork/feat/whitelist-for-sync-v2
jansegre Jul 27, 2023
126017d
feat: add get-best-blockchain capability (#686)
alexruzenhack Jul 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ jobs:
- '3.10'
- '3.11'
exclude:
# XXX: neither pypy-3.10 nor pypy-3.11 exist yet, maybe pypy-3.10 will be out on PyPy v7.3.10
- python-impl: pypy
python-version: '3.10'
# XXX: pypy-3.11 does exist yet
- python-impl: pypy
python-version: '3.11'
steps:
Expand All @@ -52,8 +50,9 @@ jobs:
python extras/github/docker.py
- name: Check version
if: steps.prep.outputs.check-version
run: |
make check-version VERSION='${{ steps.prep.outputs.check-version }}'
env:
VERSION: ${{ steps.prep.outputs.check-version }}
run: make check-custom
- name: Set up QEMU # arm64 is not available natively
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# before changing these variables, make sure the tag $PYTHON-alpine$ALPINE exists first
# list of valid tags hese: https://hub.docker.com/_/python
ARG PYTHON=3.9
ARG PYTHON=3.10
ARG DEBIAN=bullseye

# stage-0: copy pyproject.toml/poetry.lock and install the production set of dependencies
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.pypy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# before changing these variables, make sure the tag $PYTHON-alpine$ALPINE exists first
# list of valid tags hese: https://hub.docker.com/_/pypy
ARG PYTHON=3.9
ARG PYTHON=3.10
ARG DEBIAN=bullseye

# stage-0: copy pyproject.toml/poetry.lock and install the production set of dependencies
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ isort-check:
yamllint:
yamllint .

.PHONY: check-version
check-version:
bash ./extras/check_version.sh $(VERSION)
.PHONY: check-custom
check-custom:
bash ./extras/custom_checks.sh

.PHONY: check
check: check-version yamllint flake8 isort-check mypy
check: check-custom yamllint flake8 isort-check mypy

.PHONY: dcheck
dcheck: check-version yamllint flake8 isort-check dmypy
dcheck: check-custom yamllint flake8 isort-check dmypy

# formatting:

Expand Down
47 changes: 0 additions & 47 deletions extras/check_version.sh

This file was deleted.

112 changes: 112 additions & 0 deletions extras/custom_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash

# Define colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Source dirs
SOURCE_DIRS=(hathor tests)

# Define your custom linter check functions here
# Each function should return 0 if everything is OK, and 1 if something is wrong.

function check_version_match() {
# This function will check all source files containing the project version and return 1 in case
# they don't match. When a version is provided as an environment variable, it is checked against the package version.

OPENAPI_FILE="hathor/cli/openapi_files/openapi_base.json"
SRC_FILE="hathor/version.py"
PACKAGE_FILE="pyproject.toml"

OPENAPI_VERSION=`grep "version\":" ${OPENAPI_FILE} | cut -d'"' -f4`
SRC_VERSION=`grep "BASE_VERSION =" ${SRC_FILE} | cut -d "'" -f2`
PACKAGE_VERSION=`grep '^version' ${PACKAGE_FILE} | cut -d '"' -f2`

# For debugging:
# echo x${SRC_VERSION}x
# echo x${OPENAPI_VERSION}x
# echo x${PACKAGE_VERSION}x

EXITCODE=0

if [[ x${PACKAGE_VERSION}x != x${SRC_VERSION}x ]]; then
echo "Version different in ${PACKAGE_FILE} and ${SRC_FILE}"
EXITCODE=1
fi

if [[ x${PACKAGE_VERSION}x != x${OPENAPI_VERSION}x ]]; then
echo "Version different in ${PACKAGE_FILE} and ${OPENAPI_FILE}"
EXITCODE=1
fi

# We expect an optional environment variable containing a version string to be checked against the others
if [[ -n ${VERSION} ]]; then
if [[ x${PACKAGE_VERSION}x != x${VERSION}x ]]; then
echo "Version different in ${PACKAGE_FILE} and VERSION environment variable"
EXITCODE=1
fi
fi

return $EXITCODE
}

function check_do_not_use_builtin_random_in_tests() {
# If the check fails, return 1
# If the check passes, return 0
exclude=(
hathor/merged_mining/debug_api.py
hathor/client.py
hathor/cli/tx_generator.py
)
exclude_params=()
for item in "${exclude[@]}"; do
exclude_params+=(-not -path "*$item*")
done
if find "${SOURCE_DIRS[@]}" "${exclude_params[@]}" -type f -print0 | xargs -0 grep -l '\<import .*\<random\>'; then
echo '"import random" found in the files above'
echo 'use `self.rng` or `hathor.util.Random` instead of `random`'
return 1
fi
return 0
}

function check_deprecated_typing() {
if grep -R '\<typing .*\<import .*\<\(Tuple\|List\|Dict\|Set\|FrozenSet\|AbstractSet\|DefaultDict\|OrderedDict\)\>' "${SOURCE_DIRS[@]}"; then
echo 'do not use typing.List/Tuple/Dict/... for type annotations use builtin list/tuple/dict/... instead'
echo 'for more info check the PEP 585 doc: https://peps.python.org/pep-0585/'
return 1
fi
return 0
}

# List of functions to be executed
checks=(
check_version_match
check_do_not_use_builtin_random_in_tests
check_deprecated_typing
)

# Initialize a variable to track if any check fails
any_check_failed=0

# Loop over all checks
for check in "${checks[@]}"; do
$check
result=$?
if [ $result -ne 0 ]; then
echo -e "${RED}Check $check FAILED${NC}"
any_check_failed=1
else
echo -e "${GREEN}Check $check PASSED${NC}"
fi
done

# Exit with code 0 if no check failed, otherwise exit with code 1
if [ $any_check_failed -eq 0 ]; then
echo -e "${GREEN}All checks PASSED${NC}"
exit 0
else
echo -e "${RED}Some checks FAILED${NC}"
exit 1
fi
79 changes: 79 additions & 0 deletions extras/gen_release_candidate_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python
"""
This script finds all PRs that have been merged into the `master` branch but not into the `release-candidate` branch in a given GitHub repository.

Usage:

./extras/gen_release_candidate_changes.py

Example output:

```
- #701
- #697
- #686
```
"""

import yaml
import os
import requests

BASE_API_URL = 'https://api.github.com'
REPO = 'HathorNetwork/hathor-core'


def get_gh_token():
config_path = os.path.expanduser('~/.config/gh/hosts.yml')

if not os.path.exists(config_path):
print("GitHub CLI configuration not found. Please authenticate with 'gh auth login'.")
exit(1)

with open(config_path, 'r') as file:
config = yaml.safe_load(file)

token = config['github.com']['oauth_token']
return token


def get_headers(token):
return {'Authorization': f'token {token}'}


def get_commits_ahead(base, compare, token):
response = requests.get(
f'{BASE_API_URL}/repos/{REPO}/compare/{base}...{compare}',
headers=get_headers(token)
)
data = response.json()
return [commit['sha'] for commit in data['commits']]


def get_pr_for_commit(commit, token):
response = requests.get(
f'{BASE_API_URL}/repos/{REPO}/commits/{commit}/pulls',
headers=get_headers(token),
params={'state': 'all'}
)
data = response.json()
if data:
return data[0]['number']
return None


def get_new_prs_in_master(token):
commits = get_commits_ahead('release-candidate', 'master', token)
prs = []
for commit in commits:
pr = get_pr_for_commit(commit, token)
if pr and pr not in prs:
prs.append(pr)
return prs


if __name__ == '__main__':
token = get_gh_token()
prs = get_new_prs_in_master(token)
for pr in prs:
print(f'- #{pr}')
20 changes: 10 additions & 10 deletions extras/github/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_nightly_build_no_github_secret(self):
'GITHUB_EVENT_DEFAULT_BRANCH': 'master',
'GITHUB_EVENT_NUMBER': '',
'MATRIX_PYTHON_IMPL': 'python',
'MATRIX_PYTHON_VERSION': '3.9',
'MATRIX_PYTHON_VERSION': '3.10',
'SECRETS_DOCKERHUB_IMAGE': '',
'SECRETS_GHCR_IMAGE': '',
})
Expand All @@ -32,7 +32,7 @@ def test_nightly_build_no_github_secret(self):
output = prep_tags(os.environ, base_version, is_release_candidate)

self.assertEqual(output['slack-notification-version'], base_version)
self.assertEqual(output['version'], base_version + '-python3.9')
self.assertEqual(output['version'], base_version + '-python3.10')
self.assertEqual(output['login-dockerhub'], 'false')
self.assertEqual(output['login-ghcr'], 'false')
self.assertEqual(output['tags'], 'dont-push--local-only')
Expand All @@ -47,7 +47,7 @@ def test_nightly_build(self):
'GITHUB_EVENT_DEFAULT_BRANCH': 'master',
'GITHUB_EVENT_NUMBER': '',
'MATRIX_PYTHON_IMPL': 'python',
'MATRIX_PYTHON_VERSION': '3.9',
'MATRIX_PYTHON_VERSION': '3.10',
'SECRETS_DOCKERHUB_IMAGE': 'mock_image',
'SECRETS_GHCR_IMAGE': '',
})
Expand All @@ -62,12 +62,12 @@ def test_nightly_build(self):
output = prep_tags(os.environ, base_version, is_release_candidate)

self.assertEqual(output['slack-notification-version'], base_version)
self.assertEqual(output['version'], base_version + '-python3.9')
self.assertEqual(output['version'], base_version + '-python3.10')
self.assertEqual(output['login-dockerhub'], 'true')
self.assertEqual(output['login-ghcr'], 'false')
self.assertEqual(len(output['tags'].split(',')), 2)
self.assertIn('mock_image:nightly-55629a7d', output['tags'].split(','))
self.assertIn('mock_image:nightly-55629a7d-python3.9', output['tags'].split(','))
self.assertIn('mock_image:nightly-55629a7d-python3.10', output['tags'].split(','))
self.assertEqual(output['push'], 'true')
self.assertEqual(output['dockerfile'], 'Dockerfile')

Expand Down Expand Up @@ -110,7 +110,7 @@ def test_release_candidate_default_python(self):
'GITHUB_EVENT_DEFAULT_BRANCH': 'master',
'GITHUB_EVENT_NUMBER': '',
'MATRIX_PYTHON_IMPL': 'python',
'MATRIX_PYTHON_VERSION': '3.9',
'MATRIX_PYTHON_VERSION': '3.10',
'SECRETS_DOCKERHUB_IMAGE': 'mock_image',
'SECRETS_GHCR_IMAGE': '',
})
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_release_default_python(self):
'GITHUB_EVENT_DEFAULT_BRANCH': 'master',
'GITHUB_EVENT_NUMBER': '',
'MATRIX_PYTHON_IMPL': 'python',
'MATRIX_PYTHON_VERSION': '3.9',
'MATRIX_PYTHON_VERSION': '3.10',
'SECRETS_DOCKERHUB_IMAGE': 'mock_image',
'SECRETS_GHCR_IMAGE': '',
})
Expand All @@ -155,12 +155,12 @@ def test_release_default_python(self):
output = prep_tags(os.environ, base_version, is_release_candidate)

self.assertEqual(output['slack-notification-version'], base_version)
self.assertEqual(output['version'], base_version + '-python3.9')
self.assertEqual(output['version'], base_version + '-python3.10')
self.assertEqual(output['login-dockerhub'], 'true')
self.assertEqual(output['login-ghcr'], 'false')
self.assertEqual(len(output['tags'].split(',')), 4)
self.assertIn('mock_image:v0.53-python3.9', output['tags'].split(','))
self.assertIn('mock_image:v0.53.0-python3.9', output['tags'].split(','))
self.assertIn('mock_image:v0.53-python3.10', output['tags'].split(','))
self.assertIn('mock_image:v0.53.0-python3.10', output['tags'].split(','))
self.assertIn('mock_image:v0.53.0', output['tags'].split(','))
self.assertIn('mock_image:latest', output['tags'].split(','))
self.assertEqual(output['push'], 'true')
Expand Down
Loading