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

feature: Add script to download ledger snapshot and options #130

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
339d56d
Add script to download ledger snapshot and options
alpeto9 Oct 8, 2024
7f43d7e
Create dockefile for docker-compose
alpeto9 Oct 8, 2024
640b3da
Change data directory
alpeto9 Oct 8, 2024
8a5b127
Add download_community_snapshot option
alpeto9 Oct 16, 2024
0eae410
Change ledger directory to db.location
alpeto9 Oct 16, 2024
00b1546
Change downloadcommunitysnapshot argument
alpeto9 Oct 16, 2024
a05bcc5
Add download snapshot ledger question
alpeto9 Oct 16, 2024
7e792bb
Change input question
alpeto9 Oct 16, 2024
1bf8668
Fix downloading issue
alpeto9 Oct 16, 2024
0ae0472
Restoring the snapshot
alpeto9 Oct 16, 2024
a24ba3f
Download image instead of building
alpeto9 Oct 17, 2024
f9db1e2
Only extract when download
alpeto9 Oct 17, 2024
66cc2bc
Inline dockerfile
alpeto9 Oct 18, 2024
28c8429
Inline dockerfile settings
alpeto9 Oct 18, 2024
28ee53c
Cleanup
alpeto9 Oct 18, 2024
5b6b4b7
Cleanup
alpeto9 Oct 22, 2024
838e420
Formatting BaseSetup.py
alpeto9 Oct 22, 2024
147ab32
Formatting dockercommand.py
alpeto9 Oct 22, 2024
65698c7
fix tests
alpeto9 Oct 22, 2024
6ade81f
Fix typo
alpeto9 Oct 22, 2024
27bc4d3
Fix typo
alpeto9 Oct 22, 2024
e1a8a0d
Fix typo on tests
alpeto9 Oct 22, 2024
6a9cce3
Fix tetsts
alpeto9 Oct 22, 2024
064ba30
Fix tests
alpeto9 Oct 22, 2024
79633bb
Fix tests
alpeto9 Oct 22, 2024
8947a24
Disable snapshot download on test
alpeto9 Oct 22, 2024
1f8df50
add python code to download snapshots
shambupujar Nov 20, 2024
79bfa59
Use separate command for radix ledger snapshot download
shambupujar Nov 26, 2024
497ff4a
Revert previous implementation on docker command
shambupujar Nov 27, 2024
e55c731
Lint fixes
shambupujar Nov 27, 2024
689402c
Fix the missing bracket
shambupujar Nov 27, 2024
fe7bf12
Fix formatting
shambupujar Nov 27, 2024
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
12 changes: 11 additions & 1 deletion node-runner-cli/commands/dockercommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ def dockercommand(dockercommand_args=[], parent=docker_parser):
default="",
choices=["true", "false"],
),
argument(
"-dcs",
"--downloadcommunitysnapshot",
help="Boolean to indicate if in case of empty ledger, download latest community snapshot"
"Set this to false to not download the latest community snapshot"
f"The default value is true if not provided",
default="true",
action="store",
choices=["true", "false"],
)
]
)
def config(args):
Expand Down Expand Up @@ -229,7 +239,7 @@ def config(args):
help="Pass this option to update the deployed softwares to latest version."
" CLI prompts to confirm the versions if '-a' is not passed",
action="store_true",
),
)
]
)
def install(args):
Expand Down
8 changes: 8 additions & 0 deletions node-runner-cli/config/CoreDockerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, config_dict: dict):
self.core_release: str = ""
self.repo: str = os.getenv(CORE_DOCKER_REPO_OVERRIDE, "radixdlt/babylon-node")
self.data_directory: str = f"{Helpers.get_home_dir()}/babylon-ledger"
self.download_community_snapshot: bool = True
self.trusted_node: str = ""
self.memory_limit: str = "14000m"
self.validator_address: str = ""
Expand Down Expand Up @@ -53,6 +54,12 @@ def ask_data_directory(self):
if self.data_directory:
Path(self.data_directory).mkdir(parents=True, exist_ok=True)

def ask_download_community_sanpshot(self):
alpeto9 marked this conversation as resolved.
Show resolved Hide resolved
if "DETAILED" in SetupMode.instance().mode:
self.download_community_snapshot = (
BaseSetup.get_download_community_snapshot()
)

def set_trusted_node(self, trusted_node):
if not trusted_node:
trusted_node = Prompts.ask_trusted_node()
Expand All @@ -64,6 +71,7 @@ def ask_config(self, release, trustednode, ks_password, new_keystore, validator)
self.ask_validator_address(validator)
self.keydetails = BaseSetup.ask_keydetails(ks_password, new_keystore)
self.ask_data_directory()
self.ask_download_community_sanpshot()
return self

def set_validator_address(self, validator_address: str):
Expand Down
19 changes: 19 additions & 0 deletions node-runner-cli/setup/BaseSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ def get_data_dir(create_dir=True):
run_shell_command(f"sudo mkdir -p {data_dir_path}", shell=True)
return data_dir_path

@staticmethod
def get_download_community_snapshot():
Helpers.section_headline("DOWNLOAD COMMUNITY SNAPSHOT")
print(f"\n Latest snapshot version of the ledger can be downloaded")
download_community_snapshot_string = Helpers.input_guestion(
f"\nRadix node stores all the ledger data on a folder."
f"Downloading latest snapshot of the ledger will allow to sync faster when starting the node"
f"if the ledger folder is empty."
f"\n{bcolors.WARNING}Press Enter to accept default or choose to download latest snapshot of the ledger [true/false]: ",
QuestionKeys.input_download_snapshot_ledger,
)
if download_community_snapshot_string == "":
download_community_snapshot = True
elif download_community_snapshot_string == "false":
download_community_snapshot = False
else:
download_community_snapshot = True
return download_community_snapshot

@staticmethod
def load_all_config(configfile):
yaml.add_representer(type(None), Helpers.represent_none)
Expand Down
59 changes: 59 additions & 0 deletions node-runner-cli/templates/radix-fullnode-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,72 @@
version: '3.8'
services:
{% if core_node is not none and core_node is defined %}
{% if core_node.download_community_snapshot == true %}
download-community-ledger-snapshot:
alpeto9 marked this conversation as resolved.
Show resolved Hide resolved
build:
context: .
dockerfile_inline: |
FROM ubuntu:20.04 as BUILD
# Install necessary dependencies
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
wget \
zstd \
bash \
build-essential \
curl \
bash \
aria2 \
zstd \
&& rm -rf /var/lib/apt/lists/*
# Create the /usr/local/scripts directory
RUN mkdir -p /usr/local/scripts
RUN echo '#!/bin/bash\n\
DATA_DIR=$${1:-"/data"}\n\
if [ ! -d "$$DATA_DIR" ]; then\n\
echo "Creating $$DATA_DIR directory..."\n\
mkdir -p "\$$DATA_DIR"\n\
fi\n\

if [ -z "$(ls -A "$$DATA_DIR")" ]; then\n\
cd $$DATA_DIR\n\
echo "Directory $$DATA_DIR is empty. Downloading LedgerSnapshot..."\n\
echo "Fetching and executing the latest snapshot script from Radix..."\n\
wget https://snapshots.radix.live/latest-snapshot-INDEX.sh --no-check-certificate\n\
echo "Starting snapshot download"\n\
bash latest-snapshot-INDEX.sh\n\

if [ $? -eq 0 ]; then\n\
echo "Snapshot download and execution completed successfully."\n\
else\n\
echo "Snapshot download or execution failed."\n\
exit 1\n\
fi\n\
tar --use-compress-program=zstdmt -xvf RADIXDB-INDEX.tar.zst --exclude=./address_book -C .\n\
rm -rf RADIXDB-INDEX.*\n\
rm -rf latest-snapshot-INDEX.sh*\n\
echo "Snapshot restored"\n\
else\n\
echo "Directory $$DATA_DIR is not empty. Downloading Ledger Snapshot aborted:"\n\
ls -l "$$DATA_DIR"\n\
fi' > /usr/local/scripts/downloadLedgerSnapshot.sh
RUN chmod +x /usr/local/scripts/downloadLedgerSnapshot.sh
ENTRYPOINT ["/usr/local/scripts/downloadLedgerSnapshot.sh"]
volumes:
- {{ core_node.data_directory }}:{{ core_node.data_directory }}
entrypoint: ["/usr/local/scripts/downloadLedgerSnapshot.sh", {{ core_node.data_directory }}] # Pass the environment variable as an argument
{% endif %}
core:
cap_add:
- NET_ADMIN
{% if core_node.advanced_user_envs is defined and core_node.advanced_user_envs is not none %}
env_file:
- {{core_node.advanced_user_envs}}
{% endif %}
{% if core_node.download_community_snapshot == true %}
depends_on:
- download-community-ledger-snapshot
{% endif %}
environment:
JAVA_OPTS: {{core_node.java_opts or '--enable-preview -server -Xms12g -Xmx12g -XX:MaxDirectMemorySize=2048m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseCompressedOops -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStoreType=jks -Djava.security.egd=file:/dev/urandom -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector'}}
RADIXDLT_CORE_API_PORT: {{core_node.core_api_port}}
Expand Down
2 changes: 1 addition & 1 deletion node-runner-cli/templates/systemd-default.config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

ntp=false
ntp.pool=pool.ntp.org

download_community_snapshot=true
shambupujar marked this conversation as resolved.
Show resolved Hide resolved
network.id={{common_config.network_id}}
{% if common_config.genesis_bin_data_file is not none %}
network.genesis_data_file={{common_config.genesis_bin_data_file}}
Expand Down
1 change: 1 addition & 0 deletions node-runner-cli/utils/PromptFeeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class QuestionKeys:
input_path_keystore = "input_path_keystore"
enter_keystore_name = "enter_keystore_name"
input_ledger_path = "input_ledger_path"
input_download_snapshot_ledger = "input_download_snapshot_ledger"
core_nginx_setup = "core_nginx_setup"
gateway_nginx_setup = "gateway_nginx_setup"
setup_gateway = "setup_gateway"
Expand Down
Loading