def sync_from_primary_validators_initial_block(*, primary_validator): """ Sync from the primary validators initial block (seed_block_identifier or root_account_file_hash) Invoked when self (confirmation validator): - is first being initialized - has a blockchain that is out of sync with the PV """ try: self_configuration = get_self_configuration(exception_class=RuntimeError) download_root_account_file(url=primary_validator.root_account_file) self_configuration.root_account_file = get_root_account_file_url() self_configuration.root_account_file_hash = get_file_hash(settings.ROOT_ACCOUNT_FILE_PATH) self_configuration.seed_block_identifier = primary_validator.seed_block_identifier self_configuration.save() sync_accounts_table_to_root_account_file() except Exception as e: logger.exception(e) raise RuntimeError(e) rebuild_cache(head_block_hash=get_initial_block_identifier()) send_confirmation_block_history_request()
def initialize_validator(self): """ Process to initialize validator: - delete existing SelfConfiguration and related Validator objects - create SelfConfiguration and related Validator objects - create Account objects based on downloaded root_account_file - rebuild cache """ head_block_hash = self.required_input.pop('head_block_hash') node_type = self.required_input.pop('node_type') # Delete existing SelfConfiguration and related Validator objects SelfConfiguration.objects.all().delete() Validator.objects.filter( Q(ip_address=self.required_input['ip_address']) | Q(node_identifier=self.required_input['node_identifier']) ).delete() # Create SelfConfiguration and related Validator objects SelfConfiguration.objects.create(**self.required_input, node_type=node_type) sync_accounts_table_to_root_account_file() # Rebuild cache rebuild_cache(head_block_hash=head_block_hash) delete_all_valid_confirmation_blocks() self.stdout.write( self.style.SUCCESS('Validator initialization complete'))
def handle(self, *args, **options): """ Run script """ valid_environments = ['local', 'postgres_local'] if ENVIRONMENT not in valid_environments: raise RuntimeError( f'DJANGO_APPLICATION_ENVIRONMENT must be in {valid_environments}' ) ip = options['ip'] validate_ipv46_address(ip) self.install_fixture_data() self_configuration = get_self_configuration( exception_class=RuntimeError) SelfConfiguration.objects.filter(pk=self_configuration.id).update( ip_address=ip) rebuild_cache( head_block_hash=self_configuration.root_account_file_hash) self.stdout.write( self.style.SUCCESS('Validator initialization complete'))
def sync_from_primary_validators_initial_block(*, primary_validator): """ Sync from the primary validators initial block (seed_block_identifier or root_account_file_hash) Invoked when self (confirmation validator): - is first being initialized - has a blockchain that is out of sync with the PV """ try: download_root_account_file( url=primary_validator.root_account_file, destination_file_path=settings.LOCAL_ROOT_ACCOUNT_FILE_PATH) file_hash = get_file_hash(settings.LOCAL_ROOT_ACCOUNT_FILE_PATH) # TODO: root_account_file should not be a copy of PVs URL but rather a unique path # TODO: this way, every validator maintains their own copy self_configuration = get_self_configuration( exception_class=RuntimeError) self_configuration.root_account_file = primary_validator.root_account_file self_configuration.root_account_file_hash = file_hash self_configuration.seed_block_identifier = primary_validator.seed_block_identifier self_configuration.save() sync_accounts_table_to_root_account_file() except Exception as e: logger.exception(e) raise RuntimeError(e) rebuild_cache(head_block_hash=get_initial_block_identifier()) send_confirmation_block_history_request()
def confirmation_validator_configuration(monkeypatch): load_validator_fixtures(CONFIRMATION_VALIDATOR_FIXTURES_DIR) monkeypatch.setenv('NETWORK_SIGNING_KEY', '7a3359729b41f953d52818e787a312c8576e179e2ee50a2e4f28c4596b12dce0') self_configuration = get_self_configuration(exception_class=RuntimeError) rebuild_cache(head_block_hash=self_configuration.root_account_file_hash) yield self_configuration