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

Provide API endpoint to shutdown Raiden #6118

Merged
merged 1 commit into from
May 11, 2020
Merged
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 raiden/api/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,3 +1332,6 @@ def get_pending_transfers(
channel_id = partner_channel.identifier

return transfer_tasks_view(transfer_tasks, token_address, channel_id)

def shutdown(self) -> None:
self.raiden.stop()
8 changes: 8 additions & 0 deletions raiden/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
PendingTransfersResourceByTokenAndPartnerAddress,
RaidenInternalEventsResource,
RegisterTokenResource,
ShutdownResource,
StatusResource,
TokensResource,
VersionResource,
Expand Down Expand Up @@ -104,6 +105,7 @@
from raiden.transfer.state import ChannelState, NettingChannelState
from raiden.ui.sync import blocks_to_sync
from raiden.utils.formatting import optional_address_to_string, to_checksum_address
from raiden.utils.gevent import spawn_named
from raiden.utils.http import split_endpoint
from raiden.utils.runnable import Runnable
from raiden.utils.system import get_system_spec
Expand Down Expand Up @@ -166,6 +168,7 @@
"pending_transfers_resource_by_token_and_partner",
),
("/status", StatusResource),
("/shutdown", ShutdownResource),
("/_debug/blockchain_events/network", BlockchainEventsNetworkResource),
("/_debug/blockchain_events/tokens/<hexaddress:token_address>", BlockchainEventsTokenResource),
(
Expand Down Expand Up @@ -1432,3 +1435,8 @@ def get_status(self) -> Response:
return api_response(result=dict(status="syncing", blocks_to_sync=to_sync))
else:
return api_response(result=dict(status="unavailable"))

def shutdown(self) -> Response:
shutdown_greenlet = spawn_named("trigger shutdown", self.raiden_api.shutdown)
shutdown_greenlet.link_exception(self.raiden_api.raiden.on_error)
return api_response(result=dict(status="shutdown"))
6 changes: 6 additions & 0 deletions raiden/api/v1/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,9 @@ def get(self, token_address: TokenAddress, partner_address: Address) -> Response
class StatusResource(BaseResource):
def get(self) -> Response:
return self.rest_api.get_status()


class ShutdownResource(BaseResource):
@if_api_available
def post(self) -> Response:
return self.rest_api.shutdown()
16 changes: 16 additions & 0 deletions raiden/tests/integration/api/rest/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,3 +1244,19 @@ def test_api_testnet_token_mint(api_server_test_instance: APIServer, token_addre
request = grequests.post(url, json=dict(to=user_address[:-2], value=10))
response = request.send().response
assert_response_with_error(response, HTTPStatus.BAD_REQUEST)


@raise_on_failure
@pytest.mark.parametrize("number_of_nodes", [1])
@pytest.mark.parametrize("channels_per_node", [0])
@pytest.mark.parametrize("enable_rest_api", [True])
def test_shutdown(api_server_test_instance: APIServer):
""" Node must stop after shutdown is called """
url = ("http://localhost:{port}/api/v1/shutdown").format(
port=api_server_test_instance.config.port
)
response = grequests.post(url).send().response

assert_response_with_code(response, HTTPStatus.OK)
finished = gevent.joinall({api_server_test_instance}, timeout=10, raise_error=True)
assert finished, "The Raiden node did not shut down!"