-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Feature]: Persist imported Mission Control Data across restarts #8898
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
Draft
mohamedawnallah
wants to merge
3
commits into
lightningnetwork:master
Choose a base branch
from
mohamedawnallah:persistAndResetMCDataOnDisk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,8 +266,23 @@ func (m *MissionControl) init() error { | |
m.applyPaymentResult(result) | ||
} | ||
|
||
mcSnapshots, err := m.store.fetchMCData() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mcPairsPersisted := 0 | ||
for _, mcSnapshot := range mcSnapshots { | ||
err := m.ImportHistory(mcSnapshot, false, true) | ||
if err != nil { | ||
return err | ||
} | ||
mcPairsPersisted += len(mcSnapshot.Pairs) | ||
} | ||
|
||
log.Debugf("Mission control state reconstruction finished: "+ | ||
"n=%v, time=%v", len(results), time.Since(start)) | ||
"raw_payment_results_count=%v, persisted_mc_pairs_count=%v, "+ | ||
"time=%v", len(results), mcPairsPersisted, time.Since(start)) | ||
|
||
return nil | ||
} | ||
|
@@ -312,8 +327,10 @@ func (m *MissionControl) SetConfig(cfg *MissionControlConfig) error { | |
} | ||
|
||
// ResetHistory resets the history of MissionControl returning it to a state as | ||
// if no payment attempts have been made. | ||
func (m *MissionControl) ResetHistory() error { | ||
// if no payment attempts have been made. If the resetImportedPersistedMC | ||
// flag is set to true, it also resets the imported and persisted mission | ||
// control data on disk. | ||
func (m *MissionControl) ResetHistory(resetImportedPersistedMC bool) error { | ||
m.Lock() | ||
defer m.Unlock() | ||
|
||
|
@@ -323,6 +340,13 @@ func (m *MissionControl) ResetHistory() error { | |
|
||
m.state.resetHistory() | ||
|
||
if resetImportedPersistedMC { | ||
err := m.store.resetMCData() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
log.Debugf("Mission control history cleared") | ||
|
||
return nil | ||
|
@@ -360,11 +384,11 @@ func (m *MissionControl) GetHistorySnapshot() *MissionControlSnapshot { | |
return m.state.getSnapshot() | ||
} | ||
|
||
// ImportHistory imports the set of mission control results provided to our | ||
// in-memory state. These results are not persisted, so will not survive | ||
// restarts. | ||
// ImportHistory imports the set of mission control results to our in-memory | ||
// state and disk, ensuring that the mission control data is available across | ||
// restarts (if persistMC flag is set). | ||
func (m *MissionControl) ImportHistory(history *MissionControlSnapshot, | ||
force bool) error { | ||
force bool, persistMC bool) error { | ||
|
||
if history == nil { | ||
return errors.New("cannot import nil history") | ||
|
@@ -378,6 +402,13 @@ func (m *MissionControl) ImportHistory(history *MissionControlSnapshot, | |
|
||
imported := m.state.importSnapshot(history, force) | ||
|
||
if persistMC { | ||
err := m.store.persistMCData(history) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so it will first import the new data, and then flush the updated set to disk ? |
||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
log.Infof("Imported %v results to mission control", imported) | ||
|
||
return nil | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.