@@ -295,6 +295,7 @@ class LightningManager {
295295 userConfig = defaultUserConfig ,
296296 trustedZeroConfPeers = [ ] ,
297297 backupServerDetails,
298+ skipParamCheck = false ,
298299 } : TLdkStart ) : Promise < Result < string > > {
299300 if ( ! account ) {
300301 return err (
@@ -329,20 +330,24 @@ class LightningManager {
329330 }
330331 this . isStarting = true ;
331332
332- // Ensure the start params function as expected.
333- const paramCheckResponse = await startParamCheck ( {
334- account,
335- getBestBlock,
336- getTransactionData,
337- getTransactionPosition,
338- broadcastTransaction,
339- getAddress,
340- getScriptPubKeyHistory,
341- getFees,
342- network,
343- } ) ;
344- if ( paramCheckResponse . isErr ( ) ) {
345- return this . handleStartError ( paramCheckResponse ) ;
333+ if ( ! skipParamCheck ) {
334+ // Ensure the start params function as expected.
335+ const paramCheckResponse = await startParamCheck ( {
336+ account,
337+ getBestBlock,
338+ getTransactionData,
339+ getTransactionPosition,
340+ broadcastTransaction,
341+ getAddress,
342+ getScriptPubKeyHistory,
343+ getFees,
344+ network,
345+ } ) ;
346+ if ( paramCheckResponse . isErr ( ) ) {
347+ return this . handleStartError ( paramCheckResponse ) ;
348+ }
349+ } else {
350+ console . warn ( 'Skipping start param check. Switch back on for debugging.' ) ;
346351 }
347352
348353 this . getBestBlock = getBestBlock ;
@@ -402,61 +407,28 @@ class LightningManager {
402407 }
403408 }
404409
405- //Setup remote backup server
406- if ( backupServerDetails ) {
407- const backupSetupRes = await ldk . backupSetup ( {
408- seed : account . seed ,
409- network : this . network ,
410- details : backupServerDetails ,
411- } ) ;
412- if ( backupSetupRes . isErr ( ) ) {
413- return this . handleStartError ( err ( backupSetupRes . error ) ) ;
414- }
415- }
416-
417- // Step 1: Initialize the FeeEstimator
418- // Lazy loaded in native code
419- // https://docs.rs/lightning/latest/lightning/chain/chaininterface/trait.FeeEstimator.html
420-
421- // Step 2: Initialize the Logger
422- // Lazy loaded in native code
423- // https://docs.rs/lightning/latest/lightning/util/logger/index.html
424-
425- //Switch on log levels we're interested in. All levels are false by default.
426- await ldk . setLogLevel ( ELdkLogLevels . info , true ) ;
427- await ldk . setLogLevel ( ELdkLogLevels . warn , true ) ;
428- await ldk . setLogLevel ( ELdkLogLevels . error , true ) ;
429- await ldk . setLogLevel ( ELdkLogLevels . debug , true ) ;
430-
431- //TODO might not always need this one as they make the logs a little noisy
432- // await ldk.setLogLevel(ELdkLogLevels.trace, true);
433-
434- // Step 3: Initialize the BroadcasterInterface
435- // Lazy loaded in native code
436- // https://docs.rs/lightning/latest/lightning/chain/chaininterface/trait.BroadcasterInterface.html
437-
438- // Step 4: Initialize Persist
439- // Lazy loaded in native code
440- // https://docs.rs/lightning/latest/lightning/chain/chainmonitor/trait.Persist.html
441-
442- // Step 5: Initialize the ChainMonitor (happens when we init the ChannelManager)
443-
444- // Step 6: Initialize the KeysManager
445- const keysManager = await ldk . initKeysManager ( this . account . seed ) ;
446- if ( keysManager . isErr ( ) ) {
447- return this . handleStartError ( keysManager ) ;
448- }
449-
450- // Step 7: Read ChannelMonitors state from disk
451- // Handled in initChannelManager below
452-
453410 if ( network !== ENetworks . mainnet ) {
454411 //RGS and pre-populated scorer only available for mainnet
455412 rapidGossipSyncUrl = '' ;
456413 scorerDownloadUrl = '' ;
457414 }
458415
459- let promises : Promise < Result < string > > [ ] = [ ] ;
416+ //All these calls don't need to be done in any particular sequence
417+ let promises : Promise < Result < string > > [ ] = [
418+ ldk . setLogLevel ( ELdkLogLevels . info , true ) ,
419+ ldk . setLogLevel ( ELdkLogLevels . warn , true ) ,
420+ ldk . setLogLevel ( ELdkLogLevels . error , true ) ,
421+ ldk . setLogLevel ( ELdkLogLevels . debug , true ) ,
422+ // ldk.setLogLevel(ELdkLogLevels.trace, true),
423+ ldk . initKeysManager ( this . account . seed ) ,
424+ ldk . initNetworkGraph ( {
425+ network,
426+ rapidGossipSyncUrl,
427+ skipHoursThreshold : 3 ,
428+ } ) ,
429+ this . setFees ( ) ,
430+ ldk . initUserConfig ( userConfig ) ,
431+ ] ;
460432
461433 if ( scorerDownloadUrl ) {
462434 promises . push (
@@ -465,54 +437,24 @@ class LightningManager {
465437 skipHoursThreshold : 3 ,
466438 } ) ,
467439 ) ;
468- } else {
469- promises . push ( Promise . resolve ( ok ( '' ) ) ) ;
470440 }
471441
472- promises . push (
473- ldk . initNetworkGraph ( {
474- network,
475- rapidGossipSyncUrl,
476- skipHoursThreshold : 3 ,
477- } ) ,
478- ) ;
442+ if ( backupServerDetails ) {
443+ promises . push (
444+ ldk . backupSetup ( {
445+ seed : account . seed ,
446+ network : this . network ,
447+ details : backupServerDetails ,
448+ } ) ,
449+ ) ;
450+ }
479451
480- //
481- //
482- //
483- // if (scorerDownloadUrl) {
484- // const scorerRes = await ldk.downloadScorer({
485- // scorerDownloadUrl,
486- // skipHoursThreshold: 3,
487- // });
488- // if (scorerRes.isErr()) {
489- // return this.handleStartError(scorerRes);
490- // }
491- // }
492- //
493- // // Step 11: Optional: Initialize the NetGraphMsgHandler
494- // const networkGraphRes = await ldk.initNetworkGraph({
495- // network,
496- // rapidGossipSyncUrl,
497- // skipHoursThreshold: 3,
498- // });
499- // if (networkGraphRes.isErr()) {
500- // return this.handleStartError(networkGraphRes);
501- // }
502-
503- const [ scorerRes , networkGraphRes ] = await Promise . all ( promises ) ;
504- if ( scorerRes . isErr ( ) ) {
505- return this . handleStartError ( scorerRes ) ;
506- }
507- if ( networkGraphRes . isErr ( ) ) {
508- return this . handleStartError ( networkGraphRes ) ;
509- }
510-
511- // Step 8: Initialize the UserConfig ChannelManager
512- const confRes = await ldk . initUserConfig ( userConfig ) ;
513-
514- if ( confRes . isErr ( ) ) {
515- return this . handleStartError ( confRes ) ;
452+ // Check for any errors before starting channel manager.
453+ const results = await Promise . all ( promises ) ;
454+ for ( const result of results ) {
455+ if ( result . isErr ( ) ) {
456+ return this . handleStartError ( result ) ;
457+ }
516458 }
517459
518460 const channelManagerRes = await ldk . initChannelManager ( {
@@ -534,28 +476,18 @@ class LightningManager {
534476 ) ;
535477 }
536478
537- // Set fee estimates
538- await this . setFees ( ) ;
539-
540479 //Force close all channels on startup. Likely to recover funds after restoring from a stale backup.
541480 if ( forceCloseOnStartup && forceCloseOnStartup . forceClose ) {
542481 await ldk . forceCloseAllChannels ( forceCloseOnStartup . broadcastLatestTx ) ;
543482 }
544483
545484 if ( ! forceCloseOnStartup || forceCloseOnStartup . broadcastLatestTx ) {
546- // If we're force closing without broadcasting latest state don't add peers as we're likely doing this to recovery from a stale backup
547- await this . addPeers ( ) ;
485+ // If we're force closing without broadcasting the latest state don't add peers as we're likely doing this to recovery from a stale backup
486+ this . addPeers ( ) . catch ( console . error ) ;
548487 }
549488
550- // Step 9: Sync ChannelMonitors and ChannelManager to chain tip
551- await this . syncLdk ( ) ;
552-
553- // Step 10: Give ChannelMonitors to ChainMonitor
554-
555- // Step 12: Initialize the PeerManager
556- // Done with initChannelManager
557- // Step 13: Initialize networking
558- // Done with initChannelManager
489+ //Can continue in the background
490+ this . syncLdk ( ) . catch ( console . error ) ;
559491
560492 //Writes node state to log files
561493 ldk . nodeStateDump ( ) . catch ( console . error ) ;
@@ -593,9 +525,9 @@ class LightningManager {
593525 ) ;
594526 }
595527
596- async setFees ( ) : Promise < void > {
528+ async setFees ( ) : Promise < Result < string > > {
597529 const fees = await this . getFees ( ) ;
598- await ldk . updateFees ( fees ) ;
530+ return await ldk . updateFees ( fees ) ;
599531 }
600532
601533 /**
0 commit comments