Skip to content

Commit 601fca9

Browse files
committed
allow relay update when changed
1 parent d2f5a33 commit 601fca9

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

cmds/modules/api_gateway/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func action(cli *cli.Context) error {
111111
bo := backoff.NewExponentialBackOff()
112112
bo.MaxElapsedTime = 0
113113

114-
// this peer is used to allow the node to restart the peer without the need to cancel the module context
114+
// this ctx is used to allow the node to restart the peer without leaving any unwanted open connections
115115
peerCtx, cancel := context.WithCancel(ctx)
116116
defer cancel()
117117

@@ -144,11 +144,7 @@ func action(cli *cli.Context) error {
144144
return nil
145145
// check if we need to run an update on the peer and only do the update if all the changes are done successfully
146146
case <-time.After(10 * time.Minute):
147-
// if we can get time from substrate then we don't need to update the connection
148-
if _, err := gw.GetTime(); err == nil {
149-
continue
150-
}
151-
147+
log.Debug().Msg("checking for updates in zos config")
152148
env, err := environment.Get()
153149
if err != nil {
154150
// skip update if we can't get env
@@ -165,11 +161,19 @@ func action(cli *cli.Context) error {
165161
slices.Sort(updatedSubURLs)
166162
slices.Sort(updatedRelayURLs)
167163

168-
// skip update if the urls did not change
164+
// skip update if substrate and relay urls did not change
169165
if slices.Equal(subURLs, updatedSubURLs) && slices.Equal(relayURLs, updatedRelayURLs) {
170166
continue
171167
}
172168

169+
// skip update if the old substrate connection is working fine
170+
if !slices.Equal(subURLs, updatedSubURLs) {
171+
if _, err := gw.GetTime(); err == nil {
172+
log.Debug().Msg("the open connection is already working, no update needed")
173+
continue
174+
}
175+
}
176+
173177
newPeerCtx, newCancel := context.WithCancel(ctx)
174178
if err := updatePeer(newPeerCtx, updatedSubURLs, updatedRelayURLs, pair.Seed(), router.Serve); err != nil {
175179
log.Debug().Err(err).Send()

cmds/modules/noded/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@ func action(cli *cli.Context) error {
252252
for {
253253
<-time.After(10 * time.Minute)
254254

255+
log.Debug().Msg("checking for updates in zos config")
255256
cl, _, err := sub.Raw()
256257
if err == nil {
257258
// skip update if the connection is working properly
259+
log.Debug().Msg("the open connection is working, no update needed")
258260
cl.Client.Close()
259261
continue
260262
}

0 commit comments

Comments
 (0)