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

feat: add backup daemon #1032

Merged
merged 1 commit into from
Nov 2, 2019
Merged

feat: add backup daemon #1032

merged 1 commit into from
Nov 2, 2019

Conversation

michael1011
Copy link
Contributor

@michael1011 michael1011 commented Jun 14, 2019

Closes #917

This PR adds xu-backup that starts listening for new LND SCBs and writing them to the disk when executed.

I am not finished yet and have some things to do before this backup daemon can be used but please have a look at this PR nevertheless to acknowledge the concept and give me some feedback on what I have been doing in this branch.

Todo:

  • Raiden database backup (just copying the file is the recommended way of the Raiden devs)
  • XUD database backup
  • write SCB of all LNDs and Raiden database backup to disk on startup
  • writing unit/integration tests
  • intensive manual testing

@kilrau we agreed on not implementing a restoring feature for now, right?

@michael1011 michael1011 requested review from a user, sangaman and ImmanuelSegol June 14, 2019 14:25
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Skimmed through the code. Agree on the high level concept. Nice to see this is progressing well.

bin/xu-backup Outdated Show resolved Hide resolved
@kilrau
Copy link
Contributor

kilrau commented Jun 17, 2019

@kilrau we agreed on not implementing a restoring feature for now, right?

Correct, since it can be restored using lnd/raiden directly.

As far as I see it we'd have to implement lnds https://api.lightning.community/#restorechannelbackups in xud for that, track differences between btc & ltc ... but why not open an issue to keep track of it post-1.0.0 @michael1011 :)

Copy link
Collaborator

@sangaman sangaman left a comment

Choose a reason for hiding this comment

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

Looks good conceptually.

lib/backup/Backup.ts Outdated Show resolved Hide resolved
lib/backup/Backup.ts Show resolved Hide resolved
@michael1011 michael1011 force-pushed the channel-backups branch 5 times, most recently from 1af6c81 to e50a079 Compare June 22, 2019 10:14
@michael1011 michael1011 marked this pull request as ready for review June 22, 2019 10:23
@michael1011 michael1011 requested review from a user and sangaman June 22, 2019 11:01
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Left some comments/questions above. As a general style nit I noticed a lot of blank lines which is not consistent with the rest of the codebase. I think our tslint settings even display a warning/suggestion against those?

lib/backup/Backup.ts Outdated Show resolved Hide resolved
lib/backup/Backup.ts Outdated Show resolved Hide resolved
lib/backup/Backup.ts Outdated Show resolved Hide resolved
@michael1011
Copy link
Contributor Author

@erkarl regarding the style: you are right about the inconsistencies with the rest of the codebase but I didn't think that it mattered that much when actually writing the code since some other files also have some blank lines. And npm run lint didn't throw any warnings or messages so I just left it as it is now.

What do you think? Should I remove some blank lines or it is fine to leave it as is?

@ghost
Copy link

ghost commented Jun 26, 2019

What do you think? Should I remove some blank lines or it is fine to leave it as is?

Just leave it as is for now. I'll take a look at our linter configuration at some point and unify the formatting style.

@kilrau
Copy link
Contributor

kilrau commented Jul 3, 2019

Added xud.db, since we have quite important things in there (swap states). Loosing these means potentially loosing funds.

@kilrau
Copy link
Contributor

kilrau commented Aug 23, 2019

Todo's need to be updated as per #917

@michael1011 michael1011 force-pushed the channel-backups branch 3 times, most recently from 58d1ade to 9f75a56 Compare October 7, 2019 20:27
@michael1011 michael1011 requested review from a user and kilrau October 7, 2019 20:27
@kilrau kilrau added the P1 top priority label Oct 8, 2019
Copy link
Contributor

@kilrau kilrau left a comment

Choose a reason for hiding this comment

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

The filewatcher approach is nice!

Cosmetics:
Can we rename xu-backup -> xud-backup?

@michael1011
Copy link
Contributor Author

Can we rename xu-backup -> xud-backup?

Done!

Copy link
Collaborator

@sangaman sangaman left a comment

Choose a reason for hiding this comment

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

Just some minor nits/suggestions, otherwise looks very nice. I haven't tested it manually yet but I can run it tomorrow.

bin/xud-backup Outdated Show resolved Hide resolved
lib/backup/Backup.ts Outdated Show resolved Hide resolved
lib/lndclient/LndClient.ts Outdated Show resolved Hide resolved
lib/lndclient/LndClient.ts Outdated Show resolved Hide resolved
test/jest/Backup.spec.ts Outdated Show resolved Hide resolved
lib/backup/Backup.ts Outdated Show resolved Hide resolved
@kilrau
Copy link
Contributor

kilrau commented Oct 16, 2019

let's definitely do some manual testing @sangaman @erkarl @michael1011

@sangaman sangaman removed the request for review from ImmanuelSegol October 17, 2019 13:10
bin/xud-backup Outdated
describe: 'Port for the lnd gRPC interface',
type: 'number',
},
'raiden.database': {
Copy link
Collaborator

Choose a reason for hiding this comment

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

raiden.dbpath perhaps? Also would it make sense to add this property to Config.ts and RaidenClientConfig so it can be assigned a default value and get added automatically to the sample config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't do that initially because the path to the database of raiden depends not only on the network it is running on but also on a node specific id and looks like this: exchange/node_1a8e5ab4/netid_4321/network_de8a2bdd/v23_log.db.

Any ideas on how to determine a reasonable default value?

Copy link

Choose a reason for hiding this comment

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

I think raiden.dbpath could be the only value where we don't specify a default value. Thoughts @sangaman?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, that makes sense. We can just leave this out then and not have a default value.

lib/backup/Backup.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@sangaman sangaman left a comment

Choose a reason for hiding this comment

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

I'm not seeing the debug statements for when lnd channel backups are written - it should happen after swaps occur right? I tested with a BTC-LTC swap and I did see this.

24/10/2019 13:33:24.758 [BACKUP] verbose: Writing initial BTC LND channel backup
24/10/2019 13:33:24.769 [BACKUP] verbose: Listening to BTC LND channel backups
24/10/2019 13:33:24.778 [BACKUP] verbose: Writing initial LTC LND channel backup
24/10/2019 13:33:24.784 [BACKUP] verbose: Listening to LTC LND channel backups

One more suggestion is that it would be nice to be able to specify a path to the config file when it's not in the default location, which we could do using the --xudir option (the Config module looks for the config file in the xudir directory).

Lastly I'm also thinking it would be nice if on the first writes, it logs where it's saving the backup to, like Writing initial xud database backup to [path].

Copy link
Collaborator

@sangaman sangaman left a comment

Choose a reason for hiding this comment

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

I'm not seeing the debug statements for when lnd channel backups are written - it should happen after swaps occur right? I tested with a BTC-LTC swap and I did see this.

24/10/2019 13:33:24.758 [BACKUP] verbose: Writing initial BTC LND channel backup
24/10/2019 13:33:24.769 [BACKUP] verbose: Listening to BTC LND channel backups
24/10/2019 13:33:24.778 [BACKUP] verbose: Writing initial LTC LND channel backup
24/10/2019 13:33:24.784 [BACKUP] verbose: Listening to LTC LND channel backups

One more suggestion is that it would be nice to be able to specify a path to the config file when it's not in the default location, which we could do using the --xudir option (the Config module looks for the config file in the xudir directory).

Lastly I'm also thinking it would be nice if on the first writes, it logs where it's saving the backup to, like Writing initial xud database backup to [path].

@michael1011
Copy link
Contributor Author

I'm not seeing the debug statements for when lnd channel backups are written - it should happen after swaps occur right? I tested with a BTC-LTC swap and I did see this.

I am not backing up the database of LND but the SCBs (static channel backups). These backups are done once for a channel and are therefore static. This also means that a new backup will be done once you close an existing or open a new channel. When you do that it should print you a debug statement @sangaman

@michael1011 michael1011 force-pushed the channel-backups branch 3 times, most recently from 0275ed4 to 2ca28ea Compare October 29, 2019 15:38
@michael1011
Copy link
Contributor Author

The tests fail only on Travis and because of this error:

 FAIL  test/jest/Backup.spec.ts

  ● Backup › should write Raiden backups on new event

    RangeError: Maximum call stack size exceeded

        at Function.[Symbol.hasInstance] (<anonymous>)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:200:14)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:201:29)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:201:29)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:201:29)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:201:29)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:201:29)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:201:29)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:201:29)

      at WriteStream (../../node_modules/graceful-fs/graceful-fs.js:201:29)

It is an bug of one of the dependencies of Jest (jestjs/jest#9062) and was fixed recently.

What should be done about this? Wait for the next Jest release and continue working on the restore in this branch or should we update the dependency in npm-shrinkwrap.json ourselves?

@sangaman @erkarl

@sangaman
Copy link
Collaborator

Hmmm, it looks like jest doesn't release very often unfortunately. I think I'm fine with either approach, if you want to update the graceful-fs dependency directly, I'd say go for it. Or we can leave this alone until the next release, maybe they are due for one.

Another option would be to split the test case out of the commit, merge this without the test case, and then open a separate PR for the test case and merge that (along with a jest dependency update) once there's a new jest release. That actually might be my preferred approach.

@michael1011 michael1011 merged commit 225d61a into master Nov 2, 2019
@michael1011 michael1011 deleted the channel-backups branch November 2, 2019 10:44
@michael1011 michael1011 restored the channel-backups branch November 2, 2019 10:45
@michael1011 michael1011 deleted the channel-backups branch November 2, 2019 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 top priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backup
3 participants