tdex-network / tdex-daemon

Go implementation of the TDEX Beta Daemon
https://tdex.network
MIT License
11 stars 13 forks source link

Backup #665

Open altafan opened 1 year ago

altafan commented 1 year ago

At the moment, when recovering a wallet from a seed, the only thing restored is basically it's status, meant as accounts, addresses, txsa dn utxos. Thanks to some env vars and to the very specific structure of the daemon's embedded wallet we're able to restore its markets in term of just associating base and quote asset to a specific wallet account. We lose all those info like their fees, strategies etc.

In order to facilitate the restoration of all daemon's markets, we plan to add a new rpc ExportBackupFile that basically creates a JSON object with all relative information about the daemon's wallet and markets.

The following JSON is an example of the content of such backup file and we should iterate over this, so feedbacks are more than welcome:

{
   "wallet": {
       "rootPath":  "m/84'/1776'",
       "accounts": [
           {
               "name": "...",
               "derivationPath": "...",
               "balance": { ... }
           },
           ...
       ]
   },
   "markets": [
       {
           "name": "...",
           "baseAsset": "...",
           "quoteAsset": "...",
           "strategy": "...",
           "fees": {
               "percentageFee": <value>,
               "fixedFee": { ... }
           },
       },
       ...
   ]
}

@tiero @sekulicd what do you think of this as a starting point?

I also have an open question:

What should be the behavior of this rpc? Should it create the JSON file somewhere like for example in the datadir? Or, instead, should it send the serialzied json object within the response message and let the client eventually create the file?

tiero commented 1 year ago

Or, instead, should it send the serialzied json object within the response message

Yep lets keep it stateless, and return the JSON object in a string or something

altafan commented 1 year ago

Some considerations to revamp the discussion:

Improvements to the original proposal:

Translation from old to new format:

tiero commented 1 year ago

All good, but my main issue with datadir is that we cannot build GUI tools to perform "export" & "import"

If we assume "i have my 0.x daemon on the same machine where I am upgrading" that should be handled with a migration routine in V1 that if recognize a datadir with old data, will perform migration automatically under the hood.

The JSON idea was more I have my daemon (either 0.x or 1.x) running and I want to spin-up an exact clone somewhere else in a different infrastructure. Maybe we should consider the bytes option instead of JSON? Ideally can be a server-stream to chunk multiple pieces together in order to be able to handle the scale of a huge file (with grpc-gateway will still be base64 strings I guess, but with chunking make it scalable)

tiero commented 1 year ago

So as wrap-up, let's split up the task in priorities:

  1. v0.x to v1 migration routine (badger to badger I guess, as we will rollout postgres much later on)
  2. Export server-side streaming RPCs to download
  3. Investigate client-side streaming to upload (is this impossible with JSON HTTP I suppose?)