code: def _add_blockhash_to_events(storage: SQLiteStorage, cache: BlockHashCache) -> None:
      
      batch_query = storage.batch_query_event_records(
          batch_size=500,
          filters=[('_type', 'raiden.transfer.events.ContractSend%')],
      )
      for events_batch in batch_query:
          updated_events = []
          for event in events_batch:
              data = json.loads(event.data)
              assert 'triggered_by_block_hash' not in data, 'v18 events cant contain blockhash'
              # Get the state_change that triggered the event and get its hash
              matched_state_changes = storage.get_statechanges_by_identifier(
                  from_identifier=event.state_change_identifier,
                  to_identifier=event.state_change_identifier,
              )
              result_length = len(matched_state_changes)
              msg = 'multiple state changes should not exist for the same identifier'
              assert result_length == 1, msg
  
              statechange_data = json.loads(matched_state_changes[0])
              if 'block_hash' in statechange_data:
                  data['triggered_by_block_hash'] = statechange_data['block_hash']
              elif 'block_number' in statechange_data:
                  block_number = int(statechange_data['block_number'])
                  data['triggered_by_block_hash'] = cache.get(block_number)
  
              updated_events.append((
                  json.dumps(data),
                  event.event_identifier,
              ))
  
          storage.update_events(updated_events)
docs: Adds blockhash to all ContractSendXXX events