Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#9927] Fast blocks sync after being offline #9942

Merged
merged 1 commit into from
Jan 30, 2020

Conversation

rasom
Copy link
Contributor

@rasom rasom commented Jan 29, 2020

fix #9927

Front end changes:
As there is no guarantee that newblock event will be dispatched
consequently (e.g. if there was a delay after block#1 the next event
might be dispatched for a block#2000, no guarantee that block#2 will be
the next one), newTransactions field was added with a map of accounts
to the number of new transactions received to this block. In result if
there are new transactions we request them all of db instead of fetching
them on for the block specified in newblock event, as it was done
previously.

Back end changes:

  • In order to avoid handling of the reorganized blocks we use an offset
    from the latest known block when start listening to new blocks. Before
    this commit the offset was 15 blocks for all networks. This offset is
    too big for mainnet and causes noticeable delay of marking a transfer as
    confirmed in Status (comparing to etherscan). So it was changed to be 5
    blocks on mainnet and is still 15 blocks on other networks.
  • Also before this commit all new blocks were handled one by one with
    network specific interval (10s for mainnet), which means that in case of
    lost internet connection or application suspension (happens on iOS)
    receiving of new blocks would be paused and then resumed with the same
    "speed" - 1 blocks per 10s. In case if that pause is big enough the
    application would never catch up with the latest block in the network,
    and this also causes the state of transfers to be delayed in the
    application. In this commit in case if there was more than 40s delay
    after receiving of the previous block the whole history in range between
    the previous received block and ("latest"-reorgeSafetyDepth) block is
    checked at once and app catches up with a recent state of the chain.

status: ready

@rasom rasom requested a review from a team as a code owner January 29, 2020 09:24
@auto-assign auto-assign bot removed the request for review from a team January 29, 2020 09:25
@status-github-bot
Copy link

Pull Request Checklist

  • Docs: Updated the documentation, if affected
  • Docs: Added or updated inline comments explaining intention of the code
  • Tests: Ensured that all new UI elements have been assigned accessibility IDs
  • Tests: Signaled need for E2E tests with label, if applicable
  • Tests: Briefly described what was tested and what platforms were used
  • UI: In case of UI changes, ensured that UI matches Figma
  • UI: In case of UI changes, requested review from a Core UI designer
  • UI: In case of UI changes, included screenshots of implementation

@rasom rasom changed the title [#9927] Fast blocks sync afetr being offline [#9927] Fast blocks sync after being offline Jan 29, 2020
@rasom rasom self-assigned this Jan 29, 2020
@status-im-auto
Copy link
Member

status-im-auto commented Jan 29, 2020

Jenkins Builds

Click to see older builds (12)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 81f2424 #1 2020-01-29 09:38:30 ~13 min ios 📦ipa 📲
✔️ 81f2424 #1 2020-01-29 09:42:04 ~16 min android 📦apk 📲
✔️ 81f2424 #1 2020-01-29 09:43:10 ~18 min android-e2e 📦apk 📲
✔️ fef9276 #2 2020-01-29 17:06:08 ~13 min ios 📦ipa 📲
✔️ fef9276 #2 2020-01-29 17:09:29 ~16 min android-e2e 📦apk 📲
✔️ fef9276 #2 2020-01-29 17:10:51 ~18 min android 📦apk 📲
✔️ a5d9fdd #3 2020-01-30 06:34:08 ~13 min ios 📦ipa 📲
✔️ a5d9fdd #3 2020-01-30 06:38:06 ~17 min android-e2e 📦apk 📲
✔️ a5d9fdd #3 2020-01-30 06:38:53 ~18 min android 📦apk 📲
✔️ 0d6d2fb #4 2020-01-30 08:08:46 ~13 min ios 📦ipa 📲
✔️ 0d6d2fb #4 2020-01-30 08:12:07 ~16 min android-e2e 📦apk 📲
✔️ 0d6d2fb #4 2020-01-30 08:13:33 ~18 min android 📦apk 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 4396991 #5 2020-01-30 09:24:38 ~9 min ios 📦ipa 📲
✔️ 4396991 #5 2020-01-30 09:25:45 ~11 min android-e2e 📦apk 📲
✔️ 4396991 #5 2020-01-30 09:30:30 ~15 min android 📦apk 📲
✔️ b41df2f #6 2020-01-30 17:55:56 ~15 min ios 📦ipa 📲
✔️ b41df2f #6 2020-01-30 17:57:58 ~17 min android 📦apk 📲
✔️ b41df2f #6 2020-01-30 17:59:57 ~19 min android-e2e 📦apk 📲

@yenda
Copy link
Contributor

yenda commented Jan 29, 2020

@rasom could you describe what was changed and how it fixed the issue?

looks like it works better for me now, I tried on a recover account and sent funds and the transaction was updated shortly after etherescan shows the update which was not the case before. To verify I also went back to RC4 and sent a transaction after starting the app (killed for a while, no background) and it still shows as pending when etherscan already confirmed 5 blocks)

@rasom
Copy link
Contributor Author

rasom commented Jan 29, 2020

@yenda
changes on go side:

  • there is a reorgSafetyDepth constant, which is used as an offset from the latest block, so that we start listen to the new blocks starting from "latets"-reorgSafetyDepth. It is added to avoid fetching of blocks which will be reorganised, as I understand. It was 15, which is probably fine for testnet networks, but is a bit too big for mainnet. So I changed it to 5, and that's the reason why transactions appear faster right after sending.
  • another change is that in case if the next block is received after a noticeable delay (it may happen if app is suspended on iOS or when you loose internet connection), instead of fetching next blocks one by one we scan the range last-recieved-block=>("latest"-reorgSafetyDepth) using the same mechanism we have for tx history. For instance, if you are 200 blocks behind "latest", currently in develop it will take not less than 2000s to fetch these blocks, and during this time new blocks will be added. In result you are likely to stay quite far from "latest" block unless your app is always online and in foreground. I set that delay threshold to 60s but it can be 30-40s.

@yenda
Copy link
Contributor

yenda commented Jan 29, 2020

can you add the explanation in the commit message?
is it still a wip?

@rasom rasom force-pushed the fast-block-sync-after-delay branch from 81f2424 to fef9276 Compare January 29, 2020 16:52
@rasom
Copy link
Contributor Author

rasom commented Jan 29, 2020

@yenda yes it is
of course I will add explanation to commit message

@flexsurfer flexsurfer self-requested a review January 29, 2020 17:48
@rasom rasom force-pushed the fast-block-sync-after-delay branch 2 times, most recently from 0d6d2fb to 4396991 Compare January 30, 2020 09:14
@flexsurfer flexsurfer requested a review from yenda January 30, 2020 09:15
@rasom
Copy link
Contributor Author

rasom commented Jan 30, 2020

@yenda @flexsurfer ready for review and testing, message is added

@yenda
Copy link
Contributor

yenda commented Jan 30, 2020

when did we stop supporting reorg of blocks and have this delay instead?

@rasom
Copy link
Contributor Author

rasom commented Jan 30, 2020

@yenda we never stopped to support reorgs, what do you mean?

@rasom
Copy link
Contributor Author

rasom commented Jan 30, 2020

@yenda as far as I understand the idea of that safetyDepth thing was rather to minimise the occurrences of reorgs in the app to avoid "flickering" state there, that's the best I can suggest (it seems that I have no one to ask about details). But we still handle reorgs if necessary.

@statustestbot
Copy link

100% of end-end tests have passed

Total executed tests: 98
Failed tests: 0
Passed tests: 98

Passed tests (98)

Click to expand
1. test_can_see_all_transactions_in_history
Device sessions

2. test_install_pack_and_send_sticker
Device sessions

3. test_send_message_in_group_chat
Device sessions

4. test_login_with_new_account
Device sessions

5. test_clear_history_of_group_chat_via_group_view
Device sessions

6. test_timestamp_in_chats
Device sessions

7. test_password_in_logcat_sign_in
Device sessions

8. test_logcat_recovering_account
Device sessions

9. test_modify_transaction_fee_values
Device sessions

10. test_public_chat_clear_history
Device sessions

11. test_need_help_section
Device sessions

12. test_send_and_open_links
Device sessions

13. test_mobile_data_usage_popup_stop_syncing
Device sessions

14. test_mobile_data_usage_settings
Device sessions

15. test_create_new_group_chat
Device sessions

16. test_sign_typed_message
Device sessions

17. test_user_can_switch_network
Device sessions

18. test_mobile_data_usage_popup_continue_syncing
Device sessions

19. test_home_view
Device sessions

20. test_open_google_com_via_open_dapp
Device sessions

21. test_send_message_to_newly_added_contact
Device sessions

22. test_share_contact_code_and_wallet_address
Device sessions

23. test_make_admin_member_of_group_chat
Device sessions

24. test_connection_is_secure
Device sessions

25. test_add_to_contacts
Device sessions

26. test_add_account_to_multiaccount_instance
Device sessions

27. test_can_open_dapp_from_dapp_store
Device sessions

28. test_refresh_button_browsing_app_webview
Device sessions

29. test_long_press_to_delete_1_1_chat
Device sessions

30. test_can_add_existing_ens
Device sessions

31. test_transaction_wrong_password_wallet
Device sessions

32. test_public_chat_messaging
Device sessions

33. test_unread_messages_counter_public_chat
Device sessions

34. test_delete_one_to_one_chat_via_delete_button
Device sessions

35. test_long_press_to_delete_public_chat
Device sessions

36. test_text_message_1_1_chat
Device sessions

37. test_delete_public_chat_via_delete_button
Device sessions

38. test_can_use_purchased_stickers_on_recovered_account
Device sessions

39. test_open_transaction_on_etherscan
Device sessions

40. test_onboarding_screen_when_requesting_tokens_for_recovered_account
Device sessions

41. test_unread_messages_counter_1_1_chat
Device sessions

42. test_contact_profile_view
Device sessions

43. test_logcat_backup_recovery_phrase
Device sessions

44. test_delete_group_chat_via_delete_button
Device sessions

45. test_start_chat_with_ens
Device sessions

46. test_add_and_remove_contact_from_public_chat
Device sessions

47. test_open_blocked_site
Device sessions

48. test_open_chat_by_pasting_public_key
Device sessions

49. test_ens_username_recipient
Device sessions

50. test_token_with_more_than_allowed_decimals
Device sessions

51. test_fetch_more_history_in_empty_chat
Device sessions

52. test_open_public_chat_using_deep_link
Device sessions

53. test_switch_users_and_add_new_account
Device sessions

54. test_copy_contact_code_and_wallet_address
Device sessions

55. test_send_transaction_from_daap
Device sessions

56. test_send_two_transactions_one_after_another_in_dapp
Device sessions

57. test_message_marked_as_sent_in_1_1_chat
Device sessions

58. test_long_press_delete_clear_all_dapps
Device sessions

59. test_copy_and_paste_messages
Device sessions

60. test_deploy_contract_from_daap
Device sessions

61. test_back_forward_buttons_browsing_website
Device sessions

62. test_password_in_logcat_creating_account
Device sessions

63. test_add_custom_token
Device sessions

64. test_sign_message_from_daap
Device sessions

65. test_group_chat_system_messages
Device sessions

66. test_dapps_permissions
Device sessions

67. test_request_public_key_status_test_daap
Device sessions

68. test_logcat_send_transaction_from_wallet
Device sessions

69. test_log_level_and_fleet
Device sessions

70. test_add_and_delete_watch_only_account_to_multiaccount_instance
Device sessions

71. test_recover_account_from_new_user_seedphrase
Device sessions

72. test_user_can_complete_tx_to_dapp_when_onboarding_via_dapp_completed
Device sessions

73. test_send_two_transactions_in_batch_in_dapp
Device sessions

74. test_ens_in_public_and_1_1_chats
Device sessions

75. test_block_user_from_public_chat
Device sessions

76. test_fetching_balance_after_offline
Device sessions

77. test_logcat_sign_message_from_daap
Device sessions

78. test_offline_status
Device sessions

79. test_wallet_set_up
Device sessions

80. test_manage_assets
Device sessions

81. test_add_new_group_chat_member
Device sessions

82. test_offline_messaging_1_1_chat
Device sessions

83. test_decline_invitation_to_group_chat
Device sessions

84. test_account_recovery_with_uppercase_recovery_phrase
Device sessions

85. test_send_token_with_7_decimals
Device sessions

86. test_user_can_see_all_own_assets_after_account_recovering
Device sessions

87. test_pass_phrase_validation
Device sessions

88. test_send_emoji
Device sessions

89. test_filters_from_daap
Device sessions

90. test_redirect_to_public_chat_tapping_tag_message
Device sessions

91. test_pair_devices_sync_one_to_one_contacts
Device sessions

92. test_logcat_send_transaction_from_daap
Device sessions

93. test_remove_member_from_group_chat
Device sessions

94. test_send_eth_from_wallet_to_address
Device sessions

95. test_send_stt_from_wallet
Device sessions

96. test_messaging_in_different_networks
Device sessions

97. test_collectible_from_wallet_opens_in_browser_view
Device sessions

98. test_insufficient_funds_wallet_positive_balance
Device sessions

rasom added a commit that referenced this pull request Jan 30, 2020
@Serhy
Copy link
Contributor

Serhy commented Jan 30, 2020

Works great for me on Android 8, iOS 13: sent tokens and ETH from 1-1 chat / Wallet appear in Wallet history according to the confirmations I compared in Etherscan. No delay, (well maybe +- 1 block which is absolutely fine).
Balance is updated, 1-1 chat outgoing and incoming TX status picked up fast enough (right when TX appears in history).
Amazing update!

Front end changes:
 As there is no guarantee that `newblock` event will be dispatched
consequently (e.g. if there was a delay after block#1 the next event
might be dispatched for a block#2000, no guarantee that block#2 will be
the next one), `newTransactions` field was added with a map of accounts
to the number of new transactions received to this block. In result if
there are new transactions we request them all of db instead of fetching
them on for the block specified in `newblock` event, as it was done
previously.

Back end changes:
- In order to avoid handling of the reorganized blocks we use an offset
from the latest known block when start listening to new blocks. Before
this commit the offset was 15 blocks for all networks. This offset is
too big for mainnet and causes noticeable delay of marking a transfer as
confirmed in Status (comparing to etherscan). So it was changed to be 5
blocks on mainnet and is still 15 blocks on other networks.
- Also before this commit all new blocks were handled one by one with
network specific interval (10s for mainnet), which means that in case of
lost internet connection or application suspension (happens on iOS)
receiving of new blocks would be paused and then resumed with the same
"speed" - 1 blocks per 10s. In case if that pause is big enough the
application would never catch up with the latest block in the network,
and this also causes the state of transfers to be delayed in the
application. In this commit in case if there was more than 40s delay
after receiving of the previous block the whole history in range between
the previous received block and ("latest"-reorgeSafetyDepth) block is
checked at once and app catches up with a recent state of the chain.
@rasom rasom force-pushed the fast-block-sync-after-delay branch from 4396991 to b41df2f Compare January 30, 2020 17:40
@rasom rasom merged commit b41df2f into develop Jan 30, 2020
@delete-merged-branch delete-merged-branch bot deleted the fast-block-sync-after-delay branch January 30, 2020 17:40
rasom added a commit to status-im/status-go that referenced this pull request Jan 31, 2020
rasom added a commit that referenced this pull request Jan 31, 2020
rasom added a commit to status-im/status-go that referenced this pull request Jan 31, 2020
Storing absolute path for different configs breaks compatibility on iOS
as app's dir is changed after upgrade. The solution is to store relative
paths and to concatenate it with `backend.rootDataDir`. The only
exception is `LogFile` as it is stored outside `backend.rootDataDir` on
Android. `LogDir` config was added to allow adding of custom dir for log
file.
Configs concerned:
`DataDir`
`LogDir`
`LogFile`
`KeystoreDir`
`BackupDisabledDataDir`
rasom added a commit that referenced this pull request Jan 31, 2020
rasom added a commit to status-im/status-go that referenced this pull request Feb 3, 2020
Storing absolute path for different configs breaks compatibility on iOS
as app's dir is changed after upgrade. The solution is to store relative
paths and to concatenate it with `backend.rootDataDir`. The only
exception is `LogFile` as it is stored outside `backend.rootDataDir` on
Android. `LogDir` config was added to allow adding of custom dir for log
file.
Configs concerned:
`DataDir`
`LogDir`
`LogFile`
`KeystoreDir`
`BackupDisabledDataDir`
rasom added a commit to status-im/status-go that referenced this pull request Feb 3, 2020
Storing absolute path for different configs breaks compatibility on iOS
as app's dir is changed after upgrade. The solution is to store relative
paths and to concatenate it with `backend.rootDataDir`. The only
exception is `LogFile` as it is stored outside `backend.rootDataDir` on
Android. `LogDir` config was added to allow adding of custom dir for log
file.
Configs concerned:
`DataDir`
`LogDir`
`LogFile`
`KeystoreDir`
`BackupDisabledDataDir`
rasom added a commit that referenced this pull request Feb 3, 2020
Storing absolute path for different configs breaks compatibility on iOS
as app's dir is changed after upgrade. The solution is to store relative
paths and to concatenate it with `backend.rootDataDir`. The only
exception is `LogFile` as it is stored outside `backend.rootDataDir` on
Android. `LogDir` config was added to allow adding of custom dir for log
file.
Configs concerned:
`DataDir`
`LogDir`
`LogFile`
`KeystoreDir`
`BackupDisabledDataDir`
flexsurfer pushed a commit that referenced this pull request Feb 3, 2020
Storing absolute path for different configs breaks compatibility on iOS
as app's dir is changed after upgrade. The solution is to store relative
paths and to concatenate it with `backend.rootDataDir`. The only
exception is `LogFile` as it is stored outside `backend.rootDataDir` on
Android. `LogDir` config was added to allow adding of custom dir for log
file.
Configs concerned:
`DataDir`
`LogDir`
`LogFile`
`KeystoreDir`
`BackupDisabledDataDir`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Transaction history is delayed in status
6 participants