@@ -1877,6 +1877,8 @@ func (c cleaner) run() {
1877
1877
// Start starts the main daemon server, all requested listeners, and any helper
1878
1878
// goroutines.
1879
1879
// NOTE: This function is safe for concurrent access.
1880
+ //
1881
+ //nolint:funlen
1880
1882
func (s * server ) Start () error {
1881
1883
var startErr error
1882
1884
@@ -1886,194 +1888,189 @@ func (s *server) Start() error {
1886
1888
cleanup := cleaner {}
1887
1889
1888
1890
s .start .Do (func () {
1891
+ cleanup = cleanup .add (s .customMessageServer .Stop )
1889
1892
if err := s .customMessageServer .Start (); err != nil {
1890
1893
startErr = err
1891
1894
return
1892
1895
}
1893
- cleanup = cleanup .add (s .customMessageServer .Stop )
1894
1896
1895
1897
if s .hostAnn != nil {
1898
+ cleanup = cleanup .add (s .hostAnn .Stop )
1896
1899
if err := s .hostAnn .Start (); err != nil {
1897
1900
startErr = err
1898
1901
return
1899
1902
}
1900
- cleanup = cleanup .add (s .hostAnn .Stop )
1901
1903
}
1902
1904
1903
1905
if s .livenessMonitor != nil {
1906
+ cleanup = cleanup .add (s .livenessMonitor .Stop )
1904
1907
if err := s .livenessMonitor .Start (); err != nil {
1905
1908
startErr = err
1906
1909
return
1907
1910
}
1908
- cleanup = cleanup .add (s .livenessMonitor .Stop )
1909
1911
}
1910
1912
1911
1913
// Start the notification server. This is used so channel
1912
1914
// management goroutines can be notified when a funding
1913
1915
// transaction reaches a sufficient number of confirmations, or
1914
1916
// when the input for the funding transaction is spent in an
1915
1917
// attempt at an uncooperative close by the counterparty.
1918
+ cleanup = cleanup .add (s .sigPool .Stop )
1916
1919
if err := s .sigPool .Start (); err != nil {
1917
1920
startErr = err
1918
1921
return
1919
1922
}
1920
- cleanup = cleanup .add (s .sigPool .Stop )
1921
1923
1924
+ cleanup = cleanup .add (s .writePool .Stop )
1922
1925
if err := s .writePool .Start (); err != nil {
1923
1926
startErr = err
1924
1927
return
1925
1928
}
1926
- cleanup = cleanup .add (s .writePool .Stop )
1927
1929
1930
+ cleanup = cleanup .add (s .readPool .Stop )
1928
1931
if err := s .readPool .Start (); err != nil {
1929
1932
startErr = err
1930
1933
return
1931
1934
}
1932
- cleanup = cleanup .add (s .readPool .Stop )
1933
1935
1936
+ cleanup = cleanup .add (s .cc .ChainNotifier .Stop )
1934
1937
if err := s .cc .ChainNotifier .Start (); err != nil {
1935
1938
startErr = err
1936
1939
return
1937
1940
}
1938
- cleanup = cleanup .add (s .cc .ChainNotifier .Stop )
1939
1941
1942
+ cleanup = cleanup .add (s .cc .BestBlockTracker .Stop )
1940
1943
if err := s .cc .BestBlockTracker .Start (); err != nil {
1941
1944
startErr = err
1942
1945
return
1943
1946
}
1944
- cleanup = cleanup .add (s .cc .BestBlockTracker .Stop )
1945
1947
1948
+ cleanup = cleanup .add (s .channelNotifier .Stop )
1946
1949
if err := s .channelNotifier .Start (); err != nil {
1947
1950
startErr = err
1948
1951
return
1949
1952
}
1950
- cleanup = cleanup .add (s .channelNotifier .Stop )
1951
1953
1954
+ cleanup = cleanup .add (func () error {
1955
+ return s .peerNotifier .Stop ()
1956
+ })
1952
1957
if err := s .peerNotifier .Start (); err != nil {
1953
1958
startErr = err
1954
1959
return
1955
1960
}
1956
- cleanup = cleanup .add (func () error {
1957
- return s .peerNotifier .Stop ()
1958
- })
1961
+
1962
+ cleanup = cleanup .add (s .htlcNotifier .Stop )
1959
1963
if err := s .htlcNotifier .Start (); err != nil {
1960
1964
startErr = err
1961
1965
return
1962
1966
}
1963
- cleanup = cleanup .add (s .htlcNotifier .Stop )
1964
1967
1965
1968
if s .towerClientMgr != nil {
1969
+ cleanup = cleanup .add (s .towerClientMgr .Stop )
1966
1970
if err := s .towerClientMgr .Start (); err != nil {
1967
1971
startErr = err
1968
1972
return
1969
1973
}
1970
- cleanup = cleanup .add (s .towerClientMgr .Stop )
1971
1974
}
1972
1975
1976
+ cleanup = cleanup .add (s .txPublisher .Stop )
1973
1977
if err := s .txPublisher .Start (); err != nil {
1974
1978
startErr = err
1975
1979
return
1976
1980
}
1977
- cleanup = cleanup .add (func () error {
1978
- s .txPublisher .Stop ()
1979
- return nil
1980
- })
1981
1981
1982
+ cleanup = cleanup .add (s .sweeper .Stop )
1982
1983
if err := s .sweeper .Start (); err != nil {
1983
1984
startErr = err
1984
1985
return
1985
1986
}
1986
- cleanup = cleanup .add (s .sweeper .Stop )
1987
1987
1988
+ cleanup = cleanup .add (s .utxoNursery .Stop )
1988
1989
if err := s .utxoNursery .Start (); err != nil {
1989
1990
startErr = err
1990
1991
return
1991
1992
}
1992
- cleanup = cleanup .add (s .utxoNursery .Stop )
1993
1993
1994
+ cleanup = cleanup .add (s .breachArbitrator .Stop )
1994
1995
if err := s .breachArbitrator .Start (); err != nil {
1995
1996
startErr = err
1996
1997
return
1997
1998
}
1998
- cleanup = cleanup .add (s .breachArbitrator .Stop )
1999
1999
2000
+ cleanup = cleanup .add (s .fundingMgr .Stop )
2000
2001
if err := s .fundingMgr .Start (); err != nil {
2001
2002
startErr = err
2002
2003
return
2003
2004
}
2004
- cleanup = cleanup .add (s .fundingMgr .Stop )
2005
2005
2006
2006
// htlcSwitch must be started before chainArb since the latter
2007
2007
// relies on htlcSwitch to deliver resolution message upon
2008
2008
// start.
2009
+ cleanup = cleanup .add (s .htlcSwitch .Stop )
2009
2010
if err := s .htlcSwitch .Start (); err != nil {
2010
2011
startErr = err
2011
2012
return
2012
2013
}
2013
- cleanup = cleanup .add (s .htlcSwitch .Stop )
2014
2014
2015
+ cleanup = cleanup .add (s .interceptableSwitch .Stop )
2015
2016
if err := s .interceptableSwitch .Start (); err != nil {
2016
2017
startErr = err
2017
2018
return
2018
2019
}
2019
- cleanup = cleanup .add (s .interceptableSwitch .Stop )
2020
2020
2021
+ cleanup = cleanup .add (s .chainArb .Stop )
2021
2022
if err := s .chainArb .Start (); err != nil {
2022
2023
startErr = err
2023
2024
return
2024
2025
}
2025
- cleanup = cleanup .add (s .chainArb .Stop )
2026
2026
2027
+ cleanup = cleanup .add (s .authGossiper .Stop )
2027
2028
if err := s .authGossiper .Start (); err != nil {
2028
2029
startErr = err
2029
2030
return
2030
2031
}
2031
- cleanup = cleanup .add (s .authGossiper .Stop )
2032
2032
2033
+ cleanup = cleanup .add (s .graphBuilder .Stop )
2033
2034
if err := s .graphBuilder .Start (); err != nil {
2034
2035
startErr = err
2035
2036
return
2036
2037
}
2037
- cleanup = cleanup .add (s .graphBuilder .Stop )
2038
2038
2039
+ cleanup = cleanup .add (s .chanRouter .Stop )
2039
2040
if err := s .chanRouter .Start (); err != nil {
2040
2041
startErr = err
2041
2042
return
2042
2043
}
2043
- cleanup = cleanup .add (s .chanRouter .Stop )
2044
2044
2045
+ cleanup = cleanup .add (s .invoices .Stop )
2045
2046
if err := s .invoices .Start (); err != nil {
2046
2047
startErr = err
2047
2048
return
2048
2049
}
2049
- cleanup = cleanup .add (s .invoices .Stop )
2050
2050
2051
+ cleanup = cleanup .add (s .sphinx .Stop )
2051
2052
if err := s .sphinx .Start (); err != nil {
2052
2053
startErr = err
2053
2054
return
2054
2055
}
2055
- cleanup = cleanup .add (s .sphinx .Stop )
2056
2056
2057
+ cleanup = cleanup .add (s .chanStatusMgr .Stop )
2057
2058
if err := s .chanStatusMgr .Start (); err != nil {
2058
2059
startErr = err
2059
2060
return
2060
2061
}
2061
- cleanup = cleanup .add (s .chanStatusMgr .Stop )
2062
2062
2063
+ cleanup = cleanup .add (s .chanEventStore .Stop )
2063
2064
if err := s .chanEventStore .Start (); err != nil {
2064
2065
startErr = err
2065
2066
return
2066
2067
}
2067
- cleanup = cleanup .add (func () error {
2068
- s .chanEventStore .Stop ()
2069
- return nil
2070
- })
2071
2068
2072
- s .missionControl .RunStoreTicker ()
2073
2069
cleanup .add (func () error {
2074
2070
s .missionControl .StopStoreTicker ()
2075
2071
return nil
2076
2072
})
2073
+ s .missionControl .RunStoreTicker ()
2077
2074
2078
2075
// Before we start the connMgr, we'll check to see if we have
2079
2076
// any backups to recover. We do this now as we want to ensure
@@ -2107,18 +2104,18 @@ func (s *server) Start() error {
2107
2104
}
2108
2105
}
2109
2106
2107
+ cleanup = cleanup .add (s .chanSubSwapper .Stop )
2110
2108
if err := s .chanSubSwapper .Start (); err != nil {
2111
2109
startErr = err
2112
2110
return
2113
2111
}
2114
- cleanup = cleanup .add (s .chanSubSwapper .Stop )
2115
2112
2116
2113
if s .torController != nil {
2114
+ cleanup = cleanup .add (s .torController .Stop )
2117
2115
if err := s .createNewHiddenService (); err != nil {
2118
2116
startErr = err
2119
2117
return
2120
2118
}
2121
- cleanup = cleanup .add (s .torController .Stop )
2122
2119
}
2123
2120
2124
2121
if s .natTraversal != nil {
@@ -2127,11 +2124,11 @@ func (s *server) Start() error {
2127
2124
}
2128
2125
2129
2126
// Start connmgr last to prevent connections before init.
2130
- s .connMgr .Start ()
2131
2127
cleanup = cleanup .add (func () error {
2132
2128
s .connMgr .Stop ()
2133
2129
return nil
2134
2130
})
2131
+ s .connMgr .Start ()
2135
2132
2136
2133
// If peers are specified as a config option, we'll add those
2137
2134
// peers first.
@@ -2318,9 +2315,9 @@ func (s *server) Stop() error {
2318
2315
if err := s .sweeper .Stop (); err != nil {
2319
2316
srvrLog .Warnf ("failed to stop sweeper: %v" , err )
2320
2317
}
2321
-
2322
- s . txPublisher . Stop ( )
2323
-
2318
+ if err := s . txPublisher . Stop (); err != nil {
2319
+ srvrLog . Warnf ( "failed to stop txPublisher: %v" , err )
2320
+ }
2324
2321
if err := s .channelNotifier .Stop (); err != nil {
2325
2322
srvrLog .Warnf ("failed to stop channelNotifier: %v" , err )
2326
2323
}
@@ -2340,7 +2337,10 @@ func (s *server) Stop() error {
2340
2337
srvrLog .Warnf ("Unable to stop BestBlockTracker: %v" ,
2341
2338
err )
2342
2339
}
2343
- s .chanEventStore .Stop ()
2340
+ if err := s .chanEventStore .Stop (); err != nil {
2341
+ srvrLog .Warnf ("Unable to stop ChannelEventStore: %v" ,
2342
+ err )
2343
+ }
2344
2344
s .missionControl .StopStoreTicker ()
2345
2345
2346
2346
// Disconnect from each active peers to ensure that
0 commit comments