Skip to content

Commit 221b763

Browse files
authored
Merge pull request #9783 from bitromortac/2505-loadmc-fixes
lncli: establish connection after parsing of mc data for loadmc
2 parents 7b6c1cf + 306df70 commit 221b763

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

cmd/commands/cmd_import_mission_control.go

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ var loadMissionControlCommand = cli.Command{
106106
Name: "loadmc",
107107
Category: "Mission Control",
108108
Usage: "Load mission control results to the internal mission " +
109-
"control state from a file produced by querymc with the " +
109+
"control state from a file produced by `querymc` with the " +
110110
"option to shift timestamps. Note that this data is not " +
111111
"persisted across restarts.",
112112
Action: actionDecorator(loadMissionControl),
@@ -115,19 +115,15 @@ var loadMissionControlCommand = cli.Command{
115115
Name: "mcdatapath",
116116
Usage: "The path to the querymc output file (json).",
117117
},
118-
cli.BoolFlag{
119-
Name: "discard",
120-
Usage: "Discards current mission control data.",
121-
},
122118
cli.StringFlag{
123119
Name: "timeoffset",
124120
Usage: "Time offset to add to all timestamps. " +
125-
"Format: 1m for a minute, 1h for an hour, 1d " +
126-
"for one day. This can be used to let " +
127-
"mission control data appear to be more " +
128-
"recent, to trick pathfinding's in-built " +
129-
"information decay mechanism. Additionally " +
130-
"by setting 0m, this will report the most " +
121+
"Follows a format like 72h3m0.5s. " +
122+
"This can be used to make mission control " +
123+
"data appear more recent, to trick " +
124+
"pathfinding's in-built information decay " +
125+
"mechanism. Additionally, " +
126+
"by setting 0s, this will report the most " +
131127
"recent result timestamp, which can be used " +
132128
"to find out how old this data is.",
133129
},
@@ -137,6 +133,11 @@ var loadMissionControlCommand = cli.Command{
137133
"results in the database with older results " +
138134
"from the file.",
139135
},
136+
cli.BoolFlag{
137+
Name: "skip_confirmation",
138+
Usage: "Skip the confirmation prompt and import " +
139+
"immediately",
140+
},
140141
},
141142
}
142143

@@ -153,11 +154,6 @@ func loadMissionControl(ctx *cli.Context) error {
153154
return fmt.Errorf("%v does not exist", mcDataPath)
154155
}
155156

156-
conn := getClientConn(ctx, false)
157-
defer conn.Close()
158-
159-
client := routerrpc.NewRouterClient(conn)
160-
161157
// Load and unmarshal the querymc output file.
162158
mcRaw, err := os.ReadFile(mcDataPath)
163159
if err != nil {
@@ -171,21 +167,10 @@ func loadMissionControl(ctx *cli.Context) error {
171167
err)
172168
}
173169

174-
// We discard mission control data if requested.
175-
if ctx.Bool("discard") {
176-
if !promptForConfirmation("This will discard all current " +
177-
"mission control data in the database (yes/no): ") {
178-
179-
return nil
180-
}
170+
conn := getClientConn(ctx, false)
171+
defer conn.Close()
181172

182-
_, err = client.ResetMissionControl(
183-
rpcCtx, &routerrpc.ResetMissionControlRequest{},
184-
)
185-
if err != nil {
186-
return err
187-
}
188-
}
173+
client := routerrpc.NewRouterClient(conn)
189174

190175
// Add a time offset to all timestamps if requested.
191176
timeOffset := ctx.String("timeoffset")
@@ -222,14 +207,18 @@ func loadMissionControl(ctx *cli.Context) error {
222207
}
223208
}
224209

225-
fmt.Printf("Adding time offset %v to all timestamps. "+
210+
fmt.Printf("Added a time offset %v to all timestamps. "+
226211
"New max timestamp: %v\n", offset, maxTimestamp)
227212
}
228213

229214
sanitizeMCData(mc.Pairs)
230215

231216
fmt.Printf("Mission control file contains %v pairs.\n", len(mc.Pairs))
232-
if !promptForConfirmation("Import mission control data (yes/no): ") {
217+
if !ctx.Bool("skip_confirmation") &&
218+
!promptForConfirmation(
219+
"Import mission control data (yes/no): ",
220+
) {
221+
233222
return nil
234223
}
235224

docs/release-notes/release-notes-0.19.0.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ when running LND with an aux component injected (custom channels).
251251
specific IPs could be allowed or denied.
252252

253253
* A [command was created](https://github.com/lightningnetwork/lnd/pull/9781) to
254-
load mission control data generated by `lncli querymc`.
254+
load mission control data generated by `lncli querymc`. `loadmc` [also
255+
accepts](https://github.com/lightningnetwork/lnd/pull/9783) a flag
256+
`skip_confirmation` to make the command scriptable.
255257

256258
# Improvements
257259
## Functional Updates

0 commit comments

Comments
 (0)