From c004065eea658bd3262b817cd18c5b0cebdd9caf Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 15 Nov 2019 17:55:55 +0900 Subject: [PATCH] Apply some lipstick on the lnd seed backup --- BTCPayServer/Controllers/ServerController.cs | 13 ++- .../LndSeedBackupViewModel.cs | 7 +- BTCPayServer/Properties/launchSettings.json | 1 + .../Views/Server/LndSeedBackup.cshtml | 85 ++++++++++--------- .../Views/Stores/AddLightningNode.cshtml | 2 +- BTCPayServer/Views/Stores/_Nav.cshtml | 2 +- 6 files changed, 64 insertions(+), 46 deletions(-) diff --git a/BTCPayServer/Controllers/ServerController.cs b/BTCPayServer/Controllers/ServerController.cs index 3cf5ac098..08e9f0232 100644 --- a/BTCPayServer/Controllers/ServerController.cs +++ b/BTCPayServer/Controllers/ServerController.cs @@ -624,6 +624,16 @@ namespace BTCPayServer.Controllers if (service.Type == ExternalServiceTypes.LNDSeedBackup) { var model = LndSeedBackupViewModel.Parse(service.ConnectionString.CookieFilePath); + if (!model.IsWalletUnlockPresent) + { + TempData.SetStatusMessageModel(new StatusMessageModel() + { + Severity = StatusMessageModel.StatusSeverity.Warning, + Html = "Your LND does not seem to allow seed backup.
" + + "It's recommended, but not required, that you migrate as instructed by our migration blog post.
" + + "You will need to close all of your channels, and migrate your funds as we documented." + }); + } return View("LndSeedBackup", model); } if (service.Type == ExternalServiceTypes.RPC) @@ -681,7 +691,7 @@ namespace BTCPayServer.Controllers return RedirectToAction(nameof(Services)); } - if (model.Seed == null || model.Seed.Count <= 1) + if (string.IsNullOrEmpty(model.Seed)) { TempData[WellKnownTempData.ErrorMessage] = $"Seed information was already removed"; return RedirectToAction(nameof(Services)); @@ -689,6 +699,7 @@ namespace BTCPayServer.Controllers if (await model.RemoveSeedAndWrite(service.ConnectionString.CookieFilePath)) { + TempData[WellKnownTempData.ErrorMessage] = $"Seed successfully removed"; return RedirectToAction(nameof(Service), new { serviceName, cryptoCode }); } else diff --git a/BTCPayServer/Models/ServerViewModels/LndSeedBackupViewModel.cs b/BTCPayServer/Models/ServerViewModels/LndSeedBackupViewModel.cs index 0c8d18b88..544c14237 100644 --- a/BTCPayServer/Models/ServerViewModels/LndSeedBackupViewModel.cs +++ b/BTCPayServer/Models/ServerViewModels/LndSeedBackupViewModel.cs @@ -14,9 +14,9 @@ namespace BTCPayServer.Models.ServerViewModels public string WalletPassword { get; set; } - public List Seed { get; set; } - + public string Seed { get; set; } + public bool Removed { get; set; } public async Task RemoveSeedAndWrite(string lndSeedFilePath) { var removedDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture); @@ -53,8 +53,9 @@ namespace BTCPayServer.Models.ServerViewModels return new LndSeedBackupViewModel { WalletPassword = unlockFile.wallet_password, - Seed = unlockFile.cipher_seed_mnemonic, + Seed = string.Join(' ', unlockFile.cipher_seed_mnemonic), IsWalletUnlockPresent = true, + Removed = unlockFile.cipher_seed_mnemonic.Count == 1 }; } } diff --git a/BTCPayServer/Properties/launchSettings.json b/BTCPayServer/Properties/launchSettings.json index 16b856c13..0d36e8556 100644 --- a/BTCPayServer/Properties/launchSettings.json +++ b/BTCPayServer/Properties/launchSettings.json @@ -36,6 +36,7 @@ "BTCPAY_BTCLIGHTNING": "type=charge;server=http://127.0.0.1:54938/;api-token=foiewnccewuify", "BTCPAY_BTCEXTERNALLNDGRPC": "type=lnd-grpc;server=https://lnd:lnd@127.0.0.1:53280/;allowinsecure=true", "BTCPAY_BTCEXTERNALLNDREST": "type=lnd-rest;server=https://lnd:lnd@127.0.0.1:53280/lnd-rest/btc/;allowinsecure=true", + "BTCPAY_BTCEXTERNALLNDSEEDBACKUP": "../BTCPayServer.Tests/TestData/LndSeedBackup/walletunlock.json", "BTCPAY_BTCEXTERNALSPARK": "server=/spark/btc/;cookiefile=fake", "BTCPAY_BTCEXTERNALCHARGE": "server=https://127.0.0.1:53280/mycharge/btc/;cookiefilepath=fake", "BTCPAY_BTCEXPLORERURL": "http://127.0.0.1:32838/", diff --git a/BTCPayServer/Views/Server/LndSeedBackup.cshtml b/BTCPayServer/Views/Server/LndSeedBackup.cshtml index 02894bbe8..ab524ccb5 100644 --- a/BTCPayServer/Views/Server/LndSeedBackup.cshtml +++ b/BTCPayServer/Views/Server/LndSeedBackup.cshtml @@ -3,59 +3,64 @@ ViewData.SetActivePageAndTitle(ServerNavPages.Services); } -

LND Seed Backup

- -
-
-
+ +@if (TempData.HasStatusMessage()) +{ +
+
+ +
-
+} -
- -
-
- @if (Model.IsWalletUnlockPresent) +@if (Model.IsWalletUnlockPresent) +{ +
+
+
+

The LND seed backup is useful to recover funds of your LND wallet in case of a corruption of your server.

+

The recovering process is documented by LND on this page.

+
+ See confidential seed information +
+
+
+ +
+ +
+
+ @if (!Model.Removed) { -

Wallet Password: @Model.WalletPassword

- @if (Model.Seed.Count > 1) - { -

-

-
- @foreach (var item in Model.Seed) - { - @item - } -

-
- -
+
+
+
+
-

- } - else - { -

@Model.Seed.First()

- } - } - else - { -

Unlock file is NOT present

-

You have old version of LND deployment that was auto-initialized using `noseedbackup=1`.

-

Please migrate to new version of LND deployment that is auto-initialized through script which creates seed backup file as part of the startup process.

-

Visit this link for more information

+ +
+
+
+
+ +
+
}
- -
+} @section Scripts { } diff --git a/BTCPayServer/Views/Stores/AddLightningNode.cshtml b/BTCPayServer/Views/Stores/AddLightningNode.cshtml index 13f15699a..c1ab6a21e 100644 --- a/BTCPayServer/Views/Stores/AddLightningNode.cshtml +++ b/BTCPayServer/Views/Stores/AddLightningNode.cshtml @@ -12,7 +12,7 @@ Before you proceed, please understand that Lightning Network is still in the experimental stage. Do not put the money you can't afford to lose. There is a high risk of you losing the money.

- Take time to familiarize yourself with the risk. There's no backup for LND or c-lightning keys in BTCPay. Your keys are in a hot-wallet. This means : + Take time to familiarize yourself with the risk. There's no backup lightning keys automatically done by BTCPayServer. Your keys are in a hot-wallet. This means :

  • Most of BTCPay Server deployments run on a pruned node, which, while working, is not officially supported by lightning network implementations.
  • diff --git a/BTCPayServer/Views/Stores/_Nav.cshtml b/BTCPayServer/Views/Stores/_Nav.cshtml index 6a171fbe8..8db99112a 100644 --- a/BTCPayServer/Views/Stores/_Nav.cshtml +++ b/BTCPayServer/Views/Stores/_Nav.cshtml @@ -4,7 +4,7 @@ Checkout experience Access Tokens Users - Pay Button + Pay Button @inject IEnumerable Extensions; @foreach (var extension in Extensions) {