Skip to content

Commit

Permalink
Merge pull request #12 from multiversx/sync-wait
Browse files Browse the repository at this point in the history
Allow one to configure "SyncProcessTimeInMillis" and "MaxHeaderRequestsAllowed"
  • Loading branch information
andreibancioiu authored May 5, 2023
2 parents 0cb4faa + c6aa0e3 commit 6d63baa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501
3 changes: 3 additions & 0 deletions adjust_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ def main(cli_args: List[str]):
parser.add_argument("--file", required=True)
parser.add_argument("--api-simultaneous-requests", type=int, default=16384)
parser.add_argument("--no-snapshots", action="store_true", default=False)
parser.add_argument("--sync-process-time-milliseconds", type=int, default=12000)

parsed_args = parser.parse_args(cli_args)
mode = parsed_args.mode
file = parsed_args.file
api_simultaneous_requests = parsed_args.api_simultaneous_requests
no_snapshots = parsed_args.no_snapshots
snapshots_enabled = not no_snapshots
sync_process_time_milliseconds = parsed_args.sync_process_time_milliseconds

data = toml.load(file)

if mode == MODE_MAIN:
data["GeneralSettings"]["StartInEpochEnabled"] = False
data["GeneralSettings"]["SyncProcessTimeInMillis"] = sync_process_time_milliseconds
data["DbLookupExtensions"]["Enabled"] = True
data["StateTriesConfig"]["AccountsStatePruningEnabled"] = False
data["StateTriesConfig"]["SnapshotsEnabled"] = snapshots_enabled
Expand Down
40 changes: 40 additions & 0 deletions adjust_observer_src.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys
from argparse import ArgumentParser
from pathlib import Path
from typing import List

"""
python3 adjust_observer_src.py --src=...
"""


def main(cli_args: List[str]):
parser = ArgumentParser()
parser.add_argument("--src", type=Path, required=True)
parser.add_argument("--max-headers-to-request-in-advance", type=int, default=20)

parsed_args = parser.parse_args(cli_args)
src = parsed_args.src
max_headers_to_request_in_advance = parsed_args.max_headers_to_request_in_advance

replace_line_in_file(src / "process" / "constants.go", "const MaxHeadersToRequestInAdvance = 20", f"const MaxHeadersToRequestInAdvance = {max_headers_to_request_in_advance}")


def replace_line_in_file(file: Path, old: str, new: str):
lines_input = file.read_text().splitlines()
lines_output: List[str] = []

if old not in lines_input:
raise Exception(f"Line not found in {file}: {old}")

for line in lines_input:
if line == old:
lines_output.append(new)
else:
lines_output.append(line)

file.write_text("\n".join(lines_output) + "\n")


if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit 6d63baa

Please sign in to comment.