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

Use rounded derived height sync param #2364

Merged
merged 3 commits into from
Sep 21, 2023
Merged

Use rounded derived height sync param #2364

merged 3 commits into from
Sep 21, 2023

Conversation

smk762
Copy link
Collaborator

@smk762 smk762 commented Sep 20, 2023

This PR is a further improvement on Z coin activation. Previously we used the "date" sync param, which would be effectively changed in the API to a derived height based on the average block time.
As blocktime varies, this potentially resulted in the derived height not being a constant value, and in cases where it did not return the same height as calculated during a prior sync, could force a long resync.
The simplest mitigation for this was to use the height param in the RPC instead, derived by the GUI and rounding the height to the nearest 1000 so that the same date selection would be much more likely to return the same value as in the past.

To Test:

  • Use the debug build of the app from CI to see the relevant log entries
  • Activate ARRR with a date set last month. Check the logs to find "requested":2448000 value in logs on lines like below:

[14:55:02] [info] [mm2.service.cpp:1495] [2605136]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":{"UpdatingBlocksCache":{"current_scanned_block":2521275,"first_sync_block":{"actual":2448000,"is_pre_sapling":false,"requested":2448000},"latest_block":2575728}},"status":"InProgress"}}

the requested value should be divisible by 1000.

  • activate ARRR again, using same date. You should see the same value for requested.

Note: This relies on updated data in coins_config.json, so please delete your local %appdata%/0.6.1 folder and the coins file used for your wallet before launch

@borngraced
Copy link
Member

Great! Thanks for the quick resolution @smk762

@kivqa
Copy link

kivqa commented Sep 20, 2023

@smk762 I did installation from 0 (with removing old app data). But for some reason Asset list is not displaying:
image
In case click on DEX button app crashed.

Logs file contains only one exception:
[json.exception.parse_error.101] parse error at line 44053, column 3: syntax error while parsing object key - unexpected number literal; expected string literal

14:59:35] [info] [mm2.service.cpp:205] [43926]: Retrieving Wallet information of /Users/ivankiseleiv/Library/Application Support/Komodo Wallet/config/0.6.1-coins.imp2.json
[14:59:35] [error] [mm2.service.cpp:232] [43926]: exception caught: [json.exception.parse_error.101] parse error at line 44053, column 3: syntax error while parsing object key - unexpected number literal; expected string literal
[14:59:35] [debug] [mm2.service.cpp:235] [43926]: Coins file does not exist!
[14:59:35] [debug] [mm2.service.cpp:235] [43926]: Coins file does not exist!
[14:59:35] [info] [qt.global.coins.cfg.model.cpp:213] [43926]: Initializing global coin cfg model with size 1
[14:59:35] [info] [global.provider.cpp:418] [43926]: Forcing update providers
[14:59:35] [info] [qt.addressbook.page.cpp:66] [43926]: post_login: filling addressbook from cfg
[14:59:35] [warning] [main.prerequisites.hpp:93] [43926]: QIODevice::read (QFile, "/Users/ivankiseleiv/Library/Application Support/Komodo Wallet/addressbook/imp2"): device not open
[14:59:35] [warning] [addressbook.cfg.cpp:48] [43926]: Addressbook config file was invalid, use empty configuration: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal. Content was: 

@kivqa
Copy link

kivqa commented Sep 20, 2023

@smk762 Problem releated to issue in this PR: KomodoPlatform/coins#821
I fixed it locally and do retest for ARRR activation

@@ -28,7 +28,7 @@ namespace atomic_dex::mm2
{
j["params"]["ticker"] = request.coin_name;
j["params"]["activation_params"]["mode"]["rpc"] = "Light";
j["params"]["activation_params"]["mode"]["rpc_data"]["sync_params"]["date"] = request.sync_date;
j["params"]["activation_params"]["mode"]["rpc_data"]["sync_params"]["height"] = request.sync_height;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik, as soon as sync params are present, mm2 will start syncing from scratch from the specified date/height, mo matter what it's in the DB

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes only if derived starting_height != to the minimum height in db

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't follow the links to the code, it's not jumping to the specified line, so i will just trust you :-)
ok, so we rely now on some height calculation based on a 60s blocktime which can vary a lot on ARRR
does it mean there is still a chance that my app will start syncing from scratch if the calc is off eg because blocktime was 120s in the last 2 weeks? is there a way to avoid this 100%? it takes 2 days to sync from scratch and i want to avoid this at all costs, so i rather prefer to remove sync_params completely from my repo then to risk syncing from scratch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, guess if i have the date set at 2 days and the DB is 2 years old, it should never happen... just need to think to reset the date back to 2 days ago after a complete resync from 2 years ago

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes right

Copy link
Collaborator Author

@smk762 smk762 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2367 has been prepared for the next release (0.6.2) after current API dev branch is merged.

so we rely now on some height calculation based on a 60s blocktime

The calculated avg block time between the checkpoint block (19000000) and the current height was a little over 63 seconds. In the GUI side date to height calc, I've assumed a 65 sec avg blocktime (to avoid recent dates potentially returning a block_height > tip) calculated as an offset from the checkpoint block (middle out reduces the cumulative overage compared to edges in).

This calc will generally return a height for a date which errors on the side of being earlier than actual, which is better than later than actual, for example if user knows the date of a tx and syncs from there but the calc sets it ahead a day, the sync excludes the tx. If set earlier, it is sure to be included.

The real problem though that this PR aims to fix is the potential for the date to height calc to return a different value when run again later, due to the rate of block production between the first and second runs. This changed block height may force a rescan even if selected date remains unchanged, and the odds this will happen increases as the time between first and second run increases. By rounding the result to the nearest 1000, it is much less likely for this to occur, and in a large majority of cases, the returned height will be the same so that no resync is triggered and the sync will continue from the prior cache height.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get reports that rounding to 1000 still results in cases of forced resync, we can change the rounding factor to a higher value, though a value of 1000 should be enough to overcome most periods of excessively high or low block production unless they are uncharacteristically extended before reverting back to the mean.

@kivqa
Copy link

kivqa commented Sep 20, 2023

Test 1: Activation ARRR coin with default Activation date - 2 days in the past
During activation of ARRR coin I observed such logs:
ActivatingCoin stage:

[15:24:32] [info] [mm2.service.cpp:1479] [76356]: ARRR enable_z_coin Task ID: 0
[15:24:32] [info] [mm2.service.cpp:1495] [76356]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":"ActivatingCoin","status":"InProgress"}}
[15:24:32] [info] [mm2.service.cpp:1555] [76356]: Waiting for ARRR to enable [InProgress: ActivatingCoin]...

UpdatingBlocksCache stage:

[15:24:42] [info] [mm2.service.cpp:1495] [76356]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":{"UpdatingBlocksCache":{"current_scanned_block":2556581,"first_sync_block":{"actual":2554000,"is_pre_sapling":false,"requested":2554000},"latest_block":2576044}},"status":"InProgress"}}

BuildingWalletDb stage:

[15:25:07] [info] [mm2.service.cpp:1495] [76356]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":{"BuildingWalletDb":{"current_scanned_block":2554000,"first_sync_block":{"actual":2554000,"is_pre_sapling":false,"requested":2554000},"latest_block":2576044}},"status":"InProgress"}}

RequestingWalletBalance stage:

[15:28:23] [info] [mm2.service.cpp:1495] [76356]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":"RequestingWalletBalance","status":"InProgress"}}
[15:28:28] [info] [mm2.service.cpp:1495] [76356]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":{"current_block":2576046,"first_sync_block":{"actual":2554000,"is_pre_sapling":false,"requested":2554000},"ticker":"ARRR","wallet_balance":{"address":"zs1gn3mxk493yyvyu8ffsgj6kt3luajdezwr6t7lzzfjf34u4nzztze3r44wplm0ry95tp4uang9yg","balance":{"spendable":"0.998969","unspendable":"0"},"wallet_type":"Iguana"}},"status":"Ok"}}

After app restart ARRR coin activation takes about 1 minute. Activation started from RequestingWalletBalance stage:

 [15:48:34] [info] [mm2.service.cpp:1495] [104360]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":"RequestingWalletBalance","status":"InProgress"}}
[15:48:34] [info] [app.cpp:808] [104244]: Application inactive
[15:48:39] [info] [mm2.service.cpp:1495] [104360]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":{"current_block":2576090,"first_sync_block":{"actual":2554000,"is_pre_sapling":false,"requested":2554000},"ticker":"ARRR","wallet_balance":{"address":"zs1gn3mxk493yyvyu8ffsgj6kt3luajdezwr6t7lzzfjf34u4nzztze3r44wplm0ry95tp4uang9yg","balance":{"spendable":"0.998969","unspendable":"0"},"wallet_type":"Iguana"}},"status":"Ok"}}

@kivqa
Copy link

kivqa commented Sep 20, 2023

Test 2: Activate ARRR using exact Activation date. I selected 8/30/2023
ARRR coin was successfully activated. Balance and transactions are correct.
Logs example:

[16:54:26] [info] [mm2.service.cpp:1495] [172348]: ARRR Activation Status: {"id":null,"mmrpc":"2.0","result":{"details":{"BuildingWalletDb":{"current_scanned_block":2573000,"first_sync_block":{"actual":2528000,"is_pre_sapling":false,"requested":2528000},"latest_block":2576128}},"status":"InProgress"}}

After app restart ARRR activation takes less 1 minute.

NOTE: There is incorrect percentage calculation, probably it's related to rounded height
image

Copy link

@kivqa kivqa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.
ARRR coin activation works. On app restart ARRR activation takes less 1 minute.
Percentage displayed correctly. 95% is max value that displayed.

@smk762 smk762 merged commit 30b4fbe into dev Sep 21, 2023
9 checks passed
@smk762 smk762 mentioned this pull request Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants