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

fix(forknet): Fix the state parts bucket cleanup logic #12712

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
31 changes: 17 additions & 14 deletions pytest/tests/mocknet/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ def _clear_state_parts_if_exists(location, nodes):
if location is None:
return

state_dumper_node = next(filter(lambda n: n.want_state_dump, nodes), None)
if state_dumper_node is None:
logger.info('No state dumper node found, skipping state parts cleanup.')
return
logger.info('State dumper node found, cleaning up state parts.')

if location.get('Filesystem') is not None:
root_dir = location['Filesystem']['root_dir']
shutil.rmtree(root_dir)
Expand All @@ -253,13 +259,7 @@ def _clear_state_parts_if_exists(location, nodes):
# bucket where it dumped the parts.
bucket_name = location['GCS']['bucket']

state_dumper_node = next(filter(lambda n: n.want_state_dump, nodes), None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you move this block to line 247?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this function _clear_state_parts_if_exists, we want to check if the state parts exist and then clear them.

Previously, we assumed that if we are in a localtest, we always dump the parts, but is not the case.
With this change, we will make it clear to the mirror.py user if the parts were deleted or not.

if state_dumper_node is None:
logger.info('No state dumper node found, skipping state parts cleanup.')
return

logger.info('State dumper node found, cleaning up state parts.')
state_dumper_node.run_cmd(f'gsutil -m rm -r gs://{bucket_name}/chain_id=\*',
state_dumper_node.run_cmd(f'gsutil -m rm -r gs://{bucket_name}/chain_id=*',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python complains about the \* as it tries to parse it as an escape sequence. It should be safe to pass it here without escaping it.

return_on_fail=True)


Expand All @@ -276,11 +276,7 @@ def _get_state_parts_location(args):
'state-parts')
}
}
else:
if args.gcs_state_sync:
return {"GCS": {"bucket": _get_state_parts_bucket_name(args)}}
else:
return None
return {"GCS": {"bucket": _get_state_parts_bucket_name(args)}}


def new_test_cmd(args, traffic_generator, nodes):
Expand Down Expand Up @@ -320,7 +316,9 @@ def new_test_cmd(args, traffic_generator, nodes):
args.genesis_protocol_version,
genesis_time=genesis_time), targeted)

location = _get_state_parts_location(args)
location = None
if args.gcs_state_sync:
location = _get_state_parts_location(args)
logger.info('Applying default config changes')
pmap(lambda node: _apply_config_changes(node, location), targeted)

Expand Down Expand Up @@ -624,7 +622,12 @@ def __call__(self, parser, namespace, values, option_string=None):
new_test_parser.add_argument('--new-chain-id', type=str)
new_test_parser.add_argument('--genesis-protocol-version', type=int)
new_test_parser.add_argument('--stateless-setup', action='store_true')
new_test_parser.add_argument('--gcs-state-sync', action='store_true')
new_test_parser.add_argument(
'--gcs-state-sync',
action='store_true',
help=
"""Enable state dumper nodes to sync state to GCS. On localtest, it will dump locally."""
)
new_test_parser.add_argument('--yes', action='store_true')
new_test_parser.set_defaults(func=new_test_cmd)

Expand Down
Loading