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

Fixes #3028

Merged
merged 11 commits into from
Feb 19, 2025
Merged

Fixes #3028

Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/integrations_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
- name: Testnet4 Bootstrap And Catchup
test-path: integrations/testnet4_test.py

- name: Testnet4 Start and Shutdown
test-path: integrations/shutdown_test.py

# Other tests

# run the docker-compose tests
Expand Down
15 changes: 9 additions & 6 deletions counterparty-core/counterpartycore/lib/api/apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,9 @@
logger.info("Starting API Server process...")

def handle_interrupt_signal(signum, frame):
logger.warning("Keyboard interrupt received. Shutting down...")
raise KeyboardInterrupt
pass

Check warning on line 496 in counterparty-core/counterpartycore/lib/api/apiserver.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/apiserver.py#L496

Added line #L496 was not covered by tests
# logger.warning("Keyboard interrupt received. Shutting down...")
# raise KeyboardInterrupt

wsgi_server = None
parent_checker = None
Expand Down Expand Up @@ -524,7 +525,11 @@
app = init_flask_app()
app.shared_backend_height = shared_backend_height

wsgi_server = wsgi.WSGIApplication(app, args=args)
try:
wsgi_server = wsgi.WSGIApplication(app, args=args)
except OSError as e:
logger.error(f"Error starting WSGI Server: {e}")
exit(1)

Check warning on line 532 in counterparty-core/counterpartycore/lib/api/apiserver.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/apiserver.py#L530-L532

Added lines #L530 - L532 were not covered by tests

Check warning

Code scanning / pylint

Consider using 'sys.exit' instead. Warning

Consider using 'sys.exit' instead.

logger.info("Starting Parent Process Checker thread...")
parent_checker = ParentProcessChecker(wsgi_server, stop_event, parent_pid)
Expand All @@ -535,9 +540,6 @@

wsgi_server.run(server_ready_value, shared_backend_height)

except KeyboardInterrupt:
pass

finally:
logger.info("Stopping API Server...")

Expand All @@ -554,6 +556,7 @@
watcher.join()

logger.info("API Server stopped.")
server_ready_value.value = 2


# This thread is used for the following two reasons:
Expand Down
8 changes: 5 additions & 3 deletions counterparty-core/counterpartycore/lib/api/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def spawn_worker(self):
logger.info("Worker exiting (pid: %s)", worker.pid)
try:
worker.tmp.close()
self.cfg.worker_exit(self, worker)
sys.exit(-1)
# self.cfg.worker_exit(self, worker)
except Exception:
logger.warning("Exception during worker exit")

Expand Down Expand Up @@ -206,7 +207,7 @@ def __init__(self, app, args=None):
self.arbiter = None
self.ledger_db = None
self.state_db = None

self.current_state_thread = None
self.master_pid = os.getpid()
super().__init__()

Expand Down Expand Up @@ -236,7 +237,8 @@ def run(self, server_ready_value, shared_backend_height):
sys.exit(1)

def stop(self):
self.current_state_thread.stop()
if self.current_state_thread:
self.current_state_thread.stop()
if self.arbiter and self.master_pid == os.getpid():
logger.info("Stopping Gunicorn")
self.arbiter.kill_all_workers()
Expand Down
3 changes: 3 additions & 0 deletions counterparty-core/counterpartycore/lib/backend/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from requests.exceptions import ChunkedEncodingError, ConnectionError, ReadTimeout, Timeout

from counterpartycore.lib import config, exceptions
from counterpartycore.lib.ledger.currentstate import CurrentState
from counterpartycore.lib.parser import deserialize, utxosinfo

logger = logging.getLogger(config.LOGGER_NAME)
Expand All @@ -36,6 +37,8 @@

# for testing
def should_retry():
if CurrentState().block_parser_status() == "Stopping":
return False

Check warning on line 41 in counterparty-core/counterpartycore/lib/backend/bitcoind.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/backend/bitcoind.py#L40-L41

Added lines #L40 - L41 were not covered by tests
return True


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def __init__(self, indexer_config=None):
self.config["log_level"] = config.LOG_LEVEL_STRING
else:
logger.warning("Using custom indexer config.")
print(indexer_config)
self.config = indexer_config
self.config["network"] = config.NETWORK_NAME
self.fetcher = None
Expand Down
14 changes: 8 additions & 6 deletions counterparty-core/counterpartycore/lib/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ def float_range_checker(arg):
"help": "Don't parse new blocks, only run the API server",
},
],
[
("--catch-up",),
{
"choices": ["normal", "bootstrap", "bootstrap-always"],
"default": "normal",
"help": "Catch up mode (default: normal)",
},
],
]


Expand Down Expand Up @@ -457,12 +465,6 @@ def arg_parser(no_config_file=False, app_name=APP_NAME):

parser_server = subparsers.add_parser("start", help="run the server")
parser_server.add_argument("--config-file", help="the path to the configuration file")
parser_server.add_argument(
"--catch-up",
choices=["normal", "bootstrap", "bootstrap-always"],
default="normal",
help="Catch up mode (default: normal)",
)
setup.add_config_arguments(parser_server, CONFIG_ARGS, configfile)

parser_reparse = subparsers.add_parser(
Expand Down
Loading
Loading