Skip to content

Getting back your Tribler state dir after update to 7.4.2

Vadim Bulavintsev edited this page Feb 16, 2020 · 3 revisions

Tribler version 7.4.2 has a bug that results in users "losing" their Tribler state (e.g. token balance, channels, etc.) when upgrading from an earlier version. This page includes instructions on how to get your data back.

Background

7.4.x branch is the first Tribler branch to be based on Python3. The transition had to be done, as Python2 is end-of-life since 2020. Python3 changed the semantics of strings (all strings are now Unicode instead of bytes), so Python2 code (including dicts) is incompatible with Python3 and vice-versa. Tribler uses Python dicts to save information about downloads in .Tribler/dlcheckpoints dir. So, during the transition to 7.4.x series, checkpoint files had to be upgraded.

To do the upgrade safely, 7.4.x branch introduced the system of versioned state dirs. When upgrading, the existing data would not be touched by migration scripts. Instead, a new state sub-directory is created in the Tribler state dir, named accordingly to its version number. For instance, if you would upgrade from 7.3.1 to 7.4.0, in your Tribler state dir you will see a new sub-directory named 7.4.0 containing copies of your original .Tribler folder. Also, version_history.json file will be created in .Tribler folder. This file stores the history of Tribler versions upgrades. It is updated every time when the running Tribler version is different from the one that was used before.

Unfortunately, previous versions of Tribler know nothing about this system. So, the system detects that the user is running a legacy (7.3.x and earlier) version by checking if version_history.json exists. If it doesn't, the upgrading procedure infers that .Tribler directory belongs to 7.3.x or earlier Tribler version.

Tribler users are identified by their public key that is stored in *.pem files in the Tribler state dir. For a new Tribler installation, Tribler will generate a new keypair. Personal channels and token balance are bound to this key.

7.4.0 was the first release to introduce the versioned state directories system. It also included an annoying bug that made Tribler use a newly generated keypair on the first start after an upgrade from 7.3.x or earlier version. As a result, Tribler required a restart for the user to get their balance and channel back. 7.4.1 introduced a fix for that bug. However, version management was still broken and would only work for the simplest cases. 7.4.2 included a fix for that. But the fix would consistently trigger a bug deep in the version management system.

The problem

The bug in 7.4.2 results in Tribler not seeing a previous installation on upgrade and just creating a new .Tribler/7.4.2 versioned directory anew. The user's data will still remain untouched in this case, in its previous place: the unversioned .Tribler root dir for 7.3.x and earlier versions, or .Tribler/7.4.0 or .Tribler/7.4.1` for the corresponding 7.4.x versions.

7.4.3 fixed the bug, but for people who installed 7.4.2 at least once, version_history.json would still contain 7.4.2 as the last used version. This makes 7.4.3 and later versions upgrade from 7.4.2 dir, which results in zero balance, no downloads, etc.

The manual fix

To solve this problem, users who upgraded to 7.4.2 have to revert version_history.json to its pre-7.4.2 state or delete it completely, depending on their last used Tribler version. They must do it before upgrading to 7.4.3 or later. Here is how to do it.

You have to edit the version_history.json file in your Tribler state folder before installing 7.4.3. On Windows, the file is located in C:\users\<username>\appdata\roaming\.Tribler. Open version_history.json with any text editor (e.g. Notepad). Change the last_version value to 7.4.1 or 7.4.0 according to the version you had before installing 7.4.2. If you were using pre-7.4.x before installing 7.4.2, you should remove version_history.json file instead.

In short, before installing 7.4.3 or any newer version of Tribler:

  • 7.4.1 -> 7.4.2 : change version in version_history.json to 7.4.1
  • 7.4.0 -> 7.4.2 : change version in version_history.json to 7.4.0
  • 7.3 or earlier -> 7.4.2 : delete version_history.json

If you already updated 7.4.2->7.4.3

In this case, you have to delete 7.4.3 sub-directory in .Tribler dir and apply the same steps as above (e.g. change your last_version to either 7.4.0 or 7.4.1 or delete version_history.json). The reason for this is if 7.4.3 sees that there is a .Tribler/7.4.3 directory, it will not dare to upgrade and overwrite it. So, to retry update procedure to 7.4.3 you have to delete its previous directory yourself and set last_version to the version you want to upgrade from (if it is 7.4.x, otherwise delete the file).