From bda7a6b7ca25da8c1328cc36888b402e42dba293 Mon Sep 17 00:00:00 2001 From: alwx Date: Thu, 21 Mar 2024 18:27:28 +0100 Subject: [PATCH] Extend peersyncing to sync 1-to-1 messages --- appdatabase/migrations/bindata.go | 588 +++++++++++------- ...4_rename_peersyncing_group_id_field.up.sql | 5 + protocol/common/message_sender.go | 4 +- protocol/messenger.go | 3 +- protocol/messenger_handler.go | 2 +- protocol/messenger_peersyncing.go | 94 ++- protocol/messenger_peersyncing_test.go | 98 ++- protocol/peersyncing/peersyncing.go | 19 +- protocol/peersyncing/peersyncing_test.go | 39 +- protocol/peersyncing/sync_message.go | 4 +- .../peersyncing/sync_message_persistence.go | 72 +-- 11 files changed, 592 insertions(+), 336 deletions(-) create mode 100644 appdatabase/migrations/sql/1711573194_rename_peersyncing_group_id_field.up.sql diff --git a/appdatabase/migrations/bindata.go b/appdatabase/migrations/bindata.go index 24fc8c522b5..81db1b9642b 100644 --- a/appdatabase/migrations/bindata.go +++ b/appdatabase/migrations/bindata.go @@ -110,6 +110,7 @@ // 1708416025_make_sepolia_default.up.sql (81B) // 1709203128_fix_chain_colors.up.sql (244B) // 1709795716_migration_order_fix.up.sql (7.909kB) +// 1711573194_rename_peersyncing_group_id_field.up.sql (201B) // doc.go (94B) package migrations @@ -120,6 +121,7 @@ import ( "crypto/sha256" "fmt" "io" + "io/ioutil" "os" "path/filepath" "strings" @@ -129,7 +131,7 @@ import ( func bindataRead(data []byte, name string) ([]byte, error) { gz, err := gzip.NewReader(bytes.NewBuffer(data)) if err != nil { - return nil, fmt.Errorf("read %q: %w", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } var buf bytes.Buffer @@ -137,7 +139,7 @@ func bindataRead(data []byte, name string) ([]byte, error) { clErr := gz.Close() if err != nil { - return nil, fmt.Errorf("read %q: %w", name, err) + return nil, fmt.Errorf("read %q: %v", name, err) } if clErr != nil { return nil, err @@ -2378,6 +2380,26 @@ func _1709795716_migration_order_fixUpSql() (*asset, error) { return a, nil } +var __1711573194_rename_peersyncing_group_id_fieldUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\xf0\xf4\x73\x71\x8d\x50\x28\x48\x4d\x2d\x2a\xae\xcc\x4b\xce\xcc\x4b\x8f\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\x8e\x2f\xc9\xcc\x4d\x2d\x2e\x49\xcc\x2d\xb0\xe6\xe2\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x71\xc5\xaa\x58\x21\xc8\xd5\xcf\xd1\xd7\x55\xc1\xd9\xdf\x27\xd4\xd7\x4f\x21\xbd\x28\xbf\xb4\x20\x3e\x33\x45\x21\xc4\x5f\x21\x39\x23\xb1\x24\x3e\x33\xc5\x9a\x8b\xcb\x39\xc8\xd5\x31\xc4\x95\x28\x2b\x15\xfc\xfd\xb0\xaa\xd0\x80\x9a\xa6\xa3\x00\x57\xaa\x69\x0d\x08\x00\x00\xff\xff\x89\x24\xd8\xd5\xc9\x00\x00\x00") + +func _1711573194_rename_peersyncing_group_id_fieldUpSqlBytes() ([]byte, error) { + return bindataRead( + __1711573194_rename_peersyncing_group_id_fieldUpSql, + "1711573194_rename_peersyncing_group_id_field.up.sql", + ) +} + +func _1711573194_rename_peersyncing_group_id_fieldUpSql() (*asset, error) { + bytes, err := _1711573194_rename_peersyncing_group_id_fieldUpSqlBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "1711573194_rename_peersyncing_group_id_field.up.sql", size: 201, mode: os.FileMode(0644), modTime: time.Unix(1700000000, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x11, 0x8a, 0x30, 0xed, 0x4, 0x7, 0x86, 0xb, 0xe1, 0x7a, 0xc0, 0x14, 0x73, 0x66, 0xb6, 0x5e, 0x89, 0x4e, 0xf8, 0x4d, 0x2d, 0x3d, 0xe9, 0x18, 0x29, 0x22, 0x97, 0x18, 0xee, 0x9e, 0x66, 0xf8}} + return a, nil +} + var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\xcb\x41\x0e\x02\x31\x08\x05\xd0\x7d\x4f\xf1\x2f\x00\xe8\xca\xc4\xc4\xc3\xa0\x43\x08\x19\x5b\xc6\x96\xfb\xc7\x4d\xdf\xfe\x5d\xfa\x39\xd5\x0d\xeb\xf7\x6d\x4d\xc4\xf3\xe9\x36\x6c\x6a\x19\x3c\xe9\x1d\xe3\xd0\x52\x50\xcf\xa3\xa2\xdb\xeb\xfe\xb8\x6d\xa0\xeb\x74\xf4\xf0\xa9\x15\x39\x16\x28\xc1\x2c\x7b\xb0\x27\x58\xda\x3f\x00\x00\xff\xff\x57\xd4\xd5\x90\x5e\x00\x00\x00") func docGoBytes() ([]byte, error) { @@ -2489,121 +2511,230 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ - "1640111208_dummy.up.sql": _1640111208_dummyUpSql, - "1642666031_add_removed_clock_to_bookmarks.up.sql": _1642666031_add_removed_clock_to_bookmarksUpSql, - "1643644541_gif_api_key_setting.up.sql": _1643644541_gif_api_key_settingUpSql, - "1644188994_recent_stickers.up.sql": _1644188994_recent_stickersUpSql, - "1646659233_add_address_to_dapp_permisssion.up.sql": _1646659233_add_address_to_dapp_permisssionUpSql, - "1646841105_add_emoji_account.up.sql": _1646841105_add_emoji_accountUpSql, - "1647278782_display_name.up.sql": _1647278782_display_nameUpSql, - "1647862838_reset_last_backup.up.sql": _1647862838_reset_last_backupUpSql, - "1647871652_add_settings_sync_clock_table.up.sql": _1647871652_add_settings_sync_clock_tableUpSql, - "1647880168_add_torrent_config.up.sql": _1647880168_add_torrent_configUpSql, - "1647882837_add_communities_settings_table.up.sql": _1647882837_add_communities_settings_tableUpSql, - "1647956635_add_waku_messages_table.up.sql": _1647956635_add_waku_messages_tableUpSql, - "1648554928_network_test.up.sql": _1648554928_network_testUpSql, - "1649174829_add_visitble_token.up.sql": _1649174829_add_visitble_tokenUpSql, - "1649882262_add_derived_from_accounts.up.sql": _1649882262_add_derived_from_accountsUpSql, - "1650612625_add_community_message_archive_hashes_table.up.sql": _1650612625_add_community_message_archive_hashes_tableUpSql, - "1650616788_add_communities_archives_info_table.up.sql": _1650616788_add_communities_archives_info_tableUpSql, - "1652715604_add_clock_accounts.up.sql": _1652715604_add_clock_accountsUpSql, - "1653037334_add_notifications_settings_table.up.sql": _1653037334_add_notifications_settings_tableUpSql, - "1654702119_add_mutual_contact_settings.up.sql": _1654702119_add_mutual_contact_settingsUpSql, - "1655375270_add_clock_field_to_communities_settings_table.up.sql": _1655375270_add_clock_field_to_communities_settings_tableUpSql, - "1655385721_drop_networks_config.up.sql": _1655385721_drop_networks_configUpSql, - "1655385724_networks_chainColor_shortName.up.sql": _1655385724_networks_chaincolor_shortnameUpSql, - "1655456688_add_deleted_at_field_to_bookmarks_table.up.sql": _1655456688_add_deleted_at_field_to_bookmarks_tableUpSql, - "1655462032_create_bookmarks_deleted_at_index.up.sql": _1655462032_create_bookmarks_deleted_at_indexUpSql, - "1657617291_add_multi_transactions_table.up.sql": _1657617291_add_multi_transactions_tableUpSql, - "1660134042_add_social_links_settings_table.up.sql": _1660134042_add_social_links_settings_tableUpSql, - "1660134060_settings_bio.up.sql": _1660134060_settings_bioUpSql, - "1660134070_add_wakuv2_store.up.sql": _1660134070_add_wakuv2_storeUpSql, - "1660134072_waku2_store_messages.up.sql": _1660134072_waku2_store_messagesUpSql, - "1662365868_add_key_uid_accounts.up.sql": _1662365868_add_key_uid_accountsUpSql, - "1662447680_add_keypairs_table.up.sql": _1662447680_add_keypairs_tableUpSql, - "1662460056_move_favourites_to_saved_addresses.up.sql": _1662460056_move_favourites_to_saved_addressesUpSql, - "1662738097_add_base_fee_transaction.up.sql": _1662738097_add_base_fee_transactionUpSql, - "1662972194_add_keypairs_table.up.sql": _1662972194_add_keypairs_tableUpSql, - "1664392661_add_third_party_id_to_waku_messages.up.sql": _1664392661_add_third_party_id_to_waku_messagesUpSql, - "1664783660_add_sync_info_to_saved_addresses.up.sql": _1664783660_add_sync_info_to_saved_addressesUpSql, - "1668109917_wakunodes.up.sql": _1668109917_wakunodesUpSql, - "1670249678_display_name_to_settings_sync_clock_table.up.sql": _1670249678_display_name_to_settings_sync_clock_tableUpSql, - "1670836810_add_imported_flag_to_community_archive_hashes.up.sql": _1670836810_add_imported_flag_to_community_archive_hashesUpSql, - "1671438731_add_magnetlink_uri_to_communities_archive_info.up.sql": _1671438731_add_magnetlink_uri_to_communities_archive_infoUpSql, - "1672933930_switcher_card.up.sql": _1672933930_switcher_cardUpSql, - "1674056187_add_price_cache.up.sql": _1674056187_add_price_cacheUpSql, - "1674136690_ens_usernames.up.sql": _1674136690_ens_usernamesUpSql, - "1674232431_add_balance_history.up.sql": _1674232431_add_balance_historyUpSql, - "1676368933_keypairs_to_keycards.up.sql": _1676368933_keypairs_to_keycardsUpSql, - "1676951398_add_currency_format_cache.up.sql": _1676951398_add_currency_format_cacheUpSql, - "1676968196_keycards_add_clock_column.up.sql": _1676968196_keycards_add_clock_columnUpSql, - "1676968197_add_fallback_rpc_to_networks.up.sql": _1676968197_add_fallback_rpc_to_networksUpSql, - "1677674090_add_chains_ens_istest_to_saved_addresses.up.sql": _1677674090_add_chains_ens_istest_to_saved_addressesUpSql, - "1677681143_accounts_table_type_column_update.up.sql": _1677681143_accounts_table_type_column_updateUpSql, - "1678264207_accounts_table_new_columns_added.up.sql": _1678264207_accounts_table_new_columns_addedUpSql, - "1680770368_add_bio_to_settings_sync_clock_table.up.sql": _1680770368_add_bio_to_settings_sync_clock_tableUpSql, - "1681110436_add_mnemonic_to_settings_sync_clock_table.up.sql": _1681110436_add_mnemonic_to_settings_sync_clock_tableUpSql, - "1681392602_9d_sync_period.up.sql": _1681392602_9d_sync_periodUpSql, - "1681762078_default_sync_period_9d.up.sql": _1681762078_default_sync_period_9dUpSql, - "1681780680_add_clock_to_social_links_settings.up.sql": _1681780680_add_clock_to_social_links_settingsUpSql, - "1682073779_settings_table_remove_latest_derived_path_column.up.sql": _1682073779_settings_table_remove_latest_derived_path_columnUpSql, - "1682146075_add_created_at_to_saved_addresses.up.sql": _1682146075_add_created_at_to_saved_addressesUpSql, - "1682393575_sync_ens_name.up.sql": _1682393575_sync_ens_nameUpSql, - "1683457503_add_blocks_ranges_sequential_table.up.sql": _1683457503_add_blocks_ranges_sequential_tableUpSql, - "1683627613_accounts_and_keycards_improvements.up.sql": _1683627613_accounts_and_keycards_improvementsUpSql, - "1685041348_settings_table_add_latest_derived_path_column.up.sql": _1685041348_settings_table_add_latest_derived_path_columnUpSql, - "1685440989_update_color_id_accounts.up.sql": _1685440989_update_color_id_accountsUpSql, - "1685463947_add_to_asset_to_multitransaction.up.sql": _1685463947_add_to_asset_to_multitransactionUpSql, - "1685880973_add_profile_links_settings_table.up.sql": _1685880973_add_profile_links_settings_tableUpSql, - "1686041510_add_idx_transfers_blkno_loaded.up.sql": _1686041510_add_idx_transfers_blkno_loadedUpSql, - "1686048341_transfers_receipt_json_blob_out.up.sql.down.sql": _1686048341_transfers_receipt_json_blob_outUpSqlDownSql, - "1686048341_transfers_receipt_json_blob_out.up.sql.up.sql": _1686048341_transfers_receipt_json_blob_outUpSqlUpSql, - "1686825075_cleanup_token_address.up.sql": _1686825075_cleanup_token_addressUpSql, - "1687193315_transfers_extract_from_to_address.down.sql": _1687193315_transfers_extract_from_to_addressDownSql, - "1687193315_transfers_extract_from_to_address.up.sql": _1687193315_transfers_extract_from_to_addressUpSql, - "1687249080_add_position_accounts.up..sql": _1687249080_add_position_accountsUpSql, - "1687269871_add_device_name.up.sql": _1687269871_add_device_nameUpSql, - "1687506642_include_watch_only_account_setting.up.sql": _1687506642_include_watch_only_account_settingUpSql, - "1688022264_add_include_watch_only_account_to_settings_sync_clock.up.sql": _1688022264_add_include_watch_only_account_to_settings_sync_clockUpSql, - "1688054680_add_columns_to_multitransaction.up.sql": _1688054680_add_columns_to_multitransactionUpSql, - "1688636552_keycards_table_columns_update.up.sql": _1688636552_keycards_table_columns_updateUpSql, - "1689248269_add_related_chain_id_networks.up.sql": _1689248269_add_related_chain_id_networksUpSql, - "1689340211_index_filter_columns.up.sql": _1689340211_index_filter_columnsUpSql, - "1689498471_make_wallet_accounts_positions_non_negative.up.sql": _1689498471_make_wallet_accounts_positions_non_negativeUpSql, - "1689856991_add_soft_remove_column_for_keypairs_and_accounts.up.sql": _1689856991_add_soft_remove_column_for_keypairs_and_accountsUpSql, - "1690225863_add_collectibles_ownership_cache.up.sql": _1690225863_add_collectibles_ownership_cacheUpSql, - "1690734354_add_preferred_chain_ids.up.sql": _1690734354_add_preferred_chain_idsUpSql, - "1691173699_add_collectibles_and_collections_data_cache.up.sql": _1691173699_add_collectibles_and_collections_data_cacheUpSql, - "1691753758_move_wallet_tables_to_wallet_db.up.sql": _1691753758_move_wallet_tables_to_wallet_dbUpSql, - "1691753800_pubsubtopic_key.up.sql": _1691753800_pubsubtopic_keyUpSql, - "1693900971_add_profile_migration_needed_column_to_settings_table.up.sql": _1693900971_add_profile_migration_needed_column_to_settings_tableUpSql, - "1694764094_add_original_to_networks.up.sql": _1694764094_add_original_to_networksUpSql, - "1695974515_add_is_sepolia_enabled_to_settings.up.sql": _1695974515_add_is_sepolia_enabled_to_settingsUpSql, - "1696259336_settings_add_url_unfurling_mode.up.sql": _1696259336_settings_add_url_unfurling_modeUpSql, - "1697123140_drop_include_watch_only_accounts.up.sql": _1697123140_drop_include_watch_only_accountsUpSql, + "1640111208_dummy.up.sql": _1640111208_dummyUpSql, + + "1642666031_add_removed_clock_to_bookmarks.up.sql": _1642666031_add_removed_clock_to_bookmarksUpSql, + + "1643644541_gif_api_key_setting.up.sql": _1643644541_gif_api_key_settingUpSql, + + "1644188994_recent_stickers.up.sql": _1644188994_recent_stickersUpSql, + + "1646659233_add_address_to_dapp_permisssion.up.sql": _1646659233_add_address_to_dapp_permisssionUpSql, + + "1646841105_add_emoji_account.up.sql": _1646841105_add_emoji_accountUpSql, + + "1647278782_display_name.up.sql": _1647278782_display_nameUpSql, + + "1647862838_reset_last_backup.up.sql": _1647862838_reset_last_backupUpSql, + + "1647871652_add_settings_sync_clock_table.up.sql": _1647871652_add_settings_sync_clock_tableUpSql, + + "1647880168_add_torrent_config.up.sql": _1647880168_add_torrent_configUpSql, + + "1647882837_add_communities_settings_table.up.sql": _1647882837_add_communities_settings_tableUpSql, + + "1647956635_add_waku_messages_table.up.sql": _1647956635_add_waku_messages_tableUpSql, + + "1648554928_network_test.up.sql": _1648554928_network_testUpSql, + + "1649174829_add_visitble_token.up.sql": _1649174829_add_visitble_tokenUpSql, + + "1649882262_add_derived_from_accounts.up.sql": _1649882262_add_derived_from_accountsUpSql, + + "1650612625_add_community_message_archive_hashes_table.up.sql": _1650612625_add_community_message_archive_hashes_tableUpSql, + + "1650616788_add_communities_archives_info_table.up.sql": _1650616788_add_communities_archives_info_tableUpSql, + + "1652715604_add_clock_accounts.up.sql": _1652715604_add_clock_accountsUpSql, + + "1653037334_add_notifications_settings_table.up.sql": _1653037334_add_notifications_settings_tableUpSql, + + "1654702119_add_mutual_contact_settings.up.sql": _1654702119_add_mutual_contact_settingsUpSql, + + "1655375270_add_clock_field_to_communities_settings_table.up.sql": _1655375270_add_clock_field_to_communities_settings_tableUpSql, + + "1655385721_drop_networks_config.up.sql": _1655385721_drop_networks_configUpSql, + + "1655385724_networks_chainColor_shortName.up.sql": _1655385724_networks_chaincolor_shortnameUpSql, + + "1655456688_add_deleted_at_field_to_bookmarks_table.up.sql": _1655456688_add_deleted_at_field_to_bookmarks_tableUpSql, + + "1655462032_create_bookmarks_deleted_at_index.up.sql": _1655462032_create_bookmarks_deleted_at_indexUpSql, + + "1657617291_add_multi_transactions_table.up.sql": _1657617291_add_multi_transactions_tableUpSql, + + "1660134042_add_social_links_settings_table.up.sql": _1660134042_add_social_links_settings_tableUpSql, + + "1660134060_settings_bio.up.sql": _1660134060_settings_bioUpSql, + + "1660134070_add_wakuv2_store.up.sql": _1660134070_add_wakuv2_storeUpSql, + + "1660134072_waku2_store_messages.up.sql": _1660134072_waku2_store_messagesUpSql, + + "1662365868_add_key_uid_accounts.up.sql": _1662365868_add_key_uid_accountsUpSql, + + "1662447680_add_keypairs_table.up.sql": _1662447680_add_keypairs_tableUpSql, + + "1662460056_move_favourites_to_saved_addresses.up.sql": _1662460056_move_favourites_to_saved_addressesUpSql, + + "1662738097_add_base_fee_transaction.up.sql": _1662738097_add_base_fee_transactionUpSql, + + "1662972194_add_keypairs_table.up.sql": _1662972194_add_keypairs_tableUpSql, + + "1664392661_add_third_party_id_to_waku_messages.up.sql": _1664392661_add_third_party_id_to_waku_messagesUpSql, + + "1664783660_add_sync_info_to_saved_addresses.up.sql": _1664783660_add_sync_info_to_saved_addressesUpSql, + + "1668109917_wakunodes.up.sql": _1668109917_wakunodesUpSql, + + "1670249678_display_name_to_settings_sync_clock_table.up.sql": _1670249678_display_name_to_settings_sync_clock_tableUpSql, + + "1670836810_add_imported_flag_to_community_archive_hashes.up.sql": _1670836810_add_imported_flag_to_community_archive_hashesUpSql, + + "1671438731_add_magnetlink_uri_to_communities_archive_info.up.sql": _1671438731_add_magnetlink_uri_to_communities_archive_infoUpSql, + + "1672933930_switcher_card.up.sql": _1672933930_switcher_cardUpSql, + + "1674056187_add_price_cache.up.sql": _1674056187_add_price_cacheUpSql, + + "1674136690_ens_usernames.up.sql": _1674136690_ens_usernamesUpSql, + + "1674232431_add_balance_history.up.sql": _1674232431_add_balance_historyUpSql, + + "1676368933_keypairs_to_keycards.up.sql": _1676368933_keypairs_to_keycardsUpSql, + + "1676951398_add_currency_format_cache.up.sql": _1676951398_add_currency_format_cacheUpSql, + + "1676968196_keycards_add_clock_column.up.sql": _1676968196_keycards_add_clock_columnUpSql, + + "1676968197_add_fallback_rpc_to_networks.up.sql": _1676968197_add_fallback_rpc_to_networksUpSql, + + "1677674090_add_chains_ens_istest_to_saved_addresses.up.sql": _1677674090_add_chains_ens_istest_to_saved_addressesUpSql, + + "1677681143_accounts_table_type_column_update.up.sql": _1677681143_accounts_table_type_column_updateUpSql, + + "1678264207_accounts_table_new_columns_added.up.sql": _1678264207_accounts_table_new_columns_addedUpSql, + + "1680770368_add_bio_to_settings_sync_clock_table.up.sql": _1680770368_add_bio_to_settings_sync_clock_tableUpSql, + + "1681110436_add_mnemonic_to_settings_sync_clock_table.up.sql": _1681110436_add_mnemonic_to_settings_sync_clock_tableUpSql, + + "1681392602_9d_sync_period.up.sql": _1681392602_9d_sync_periodUpSql, + + "1681762078_default_sync_period_9d.up.sql": _1681762078_default_sync_period_9dUpSql, + + "1681780680_add_clock_to_social_links_settings.up.sql": _1681780680_add_clock_to_social_links_settingsUpSql, + + "1682073779_settings_table_remove_latest_derived_path_column.up.sql": _1682073779_settings_table_remove_latest_derived_path_columnUpSql, + + "1682146075_add_created_at_to_saved_addresses.up.sql": _1682146075_add_created_at_to_saved_addressesUpSql, + + "1682393575_sync_ens_name.up.sql": _1682393575_sync_ens_nameUpSql, + + "1683457503_add_blocks_ranges_sequential_table.up.sql": _1683457503_add_blocks_ranges_sequential_tableUpSql, + + "1683627613_accounts_and_keycards_improvements.up.sql": _1683627613_accounts_and_keycards_improvementsUpSql, + + "1685041348_settings_table_add_latest_derived_path_column.up.sql": _1685041348_settings_table_add_latest_derived_path_columnUpSql, + + "1685440989_update_color_id_accounts.up.sql": _1685440989_update_color_id_accountsUpSql, + + "1685463947_add_to_asset_to_multitransaction.up.sql": _1685463947_add_to_asset_to_multitransactionUpSql, + + "1685880973_add_profile_links_settings_table.up.sql": _1685880973_add_profile_links_settings_tableUpSql, + + "1686041510_add_idx_transfers_blkno_loaded.up.sql": _1686041510_add_idx_transfers_blkno_loadedUpSql, + + "1686048341_transfers_receipt_json_blob_out.up.sql.down.sql": _1686048341_transfers_receipt_json_blob_outUpSqlDownSql, + + "1686048341_transfers_receipt_json_blob_out.up.sql.up.sql": _1686048341_transfers_receipt_json_blob_outUpSqlUpSql, + + "1686825075_cleanup_token_address.up.sql": _1686825075_cleanup_token_addressUpSql, + + "1687193315_transfers_extract_from_to_address.down.sql": _1687193315_transfers_extract_from_to_addressDownSql, + + "1687193315_transfers_extract_from_to_address.up.sql": _1687193315_transfers_extract_from_to_addressUpSql, + + "1687249080_add_position_accounts.up..sql": _1687249080_add_position_accountsUpSql, + + "1687269871_add_device_name.up.sql": _1687269871_add_device_nameUpSql, + + "1687506642_include_watch_only_account_setting.up.sql": _1687506642_include_watch_only_account_settingUpSql, + + "1688022264_add_include_watch_only_account_to_settings_sync_clock.up.sql": _1688022264_add_include_watch_only_account_to_settings_sync_clockUpSql, + + "1688054680_add_columns_to_multitransaction.up.sql": _1688054680_add_columns_to_multitransactionUpSql, + + "1688636552_keycards_table_columns_update.up.sql": _1688636552_keycards_table_columns_updateUpSql, + + "1689248269_add_related_chain_id_networks.up.sql": _1689248269_add_related_chain_id_networksUpSql, + + "1689340211_index_filter_columns.up.sql": _1689340211_index_filter_columnsUpSql, + + "1689498471_make_wallet_accounts_positions_non_negative.up.sql": _1689498471_make_wallet_accounts_positions_non_negativeUpSql, + + "1689856991_add_soft_remove_column_for_keypairs_and_accounts.up.sql": _1689856991_add_soft_remove_column_for_keypairs_and_accountsUpSql, + + "1690225863_add_collectibles_ownership_cache.up.sql": _1690225863_add_collectibles_ownership_cacheUpSql, + + "1690734354_add_preferred_chain_ids.up.sql": _1690734354_add_preferred_chain_idsUpSql, + + "1691173699_add_collectibles_and_collections_data_cache.up.sql": _1691173699_add_collectibles_and_collections_data_cacheUpSql, + + "1691753758_move_wallet_tables_to_wallet_db.up.sql": _1691753758_move_wallet_tables_to_wallet_dbUpSql, + + "1691753800_pubsubtopic_key.up.sql": _1691753800_pubsubtopic_keyUpSql, + + "1693900971_add_profile_migration_needed_column_to_settings_table.up.sql": _1693900971_add_profile_migration_needed_column_to_settings_tableUpSql, + + "1694764094_add_original_to_networks.up.sql": _1694764094_add_original_to_networksUpSql, + + "1695974515_add_is_sepolia_enabled_to_settings.up.sql": _1695974515_add_is_sepolia_enabled_to_settingsUpSql, + + "1696259336_settings_add_url_unfurling_mode.up.sql": _1696259336_settings_add_url_unfurling_modeUpSql, + + "1697123140_drop_include_watch_only_accounts.up.sql": _1697123140_drop_include_watch_only_accountsUpSql, + "1697123233_drop_include_watch_only_account_to_settings_sync_clock.up.sql": _1697123233_drop_include_watch_only_account_to_settings_sync_clockUpSql, - "1697623289_add_omit_transfers_history_scan_to_settings.up.sql": _1697623289_add_omit_transfers_history_scan_to_settingsUpSql, - "1699577175_use_shards.up.sql": _1699577175_use_shardsUpSql, - "1700741911_clusterID.up.sql": _1700741911_clusteridUpSql, - "1701084316_add_wallet_was_not_shown_to_keypairs_accounts.up.sql": _1701084316_add_wallet_was_not_shown_to_keypairs_accountsUpSql, - "1701084317_add_mnemonic_was_not_shown_to_settings.up.sql": _1701084317_add_mnemonic_was_not_shown_to_settingsUpSql, - "1701444172_token_preferences.up.sql": _1701444172_token_preferencesUpSql, - "1701961850_shards_test.up.sql": _1701961850_shards_testUpSql, - "1702395750_fix_enr_shards_test.up.sql": _1702395750_fix_enr_shards_testUpSql, - "1702999401_add_dns_discovery_url.up.sql": _1702999401_add_dns_discovery_urlUpSql, - "1704281285_tokens_advanced_settings.up.sql": _1704281285_tokens_advanced_settingsUpSql, - "1705338819_collectible_preferences.up.sql": _1705338819_collectible_preferencesUpSql, - "1706097653_migration_order_fix.up.sql": _1706097653_migration_order_fixUpSql, - "1706955596_community_storenodes.up.sql": _1706955596_community_storenodesUpSql, - "1708352924_add_peer_syncing_enabled_to_settings.up.sql": _1708352924_add_peer_syncing_enabled_to_settingsUpSql, - "1708416025_make_sepolia_default.up.sql": _1708416025_make_sepolia_defaultUpSql, - "1709203128_fix_chain_colors.up.sql": _1709203128_fix_chain_colorsUpSql, - "1709795716_migration_order_fix.up.sql": _1709795716_migration_order_fixUpSql, - "doc.go": docGo, -} - -// AssetDebug is true if the assets were built with the debug flag enabled. -const AssetDebug = false + + "1697623289_add_omit_transfers_history_scan_to_settings.up.sql": _1697623289_add_omit_transfers_history_scan_to_settingsUpSql, + + "1699577175_use_shards.up.sql": _1699577175_use_shardsUpSql, + + "1700741911_clusterID.up.sql": _1700741911_clusteridUpSql, + + "1701084316_add_wallet_was_not_shown_to_keypairs_accounts.up.sql": _1701084316_add_wallet_was_not_shown_to_keypairs_accountsUpSql, + + "1701084317_add_mnemonic_was_not_shown_to_settings.up.sql": _1701084317_add_mnemonic_was_not_shown_to_settingsUpSql, + + "1701444172_token_preferences.up.sql": _1701444172_token_preferencesUpSql, + + "1701961850_shards_test.up.sql": _1701961850_shards_testUpSql, + + "1702395750_fix_enr_shards_test.up.sql": _1702395750_fix_enr_shards_testUpSql, + + "1702999401_add_dns_discovery_url.up.sql": _1702999401_add_dns_discovery_urlUpSql, + + "1704281285_tokens_advanced_settings.up.sql": _1704281285_tokens_advanced_settingsUpSql, + + "1705338819_collectible_preferences.up.sql": _1705338819_collectible_preferencesUpSql, + + "1706097653_migration_order_fix.up.sql": _1706097653_migration_order_fixUpSql, + + "1706955596_community_storenodes.up.sql": _1706955596_community_storenodesUpSql, + + "1708352924_add_peer_syncing_enabled_to_settings.up.sql": _1708352924_add_peer_syncing_enabled_to_settingsUpSql, + + "1708416025_make_sepolia_default.up.sql": _1708416025_make_sepolia_defaultUpSql, + + "1709203128_fix_chain_colors.up.sql": _1709203128_fix_chain_colorsUpSql, + + "1709795716_migration_order_fix.up.sql": _1709795716_migration_order_fixUpSql, + + "1711573194_rename_peersyncing_group_id_field.up.sql": _1711573194_rename_peersyncing_group_id_fieldUpSql, + + "doc.go": docGo, +} // AssetDir returns the file names below a certain // directory embedded in the file by go-bindata. @@ -2648,117 +2779,118 @@ type bintree struct { } var _bintree = &bintree{nil, map[string]*bintree{ - "1640111208_dummy.up.sql": {_1640111208_dummyUpSql, map[string]*bintree{}}, - "1642666031_add_removed_clock_to_bookmarks.up.sql": {_1642666031_add_removed_clock_to_bookmarksUpSql, map[string]*bintree{}}, - "1643644541_gif_api_key_setting.up.sql": {_1643644541_gif_api_key_settingUpSql, map[string]*bintree{}}, - "1644188994_recent_stickers.up.sql": {_1644188994_recent_stickersUpSql, map[string]*bintree{}}, - "1646659233_add_address_to_dapp_permisssion.up.sql": {_1646659233_add_address_to_dapp_permisssionUpSql, map[string]*bintree{}}, - "1646841105_add_emoji_account.up.sql": {_1646841105_add_emoji_accountUpSql, map[string]*bintree{}}, - "1647278782_display_name.up.sql": {_1647278782_display_nameUpSql, map[string]*bintree{}}, - "1647862838_reset_last_backup.up.sql": {_1647862838_reset_last_backupUpSql, map[string]*bintree{}}, - "1647871652_add_settings_sync_clock_table.up.sql": {_1647871652_add_settings_sync_clock_tableUpSql, map[string]*bintree{}}, - "1647880168_add_torrent_config.up.sql": {_1647880168_add_torrent_configUpSql, map[string]*bintree{}}, - "1647882837_add_communities_settings_table.up.sql": {_1647882837_add_communities_settings_tableUpSql, map[string]*bintree{}}, - "1647956635_add_waku_messages_table.up.sql": {_1647956635_add_waku_messages_tableUpSql, map[string]*bintree{}}, - "1648554928_network_test.up.sql": {_1648554928_network_testUpSql, map[string]*bintree{}}, - "1649174829_add_visitble_token.up.sql": {_1649174829_add_visitble_tokenUpSql, map[string]*bintree{}}, - "1649882262_add_derived_from_accounts.up.sql": {_1649882262_add_derived_from_accountsUpSql, map[string]*bintree{}}, - "1650612625_add_community_message_archive_hashes_table.up.sql": {_1650612625_add_community_message_archive_hashes_tableUpSql, map[string]*bintree{}}, - "1650616788_add_communities_archives_info_table.up.sql": {_1650616788_add_communities_archives_info_tableUpSql, map[string]*bintree{}}, - "1652715604_add_clock_accounts.up.sql": {_1652715604_add_clock_accountsUpSql, map[string]*bintree{}}, - "1653037334_add_notifications_settings_table.up.sql": {_1653037334_add_notifications_settings_tableUpSql, map[string]*bintree{}}, - "1654702119_add_mutual_contact_settings.up.sql": {_1654702119_add_mutual_contact_settingsUpSql, map[string]*bintree{}}, - "1655375270_add_clock_field_to_communities_settings_table.up.sql": {_1655375270_add_clock_field_to_communities_settings_tableUpSql, map[string]*bintree{}}, - "1655385721_drop_networks_config.up.sql": {_1655385721_drop_networks_configUpSql, map[string]*bintree{}}, - "1655385724_networks_chainColor_shortName.up.sql": {_1655385724_networks_chaincolor_shortnameUpSql, map[string]*bintree{}}, - "1655456688_add_deleted_at_field_to_bookmarks_table.up.sql": {_1655456688_add_deleted_at_field_to_bookmarks_tableUpSql, map[string]*bintree{}}, - "1655462032_create_bookmarks_deleted_at_index.up.sql": {_1655462032_create_bookmarks_deleted_at_indexUpSql, map[string]*bintree{}}, - "1657617291_add_multi_transactions_table.up.sql": {_1657617291_add_multi_transactions_tableUpSql, map[string]*bintree{}}, - "1660134042_add_social_links_settings_table.up.sql": {_1660134042_add_social_links_settings_tableUpSql, map[string]*bintree{}}, - "1660134060_settings_bio.up.sql": {_1660134060_settings_bioUpSql, map[string]*bintree{}}, - "1660134070_add_wakuv2_store.up.sql": {_1660134070_add_wakuv2_storeUpSql, map[string]*bintree{}}, - "1660134072_waku2_store_messages.up.sql": {_1660134072_waku2_store_messagesUpSql, map[string]*bintree{}}, - "1662365868_add_key_uid_accounts.up.sql": {_1662365868_add_key_uid_accountsUpSql, map[string]*bintree{}}, - "1662447680_add_keypairs_table.up.sql": {_1662447680_add_keypairs_tableUpSql, map[string]*bintree{}}, - "1662460056_move_favourites_to_saved_addresses.up.sql": {_1662460056_move_favourites_to_saved_addressesUpSql, map[string]*bintree{}}, - "1662738097_add_base_fee_transaction.up.sql": {_1662738097_add_base_fee_transactionUpSql, map[string]*bintree{}}, - "1662972194_add_keypairs_table.up.sql": {_1662972194_add_keypairs_tableUpSql, map[string]*bintree{}}, - "1664392661_add_third_party_id_to_waku_messages.up.sql": {_1664392661_add_third_party_id_to_waku_messagesUpSql, map[string]*bintree{}}, - "1664783660_add_sync_info_to_saved_addresses.up.sql": {_1664783660_add_sync_info_to_saved_addressesUpSql, map[string]*bintree{}}, - "1668109917_wakunodes.up.sql": {_1668109917_wakunodesUpSql, map[string]*bintree{}}, - "1670249678_display_name_to_settings_sync_clock_table.up.sql": {_1670249678_display_name_to_settings_sync_clock_tableUpSql, map[string]*bintree{}}, - "1670836810_add_imported_flag_to_community_archive_hashes.up.sql": {_1670836810_add_imported_flag_to_community_archive_hashesUpSql, map[string]*bintree{}}, - "1671438731_add_magnetlink_uri_to_communities_archive_info.up.sql": {_1671438731_add_magnetlink_uri_to_communities_archive_infoUpSql, map[string]*bintree{}}, - "1672933930_switcher_card.up.sql": {_1672933930_switcher_cardUpSql, map[string]*bintree{}}, - "1674056187_add_price_cache.up.sql": {_1674056187_add_price_cacheUpSql, map[string]*bintree{}}, - "1674136690_ens_usernames.up.sql": {_1674136690_ens_usernamesUpSql, map[string]*bintree{}}, - "1674232431_add_balance_history.up.sql": {_1674232431_add_balance_historyUpSql, map[string]*bintree{}}, - "1676368933_keypairs_to_keycards.up.sql": {_1676368933_keypairs_to_keycardsUpSql, map[string]*bintree{}}, - "1676951398_add_currency_format_cache.up.sql": {_1676951398_add_currency_format_cacheUpSql, map[string]*bintree{}}, - "1676968196_keycards_add_clock_column.up.sql": {_1676968196_keycards_add_clock_columnUpSql, map[string]*bintree{}}, - "1676968197_add_fallback_rpc_to_networks.up.sql": {_1676968197_add_fallback_rpc_to_networksUpSql, map[string]*bintree{}}, - "1677674090_add_chains_ens_istest_to_saved_addresses.up.sql": {_1677674090_add_chains_ens_istest_to_saved_addressesUpSql, map[string]*bintree{}}, - "1677681143_accounts_table_type_column_update.up.sql": {_1677681143_accounts_table_type_column_updateUpSql, map[string]*bintree{}}, - "1678264207_accounts_table_new_columns_added.up.sql": {_1678264207_accounts_table_new_columns_addedUpSql, map[string]*bintree{}}, - "1680770368_add_bio_to_settings_sync_clock_table.up.sql": {_1680770368_add_bio_to_settings_sync_clock_tableUpSql, map[string]*bintree{}}, - "1681110436_add_mnemonic_to_settings_sync_clock_table.up.sql": {_1681110436_add_mnemonic_to_settings_sync_clock_tableUpSql, map[string]*bintree{}}, - "1681392602_9d_sync_period.up.sql": {_1681392602_9d_sync_periodUpSql, map[string]*bintree{}}, - "1681762078_default_sync_period_9d.up.sql": {_1681762078_default_sync_period_9dUpSql, map[string]*bintree{}}, - "1681780680_add_clock_to_social_links_settings.up.sql": {_1681780680_add_clock_to_social_links_settingsUpSql, map[string]*bintree{}}, - "1682073779_settings_table_remove_latest_derived_path_column.up.sql": {_1682073779_settings_table_remove_latest_derived_path_columnUpSql, map[string]*bintree{}}, - "1682146075_add_created_at_to_saved_addresses.up.sql": {_1682146075_add_created_at_to_saved_addressesUpSql, map[string]*bintree{}}, - "1682393575_sync_ens_name.up.sql": {_1682393575_sync_ens_nameUpSql, map[string]*bintree{}}, - "1683457503_add_blocks_ranges_sequential_table.up.sql": {_1683457503_add_blocks_ranges_sequential_tableUpSql, map[string]*bintree{}}, - "1683627613_accounts_and_keycards_improvements.up.sql": {_1683627613_accounts_and_keycards_improvementsUpSql, map[string]*bintree{}}, - "1685041348_settings_table_add_latest_derived_path_column.up.sql": {_1685041348_settings_table_add_latest_derived_path_columnUpSql, map[string]*bintree{}}, - "1685440989_update_color_id_accounts.up.sql": {_1685440989_update_color_id_accountsUpSql, map[string]*bintree{}}, - "1685463947_add_to_asset_to_multitransaction.up.sql": {_1685463947_add_to_asset_to_multitransactionUpSql, map[string]*bintree{}}, - "1685880973_add_profile_links_settings_table.up.sql": {_1685880973_add_profile_links_settings_tableUpSql, map[string]*bintree{}}, - "1686041510_add_idx_transfers_blkno_loaded.up.sql": {_1686041510_add_idx_transfers_blkno_loadedUpSql, map[string]*bintree{}}, - "1686048341_transfers_receipt_json_blob_out.up.sql.down.sql": {_1686048341_transfers_receipt_json_blob_outUpSqlDownSql, map[string]*bintree{}}, - "1686048341_transfers_receipt_json_blob_out.up.sql.up.sql": {_1686048341_transfers_receipt_json_blob_outUpSqlUpSql, map[string]*bintree{}}, - "1686825075_cleanup_token_address.up.sql": {_1686825075_cleanup_token_addressUpSql, map[string]*bintree{}}, - "1687193315_transfers_extract_from_to_address.down.sql": {_1687193315_transfers_extract_from_to_addressDownSql, map[string]*bintree{}}, - "1687193315_transfers_extract_from_to_address.up.sql": {_1687193315_transfers_extract_from_to_addressUpSql, map[string]*bintree{}}, - "1687249080_add_position_accounts.up..sql": {_1687249080_add_position_accountsUpSql, map[string]*bintree{}}, - "1687269871_add_device_name.up.sql": {_1687269871_add_device_nameUpSql, map[string]*bintree{}}, - "1687506642_include_watch_only_account_setting.up.sql": {_1687506642_include_watch_only_account_settingUpSql, map[string]*bintree{}}, - "1688022264_add_include_watch_only_account_to_settings_sync_clock.up.sql": {_1688022264_add_include_watch_only_account_to_settings_sync_clockUpSql, map[string]*bintree{}}, - "1688054680_add_columns_to_multitransaction.up.sql": {_1688054680_add_columns_to_multitransactionUpSql, map[string]*bintree{}}, - "1688636552_keycards_table_columns_update.up.sql": {_1688636552_keycards_table_columns_updateUpSql, map[string]*bintree{}}, - "1689248269_add_related_chain_id_networks.up.sql": {_1689248269_add_related_chain_id_networksUpSql, map[string]*bintree{}}, - "1689340211_index_filter_columns.up.sql": {_1689340211_index_filter_columnsUpSql, map[string]*bintree{}}, - "1689498471_make_wallet_accounts_positions_non_negative.up.sql": {_1689498471_make_wallet_accounts_positions_non_negativeUpSql, map[string]*bintree{}}, - "1689856991_add_soft_remove_column_for_keypairs_and_accounts.up.sql": {_1689856991_add_soft_remove_column_for_keypairs_and_accountsUpSql, map[string]*bintree{}}, - "1690225863_add_collectibles_ownership_cache.up.sql": {_1690225863_add_collectibles_ownership_cacheUpSql, map[string]*bintree{}}, - "1690734354_add_preferred_chain_ids.up.sql": {_1690734354_add_preferred_chain_idsUpSql, map[string]*bintree{}}, - "1691173699_add_collectibles_and_collections_data_cache.up.sql": {_1691173699_add_collectibles_and_collections_data_cacheUpSql, map[string]*bintree{}}, - "1691753758_move_wallet_tables_to_wallet_db.up.sql": {_1691753758_move_wallet_tables_to_wallet_dbUpSql, map[string]*bintree{}}, - "1691753800_pubsubtopic_key.up.sql": {_1691753800_pubsubtopic_keyUpSql, map[string]*bintree{}}, - "1693900971_add_profile_migration_needed_column_to_settings_table.up.sql": {_1693900971_add_profile_migration_needed_column_to_settings_tableUpSql, map[string]*bintree{}}, - "1694764094_add_original_to_networks.up.sql": {_1694764094_add_original_to_networksUpSql, map[string]*bintree{}}, - "1695974515_add_is_sepolia_enabled_to_settings.up.sql": {_1695974515_add_is_sepolia_enabled_to_settingsUpSql, map[string]*bintree{}}, - "1696259336_settings_add_url_unfurling_mode.up.sql": {_1696259336_settings_add_url_unfurling_modeUpSql, map[string]*bintree{}}, - "1697123140_drop_include_watch_only_accounts.up.sql": {_1697123140_drop_include_watch_only_accountsUpSql, map[string]*bintree{}}, - "1697123233_drop_include_watch_only_account_to_settings_sync_clock.up.sql": {_1697123233_drop_include_watch_only_account_to_settings_sync_clockUpSql, map[string]*bintree{}}, - "1697623289_add_omit_transfers_history_scan_to_settings.up.sql": {_1697623289_add_omit_transfers_history_scan_to_settingsUpSql, map[string]*bintree{}}, - "1699577175_use_shards.up.sql": {_1699577175_use_shardsUpSql, map[string]*bintree{}}, - "1700741911_clusterID.up.sql": {_1700741911_clusteridUpSql, map[string]*bintree{}}, - "1701084316_add_wallet_was_not_shown_to_keypairs_accounts.up.sql": {_1701084316_add_wallet_was_not_shown_to_keypairs_accountsUpSql, map[string]*bintree{}}, - "1701084317_add_mnemonic_was_not_shown_to_settings.up.sql": {_1701084317_add_mnemonic_was_not_shown_to_settingsUpSql, map[string]*bintree{}}, - "1701444172_token_preferences.up.sql": {_1701444172_token_preferencesUpSql, map[string]*bintree{}}, - "1701961850_shards_test.up.sql": {_1701961850_shards_testUpSql, map[string]*bintree{}}, - "1702395750_fix_enr_shards_test.up.sql": {_1702395750_fix_enr_shards_testUpSql, map[string]*bintree{}}, - "1702999401_add_dns_discovery_url.up.sql": {_1702999401_add_dns_discovery_urlUpSql, map[string]*bintree{}}, - "1704281285_tokens_advanced_settings.up.sql": {_1704281285_tokens_advanced_settingsUpSql, map[string]*bintree{}}, - "1705338819_collectible_preferences.up.sql": {_1705338819_collectible_preferencesUpSql, map[string]*bintree{}}, - "1706097653_migration_order_fix.up.sql": {_1706097653_migration_order_fixUpSql, map[string]*bintree{}}, - "1706955596_community_storenodes.up.sql": {_1706955596_community_storenodesUpSql, map[string]*bintree{}}, - "1708352924_add_peer_syncing_enabled_to_settings.up.sql": {_1708352924_add_peer_syncing_enabled_to_settingsUpSql, map[string]*bintree{}}, - "1708416025_make_sepolia_default.up.sql": {_1708416025_make_sepolia_defaultUpSql, map[string]*bintree{}}, - "1709203128_fix_chain_colors.up.sql": {_1709203128_fix_chain_colorsUpSql, map[string]*bintree{}}, - "1709795716_migration_order_fix.up.sql": {_1709795716_migration_order_fixUpSql, map[string]*bintree{}}, - "doc.go": {docGo, map[string]*bintree{}}, + "1640111208_dummy.up.sql": &bintree{_1640111208_dummyUpSql, map[string]*bintree{}}, + "1642666031_add_removed_clock_to_bookmarks.up.sql": &bintree{_1642666031_add_removed_clock_to_bookmarksUpSql, map[string]*bintree{}}, + "1643644541_gif_api_key_setting.up.sql": &bintree{_1643644541_gif_api_key_settingUpSql, map[string]*bintree{}}, + "1644188994_recent_stickers.up.sql": &bintree{_1644188994_recent_stickersUpSql, map[string]*bintree{}}, + "1646659233_add_address_to_dapp_permisssion.up.sql": &bintree{_1646659233_add_address_to_dapp_permisssionUpSql, map[string]*bintree{}}, + "1646841105_add_emoji_account.up.sql": &bintree{_1646841105_add_emoji_accountUpSql, map[string]*bintree{}}, + "1647278782_display_name.up.sql": &bintree{_1647278782_display_nameUpSql, map[string]*bintree{}}, + "1647862838_reset_last_backup.up.sql": &bintree{_1647862838_reset_last_backupUpSql, map[string]*bintree{}}, + "1647871652_add_settings_sync_clock_table.up.sql": &bintree{_1647871652_add_settings_sync_clock_tableUpSql, map[string]*bintree{}}, + "1647880168_add_torrent_config.up.sql": &bintree{_1647880168_add_torrent_configUpSql, map[string]*bintree{}}, + "1647882837_add_communities_settings_table.up.sql": &bintree{_1647882837_add_communities_settings_tableUpSql, map[string]*bintree{}}, + "1647956635_add_waku_messages_table.up.sql": &bintree{_1647956635_add_waku_messages_tableUpSql, map[string]*bintree{}}, + "1648554928_network_test.up.sql": &bintree{_1648554928_network_testUpSql, map[string]*bintree{}}, + "1649174829_add_visitble_token.up.sql": &bintree{_1649174829_add_visitble_tokenUpSql, map[string]*bintree{}}, + "1649882262_add_derived_from_accounts.up.sql": &bintree{_1649882262_add_derived_from_accountsUpSql, map[string]*bintree{}}, + "1650612625_add_community_message_archive_hashes_table.up.sql": &bintree{_1650612625_add_community_message_archive_hashes_tableUpSql, map[string]*bintree{}}, + "1650616788_add_communities_archives_info_table.up.sql": &bintree{_1650616788_add_communities_archives_info_tableUpSql, map[string]*bintree{}}, + "1652715604_add_clock_accounts.up.sql": &bintree{_1652715604_add_clock_accountsUpSql, map[string]*bintree{}}, + "1653037334_add_notifications_settings_table.up.sql": &bintree{_1653037334_add_notifications_settings_tableUpSql, map[string]*bintree{}}, + "1654702119_add_mutual_contact_settings.up.sql": &bintree{_1654702119_add_mutual_contact_settingsUpSql, map[string]*bintree{}}, + "1655375270_add_clock_field_to_communities_settings_table.up.sql": &bintree{_1655375270_add_clock_field_to_communities_settings_tableUpSql, map[string]*bintree{}}, + "1655385721_drop_networks_config.up.sql": &bintree{_1655385721_drop_networks_configUpSql, map[string]*bintree{}}, + "1655385724_networks_chainColor_shortName.up.sql": &bintree{_1655385724_networks_chaincolor_shortnameUpSql, map[string]*bintree{}}, + "1655456688_add_deleted_at_field_to_bookmarks_table.up.sql": &bintree{_1655456688_add_deleted_at_field_to_bookmarks_tableUpSql, map[string]*bintree{}}, + "1655462032_create_bookmarks_deleted_at_index.up.sql": &bintree{_1655462032_create_bookmarks_deleted_at_indexUpSql, map[string]*bintree{}}, + "1657617291_add_multi_transactions_table.up.sql": &bintree{_1657617291_add_multi_transactions_tableUpSql, map[string]*bintree{}}, + "1660134042_add_social_links_settings_table.up.sql": &bintree{_1660134042_add_social_links_settings_tableUpSql, map[string]*bintree{}}, + "1660134060_settings_bio.up.sql": &bintree{_1660134060_settings_bioUpSql, map[string]*bintree{}}, + "1660134070_add_wakuv2_store.up.sql": &bintree{_1660134070_add_wakuv2_storeUpSql, map[string]*bintree{}}, + "1660134072_waku2_store_messages.up.sql": &bintree{_1660134072_waku2_store_messagesUpSql, map[string]*bintree{}}, + "1662365868_add_key_uid_accounts.up.sql": &bintree{_1662365868_add_key_uid_accountsUpSql, map[string]*bintree{}}, + "1662447680_add_keypairs_table.up.sql": &bintree{_1662447680_add_keypairs_tableUpSql, map[string]*bintree{}}, + "1662460056_move_favourites_to_saved_addresses.up.sql": &bintree{_1662460056_move_favourites_to_saved_addressesUpSql, map[string]*bintree{}}, + "1662738097_add_base_fee_transaction.up.sql": &bintree{_1662738097_add_base_fee_transactionUpSql, map[string]*bintree{}}, + "1662972194_add_keypairs_table.up.sql": &bintree{_1662972194_add_keypairs_tableUpSql, map[string]*bintree{}}, + "1664392661_add_third_party_id_to_waku_messages.up.sql": &bintree{_1664392661_add_third_party_id_to_waku_messagesUpSql, map[string]*bintree{}}, + "1664783660_add_sync_info_to_saved_addresses.up.sql": &bintree{_1664783660_add_sync_info_to_saved_addressesUpSql, map[string]*bintree{}}, + "1668109917_wakunodes.up.sql": &bintree{_1668109917_wakunodesUpSql, map[string]*bintree{}}, + "1670249678_display_name_to_settings_sync_clock_table.up.sql": &bintree{_1670249678_display_name_to_settings_sync_clock_tableUpSql, map[string]*bintree{}}, + "1670836810_add_imported_flag_to_community_archive_hashes.up.sql": &bintree{_1670836810_add_imported_flag_to_community_archive_hashesUpSql, map[string]*bintree{}}, + "1671438731_add_magnetlink_uri_to_communities_archive_info.up.sql": &bintree{_1671438731_add_magnetlink_uri_to_communities_archive_infoUpSql, map[string]*bintree{}}, + "1672933930_switcher_card.up.sql": &bintree{_1672933930_switcher_cardUpSql, map[string]*bintree{}}, + "1674056187_add_price_cache.up.sql": &bintree{_1674056187_add_price_cacheUpSql, map[string]*bintree{}}, + "1674136690_ens_usernames.up.sql": &bintree{_1674136690_ens_usernamesUpSql, map[string]*bintree{}}, + "1674232431_add_balance_history.up.sql": &bintree{_1674232431_add_balance_historyUpSql, map[string]*bintree{}}, + "1676368933_keypairs_to_keycards.up.sql": &bintree{_1676368933_keypairs_to_keycardsUpSql, map[string]*bintree{}}, + "1676951398_add_currency_format_cache.up.sql": &bintree{_1676951398_add_currency_format_cacheUpSql, map[string]*bintree{}}, + "1676968196_keycards_add_clock_column.up.sql": &bintree{_1676968196_keycards_add_clock_columnUpSql, map[string]*bintree{}}, + "1676968197_add_fallback_rpc_to_networks.up.sql": &bintree{_1676968197_add_fallback_rpc_to_networksUpSql, map[string]*bintree{}}, + "1677674090_add_chains_ens_istest_to_saved_addresses.up.sql": &bintree{_1677674090_add_chains_ens_istest_to_saved_addressesUpSql, map[string]*bintree{}}, + "1677681143_accounts_table_type_column_update.up.sql": &bintree{_1677681143_accounts_table_type_column_updateUpSql, map[string]*bintree{}}, + "1678264207_accounts_table_new_columns_added.up.sql": &bintree{_1678264207_accounts_table_new_columns_addedUpSql, map[string]*bintree{}}, + "1680770368_add_bio_to_settings_sync_clock_table.up.sql": &bintree{_1680770368_add_bio_to_settings_sync_clock_tableUpSql, map[string]*bintree{}}, + "1681110436_add_mnemonic_to_settings_sync_clock_table.up.sql": &bintree{_1681110436_add_mnemonic_to_settings_sync_clock_tableUpSql, map[string]*bintree{}}, + "1681392602_9d_sync_period.up.sql": &bintree{_1681392602_9d_sync_periodUpSql, map[string]*bintree{}}, + "1681762078_default_sync_period_9d.up.sql": &bintree{_1681762078_default_sync_period_9dUpSql, map[string]*bintree{}}, + "1681780680_add_clock_to_social_links_settings.up.sql": &bintree{_1681780680_add_clock_to_social_links_settingsUpSql, map[string]*bintree{}}, + "1682073779_settings_table_remove_latest_derived_path_column.up.sql": &bintree{_1682073779_settings_table_remove_latest_derived_path_columnUpSql, map[string]*bintree{}}, + "1682146075_add_created_at_to_saved_addresses.up.sql": &bintree{_1682146075_add_created_at_to_saved_addressesUpSql, map[string]*bintree{}}, + "1682393575_sync_ens_name.up.sql": &bintree{_1682393575_sync_ens_nameUpSql, map[string]*bintree{}}, + "1683457503_add_blocks_ranges_sequential_table.up.sql": &bintree{_1683457503_add_blocks_ranges_sequential_tableUpSql, map[string]*bintree{}}, + "1683627613_accounts_and_keycards_improvements.up.sql": &bintree{_1683627613_accounts_and_keycards_improvementsUpSql, map[string]*bintree{}}, + "1685041348_settings_table_add_latest_derived_path_column.up.sql": &bintree{_1685041348_settings_table_add_latest_derived_path_columnUpSql, map[string]*bintree{}}, + "1685440989_update_color_id_accounts.up.sql": &bintree{_1685440989_update_color_id_accountsUpSql, map[string]*bintree{}}, + "1685463947_add_to_asset_to_multitransaction.up.sql": &bintree{_1685463947_add_to_asset_to_multitransactionUpSql, map[string]*bintree{}}, + "1685880973_add_profile_links_settings_table.up.sql": &bintree{_1685880973_add_profile_links_settings_tableUpSql, map[string]*bintree{}}, + "1686041510_add_idx_transfers_blkno_loaded.up.sql": &bintree{_1686041510_add_idx_transfers_blkno_loadedUpSql, map[string]*bintree{}}, + "1686048341_transfers_receipt_json_blob_out.up.sql.down.sql": &bintree{_1686048341_transfers_receipt_json_blob_outUpSqlDownSql, map[string]*bintree{}}, + "1686048341_transfers_receipt_json_blob_out.up.sql.up.sql": &bintree{_1686048341_transfers_receipt_json_blob_outUpSqlUpSql, map[string]*bintree{}}, + "1686825075_cleanup_token_address.up.sql": &bintree{_1686825075_cleanup_token_addressUpSql, map[string]*bintree{}}, + "1687193315_transfers_extract_from_to_address.down.sql": &bintree{_1687193315_transfers_extract_from_to_addressDownSql, map[string]*bintree{}}, + "1687193315_transfers_extract_from_to_address.up.sql": &bintree{_1687193315_transfers_extract_from_to_addressUpSql, map[string]*bintree{}}, + "1687249080_add_position_accounts.up..sql": &bintree{_1687249080_add_position_accountsUpSql, map[string]*bintree{}}, + "1687269871_add_device_name.up.sql": &bintree{_1687269871_add_device_nameUpSql, map[string]*bintree{}}, + "1687506642_include_watch_only_account_setting.up.sql": &bintree{_1687506642_include_watch_only_account_settingUpSql, map[string]*bintree{}}, + "1688022264_add_include_watch_only_account_to_settings_sync_clock.up.sql": &bintree{_1688022264_add_include_watch_only_account_to_settings_sync_clockUpSql, map[string]*bintree{}}, + "1688054680_add_columns_to_multitransaction.up.sql": &bintree{_1688054680_add_columns_to_multitransactionUpSql, map[string]*bintree{}}, + "1688636552_keycards_table_columns_update.up.sql": &bintree{_1688636552_keycards_table_columns_updateUpSql, map[string]*bintree{}}, + "1689248269_add_related_chain_id_networks.up.sql": &bintree{_1689248269_add_related_chain_id_networksUpSql, map[string]*bintree{}}, + "1689340211_index_filter_columns.up.sql": &bintree{_1689340211_index_filter_columnsUpSql, map[string]*bintree{}}, + "1689498471_make_wallet_accounts_positions_non_negative.up.sql": &bintree{_1689498471_make_wallet_accounts_positions_non_negativeUpSql, map[string]*bintree{}}, + "1689856991_add_soft_remove_column_for_keypairs_and_accounts.up.sql": &bintree{_1689856991_add_soft_remove_column_for_keypairs_and_accountsUpSql, map[string]*bintree{}}, + "1690225863_add_collectibles_ownership_cache.up.sql": &bintree{_1690225863_add_collectibles_ownership_cacheUpSql, map[string]*bintree{}}, + "1690734354_add_preferred_chain_ids.up.sql": &bintree{_1690734354_add_preferred_chain_idsUpSql, map[string]*bintree{}}, + "1691173699_add_collectibles_and_collections_data_cache.up.sql": &bintree{_1691173699_add_collectibles_and_collections_data_cacheUpSql, map[string]*bintree{}}, + "1691753758_move_wallet_tables_to_wallet_db.up.sql": &bintree{_1691753758_move_wallet_tables_to_wallet_dbUpSql, map[string]*bintree{}}, + "1691753800_pubsubtopic_key.up.sql": &bintree{_1691753800_pubsubtopic_keyUpSql, map[string]*bintree{}}, + "1693900971_add_profile_migration_needed_column_to_settings_table.up.sql": &bintree{_1693900971_add_profile_migration_needed_column_to_settings_tableUpSql, map[string]*bintree{}}, + "1694764094_add_original_to_networks.up.sql": &bintree{_1694764094_add_original_to_networksUpSql, map[string]*bintree{}}, + "1695974515_add_is_sepolia_enabled_to_settings.up.sql": &bintree{_1695974515_add_is_sepolia_enabled_to_settingsUpSql, map[string]*bintree{}}, + "1696259336_settings_add_url_unfurling_mode.up.sql": &bintree{_1696259336_settings_add_url_unfurling_modeUpSql, map[string]*bintree{}}, + "1697123140_drop_include_watch_only_accounts.up.sql": &bintree{_1697123140_drop_include_watch_only_accountsUpSql, map[string]*bintree{}}, + "1697123233_drop_include_watch_only_account_to_settings_sync_clock.up.sql": &bintree{_1697123233_drop_include_watch_only_account_to_settings_sync_clockUpSql, map[string]*bintree{}}, + "1697623289_add_omit_transfers_history_scan_to_settings.up.sql": &bintree{_1697623289_add_omit_transfers_history_scan_to_settingsUpSql, map[string]*bintree{}}, + "1699577175_use_shards.up.sql": &bintree{_1699577175_use_shardsUpSql, map[string]*bintree{}}, + "1700741911_clusterID.up.sql": &bintree{_1700741911_clusteridUpSql, map[string]*bintree{}}, + "1701084316_add_wallet_was_not_shown_to_keypairs_accounts.up.sql": &bintree{_1701084316_add_wallet_was_not_shown_to_keypairs_accountsUpSql, map[string]*bintree{}}, + "1701084317_add_mnemonic_was_not_shown_to_settings.up.sql": &bintree{_1701084317_add_mnemonic_was_not_shown_to_settingsUpSql, map[string]*bintree{}}, + "1701444172_token_preferences.up.sql": &bintree{_1701444172_token_preferencesUpSql, map[string]*bintree{}}, + "1701961850_shards_test.up.sql": &bintree{_1701961850_shards_testUpSql, map[string]*bintree{}}, + "1702395750_fix_enr_shards_test.up.sql": &bintree{_1702395750_fix_enr_shards_testUpSql, map[string]*bintree{}}, + "1702999401_add_dns_discovery_url.up.sql": &bintree{_1702999401_add_dns_discovery_urlUpSql, map[string]*bintree{}}, + "1704281285_tokens_advanced_settings.up.sql": &bintree{_1704281285_tokens_advanced_settingsUpSql, map[string]*bintree{}}, + "1705338819_collectible_preferences.up.sql": &bintree{_1705338819_collectible_preferencesUpSql, map[string]*bintree{}}, + "1706097653_migration_order_fix.up.sql": &bintree{_1706097653_migration_order_fixUpSql, map[string]*bintree{}}, + "1706955596_community_storenodes.up.sql": &bintree{_1706955596_community_storenodesUpSql, map[string]*bintree{}}, + "1708352924_add_peer_syncing_enabled_to_settings.up.sql": &bintree{_1708352924_add_peer_syncing_enabled_to_settingsUpSql, map[string]*bintree{}}, + "1708416025_make_sepolia_default.up.sql": &bintree{_1708416025_make_sepolia_defaultUpSql, map[string]*bintree{}}, + "1709203128_fix_chain_colors.up.sql": &bintree{_1709203128_fix_chain_colorsUpSql, map[string]*bintree{}}, + "1709795716_migration_order_fix.up.sql": &bintree{_1709795716_migration_order_fixUpSql, map[string]*bintree{}}, + "1711573194_rename_peersyncing_group_id_field.up.sql": &bintree{_1711573194_rename_peersyncing_group_id_fieldUpSql, map[string]*bintree{}}, + "doc.go": &bintree{docGo, map[string]*bintree{}}, }} // RestoreAsset restores an asset under the given directory. @@ -2775,7 +2907,7 @@ func RestoreAsset(dir, name string) error { if err != nil { return err } - err = os.WriteFile(_filePath(dir, name), data, info.Mode()) + err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) if err != nil { return err } diff --git a/appdatabase/migrations/sql/1711573194_rename_peersyncing_group_id_field.up.sql b/appdatabase/migrations/sql/1711573194_rename_peersyncing_group_id_field.up.sql new file mode 100644 index 00000000000..ca15ed52b4c --- /dev/null +++ b/appdatabase/migrations/sql/1711573194_rename_peersyncing_group_id_field.up.sql @@ -0,0 +1,5 @@ +DROP INDEX peersyncing_messages_timestamp; + +ALTER TABLE peersyncing_messages RENAME COLUMN group_id TO chat_id; + +CREATE INDEX peersyncing_messages_timestamp ON peersyncing_messages(chat_id, timestamp); diff --git a/protocol/common/message_sender.go b/protocol/common/message_sender.go index 2bcbd6c3bf2..fa0d2a55e0e 100644 --- a/protocol/common/message_sender.go +++ b/protocol/common/message_sender.go @@ -763,7 +763,7 @@ func (s *MessageSender) unwrapDatasyncMessage(m *v1protocol.StatusMessage, respo response.DatasyncRequests = append(response.DatasyncRequests, datasyncMessage.Requests...) for _, o := range datasyncMessage.GroupOffers { for _, mID := range o.MessageIds { - response.DatasyncOffers = append(response.DatasyncOffers, DatasyncOffer{GroupID: o.GroupId, MessageID: mID}) + response.DatasyncOffers = append(response.DatasyncOffers, DatasyncOffer{ChatID: o.GroupId, MessageID: mID}) } } @@ -837,7 +837,7 @@ func (s *MessageSender) HandleMessages(wakuMessage *types.Message) (*HandleMessa } type DatasyncOffer struct { - GroupID []byte + ChatID []byte MessageID []byte } diff --git a/protocol/messenger.go b/protocol/messenger.go index 652e614874c..f46f66f855c 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -2521,7 +2521,6 @@ func (m *Messenger) sendChatMessage(ctx context.Context, message *common.Message syncMessageType = peersyncing.SyncMessageCommunityType } else if chat.PrivateGroupChat() { syncMessageType = peersyncing.SyncMessagePrivateGroup - } wrappedMessage, err := v1protocol.WrapMessageV1(rawMessage.Payload, rawMessage.MessageType, rawMessage.Sender) @@ -2532,7 +2531,7 @@ func (m *Messenger) sendChatMessage(ctx context.Context, message *common.Message syncMessage := peersyncing.SyncMessage{ Type: syncMessageType, ID: types.Hex2Bytes(rawMessage.ID), - GroupID: []byte(chat.ID), + ChatID: []byte(chat.ID), Payload: wrappedMessage, Timestamp: m.transport.GetCurrentTime() / 1000, } diff --git a/protocol/messenger_handler.go b/protocol/messenger_handler.go index cc1ff3ba283..dad11dbe22b 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -2457,7 +2457,7 @@ func (m *Messenger) addPeersyncingMessage(chat *Chat, msg *v1protocol.StatusMess syncMessage := peersyncing.SyncMessage{ Type: syncMessageType, ID: msg.ApplicationLayer.ID, - GroupID: []byte(chat.ID), + ChatID: []byte(chat.ID), Payload: msg.EncryptionLayer.Payload, Timestamp: uint64(msg.TransportLayer.Message.Timestamp), } diff --git a/protocol/messenger_peersyncing.go b/protocol/messenger_peersyncing.go index a8cdf16455c..1149187a688 100644 --- a/protocol/messenger_peersyncing.go +++ b/protocol/messenger_peersyncing.go @@ -22,7 +22,7 @@ import ( v1protocol "github.com/status-im/status-go/protocol/v1" ) -var peerSyncingLoopInterval time.Duration = 60 * time.Second +var peerSyncingLoopInterval = 60 * time.Second var maxAdvertiseMessages = 40 func (m *Messenger) markDeliveredMessages(acks [][]byte) { @@ -118,37 +118,47 @@ func (m *Messenger) sendDatasyncOffers() error { return nil } - communities, err := m.communitiesManager.Joined() + err = m.sendDatasyncOffersForCommunities() if err != nil { return err } - for _, community := range communities { + err = m.sendDatasyncOffersForChats() + if err != nil { + return err + } + + // Check all the group ids that need to be on offer + // Get all the messages that need to be offered + // Prepare datasync messages + // Dispatch them to the right group + return nil +} + +func (m *Messenger) sendDatasyncOffersForCommunities() error { + joinedCommunities, err := m.communitiesManager.Joined() + if err != nil { + return err + } + + for _, community := range joinedCommunities { var chatIDs [][]byte for id := range community.Chats() { chatIDs = append(chatIDs, []byte(community.IDString()+id)) } - if len(chatIDs) == 0 { continue } - - availableMessages, err := m.peersyncing.AvailableMessagesByGroupIDs(chatIDs, maxAdvertiseMessages) + availableMessagesMap, err := m.peersyncing.AvailableMessagesMapByChatIDs(chatIDs, maxAdvertiseMessages) if err != nil { return err } - availableMessagesMap := make(map[string][][]byte) - for _, m := range availableMessages { - groupID := types.Bytes2Hex(m.GroupID) - availableMessagesMap[groupID] = append(availableMessagesMap[groupID], m.ID) - } - datasyncMessage := &datasyncproto.Payload{} - if len(availableMessages) == 0 { + if len(availableMessagesMap) == 0 { continue } - for groupID, m := range availableMessagesMap { - datasyncMessage.GroupOffers = append(datasyncMessage.GroupOffers, &datasyncproto.Offer{GroupId: types.Hex2Bytes(groupID), MessageIds: m}) + for chatID, m := range availableMessagesMap { + datasyncMessage.GroupOffers = append(datasyncMessage.GroupOffers, &datasyncproto.Offer{GroupId: types.Hex2Bytes(chatID), MessageIds: m}) } payload, err := proto.Marshal(datasyncMessage) if err != nil { @@ -164,12 +174,43 @@ func (m *Messenger) sendDatasyncOffers() error { if err != nil { return err } + } + return nil +} +func (m *Messenger) sendDatasyncOffersForChats() error { + for _, chat := range m.Chats() { + chatIDBytes := []byte(chat.ID) + availableMessagesMap, err := m.peersyncing.AvailableMessagesMapByChatIDs([][]byte{chatIDBytes}, maxAdvertiseMessages) + if err != nil { + return err + } + datasyncMessage := &datasyncproto.Payload{} + if len(availableMessagesMap) == 0 { + continue + } + for _, message := range availableMessagesMap { + datasyncMessage.GroupOffers = append(datasyncMessage.GroupOffers, &datasyncproto.Offer{GroupId: chatIDBytes, MessageIds: message}) + } + payload, err := proto.Marshal(datasyncMessage) + if err != nil { + return err + } + + publicKey, err := chat.PublicKey() + if err != nil { + return err + } + rawMessage := common.RawMessage{ + Payload: payload, + Ephemeral: true, + SkipApplicationWrap: true, + } + _, err = m.sender.SendPrivate(context.Background(), publicKey, &rawMessage) + if err != nil { + return err + } } - // Check all the group ids that need to be on offer - // Get all the messages that need to be offered - // Prepare datasync messages - // Dispatch them to the right group return nil } @@ -188,7 +229,7 @@ func (m *Messenger) OnDatasyncOffer(response *common.HandleMessageResponse) erro var offeredMessages []peersyncing.SyncMessage for _, o := range offers { - offeredMessages = append(offeredMessages, peersyncing.SyncMessage{GroupID: o.GroupID, ID: o.MessageID}) + offeredMessages = append(offeredMessages, peersyncing.SyncMessage{ChatID: o.ChatID, ID: o.MessageID}) } messagesToFetch, err := m.peersyncing.OnOffer(offeredMessages) @@ -235,7 +276,7 @@ func (m *Messenger) OnDatasyncOffer(response *common.HandleMessageResponse) erro func (m *Messenger) canSyncMessageWith(message peersyncing.SyncMessage, peer *ecdsa.PublicKey) (bool, error) { switch message.Type { case peersyncing.SyncMessageCommunityType: - chat, ok := m.allChats.Load(string(message.GroupID)) + chat, ok := m.allChats.Load(string(message.ChatID)) if !ok { return false, nil } @@ -245,7 +286,12 @@ func (m *Messenger) canSyncMessageWith(message peersyncing.SyncMessage, peer *ec } return m.canSyncCommunityMessageWith(chat, community, peer) - + case peersyncing.SyncMessageOneToOneType: + chat, ok := m.allChats.Load(string(message.ChatID)) + if !ok { + return false, nil + } + return m.canSyncOneToOneMessageWith(chat, peer) default: return false, nil } @@ -258,6 +304,10 @@ func (m *Messenger) canSyncCommunityMessageWith(chat *Chat, community *communiti return community.IsMemberInChat(peer, chat.CommunityChatID()), nil } +func (m *Messenger) canSyncOneToOneMessageWith(chat *Chat, peer *ecdsa.PublicKey) (bool, error) { + return chat.HasMember(common.PubkeyToHex(peer)), nil +} + func (m *Messenger) OnDatasyncRequests(requester *ecdsa.PublicKey, messageIDs [][]byte) error { if len(messageIDs) == 0 { return nil diff --git a/protocol/messenger_peersyncing_test.go b/protocol/messenger_peersyncing_test.go index 44b4655047b..e901bde0c33 100644 --- a/protocol/messenger_peersyncing_test.go +++ b/protocol/messenger_peersyncing_test.go @@ -2,6 +2,7 @@ package protocol import ( "context" + "encoding/hex" "testing" "time" @@ -9,6 +10,7 @@ import ( "go.uber.org/zap" gethbridge "github.com/status-im/status-go/eth-node/bridge/geth" + "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/protocol/common" "github.com/status-im/status-go/protocol/communities" @@ -243,7 +245,7 @@ func (s *MessengerPeersyncingSuite) TestCanSyncMessageWith() { syncMessage := peersyncing.SyncMessage{ ID: []byte("test-id"), - GroupID: []byte(chat.ID), + ChatID: []byte(chat.ID), Type: peersyncing.SyncMessageCommunityType, Payload: []byte("some-payload"), Timestamp: 1, @@ -261,3 +263,97 @@ func (s *MessengerPeersyncingSuite) TestCanSyncMessageWith() { s.Require().NoError(err) s.Require().True(canSyncWithAlice) } + +func (s *MessengerPeersyncingSuite) TestSyncOneToOne() { + s.alice.featureFlags.Peersyncing = true + s.owner.featureFlags.Peersyncing = true + + pkString := hex.EncodeToString(crypto.FromECDSAPub(&s.alice.identity.PublicKey)) + chat := CreateOneToOneChat(pkString, &s.alice.identity.PublicKey, s.owner.transport) + + chat.LastClockValue = uint64(100000000000000) + err := s.owner.SaveChat(chat) + s.NoError(err) + _, err = s.alice.Join(chat) + s.NoError(err) + + chatID := chat.ID + inputMessage := common.NewMessage() + inputMessage.ChatId = chatID + inputMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN + inputMessage.Text = "some text" + + ctx := context.Background() + + // Send message, it should be received + response, err := s.alice.SendChatMessage(ctx, inputMessage) + s.Require().NoError(err) + s.Require().Len(response.Messages(), 1) + messageID := response.Messages()[0].ID + + // Make sure the message makes it to the owner + response, err = WaitOnMessengerResponse( + s.owner, + func(r *MessengerResponse) bool { + return len(r.Messages()) == 1 && r.Messages()[0].ID == messageID + }, + "message not received", + ) + s.Require().NoError(err) + s.Require().NotNil(response) + + msg, err := s.owner.peersyncing.AvailableMessages() + s.Require().NoError(err) + s.Require().Len(msg, 1) + + // Alice should now send an offer + _, err = WaitOnMessengerResponse( + s.alice, + func(r *MessengerResponse) bool { + return s.alice.peersyncingOffers[messageID[2:]] != 0 + }, + "offer not sent", + ) + s.Require().NoError(err) + + // Owner should now reply to the offer + _, err = WaitOnMessengerResponse( + s.owner, + func(r *MessengerResponse) bool { + return s.owner.peersyncingRequests[s.alice.myHexIdentity()+messageID[2:]] != 0 + }, + "request not sent", + ) + s.Require().NoError(err) +} + +func (s *MessengerPeersyncingSuite) TestCanSyncOneToOneMessageWith() { + s.alice.featureFlags.Peersyncing = true + s.owner.featureFlags.Peersyncing = true + + pkString := hex.EncodeToString(crypto.FromECDSAPub(&s.alice.identity.PublicKey)) + chat := CreateOneToOneChat(pkString, &s.alice.identity.PublicKey, s.owner.transport) + + chat.LastClockValue = uint64(100000000000000) + err := s.owner.SaveChat(chat) + s.NoError(err) + _, err = s.alice.Join(chat) + s.NoError(err) + + syncMessage := peersyncing.SyncMessage{ + ID: []byte("test-id"), + ChatID: []byte(chat.ID), + Type: peersyncing.SyncMessageOneToOneType, + Payload: []byte("some-payload"), + Timestamp: chat.LastClockValue, + } + s.Require().NoError(s.owner.peersyncing.Add(syncMessage)) + + canSyncWithBob, err := s.owner.canSyncOneToOneMessageWith(chat, &s.bob.identity.PublicKey) + s.Require().NoError(err) + s.Require().False(canSyncWithBob) + + canSyncWithAlice, err := s.owner.canSyncOneToOneMessageWith(chat, &s.alice.identity.PublicKey) + s.Require().NoError(err) + s.Require().True(canSyncWithAlice) +} diff --git a/protocol/peersyncing/peersyncing.go b/protocol/peersyncing/peersyncing.go index b598d162445..a8b5c166f71 100644 --- a/protocol/peersyncing/peersyncing.go +++ b/protocol/peersyncing/peersyncing.go @@ -1,5 +1,7 @@ package peersyncing +import "github.com/status-im/status-go/eth-node/types" + type PeerSyncing struct { persistence SyncMessagePersistence config Config @@ -25,12 +27,17 @@ func (p *PeerSyncing) AvailableMessages() ([]SyncMessage, error) { return p.persistence.All() } -func (p *PeerSyncing) AvailableMessagesByGroupID(groupID []byte, limit int) ([]SyncMessage, error) { - return p.persistence.ByGroupID(groupID, limit) -} - -func (p *PeerSyncing) AvailableMessagesByGroupIDs(groupIDs [][]byte, limit int) ([]SyncMessage, error) { - return p.persistence.ByGroupIDs(groupIDs, limit) +func (p *PeerSyncing) AvailableMessagesMapByChatIDs(groupIDs [][]byte, limit int) (map[string][][]byte, error) { + availableMessages, err := p.persistence.ByChatIDs(groupIDs, limit) + if err != nil { + return nil, err + } + availableMessagesMap := make(map[string][][]byte) + for _, m := range availableMessages { + chatID := types.Bytes2Hex(m.ChatID) + availableMessagesMap[chatID] = append(availableMessagesMap[chatID], m.ID) + } + return availableMessagesMap, err } func (p *PeerSyncing) MessagesByIDs(messageIDs [][]byte) ([]SyncMessage, error) { diff --git a/protocol/peersyncing/peersyncing_test.go b/protocol/peersyncing/peersyncing_test.go index 0b1e916f8f4..6abe992c418 100644 --- a/protocol/peersyncing/peersyncing_test.go +++ b/protocol/peersyncing/peersyncing_test.go @@ -29,13 +29,13 @@ func (s *PeerSyncingSuite) SetupTest() { s.p = New(Config{Database: db}) } -var testGroupID = []byte("group-id") +var testCommunityID = []byte("community-id") func (s *PeerSyncingSuite) TestBasic() { syncMessage := SyncMessage{ ID: []byte("test-id"), - GroupID: testGroupID, + ChatID: testCommunityID, Type: SyncMessageCommunityType, Payload: []byte("test"), Timestamp: 1, @@ -48,19 +48,19 @@ func (s *PeerSyncingSuite) TestBasic() { s.Require().NoError(err) s.Require().Len(allMessages, 1) - byGroupID, err := s.p.AvailableMessagesByGroupID(syncMessage.GroupID, 10) + byChatID, err := s.p.AvailableMessagesMapByChatIDs([][]byte{syncMessage.ChatID}, 10) s.Require().NoError(err) - s.Require().Len(byGroupID, 1) + s.Require().Len(byChatID, 1) - byGroupID, err = s.p.AvailableMessagesByGroupID([]byte("random-group-id"), 10) + byChatID, err = s.p.AvailableMessagesMapByChatIDs([][]byte{[]byte("random-group-id")}, 10) s.Require().NoError(err) - s.Require().Len(byGroupID, 0) + s.Require().Len(byChatID, 0) newSyncMessage := SyncMessage{ ID: []byte("test-id-2"), - GroupID: testGroupID, + ChatID: testCommunityID, Type: SyncMessageCommunityType, Payload: []byte("test-2"), Timestamp: 2, @@ -77,7 +77,7 @@ func (s *PeerSyncingSuite) TestOrderAndLimit() { syncMessage1 := SyncMessage{ ID: []byte("test-id-1"), - GroupID: testGroupID, + ChatID: testCommunityID, Type: SyncMessageCommunityType, Payload: []byte("test"), Timestamp: 1, @@ -85,7 +85,7 @@ func (s *PeerSyncingSuite) TestOrderAndLimit() { syncMessage2 := SyncMessage{ ID: []byte("test-id-2"), - GroupID: testGroupID, + ChatID: testCommunityID, Type: SyncMessageCommunityType, Payload: []byte("test"), Timestamp: 2, @@ -93,7 +93,7 @@ func (s *PeerSyncingSuite) TestOrderAndLimit() { syncMessage3 := SyncMessage{ ID: []byte("test-id-3"), - GroupID: testGroupID, + ChatID: testCommunityID, Type: SyncMessageCommunityType, Payload: []byte("test"), Timestamp: 3, @@ -101,7 +101,7 @@ func (s *PeerSyncingSuite) TestOrderAndLimit() { syncMessage4 := SyncMessage{ ID: []byte("test-id-4"), - GroupID: testGroupID, + ChatID: testCommunityID, Type: SyncMessageCommunityType, Payload: []byte("test"), Timestamp: 4, @@ -112,22 +112,13 @@ func (s *PeerSyncingSuite) TestOrderAndLimit() { s.Require().NoError(s.p.Add(syncMessage3)) s.Require().NoError(s.p.Add(syncMessage4)) - byGroupID, err := s.p.AvailableMessagesByGroupID(testGroupID, 10) + byChatID, err := s.p.AvailableMessagesMapByChatIDs([][]byte{testCommunityID}, 10) s.Require().NoError(err) - s.Require().Len(byGroupID, 4) + s.Require().Len(byChatID, 4) - s.Require().Equal(syncMessage1.ID, byGroupID[3].ID) - s.Require().Equal(syncMessage2.ID, byGroupID[2].ID) - s.Require().Equal(syncMessage3.ID, byGroupID[1].ID) - s.Require().Equal(syncMessage4.ID, byGroupID[0].ID) - - byGroupID, err = s.p.AvailableMessagesByGroupID(testGroupID, 3) + byChatID, err = s.p.AvailableMessagesMapByChatIDs([][]byte{testCommunityID}, 3) s.Require().NoError(err) - s.Require().Len(byGroupID, 3) - - s.Require().Equal(syncMessage2.ID, byGroupID[2].ID) - s.Require().Equal(syncMessage3.ID, byGroupID[1].ID) - s.Require().Equal(syncMessage4.ID, byGroupID[0].ID) + s.Require().Len(byChatID, 3) } diff --git a/protocol/peersyncing/sync_message.go b/protocol/peersyncing/sync_message.go index 8e5df1025e7..895f4827543 100644 --- a/protocol/peersyncing/sync_message.go +++ b/protocol/peersyncing/sync_message.go @@ -7,7 +7,7 @@ type SyncMessageType int type SyncMessage struct { ID []byte Type SyncMessageType - GroupID []byte + ChatID []byte Payload []byte Timestamp uint64 } @@ -15,7 +15,7 @@ type SyncMessage struct { var ErrSyncMessageNotValid = errors.New("sync message not valid") func (s *SyncMessage) Valid() error { - valid := len(s.ID) != 0 && s.Type != SyncMessageNoType && len(s.GroupID) != 0 && len(s.Payload) != 0 && s.Timestamp != 0 + valid := len(s.ID) != 0 && s.Type != SyncMessageNoType && len(s.ChatID) != 0 && len(s.Payload) != 0 && s.Timestamp != 0 if !valid { return ErrSyncMessageNotValid } diff --git a/protocol/peersyncing/sync_message_persistence.go b/protocol/peersyncing/sync_message_persistence.go index 78e3e40bd2b..1e6a119186b 100644 --- a/protocol/peersyncing/sync_message_persistence.go +++ b/protocol/peersyncing/sync_message_persistence.go @@ -11,8 +11,7 @@ type SyncMessagePersistence interface { Add(SyncMessage) error All() ([]SyncMessage, error) Complement([]SyncMessage) ([]SyncMessage, error) - ByGroupID([]byte, int) ([]SyncMessage, error) - ByGroupIDs([][]byte, int) ([]SyncMessage, error) + ByChatIDs([][]byte, int) ([]SyncMessage, error) ByMessageIDs([][]byte) ([]SyncMessage, error) } @@ -28,13 +27,13 @@ func (p *SyncMessageSQLitePersistence) Add(message SyncMessage) error { if err := message.Valid(); err != nil { return err } - _, err := p.db.Exec(`INSERT INTO peersyncing_messages (id, type, group_id, payload, timestamp) VALUES (?, ?, ?, ?, ?)`, message.ID, message.Type, message.GroupID, message.Payload, message.Timestamp) + _, err := p.db.Exec(`INSERT INTO peersyncing_messages (id, type, chat_id, payload, timestamp) VALUES (?, ?, ?, ?, ?)`, message.ID, message.Type, message.ChatID, message.Payload, message.Timestamp) return err } func (p *SyncMessageSQLitePersistence) All() ([]SyncMessage, error) { var messages []SyncMessage - rows, err := p.db.Query(`SELECT id, type, group_id, payload, timestamp FROM peersyncing_messages`) + rows, err := p.db.Query(`SELECT id, type, chat_id, payload, timestamp FROM peersyncing_messages`) if err != nil { return nil, err } @@ -44,7 +43,7 @@ func (p *SyncMessageSQLitePersistence) All() ([]SyncMessage, error) { for rows.Next() { var m SyncMessage - err := rows.Scan(&m.ID, &m.Type, &m.GroupID, &m.Payload, &m.Timestamp) + err := rows.Scan(&m.ID, &m.Type, &m.ChatID, &m.Payload, &m.Timestamp) if err != nil { return nil, err } @@ -54,9 +53,22 @@ func (p *SyncMessageSQLitePersistence) All() ([]SyncMessage, error) { return messages, nil } -func (p *SyncMessageSQLitePersistence) ByGroupID(groupID []byte, limit int) ([]SyncMessage, error) { +func (p *SyncMessageSQLitePersistence) ByChatIDs(ids [][]byte, limit int) ([]SyncMessage, error) { + if len(ids) == 0 { + return nil, nil + } + + queryArgs := make([]interface{}, 0, len(ids)) + for _, id := range ids { + queryArgs = append(queryArgs, id) + } + queryArgs = append(queryArgs, limit) + + inVector := strings.Repeat("?, ", len(ids)-1) + "?" + query := "SELECT id, type, chat_id, payload, timestamp FROM peersyncing_messages WHERE chat_id IN (" + inVector + ") ORDER BY timestamp DESC LIMIT ?" // nolint: gosec + var messages []SyncMessage - rows, err := p.db.Query(`SELECT id, type, group_id, payload, timestamp FROM peersyncing_messages WHERE group_id = ? ORDER BY timestamp DESC LIMIT ?`, groupID, limit) + rows, err := p.db.Query(query, queryArgs...) if err != nil { return nil, err } @@ -66,7 +78,7 @@ func (p *SyncMessageSQLitePersistence) ByGroupID(groupID []byte, limit int) ([]S for rows.Next() { var m SyncMessage - err := rows.Scan(&m.ID, &m.Type, &m.GroupID, &m.Payload, &m.Timestamp) + err := rows.Scan(&m.ID, &m.Type, &m.ChatID, &m.Payload, &m.Timestamp) if err != nil { return nil, err } @@ -87,7 +99,7 @@ func (p *SyncMessageSQLitePersistence) Complement(messages []SyncMessage) ([]Syn } inVector := strings.Repeat("?, ", len(ids)-1) + "?" - query := "SELECT id, type, group_id, payload, timestamp FROM peersyncing_messages WHERE id IN (" + inVector + ")" // nolint: gosec + query := "SELECT id, type, chat_id, payload, timestamp FROM peersyncing_messages WHERE id IN (" + inVector + ")" // nolint: gosec availableMessages := make(map[string]SyncMessage) rows, err := p.db.Query(query, ids...) @@ -100,7 +112,7 @@ func (p *SyncMessageSQLitePersistence) Complement(messages []SyncMessage) ([]Syn for rows.Next() { var m SyncMessage - err := rows.Scan(&m.ID, &m.Type, &m.GroupID, &m.Payload, &m.Timestamp) + err := rows.Scan(&m.ID, &m.Type, &m.ChatID, &m.Payload, &m.Timestamp) if err != nil { return nil, err } @@ -120,42 +132,6 @@ func (p *SyncMessageSQLitePersistence) Complement(messages []SyncMessage) ([]Syn return complement, nil } -func (p *SyncMessageSQLitePersistence) ByGroupIDs(ids [][]byte, limit int) ([]SyncMessage, error) { - if len(ids) == 0 { - return nil, nil - } - - queryArgs := make([]interface{}, 0, len(ids)) - for _, id := range ids { - queryArgs = append(queryArgs, id) - } - queryArgs = append(queryArgs, limit) - - inVector := strings.Repeat("?, ", len(ids)-1) + "?" - query := "SELECT id, type, group_id, payload, timestamp FROM peersyncing_messages WHERE group_id IN (" + inVector + ") ORDER BY timestamp DESC LIMIT ?" // nolint: gosec - - var messages []SyncMessage - rows, err := p.db.Query(query, queryArgs...) - if err != nil { - return nil, err - } - - defer rows.Close() - - for rows.Next() { - var m SyncMessage - - err := rows.Scan(&m.ID, &m.Type, &m.GroupID, &m.Payload, &m.Timestamp) - if err != nil { - return nil, err - } - - messages = append(messages, m) - } - return messages, nil - -} - func (p *SyncMessageSQLitePersistence) ByMessageIDs(ids [][]byte) ([]SyncMessage, error) { if len(ids) == 0 { return nil, nil @@ -167,7 +143,7 @@ func (p *SyncMessageSQLitePersistence) ByMessageIDs(ids [][]byte) ([]SyncMessage } inVector := strings.Repeat("?, ", len(ids)-1) + "?" - query := "SELECT id, type, group_id, payload, timestamp FROM peersyncing_messages WHERE id IN (" + inVector + ")" // nolint: gosec + query := "SELECT id, type, chat_id, payload, timestamp FROM peersyncing_messages WHERE id IN (" + inVector + ")" // nolint: gosec var messages []SyncMessage rows, err := p.db.Query(query, queryArgs...) @@ -180,7 +156,7 @@ func (p *SyncMessageSQLitePersistence) ByMessageIDs(ids [][]byte) ([]SyncMessage for rows.Next() { var m SyncMessage - err := rows.Scan(&m.ID, &m.Type, &m.GroupID, &m.Payload, &m.Timestamp) + err := rows.Scan(&m.ID, &m.Type, &m.ChatID, &m.Payload, &m.Timestamp) if err != nil { return nil, err }