-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
chanbackup: archive old channel backup files #9232
base: master
Are you sure you want to change the base?
chanbackup: archive old channel backup files #9232
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
bd7fb87
to
71ee590
Compare
71ee590
to
375e0fb
Compare
@Abdulkbk, remember to re-request review from reviewers when ready |
LGTM 👌 |
Could you do a rebase and push so the CI can run again, wanna check what's going in the logs but they are expired. |
375e0fb
to
ade9d50
Compare
I've rebased and pushed |
@@ -147,3 +173,48 @@ func (b *MultiFile) ExtractMulti(keyChain keychain.KeyRing) (*Multi, error) { | |||
packedMulti := PackedMulti(multiBytes) | |||
return packedMulti.Unpack(keyChain) | |||
} | |||
|
|||
func createArchiveFile(archiveDir string, fileName string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing godocs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, nice catch 👍
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think ade9d50 should be squashed into this commit instead since it's testing the newly introduced method createArchiveFile
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
chanbackup/backupfile.go
Outdated
@@ -17,6 +19,10 @@ const ( | |||
// file that we'll use to atomically update the primary back up file | |||
// when new channel are detected. | |||
DefaultTempBackupFileName = "temp-dont-use.backup" | |||
|
|||
// DefaultChanBackupDirName is the default name of the directory that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// DefaultChanBackupDirName is the default name of the directory that | |
// DefaultChanBackupArchiveDirName is the default name of the directory that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
chanbackup/backupfile_test.go
Outdated
|
||
// First, we'll create a temporary directory for our test files. | ||
tempDir := t.TempDir() | ||
archiveDir := filepath.Join(tempDir, "chan-backup-archives") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the var DefaultChanBackupArchiveDirName
?
chanbackup/backupfile_test.go
Outdated
archiveDir := filepath.Join(tempDir, "chan-backup-archives") | ||
|
||
// Next, we'll create a test backup file and write some content to it. | ||
backupFile := filepath.Join(tempDir, "channel.backup") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the var DefaultBackupFileName
chanbackup/backupfile.go
Outdated
@@ -117,6 +130,19 @@ func (b *MultiFile) UpdateAndSwap(newBackup PackedMulti) error { | |||
return fmt.Errorf("unable to close file: %w", err) | |||
} | |||
|
|||
// We check if the main backup file exists, if it does we archive it | |||
// before replacing it with the new backup. | |||
if _, err := os.Stat(b.fileName); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: should we return the error here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we return an error here, LND will fail to start during the first run because channel.backup
does not exist then. Should we add a log here instead?
I will also update the comment to capture this.
@@ -360,6 +366,8 @@ type Config struct { | |||
MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."` | |||
BackupFilePath string `long:"backupfilepath" description:"The target location of the channel backup file"` | |||
|
|||
DisableBackupArchive bool `long:"disable-backup-archive" description:"If set to true, channel backups will be deleted or replaced rather than being archived to a separate location."` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think it'd be better if we could name it ArchiveBackup
- then we don't need to use a double negative to decide whether we wanna create this archive or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this approach is when you try to disable this feature (since its enabled by default) using a CLI arg. Running the command lnd --archivebackup=false
results in an error although setting archivebackup=false
in the lnd.conf
file works fine.
I think the alternative is to disable this feature by default and then the user can then run lnd --archivebackup
to enable it without getting any errors. In this case there won't be any need for lnd --archivebackup=false
@@ -74,6 +74,9 @@ | |||
This is a protocol gadget required for Dynamic Commitments and Splicing that | |||
will be added later. | |||
|
|||
* Add support for [archiving channel backup](https://github.com/lightningnetwork/lnd/pull/9232) | |||
in a designated folder which allows for easy referencing in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also mention the newly introduced config value here.
@@ -117,6 +134,21 @@ func (b *MultiFile) UpdateAndSwap(newBackup PackedMulti) error { | |||
return fmt.Errorf("unable to close file: %w", err) | |||
} | |||
|
|||
if !b.deleteOldBackup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also update the docs in UpdateAndSwap
about this new behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
@@ -94,7 +94,7 @@ func TestUpdateAndSwap(t *testing.T) { | |||
}, | |||
} | |||
for i, testCase := range testCases { | |||
backupFile := NewMultiFile(testCase.fileName) | |||
backupFile := NewMultiFile(testCase.fileName, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think this test should also be updated to check the new behavior, maybe a new test TestUpdateAndSwapWithArchive
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is in the next commit ade9d50, I will squash it into the first commit.
In this commit, we first check if a previous backup file exists, if it does we copy it to archive folder before replacing it with a new backup file.
In this commit, we add the --disable-backup-archive with a default as false. When set to true then previous channel backup file will not be archived but replaced.
7dd1be4
to
c5a1f13
Compare
Closes #8906
Change Description
From the feature description:
This PR allows for the archiving of channel backups, enabling users to choose whether to permanently delete previous backup files or archive them by moving them to a designated archives folder.
Problem:
LND currently overwrites old channel backup files when creating new ones. This means:
Solution:
We modify the current flow of creating
channel.backup
. We start by creating a folder in the same directory where we store thechannel.backup
file (chan-backup-archives). We ensure that thechannel.backup
file is copied to the archive directory and timestamped before finally replacing it with the new file.We set the LND's default behavior to archive old channel backups, but we provide a configuration option that can be passed as an argument or specified in
lnd.conf
to disable this behavior. This option allows LND to deletechannel.backup
files instead of archiving them. This can be achieved by settingdisable-backup-archive=true
inlnd.conf
or passed as argument:Steps to Test
disable-backup-archive=true
is not set inlnd.conf
):channel.backup
file is stored. You will find a new folder calledchan-backup-archives
, where the backup files are archived.To test disabling this feature
chan-backup-archives
directory will not be created (if it does not already exist). If it already exists a new archive will not be created.Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.