taler-docs

Documentation for GNU Taler components, APIs and protocols
Log | Files | Refs | README | LICENSE

019-wallet-backup-merge.rst (9868B)


      1 XX 19: Wallet Backup Merging
      2 ############################
      3 
      4 .. warning::
      5 
      6   This design document is deprecated.  The incremental backup and sync
      7   protocol described in `DD 92`_ supersedes it.
      8 
      9 .. _DD 92: https://docs.taler.net/design-documents/092-incremental-backup-sync.html
     10 
     11 Summary
     12 =======
     13 
     14 This design doc discusses considerations for merging wallet backups.
     15 
     16 
     17 Motivation
     18 ==========
     19 
     20 The wallet backup functionality is meant to be used primarily with one device
     21 per backup account.  Multiple devices sharing one backup account is heavily
     22 discouraged, as it can lead to unexpected and unwanted user experiences, such
     23 as money suddenly vanishing when it has been spent by another device
     24 that shares the same backup account.
     25 
     26 However, there are some situations where more than one device
     27 accesses the same backup account.  This happens when:
     28 
     29 1. A wallet backup is restored on a new device, but the
     30    old device is still active.  In this scenario, the devices
     31    have different device IDs, but share the same wallet root
     32    public key.
     33 2. An old wallet backup is taken over by an existing wallet.
     34    In this scenario, the devices have different devices IDs and
     35    different wallet root public keys.
     36    ### CG: This is not exactly more than one device accessing the same backup account!
     37    ### CG: Maybe formulate intro differently, to talk about key scenarios that deserve consideration / need to be distinguished?
     38 3. A wallet device is copied, for example by restoring the whole
     39    device from a device-level backup (not a wallet backup!).
     40    In this scenario, the devices have the same device ID
     41    and the same wallet root public key.
     42 
     43 
     44 Requirements
     45 ============
     46 
     47 The backup merging must ensure that:
     48 
     49 * No data that the user wants to keep is lost.
     50 * No data resurfaces that the user has previously intentionally deleted.
     51 * Conflicts should be resolved automatically wherever possible.
     52 * The solution tolerates system clocks not being monotonic.
     53 
     54 
     55 Proposed Solution
     56 =================
     57 
     58 Stored Information
     59 ------------------
     60 
     61 * Every wallet keeps track of the following data:
     62 
     63   * The current version number (positive integer)
     64   * The current wallet root public key (Ed25519 public key)
     65     ### CG: public key? Not the private key? What is the private information the wallet usually keeps?
     66   * The current device ID (human-readable string)
     67   * The status of every backup service account (not defined further here)
     68   * The last system time observed on the current device (by device ID).
     69 
     70 * A backup blob stores the following information relevant for backup merging:
     71 
     72   * The backup's version number, equal to the version number of
     73     the wallet when the backup was uploaded.
     74   * The wallet root public key of the wallet that **owns** the backup account
     75   * The device ID of the wallet that **owns** the backup account.
     76 
     77 * Every record and tombstone in the wallet's database and the backup blob keeps
     78   track of:
     79 
     80   * The version number at which the entry was created.
     81   * A timestamp for the entry, based on enforced monotonic time (per device ID).
     82 
     83 The version number is incremented with every operation that adds an record or
     84 tombstone to the wallet's database.
     85 ### CG: operation or transaction? I would prefer transaction here.
     86 
     87 
     88 Resolving Conflicts
     89 -------------------
     90 
     91 This section describes how conflicts are resolved when a wallet (with ``wallet_version``, ``wallet_device_id``
     92 and ``wallet_root_pub``) is merged with a backup (with ``backup_version``, ``backup_device_id``, and
     93 ``backup_root_pub``).
     94 ### CG: The term 'merged' is something I do not like. Is this during 'backup', 'restore', or 'sync'?
     95 ###     I suspect these cases need to be distinguished, because the user asking for a 'restore' is
     96 ###     not creating the same situation than a wallet 'sync'ing during an automated backup, and
     97 ###     that may again differ from an _initial_ backup (where I guess there are no conflicts, but
     98 ###     to improve understanding
     99 
    100 * If ``wallet_root_pub != backup_root_pub``:  The user is shown a warning "the backup
    101   account was written to by another wallet and can't be read by this wallet", and offered a dialog to either:
    102 
    103   a. "Take over" the backup account and migrate it to the existing wallet root public key.
    104      A clear warning must be shown that this will kick out the other device currently connected
    105      to this account **and** will cause all data from the backup account to be lost.
    106      ### CG: Do we even want to allow this? How _can_ this happen exactly? What is the relationship between backup account and root key?
    107      ### CG: The private account key is derived from the root public key;
    108      ###     I do not see us saying anywhere that we would even support
    109      ###     extracting/exchanging account keys. Hence, I think this basically
    110      ###     cannot happen: to access the backup, I already must know the root private key.
    111   b. Remove the backup account from the list.
    112 
    113   Note that when first adding the backup account via a recovery code, there is a third option:
    114   Migrate wallet to the account's wallet root public key.  This is **only** possible when
    115   scanning the recovery code, as the wallet needs the wallet root secret key to migrate
    116   to the account.
    117   ### CG: I think this should be the only thing that can possibly happen, by UI/UX.
    118   ###     Of course _theroretically_ someone could extract ONLY an account-priv and
    119   ###     use that to download the backup, but then they should just not be able to
    120   ###     decrypt it. End of story.
    121 
    122 * If ``wallet_root_pub == backup_root_pub`` and ``wallet_device_id != backup_device_id``:  The
    123   user is shown a warning "two wallet devices are using the same backup account", and given
    124   the option of:
    125 
    126   a. Taking over the backup account from the existing device.  This will not cause data loss,
    127      but the other device (if it still exists!) will stop syncing.
    128   b. To "abandon" the current wallet.  This (optional, but recommended) will sync the current wallet state
    129      with a special marker in the backup blob (so the other wallet continues syncing without
    130      having to ask the user), and then delete the database contends and create a new ``wallet_root_pub``.
    131      ### CG: I do not think we can 'recommend' option b, because we do not know if the other
    132      ### device still exists. So the UI should be neutral here between the two equally valid choices.
    133 
    134 * If ``wallet_root_pub == backup_root_pub`` and ``wallet_device_id == backup_device_id``:
    135 
    136   * If ``wallet_version > backup_version``, do a normal backup
    137     cycle (merge backup blob into wallet and upload a new backup).
    138     ### CG: We should note that the motivation for a merge arises
    139     ###     from the 3rd scenario under Motivation: full device backup&recovery.
    140 
    141   * If ``wallet_version <= backup_version``, another wallet with the same
    142     root public key must have "tampered"
    143     with the wallet's state.  Do a normal backup cycle, but consider displaying
    144     a warning/notification to the user.
    145     ### CG: I think there is no point in distinguishing these two cases;
    146     ###     in both cases, if the merge is non-trivial, something odd happened.
    147     ###     Still, I am not sure that a warning/notification is helpful, as
    148     ###     it is hardly actionable for the user.
    149 
    150 
    151 Garbage-collecting Tombstones
    152 -----------------------------
    153 
    154 Tombstones should be automatically garbage-collected when the following criteria
    155 are both fulfilled:
    156 
    157 * The versions of active backup accounts are all larger than
    158   the tombstone's version, and
    159 * the tombstone exceeded a threshold age (say, 3 days).
    160 
    161 ### CG: I backup at providers A and B. Make transaction T. Then I remove
    162 ###     provider A from my provider list. I then delete T. Eventually, I backup
    163 ###     again at provider B without the expired tombstone.  Finally,
    164 ###     I restore from provider A, and then merge with provider B.
    165 ###     Here, the 'merge' has to be somehow smart enough to drop
    166 ###     the deleted data from provider A's backup without the tombstone.
    167 ###     I think we can safely decide that this is the case because
    168 ###     backup from A says that it was---at the time---synced with provider B.
    169 ###     However, this means that we do need to additionally retain the
    170 ###     historic chain of backup providers and their last merge points/versions!
    171 
    172 
    173 Q / A
    174 =====
    175 
    176 * Q: Why are version numbers and tombstones necessary in backups?
    177 
    178   * A: When syncing with a backup server that still has an old version
    179     (but same device ID and wallet root pub), the tombstones ensure
    180     that no old data is re-surfaced that has been deleted in later
    181     versions.  This can happen in practice even with only one device,
    182     namely when a backup provider is unavailable for a long time,
    183     but then becomes available again.
    184 
    185 * Q: Why are tombstones only GCed after exceeding an age threshold?
    186 
    187   * A:  If we deleted them immediately, this might cause data to resurface
    188     if a user temporarily removes and adds a backup account (say by accident)
    189     that hasn't been synced in a while.
    190     ### CG: See above: the timeout does IMO not help here.
    191     ###     I think we need to track removed backup accounts
    192     ###     and the last version that was synced there,
    193     ###     and then basically determine if a sync/merge-chain exists
    194     ###     from the (possibly resurfaced) transaction version to
    195     ###     the current wallet version!
    196 
    197 * Q: Why doesn't the wallet root public key get rotated every time
    198   that a wallet backup is restored on a new device?
    199 
    200   * A: Because that would mean that old "paper backups" and Anastasis
    201     backups stop working, because they are based on the wallet root key.
    202 
    203 * Q: Why can't the wallet obtain some unique devices identifier to exclude
    204   case 3 (same device ID, same wallet root pub)?
    205 
    206   * A: Because we don't have a reliable API for this on many platforms.
    207     Even if we had one, we shouldn't rely on it.