Skip to content

Commit 0dddf42

Browse files
committed
update archive ttl question
1 parent d2b5d1c commit 0dddf42

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

scripts/install.py

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,53 @@
1+
import datetime
12
import os
23
import subprocess
4+
import time
35
import inquirer
6+
import requests
7+
8+
9+
def get_archive_ttl_message(answers: dict):
10+
global default_archive_ttl
11+
archive_blocks = answers.get('archive-blocks')
12+
if not archive_blocks and answers['archive-blocks'] != 0:
13+
return 'Send the number of seconds to keep the block data in the node database. Default is 2592000 (30 days)'
14+
block_from = archive_blocks.split()[0]
15+
# or sent -1 to store downloaded blocks always
16+
if block_from.isdigit():
17+
seqno = int(block_from)
18+
url = f'https://toncenter.com/api/v2/getBlockHeader?workchain=-1&shard={-2**63}&seqno={seqno}'
19+
if answers['network'] == 'Testnet':
20+
url = url.replace('toncenter.com', 'testnet.toncenter.com')
21+
data = requests.get(url).json()
22+
utime = int(data['result']['gen_utime'])
23+
else:
24+
utime = int(datetime.datetime.strptime(block_from, '%Y-%m-%d').timestamp())
25+
default_archive_ttl = int(time.time() - (utime - datetime.timedelta(days=30).total_seconds()))
26+
answers['archive-ttl-default'] = default_archive_ttl
27+
return f'Send the number of seconds to keep the block data in the node database. Default is {default_archive_ttl} to keep archive blocks from {datetime.datetime.fromtimestamp(utime - datetime.timedelta(days=30).total_seconds())}\nOr send -1 to keep downloaded blocks always (recommended).'
28+
29+
30+
def is_valid_date_format(date_str):
31+
try:
32+
datetime.datetime.strptime(date_str, '%Y-%m-%d')
33+
return True
34+
except ValueError:
35+
return False
36+
37+
38+
def validate_archive_blocks(_, value):
39+
if not value:
40+
return True
41+
parts = value.split()
42+
if len(parts) > 2:
43+
return False
44+
45+
for part in parts:
46+
if part.isdigit() and int(part) < 0:
47+
return False
48+
elif not is_valid_date_format(part):
49+
return False
50+
return True
451

552

653
def run_cli():
@@ -21,13 +68,6 @@ def run_cli():
2168
ignore=lambda x: x["network"] != "Other", # do not ask this question if network is not 'Other'
2269
validate=lambda _, x: x.startswith("http"),
2370
),
24-
inquirer.Text(
25-
"archive-ttl",
26-
message="Send the number of seconds to keep the block data in the node database. Default is 2592000 (30 days)",
27-
ignore=lambda x: x["mode"] != "liteserver", # do not ask this question if mode is not liteserver
28-
validate=lambda _, x: not x or x.isdigit(), # must be empty string or a number
29-
# default=2592000
30-
),
3171
inquirer.List(
3272
"validator-mode",
3373
message="Select mode for validator usage. You can skip and set up this later",
@@ -36,9 +76,18 @@ def run_cli():
3676
),
3777
inquirer.Text(
3878
"archive-blocks",
39-
message="Do you want to download archive blocks via TON Storage? If yes, provide block seqno to start from or press Enter to skip.",
79+
message="Do you want to download archive blocks via TON Storage? Press Enter to skip.\n"
80+
"If yes, provide block seqno or date to start from and (optionally) block seqno or date to end with (send 0 to download all blocks and setup full archive node).\n"
81+
"Examples: `30850000`, `10000000 10200000`, `2025-01-01`, `2025-01-01 2025-01-30`",
4082
ignore=lambda x: x["mode"] == "validator",
41-
validate=lambda _, x: not x or (x.isdigit() and int(x) >= 0),
83+
validate=validate_archive_blocks,
84+
),
85+
inquirer.Text(
86+
"archive-ttl",
87+
message=get_archive_ttl_message,
88+
ignore=lambda x: x["mode"] != "liteserver", # do not ask this question if mode is not liteserver
89+
validate=lambda _, x: not x or x.isdigit(), # must be empty string or a number
90+
# default=get_default_archive_ttl
4291
),
4392
inquirer.Confirm(
4493
"dump",
@@ -64,7 +113,7 @@ def parse_args(answers: dict):
64113
mode = answers["mode"]
65114
network = answers["network"].lower()
66115
config = answers["config"]
67-
archive_ttl = answers["archive-ttl"]
116+
archive_ttl = answers["archive-ttl"] or answers.get("archive-ttl-default")
68117
add_shard = answers["add-shard"]
69118
validator_mode = answers["validator-mode"]
70119
archive_blocks = answers["archive-blocks"]

0 commit comments

Comments
 (0)