diff --git a/ethstaker_deposit/cli/exit_transaction_keystore.py b/ethstaker_deposit/cli/exit_transaction_keystore.py index d74f1ce7..f2812c67 100644 --- a/ethstaker_deposit/cli/exit_transaction_keystore.py +++ b/ethstaker_deposit/cli/exit_transaction_keystore.py @@ -1,5 +1,6 @@ import click import os +import time from typing import Any from ethstaker_deposit.exit_transaction import exit_transaction_generation, export_exit_transaction_json @@ -118,7 +119,7 @@ def exit_transaction_keystore( os.mkdir(folder) click.echo(load_text(['msg_exit_transaction_creation'])) - saved_folder = export_exit_transaction_json(folder=folder, signed_exit=signed_exit) + saved_folder = export_exit_transaction_json(folder=folder, signed_exit=signed_exit, timestamp=time.time()) click.echo(load_text(['msg_verify_exit_transaction'])) if (not verify_signed_exit_json(saved_folder, keystore.pubkey, chain_settings)): diff --git a/ethstaker_deposit/cli/exit_transaction_mnemonic.py b/ethstaker_deposit/cli/exit_transaction_mnemonic.py index 7cd1c2e4..39de5a5f 100644 --- a/ethstaker_deposit/cli/exit_transaction_mnemonic.py +++ b/ethstaker_deposit/cli/exit_transaction_mnemonic.py @@ -1,6 +1,7 @@ import click -import os import concurrent.futures +import os +import time from typing import Any, Sequence, Dict from ethstaker_deposit.cli.existing_mnemonic import load_mnemonic_arguments_decorator @@ -141,6 +142,7 @@ def exit_transaction_mnemonic( 'validator_index': validator_index, 'epoch': epoch, 'folder': folder, + 'timestamp': time.time(), } for credential, validator_index in zip(credentials, validator_indices)] with concurrent.futures.ProcessPoolExecutor() as executor: diff --git a/ethstaker_deposit/cli/generate_keys.py b/ethstaker_deposit/cli/generate_keys.py index 8f9eac02..af27932f 100644 --- a/ethstaker_deposit/cli/generate_keys.py +++ b/ethstaker_deposit/cli/generate_keys.py @@ -1,5 +1,6 @@ -import os import click +import os +import time from typing import ( Any, Callable, @@ -142,8 +143,11 @@ def generate_keys(ctx: click.Context, validator_start_index: int, hex_withdrawal_address=withdrawal_address, use_pbkdf2=pbkdf2 ) - keystore_filefolders = credentials.export_keystores(password=keystore_password, folder=folder) - deposits_file = credentials.export_deposit_data_json(folder=folder) + + timestamp = time.time() + + keystore_filefolders = credentials.export_keystores(password=keystore_password, folder=folder, timestamp=timestamp) + deposits_file = credentials.export_deposit_data_json(folder=folder, timestamp=timestamp) if not credentials.verify_keystores(keystore_filefolders=keystore_filefolders, password=keystore_password): raise ValidationError(load_text(['err_verify_keystores'])) if not verify_deposit_data_json(deposits_file, credentials.credentials): diff --git a/ethstaker_deposit/credentials.py b/ethstaker_deposit/credentials.py index a98f8cb2..ef7f4ea1 100644 --- a/ethstaker_deposit/credentials.py +++ b/ethstaker_deposit/credentials.py @@ -158,9 +158,9 @@ def signing_keystore(self, password: str) -> Keystore: else: return ScryptKeystore.encrypt(secret=secret, password=password, path=self.signing_key_path) - def save_signing_keystore(self, password: str, folder: str) -> str: + def save_signing_keystore(self, password: str, folder: str, timestamp: float) -> str: keystore = self.signing_keystore(password) - filefolder = os.path.join(folder, 'keystore-%s-%i.json' % (keystore.path.replace('/', '_'), time.time())) + filefolder = os.path.join(folder, 'keystore-%s-%i.json' % (keystore.path.replace('/', '_'), timestamp)) keystore.save(filefolder) return filefolder @@ -218,7 +218,7 @@ def get_bls_to_execution_change_dict(self, validator_index: int) -> Dict[str, by result_dict.update({'metadata': metadata}) return result_dict - def save_exit_transaction(self, validator_index: int, epoch: int, folder: str) -> str: + def save_exit_transaction(self, validator_index: int, epoch: int, folder: str, timestamp: float) -> str: signing_key = self.signing_sk signed_voluntary_exit = exit_transaction_generation( @@ -228,7 +228,7 @@ def save_exit_transaction(self, validator_index: int, epoch: int, folder: str) - epoch=epoch ) - return export_exit_transaction_json(folder=folder, signed_exit=signed_voluntary_exit) + return export_exit_transaction_json(folder=folder, signed_exit=signed_voluntary_exit, timestamp=timestamp) def _credential_builder(kwargs: Dict[str, Any]) -> Credential: @@ -297,7 +297,7 @@ def from_mnemonic(cls, bar.update(1) return cls(credentials) - def export_keystores(self, password: str, folder: str) -> List[str]: + def export_keystores(self, password: str, folder: str, timestamp: float) -> List[str]: filefolders: List[str] = [] with click.progressbar(length=len(self.credentials), label=load_text(['msg_keystore_creation']), show_percent=False, show_pos=True) as bar: @@ -305,6 +305,7 @@ def export_keystores(self, password: str, folder: str) -> List[str]: 'credential': credential, 'password': password, 'folder': folder, + 'timestamp': timestamp, } for credential in self.credentials] with concurrent.futures.ProcessPoolExecutor() as executor: @@ -313,7 +314,7 @@ def export_keystores(self, password: str, folder: str) -> List[str]: bar.update(1) return filefolders - def export_deposit_data_json(self, folder: str) -> str: + def export_deposit_data_json(self, folder: str, timestamp: float) -> str: deposit_data = [] with click.progressbar(length=len(self.credentials), label=load_text(['msg_depositdata_creation']), show_percent=False, show_pos=True) as bar: @@ -323,7 +324,7 @@ def export_deposit_data_json(self, folder: str) -> str: deposit_data.append(datum_dict) bar.update(1) - filefolder = os.path.join(folder, 'deposit_data-%i.json' % time.time()) + filefolder = os.path.join(folder, 'deposit_data-%i.json' % timestamp) with open(filefolder, 'w') as f: json.dump(deposit_data, f, default=lambda x: x.hex()) if os.name == 'posix': diff --git a/ethstaker_deposit/exit_transaction.py b/ethstaker_deposit/exit_transaction.py index 570ea2ab..d0d3b49f 100644 --- a/ethstaker_deposit/exit_transaction.py +++ b/ethstaker_deposit/exit_transaction.py @@ -1,6 +1,5 @@ import json import os -import time from typing import Any, Dict from py_ecc.bls import G2ProofOfPossession as bls @@ -39,7 +38,7 @@ def exit_transaction_generation( return signed_exit -def export_exit_transaction_json(folder: str, signed_exit: SignedVoluntaryExit) -> str: +def export_exit_transaction_json(folder: str, signed_exit: SignedVoluntaryExit, timestamp: float) -> str: signed_exit_json: Dict[str, Any] = {} message = { 'epoch': str(signed_exit.message.epoch), # type: ignore[attr-defined] @@ -51,7 +50,8 @@ def export_exit_transaction_json(folder: str, signed_exit: SignedVoluntaryExit) filefolder = os.path.join( folder, 'signed_exit_transaction-%s-%i.json' % ( - signed_exit.message.validator_index, time.time() # type: ignore[attr-defined] + signed_exit.message.validator_index, # type: ignore[attr-defined] + timestamp, ) ) diff --git a/tests/test_cli/test_exit_transaction_keystore.py b/tests/test_cli/test_exit_transaction_keystore.py index 12c20c38..2aa6f090 100644 --- a/tests/test_cli/test_exit_transaction_keystore.py +++ b/tests/test_cli/test_exit_transaction_keystore.py @@ -1,4 +1,5 @@ import os +import time from click.testing import CliRunner @@ -41,7 +42,7 @@ def test_exit_transaction_keystore() -> None: ) # Save keystore file - keystore_filepath = credential.save_signing_keystore(keystore_password, exit_transaction_folder_path) + keystore_filepath = credential.save_signing_keystore(keystore_password, exit_transaction_folder_path, time.time()) runner = CliRunner() arguments = [ @@ -126,10 +127,12 @@ def test_exit_transaction_with_pbkdf2() -> None: pbkdf2_keystore_filepath = pbkdf2_credential.save_signing_keystore( keystore_password, pbkdf2_exit_transaction_folder_path, + time.time(), ) scrypt_keystore_filepath = scrypt_credential.save_signing_keystore( keystore_password, scrypt_exit_transaction_folder_path, + time.time(), ) runner = CliRunner() @@ -260,7 +263,7 @@ def test_invalid_keystore_password() -> None: ) # Save keystore file - keystore_filepath = credential.save_signing_keystore(keystore_password, exit_transaction_folder_path) + keystore_filepath = credential.save_signing_keystore(keystore_password, exit_transaction_folder_path, time.time()) runner = CliRunner() inputs = [] data = '\n'.join(inputs)