Skip to content

Commit 6429ab7

Browse files
committed
update substrate gateway to allow updating sub connection
1 parent 0f01219 commit 6429ab7

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

pkg/api_gateway.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
//go:generate zbusc -module api-gateway -version 0.0.1 -name api-gateway -package stubs github.com/threefoldtech/zosbase/pkg+SubstrateGateway stubs/api_gateway_stub.go
1111

1212
type SubstrateGateway interface {
13+
UpdateSubstrateGatewayConnection(manager substrate.Manager) (err error)
1314
CreateNode(node substrate.Node) (uint32, error)
1415
CreateTwin(relay string, pk []byte) (uint32, error)
1516
EnsureAccount(activationURL []string, termsAndConditionsLink string, termsAndConditionsHash string) (info substrate.AccountInfo, err error)

pkg/stubs/api_gateway_stub.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,18 @@ func (s *SubstrateGatewayStub) UpdateNodeUptimeV2(ctx context.Context, arg0 uint
387387
}
388388
return
389389
}
390+
391+
func (s *SubstrateGatewayStub) UpdateSubstrateGatewayConnection(ctx context.Context, arg0 tfchainclientgo.Manager) (ret0 error) {
392+
args := []interface{}{arg0}
393+
result, err := s.client.RequestContext(ctx, s.module, s.object, "UpdateSubstrateGatewayConnection", args...)
394+
if err != nil {
395+
panic(err)
396+
}
397+
result.PanicOnError()
398+
ret0 = result.CallError()
399+
loader := zbus.Loader{}
400+
if err := result.Unmarshal(&loader); err != nil {
401+
panic(err)
402+
}
403+
return
404+
}

pkg/substrate_gateway/substrate_gateway.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ func NewSubstrateGateway(manager substrate.Manager, identity substrate.Identity)
3131
return gw, nil
3232
}
3333

34+
// UpdateSubstrateGatewayConnection allow modules to update substrate manager so that the node can recover chain outage
35+
func (g *substrateGateway) UpdateSubstrateGatewayConnection(manager substrate.Manager) error {
36+
sub, err := manager.Substrate()
37+
if err != nil {
38+
return err
39+
}
40+
41+
// close the old connection
42+
g.sub.Close()
43+
44+
g.sub = sub
45+
return nil
46+
}
47+
3448
func (g *substrateGateway) GetZosVersion() (string, error) {
3549
log.Debug().Str("method", "GetZosVersion").Msg("method called")
3650

@@ -207,6 +221,7 @@ func (g *substrateGateway) UpdateNodeUptimeV2(uptime uint64, timestampHint uint6
207221
defer g.mu.Unlock()
208222
return g.sub.UpdateNodeUptimeV2(g.identity, uptime, timestampHint)
209223
}
224+
210225
func (g *substrateGateway) GetTime() (time.Time, error) {
211226
log.Trace().Str("method", "Time").Msg("method called")
212227

0 commit comments

Comments
 (0)