Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Metadata from xtz-shots #525

Merged
merged 31 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
48a1be3
Handle Metadata from xtz-shots
nicolasochem Dec 16, 2022
c98794a
eval PREFER_TARBALLS as a python bool
nicolasochem Dec 27, 2022
997dce9
Merge branch 'master' into snapshot_metadata
nicolasochem Dec 27, 2022
6bc71d1
look up CHAIN_NAME inside function per review
nicolasochem Dec 27, 2022
3f968f0
simplify logic to grab the octez version with regexp
nicolasochem Dec 27, 2022
e6ce5d1
better explanation of snapshot_source in default values.yaml
nicolasochem Dec 27, 2022
84d44e4
grab env var `SNAPSHOT_SOURCE` where it's actually needed
nicolasochem Dec 27, 2022
8737fd3
lint values.yaml explanation of hardcoded snapshot URLs
nicolasochem Dec 27, 2022
33fae45
return None instead of {} when snapshot not found
nicolasochem Dec 27, 2022
b65e0d2
when octez_version is not known, pick snapshot of any version
nicolasochem Dec 27, 2022
973930a
throw an error when history mode is unknown
nicolasochem Dec 27, 2022
aa35ff3
snapshot importer: verify there is a snapshot to import first
nicolasochem Dec 27, 2022
a17117c
fix true/false handling for `prefer_tarballs`
nicolasochem Dec 27, 2022
e168f84
handle sha256 check failure for tarball; delete data
nicolasochem Dec 28, 2022
c5b553b
also handle disk check failure
nicolasochem Dec 28, 2022
24d73f6
handle case where octez image is defined in statefulset
nicolasochem Dec 28, 2022
73bce9f
query env vars with get()
nicolasochem Dec 28, 2022
7dec366
query manual snapshot env vars with get()
nicolasochem Dec 28, 2022
ff32e1b
simplify snapshot-importer
nicolasochem Dec 28, 2022
866e311
do not wrap sort function in try/except, return last if exists
nicolasochem Dec 28, 2022
db481da
fix tests
nicolasochem Dec 28, 2022
bf43020
black
nicolasochem Dec 28, 2022
109b916
get PREFER_TARBALLS env var
nicolasochem Dec 28, 2022
01b7903
do not download file if there is no space
nicolasochem Dec 28, 2022
2e58d5a
default to "" so it doesn't do lower() on none type
nicolasochem Dec 28, 2022
88a0b2b
use get() for every attribute lookup from snapshot metadata file
nicolasochem Dec 28, 2022
9e9a670
rm snapshot when sha256 fails
nicolasochem Dec 28, 2022
e06fd56
log too small size
nicolasochem Dec 28, 2022
1d5094b
function return when sha256 check fail (not needed now but mb later)
nicolasochem Dec 28, 2022
0a98d1b
default tezos_version when not found in snapshot matching func
nicolasochem Dec 28, 2022
bf50654
do not create snapshot_config.json when there's no artifact
nicolasochem Dec 28, 2022
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
13 changes: 11 additions & 2 deletions charts/tezos/scripts/snapshot-importer.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set -ex
set -e

bin_dir="/usr/local/bin"
data_dir="/var/tezos"
Expand All @@ -7,6 +7,11 @@ node_data_dir="$node_dir/data"
node="$bin_dir/octez-node"
snapshot_file=${node_dir}/chain.snapshot

if [ ! -f ${snapshot_file} ]; then
echo "No snapshot to import."
exit 0
fi
nicolasochem marked this conversation as resolved.
Show resolved Hide resolved

if [ -d ${node_data_dir}/context ]; then
echo "Blockchain has already been imported. If a tarball"
echo "instead of a regular tezos snapshot was used, it was"
Expand All @@ -16,8 +21,12 @@ fi

cp -v /etc/tezos/config.json ${node_data_dir}

if [ -f ${node_dir}/chain.snapshot.block_hash ]; then
block_hash_arg="--block $(cat ${node_dir}/chain.snapshot.block_hash)"
fi

${node} snapshot import ${snapshot_file} --data-dir ${node_data_dir} \
--network $CHAIN_NAME
--network $CHAIN_NAME ${block_hash_arg}
find ${node_dir}

rm -rvf ${snapshot_file}
2 changes: 1 addition & 1 deletion charts/tezos/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{{- define "tezos.shouldDownloadSnapshot" -}}
{{- if or (.Values.full_snapshot_url) (.Values.full_tarball_url)
(.Values.rolling_snapshot_url) (.Values.rolling_tarball_url)
(.Values.archive_tarball_url) }}
(.Values.archive_tarball_url) (.Values.snapshot_source) }}
{{- if or (and (.Values.rolling_tarball_url) (.Values.rolling_snapshot_url))
(and (.Values.full_tarball_url) (.Values.full_snapshot_url))
}}
Expand Down
3 changes: 3 additions & 0 deletions charts/tezos/templates/configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ data:
ROLLING_SNAPSHOT_URL: "{{ .Values.rolling_snapshot_url }}"
ROLLING_TARBALL_URL: "{{ .Values.rolling_tarball_url }}"
ARCHIVE_TARBALL_URL: "{{ .Values.archive_tarball_url }}"
PREFER_TARBALLS: "{{ .Values.prefer_tarballs }}"
harryttd marked this conversation as resolved.
Show resolved Hide resolved
SNAPSHOT_SOURCE: "{{ .Values.snapshot_source }}"
OCTEZ_VERSION: "{{ .Values.images.octez }}"
NODE_GLOBALS: |
{{ .Values.node_globals | mustToPrettyJson | indent 4 }}

Expand Down
33 changes: 23 additions & 10 deletions charts/tezos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,30 @@ signers: {}
# ```
# End Signers

## Where full and rolling history mode nodes will get their Tezos snapshots from.
full_snapshot_url: https://mainnet.xtz-shots.io/full
rolling_snapshot_url: https://mainnet.xtz-shots.io/rolling
# When spinning up nodes, tezos-k8s will attempt to download a snapshot from a
# known source. This should be a url to a json metadata file in the format
# xtz-shots uses. If you want to sync from scratch or for a private chain, set
# to `null`.
snapshot_source: https://xtz-shots.io/tezos-snapshots.json

## Alternatively to a Tezos snapshot, you can download an LZ4-compressed
## filesystem tar of a node's data directory by setting `archive_tarball_url`
## and `rolling_tarball_url` fields to the URL of the file. NOTE:
## `rolling_tarball_url` and `rolling_snapshot_url` are mutually exclusive and
## cannot both be specified at the same time.
archive_tarball_url: https://mainnet.xtz-shots.io/archive-tarball
# rolling_tarball_url: "https://mainnet.xtz-shots.io/rolling-tarball
# By default, tezos-k8s will download and unpack snapshots.
# A tarball is a LZ4-compressed filesystem tar of a node's data directory.
# You must trust the tarball provider to provide good data, as no check is
# performed by the node.
# If you prefer tarballs, set to "true" below.
prefer_tarballs: false

# By default, tezos-k8s will attempt to download the right artifact from
# `snapshot_source` set above. You can override and hard-code a snapshot URL
# source below. When any of the below variables are set, `snapshot_source` above
# will be ignored for all artifact types.
## NOTE: `*_tarball_url` and `*_snapshot_url` are mutually exclusive
## and cannot both be specified at the same time.
archive_tarball_url: null # e.g. https://mainnet.xtz-shots.io/archive-tarball
full_snapshot_url: null
full_tarball_url: null
rolling_snapshot_url: null
rolling_tarball_url: null

# List of peers for nodes to connect to. Gets set under config.json `p2p` field
bootstrap_peers: []
Expand Down
5 changes: 1 addition & 4 deletions mkchain/tqchain/mkchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ def main():
"zerotier_token": args.zerotier_token,
},
# Custom chains should not pull snapshots or tarballs
"full_snapshot_url": None,
"rolling_snapshot_url": None,
"archive_tarball_url": None,
"rolling_tarball_url": None,
"snapshot_source": None,
"node_globals": {
# Needs a quotedstring otherwise helm interprets "Y" as true and it does not work
"env": {
Expand Down
22 changes: 17 additions & 5 deletions test/charts/mainnet.expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ data:
},
"protocol_activation": null
}
FULL_SNAPSHOT_URL: "https://mainnet.xtz-shots.io/full"
FULL_SNAPSHOT_URL: ""
FULL_TARBALL_URL: ""
ROLLING_SNAPSHOT_URL: "https://mainnet.xtz-shots.io/rolling"
ROLLING_SNAPSHOT_URL: ""
ROLLING_TARBALL_URL: ""
ARCHIVE_TARBALL_URL: "https://mainnet.xtz-shots.io/archive-tarball"
ARCHIVE_TARBALL_URL: ""
PREFER_TARBALLS: "false"
SNAPSHOT_SOURCE: "https://xtz-shots.io/tezos-snapshots.json"
OCTEZ_VERSION: "tezos/tezos:v15-release"
NODE_GLOBALS: |
{
"env": {}
Expand Down Expand Up @@ -317,7 +320,7 @@ spec:
args:
- "-c"
- |
set -ex
set -e

bin_dir="/usr/local/bin"
data_dir="/var/tezos"
Expand All @@ -326,6 +329,11 @@ spec:
node="$bin_dir/octez-node"
snapshot_file=${node_dir}/chain.snapshot

if [ ! -f ${snapshot_file} ]; then
echo "No snapshot to import."
exit 0
fi

if [ -d ${node_data_dir}/context ]; then
echo "Blockchain has already been imported. If a tarball"
echo "instead of a regular tezos snapshot was used, it was"
Expand All @@ -335,8 +343,12 @@ spec:

cp -v /etc/tezos/config.json ${node_data_dir}

if [ -f ${node_dir}/chain.snapshot.block_hash ]; then
block_hash_arg="--block $(cat ${node_dir}/chain.snapshot.block_hash)"
fi

${node} snapshot import ${snapshot_file} --data-dir ${node_data_dir} \
--network $CHAIN_NAME
--network $CHAIN_NAME ${block_hash_arg}
find ${node_dir}

rm -rvf ${snapshot_file}
Expand Down
35 changes: 28 additions & 7 deletions test/charts/mainnet2.expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ data:
},
"protocol_activation": null
}
FULL_SNAPSHOT_URL: "https://mainnet.xtz-shots.io/full"
FULL_SNAPSHOT_URL: ""
FULL_TARBALL_URL: ""
ROLLING_SNAPSHOT_URL: "https://mainnet.xtz-shots.io/rolling"
ROLLING_SNAPSHOT_URL: ""
ROLLING_TARBALL_URL: ""
ARCHIVE_TARBALL_URL: "https://mainnet.xtz-shots.io/archive-tarball"
ARCHIVE_TARBALL_URL: ""
PREFER_TARBALLS: "false"
SNAPSHOT_SOURCE: "https://xtz-shots.io/tezos-snapshots.json"
OCTEZ_VERSION: "tezos/tezos:v15-release"
NODE_GLOBALS: |
{
"env": {
Expand Down Expand Up @@ -426,7 +429,7 @@ spec:
args:
- "-c"
- |
set -ex
set -e

bin_dir="/usr/local/bin"
data_dir="/var/tezos"
Expand All @@ -435,6 +438,11 @@ spec:
node="$bin_dir/octez-node"
snapshot_file=${node_dir}/chain.snapshot

if [ ! -f ${snapshot_file} ]; then
echo "No snapshot to import."
exit 0
fi

if [ -d ${node_data_dir}/context ]; then
echo "Blockchain has already been imported. If a tarball"
echo "instead of a regular tezos snapshot was used, it was"
Expand All @@ -444,8 +452,12 @@ spec:

cp -v /etc/tezos/config.json ${node_data_dir}

if [ -f ${node_dir}/chain.snapshot.block_hash ]; then
block_hash_arg="--block $(cat ${node_dir}/chain.snapshot.block_hash)"
fi

${node} snapshot import ${snapshot_file} --data-dir ${node_data_dir} \
--network $CHAIN_NAME
--network $CHAIN_NAME ${block_hash_arg}
find ${node_dir}

rm -rvf ${snapshot_file}
Expand Down Expand Up @@ -789,7 +801,7 @@ spec:
args:
- "-c"
- |
set -ex
set -e

bin_dir="/usr/local/bin"
data_dir="/var/tezos"
Expand All @@ -798,6 +810,11 @@ spec:
node="$bin_dir/octez-node"
snapshot_file=${node_dir}/chain.snapshot

if [ ! -f ${snapshot_file} ]; then
echo "No snapshot to import."
exit 0
fi

if [ -d ${node_data_dir}/context ]; then
echo "Blockchain has already been imported. If a tarball"
echo "instead of a regular tezos snapshot was used, it was"
Expand All @@ -807,8 +824,12 @@ spec:

cp -v /etc/tezos/config.json ${node_data_dir}

if [ -f ${node_dir}/chain.snapshot.block_hash ]; then
block_hash_arg="--block $(cat ${node_dir}/chain.snapshot.block_hash)"
fi

${node} snapshot import ${snapshot_file} --data-dir ${node_data_dir} \
--network $CHAIN_NAME
--network $CHAIN_NAME ${block_hash_arg}
find ${node_dir}

rm -rvf ${snapshot_file}
Expand Down
3 changes: 3 additions & 0 deletions test/charts/private-chain.expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ data:
ROLLING_SNAPSHOT_URL: ""
ROLLING_TARBALL_URL: ""
ARCHIVE_TARBALL_URL: ""
PREFER_TARBALLS: "false"
SNAPSHOT_SOURCE: ""
OCTEZ_VERSION: "tezos/tezos:v15-release"
NODE_GLOBALS: |
{
"env": {}
Expand Down
4 changes: 1 addition & 3 deletions test/charts/private-chain.in.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ activation:
sc_rollup_max_available_messages: 1000000
bootstrap_peers: []
expected_proof_of_work: 0
full_snapshot_url: null
rolling_snapshot_url: null
archive_tarball_url: null
snapshot_source: null
images:
octez: 'tezos/tezos:v15-release'
is_invitation: false
Expand Down
6 changes: 4 additions & 2 deletions utils/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.9-alpine
FROM python:3.10-alpine
# TODO: update to 3.11 once the bug is fixed:
# https://github.com/baking-bad/pytezos/issues/336
ENV PYTHONUNBUFFERED=1

#
Expand All @@ -14,7 +16,7 @@ RUN PIP="pip --no-cache install" \
$APK_ADD --virtual .build-deps gcc python3-dev \
libffi-dev musl-dev make \
&& $APK_ADD libsodium-dev libsecp256k1-dev gmp-dev \
&& $APK_ADD zeromq-dev \
&& $APK_ADD zeromq-dev findmnt \
&& $PIP install base58 pynacl \
&& $PIP install mnemonic pytezos requests \
&& $PIP install pyblake2 pysodium flask \
Expand Down
Loading