serverpool.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. // Copyright 2020 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package les
  17. import (
  18. "errors"
  19. "math/rand"
  20. "reflect"
  21. "sync"
  22. "sync/atomic"
  23. "time"
  24. "github.com/ethereum/go-ethereum/common/mclock"
  25. "github.com/ethereum/go-ethereum/ethdb"
  26. lpc "github.com/ethereum/go-ethereum/les/lespay/client"
  27. "github.com/ethereum/go-ethereum/les/utils"
  28. "github.com/ethereum/go-ethereum/log"
  29. "github.com/ethereum/go-ethereum/p2p/enode"
  30. "github.com/ethereum/go-ethereum/p2p/enr"
  31. "github.com/ethereum/go-ethereum/p2p/nodestate"
  32. "github.com/ethereum/go-ethereum/rlp"
  33. )
  34. const (
  35. minTimeout = time.Millisecond * 500 // minimum request timeout suggested by the server pool
  36. timeoutRefresh = time.Second * 5 // recalculate timeout if older than this
  37. dialCost = 10000 // cost of a TCP dial (used for known node selection weight calculation)
  38. dialWaitStep = 1.5 // exponential multiplier of redial wait time when no value was provided by the server
  39. queryCost = 500 // cost of a UDP pre-negotiation query
  40. queryWaitStep = 1.02 // exponential multiplier of redial wait time when no value was provided by the server
  41. waitThreshold = time.Hour * 2000 // drop node if waiting time is over the threshold
  42. nodeWeightMul = 1000000 // multiplier constant for node weight calculation
  43. nodeWeightThreshold = 100 // minimum weight for keeping a node in the the known (valuable) set
  44. minRedialWait = 10 // minimum redial wait time in seconds
  45. preNegLimit = 5 // maximum number of simultaneous pre-negotiation queries
  46. maxQueryFails = 100 // number of consecutive UDP query failures before we print a warning
  47. )
  48. // serverPool provides a node iterator for dial candidates. The output is a mix of newly discovered
  49. // nodes, a weighted random selection of known (previously valuable) nodes and trusted/paid nodes.
  50. type serverPool struct {
  51. clock mclock.Clock
  52. unixTime func() int64
  53. db ethdb.KeyValueStore
  54. ns *nodestate.NodeStateMachine
  55. vt *lpc.ValueTracker
  56. mixer *enode.FairMix
  57. mixSources []enode.Iterator
  58. dialIterator enode.Iterator
  59. validSchemes enr.IdentityScheme
  60. trustedURLs []string
  61. fillSet *lpc.FillSet
  62. queryFails uint32
  63. timeoutLock sync.RWMutex
  64. timeout time.Duration
  65. timeWeights lpc.ResponseTimeWeights
  66. timeoutRefreshed mclock.AbsTime
  67. }
  68. // nodeHistory keeps track of dial costs which determine node weight together with the
  69. // service value calculated by lpc.ValueTracker.
  70. type nodeHistory struct {
  71. dialCost utils.ExpiredValue
  72. redialWaitStart, redialWaitEnd int64 // unix time (seconds)
  73. }
  74. type nodeHistoryEnc struct {
  75. DialCost utils.ExpiredValue
  76. RedialWaitStart, RedialWaitEnd uint64
  77. }
  78. // queryFunc sends a pre-negotiation query and blocks until a response arrives or timeout occurs.
  79. // It returns 1 if the remote node has confirmed that connection is possible, 0 if not
  80. // possible and -1 if no response arrived (timeout).
  81. type queryFunc func(*enode.Node) int
  82. var (
  83. serverPoolSetup = &nodestate.Setup{Version: 1}
  84. sfHasValue = serverPoolSetup.NewPersistentFlag("hasValue")
  85. sfQueried = serverPoolSetup.NewFlag("queried")
  86. sfCanDial = serverPoolSetup.NewFlag("canDial")
  87. sfDialing = serverPoolSetup.NewFlag("dialed")
  88. sfWaitDialTimeout = serverPoolSetup.NewFlag("dialTimeout")
  89. sfConnected = serverPoolSetup.NewFlag("connected")
  90. sfRedialWait = serverPoolSetup.NewFlag("redialWait")
  91. sfAlwaysConnect = serverPoolSetup.NewFlag("alwaysConnect")
  92. sfDisableSelection = nodestate.MergeFlags(sfQueried, sfCanDial, sfDialing, sfConnected, sfRedialWait)
  93. sfiNodeHistory = serverPoolSetup.NewPersistentField("nodeHistory", reflect.TypeOf(nodeHistory{}),
  94. func(field interface{}) ([]byte, error) {
  95. if n, ok := field.(nodeHistory); ok {
  96. ne := nodeHistoryEnc{
  97. DialCost: n.dialCost,
  98. RedialWaitStart: uint64(n.redialWaitStart),
  99. RedialWaitEnd: uint64(n.redialWaitEnd),
  100. }
  101. enc, err := rlp.EncodeToBytes(&ne)
  102. return enc, err
  103. }
  104. return nil, errors.New("invalid field type")
  105. },
  106. func(enc []byte) (interface{}, error) {
  107. var ne nodeHistoryEnc
  108. err := rlp.DecodeBytes(enc, &ne)
  109. n := nodeHistory{
  110. dialCost: ne.DialCost,
  111. redialWaitStart: int64(ne.RedialWaitStart),
  112. redialWaitEnd: int64(ne.RedialWaitEnd),
  113. }
  114. return n, err
  115. },
  116. )
  117. sfiNodeWeight = serverPoolSetup.NewField("nodeWeight", reflect.TypeOf(uint64(0)))
  118. sfiConnectedStats = serverPoolSetup.NewField("connectedStats", reflect.TypeOf(lpc.ResponseTimeStats{}))
  119. )
  120. // newServerPool creates a new server pool
  121. func newServerPool(db ethdb.KeyValueStore, dbKey []byte, vt *lpc.ValueTracker, mixTimeout time.Duration, query queryFunc, clock mclock.Clock, trustedURLs []string) *serverPool {
  122. s := &serverPool{
  123. db: db,
  124. clock: clock,
  125. unixTime: func() int64 { return time.Now().Unix() },
  126. validSchemes: enode.ValidSchemes,
  127. trustedURLs: trustedURLs,
  128. vt: vt,
  129. ns: nodestate.NewNodeStateMachine(db, []byte(string(dbKey)+"ns:"), clock, serverPoolSetup),
  130. }
  131. s.recalTimeout()
  132. s.mixer = enode.NewFairMix(mixTimeout)
  133. knownSelector := lpc.NewWrsIterator(s.ns, sfHasValue, sfDisableSelection, sfiNodeWeight)
  134. alwaysConnect := lpc.NewQueueIterator(s.ns, sfAlwaysConnect, sfDisableSelection, true, nil)
  135. s.mixSources = append(s.mixSources, knownSelector)
  136. s.mixSources = append(s.mixSources, alwaysConnect)
  137. iter := enode.Iterator(s.mixer)
  138. if query != nil {
  139. iter = s.addPreNegFilter(iter, query)
  140. }
  141. s.dialIterator = enode.Filter(iter, func(node *enode.Node) bool {
  142. s.ns.SetState(node, sfDialing, sfCanDial, 0)
  143. s.ns.SetState(node, sfWaitDialTimeout, nodestate.Flags{}, time.Second*10)
  144. return true
  145. })
  146. s.ns.SubscribeState(nodestate.MergeFlags(sfWaitDialTimeout, sfConnected), func(n *enode.Node, oldState, newState nodestate.Flags) {
  147. if oldState.Equals(sfWaitDialTimeout) && newState.IsEmpty() {
  148. // dial timeout, no connection
  149. s.setRedialWait(n, dialCost, dialWaitStep)
  150. s.ns.SetStateSub(n, nodestate.Flags{}, sfDialing, 0)
  151. }
  152. })
  153. s.ns.AddLogMetrics(sfHasValue, sfDisableSelection, "selectable", nil, nil, serverSelectableGauge)
  154. s.ns.AddLogMetrics(sfDialing, nodestate.Flags{}, "dialed", serverDialedMeter, nil, nil)
  155. s.ns.AddLogMetrics(sfConnected, nodestate.Flags{}, "connected", nil, nil, serverConnectedGauge)
  156. return s
  157. }
  158. // addSource adds a node discovery source to the server pool (should be called before start)
  159. func (s *serverPool) addSource(source enode.Iterator) {
  160. if source != nil {
  161. s.mixSources = append(s.mixSources, source)
  162. }
  163. }
  164. // addPreNegFilter installs a node filter mechanism that performs a pre-negotiation query.
  165. // Nodes that are filtered out and does not appear on the output iterator are put back
  166. // into redialWait state.
  167. func (s *serverPool) addPreNegFilter(input enode.Iterator, query queryFunc) enode.Iterator {
  168. s.fillSet = lpc.NewFillSet(s.ns, input, sfQueried)
  169. s.ns.SubscribeState(sfQueried, func(n *enode.Node, oldState, newState nodestate.Flags) {
  170. if newState.Equals(sfQueried) {
  171. fails := atomic.LoadUint32(&s.queryFails)
  172. if fails == maxQueryFails {
  173. log.Warn("UDP pre-negotiation query does not seem to work")
  174. }
  175. if fails > maxQueryFails {
  176. fails = maxQueryFails
  177. }
  178. if rand.Intn(maxQueryFails*2) < int(fails) {
  179. // skip pre-negotiation with increasing chance, max 50%
  180. // this ensures that the client can operate even if UDP is not working at all
  181. s.ns.SetStateSub(n, sfCanDial, nodestate.Flags{}, time.Second*10)
  182. // set canDial before resetting queried so that FillSet will not read more
  183. // candidates unnecessarily
  184. s.ns.SetStateSub(n, nodestate.Flags{}, sfQueried, 0)
  185. return
  186. }
  187. go func() {
  188. q := query(n)
  189. if q == -1 {
  190. atomic.AddUint32(&s.queryFails, 1)
  191. } else {
  192. atomic.StoreUint32(&s.queryFails, 0)
  193. }
  194. s.ns.Operation(func() {
  195. // we are no longer running in the operation that the callback belongs to, start a new one because of setRedialWait
  196. if q == 1 {
  197. s.ns.SetStateSub(n, sfCanDial, nodestate.Flags{}, time.Second*10)
  198. } else {
  199. s.setRedialWait(n, queryCost, queryWaitStep)
  200. }
  201. s.ns.SetStateSub(n, nodestate.Flags{}, sfQueried, 0)
  202. })
  203. }()
  204. }
  205. })
  206. return lpc.NewQueueIterator(s.ns, sfCanDial, nodestate.Flags{}, false, func(waiting bool) {
  207. if waiting {
  208. s.fillSet.SetTarget(preNegLimit)
  209. } else {
  210. s.fillSet.SetTarget(0)
  211. }
  212. })
  213. }
  214. // start starts the server pool. Note that NodeStateMachine should be started first.
  215. func (s *serverPool) start() {
  216. s.ns.Start()
  217. for _, iter := range s.mixSources {
  218. // add sources to mixer at startup because the mixer instantly tries to read them
  219. // which should only happen after NodeStateMachine has been started
  220. s.mixer.AddSource(iter)
  221. }
  222. for _, url := range s.trustedURLs {
  223. if node, err := enode.Parse(s.validSchemes, url); err == nil {
  224. s.ns.SetState(node, sfAlwaysConnect, nodestate.Flags{}, 0)
  225. } else {
  226. log.Error("Invalid trusted server URL", "url", url, "error", err)
  227. }
  228. }
  229. unixTime := s.unixTime()
  230. s.ns.Operation(func() {
  231. s.ns.ForEach(sfHasValue, nodestate.Flags{}, func(node *enode.Node, state nodestate.Flags) {
  232. s.calculateWeight(node)
  233. if n, ok := s.ns.GetField(node, sfiNodeHistory).(nodeHistory); ok && n.redialWaitEnd > unixTime {
  234. wait := n.redialWaitEnd - unixTime
  235. lastWait := n.redialWaitEnd - n.redialWaitStart
  236. if wait > lastWait {
  237. // if the time until expiration is larger than the last suggested
  238. // waiting time then the system clock was probably adjusted
  239. wait = lastWait
  240. }
  241. s.ns.SetStateSub(node, sfRedialWait, nodestate.Flags{}, time.Duration(wait)*time.Second)
  242. }
  243. })
  244. })
  245. }
  246. // stop stops the server pool
  247. func (s *serverPool) stop() {
  248. s.dialIterator.Close()
  249. if s.fillSet != nil {
  250. s.fillSet.Close()
  251. }
  252. s.ns.Operation(func() {
  253. s.ns.ForEach(sfConnected, nodestate.Flags{}, func(n *enode.Node, state nodestate.Flags) {
  254. // recalculate weight of connected nodes in order to update hasValue flag if necessary
  255. s.calculateWeight(n)
  256. })
  257. })
  258. s.ns.Stop()
  259. }
  260. // registerPeer implements serverPeerSubscriber
  261. func (s *serverPool) registerPeer(p *serverPeer) {
  262. s.ns.SetState(p.Node(), sfConnected, sfDialing.Or(sfWaitDialTimeout), 0)
  263. nvt := s.vt.Register(p.ID())
  264. s.ns.SetField(p.Node(), sfiConnectedStats, nvt.RtStats())
  265. p.setValueTracker(s.vt, nvt)
  266. p.updateVtParams()
  267. }
  268. // unregisterPeer implements serverPeerSubscriber
  269. func (s *serverPool) unregisterPeer(p *serverPeer) {
  270. s.ns.Operation(func() {
  271. s.setRedialWait(p.Node(), dialCost, dialWaitStep)
  272. s.ns.SetStateSub(p.Node(), nodestate.Flags{}, sfConnected, 0)
  273. s.ns.SetFieldSub(p.Node(), sfiConnectedStats, nil)
  274. })
  275. s.vt.Unregister(p.ID())
  276. p.setValueTracker(nil, nil)
  277. }
  278. // recalTimeout calculates the current recommended timeout. This value is used by
  279. // the client as a "soft timeout" value. It also affects the service value calculation
  280. // of individual nodes.
  281. func (s *serverPool) recalTimeout() {
  282. // Use cached result if possible, avoid recalculating too frequently.
  283. s.timeoutLock.RLock()
  284. refreshed := s.timeoutRefreshed
  285. s.timeoutLock.RUnlock()
  286. now := s.clock.Now()
  287. if refreshed != 0 && time.Duration(now-refreshed) < timeoutRefresh {
  288. return
  289. }
  290. // Cached result is stale, recalculate a new one.
  291. rts := s.vt.RtStats()
  292. // Add a fake statistic here. It is an easy way to initialize with some
  293. // conservative values when the database is new. As soon as we have a
  294. // considerable amount of real stats this small value won't matter.
  295. rts.Add(time.Second*2, 10, s.vt.StatsExpFactor())
  296. // Use either 10% failure rate timeout or twice the median response time
  297. // as the recommended timeout.
  298. timeout := minTimeout
  299. if t := rts.Timeout(0.1); t > timeout {
  300. timeout = t
  301. }
  302. if t := rts.Timeout(0.5) * 2; t > timeout {
  303. timeout = t
  304. }
  305. s.timeoutLock.Lock()
  306. if s.timeout != timeout {
  307. s.timeout = timeout
  308. s.timeWeights = lpc.TimeoutWeights(s.timeout)
  309. suggestedTimeoutGauge.Update(int64(s.timeout / time.Millisecond))
  310. totalValueGauge.Update(int64(rts.Value(s.timeWeights, s.vt.StatsExpFactor())))
  311. }
  312. s.timeoutRefreshed = now
  313. s.timeoutLock.Unlock()
  314. }
  315. // getTimeout returns the recommended request timeout.
  316. func (s *serverPool) getTimeout() time.Duration {
  317. s.recalTimeout()
  318. s.timeoutLock.RLock()
  319. defer s.timeoutLock.RUnlock()
  320. return s.timeout
  321. }
  322. // getTimeoutAndWeight returns the recommended request timeout as well as the
  323. // response time weight which is necessary to calculate service value.
  324. func (s *serverPool) getTimeoutAndWeight() (time.Duration, lpc.ResponseTimeWeights) {
  325. s.recalTimeout()
  326. s.timeoutLock.RLock()
  327. defer s.timeoutLock.RUnlock()
  328. return s.timeout, s.timeWeights
  329. }
  330. // addDialCost adds the given amount of dial cost to the node history and returns the current
  331. // amount of total dial cost
  332. func (s *serverPool) addDialCost(n *nodeHistory, amount int64) uint64 {
  333. logOffset := s.vt.StatsExpirer().LogOffset(s.clock.Now())
  334. if amount > 0 {
  335. n.dialCost.Add(amount, logOffset)
  336. }
  337. totalDialCost := n.dialCost.Value(logOffset)
  338. if totalDialCost < dialCost {
  339. totalDialCost = dialCost
  340. }
  341. return totalDialCost
  342. }
  343. // serviceValue returns the service value accumulated in this session and in total
  344. func (s *serverPool) serviceValue(node *enode.Node) (sessionValue, totalValue float64) {
  345. nvt := s.vt.GetNode(node.ID())
  346. if nvt == nil {
  347. return 0, 0
  348. }
  349. currentStats := nvt.RtStats()
  350. _, timeWeights := s.getTimeoutAndWeight()
  351. expFactor := s.vt.StatsExpFactor()
  352. totalValue = currentStats.Value(timeWeights, expFactor)
  353. if connStats, ok := s.ns.GetField(node, sfiConnectedStats).(lpc.ResponseTimeStats); ok {
  354. diff := currentStats
  355. diff.SubStats(&connStats)
  356. sessionValue = diff.Value(timeWeights, expFactor)
  357. sessionValueMeter.Mark(int64(sessionValue))
  358. }
  359. return
  360. }
  361. // updateWeight calculates the node weight and updates the nodeWeight field and the
  362. // hasValue flag. It also saves the node state if necessary.
  363. // Note: this function should run inside a NodeStateMachine operation
  364. func (s *serverPool) updateWeight(node *enode.Node, totalValue float64, totalDialCost uint64) {
  365. weight := uint64(totalValue * nodeWeightMul / float64(totalDialCost))
  366. if weight >= nodeWeightThreshold {
  367. s.ns.SetStateSub(node, sfHasValue, nodestate.Flags{}, 0)
  368. s.ns.SetFieldSub(node, sfiNodeWeight, weight)
  369. } else {
  370. s.ns.SetStateSub(node, nodestate.Flags{}, sfHasValue, 0)
  371. s.ns.SetFieldSub(node, sfiNodeWeight, nil)
  372. s.ns.SetFieldSub(node, sfiNodeHistory, nil)
  373. }
  374. s.ns.Persist(node) // saved if node history or hasValue changed
  375. }
  376. // setRedialWait calculates and sets the redialWait timeout based on the service value
  377. // and dial cost accumulated during the last session/attempt and in total.
  378. // The waiting time is raised exponentially if no service value has been received in order
  379. // to prevent dialing an unresponsive node frequently for a very long time just because it
  380. // was useful in the past. It can still be occasionally dialed though and once it provides
  381. // a significant amount of service value again its waiting time is quickly reduced or reset
  382. // to the minimum.
  383. // Note: node weight is also recalculated and updated by this function.
  384. // Note 2: this function should run inside a NodeStateMachine operation
  385. func (s *serverPool) setRedialWait(node *enode.Node, addDialCost int64, waitStep float64) {
  386. n, _ := s.ns.GetField(node, sfiNodeHistory).(nodeHistory)
  387. sessionValue, totalValue := s.serviceValue(node)
  388. totalDialCost := s.addDialCost(&n, addDialCost)
  389. // if the current dial session has yielded at least the average value/dial cost ratio
  390. // then the waiting time should be reset to the minimum. If the session value
  391. // is below average but still positive then timeout is limited to the ratio of
  392. // average / current service value multiplied by the minimum timeout. If the attempt
  393. // was unsuccessful then timeout is raised exponentially without limitation.
  394. // Note: dialCost is used in the formula below even if dial was not attempted at all
  395. // because the pre-negotiation query did not return a positive result. In this case
  396. // the ratio has no meaning anyway and waitFactor is always raised, though in smaller
  397. // steps because queries are cheaper and therefore we can allow more failed attempts.
  398. unixTime := s.unixTime()
  399. plannedTimeout := float64(n.redialWaitEnd - n.redialWaitStart) // last planned redialWait timeout
  400. var actualWait float64 // actual waiting time elapsed
  401. if unixTime > n.redialWaitEnd {
  402. // the planned timeout has elapsed
  403. actualWait = plannedTimeout
  404. } else {
  405. // if the node was redialed earlier then we do not raise the planned timeout
  406. // exponentially because that could lead to the timeout rising very high in
  407. // a short amount of time
  408. // Note that in case of an early redial actualWait also includes the dial
  409. // timeout or connection time of the last attempt but it still serves its
  410. // purpose of preventing the timeout rising quicker than linearly as a function
  411. // of total time elapsed without a successful connection.
  412. actualWait = float64(unixTime - n.redialWaitStart)
  413. }
  414. // raise timeout exponentially if the last planned timeout has elapsed
  415. // (use at least the last planned timeout otherwise)
  416. nextTimeout := actualWait * waitStep
  417. if plannedTimeout > nextTimeout {
  418. nextTimeout = plannedTimeout
  419. }
  420. // we reduce the waiting time if the server has provided service value during the
  421. // connection (but never under the minimum)
  422. a := totalValue * dialCost * float64(minRedialWait)
  423. b := float64(totalDialCost) * sessionValue
  424. if a < b*nextTimeout {
  425. nextTimeout = a / b
  426. }
  427. if nextTimeout < minRedialWait {
  428. nextTimeout = minRedialWait
  429. }
  430. wait := time.Duration(float64(time.Second) * nextTimeout)
  431. if wait < waitThreshold {
  432. n.redialWaitStart = unixTime
  433. n.redialWaitEnd = unixTime + int64(nextTimeout)
  434. s.ns.SetFieldSub(node, sfiNodeHistory, n)
  435. s.ns.SetStateSub(node, sfRedialWait, nodestate.Flags{}, wait)
  436. s.updateWeight(node, totalValue, totalDialCost)
  437. } else {
  438. // discard known node statistics if waiting time is very long because the node
  439. // hasn't been responsive for a very long time
  440. s.ns.SetFieldSub(node, sfiNodeHistory, nil)
  441. s.ns.SetFieldSub(node, sfiNodeWeight, nil)
  442. s.ns.SetStateSub(node, nodestate.Flags{}, sfHasValue, 0)
  443. }
  444. }
  445. // calculateWeight calculates and sets the node weight without altering the node history.
  446. // This function should be called during startup and shutdown only, otherwise setRedialWait
  447. // will keep the weights updated as the underlying statistics are adjusted.
  448. // Note: this function should run inside a NodeStateMachine operation
  449. func (s *serverPool) calculateWeight(node *enode.Node) {
  450. n, _ := s.ns.GetField(node, sfiNodeHistory).(nodeHistory)
  451. _, totalValue := s.serviceValue(node)
  452. totalDialCost := s.addDialCost(&n, 0)
  453. s.updateWeight(node, totalValue, totalDialCost)
  454. }