Skip to content

Commit

Permalink
Merge pull request #1286 from threefoldtech/development-remove-extra-…
Browse files Browse the repository at this point in the history
…substrate-connection

Development remove extra substrate connection
  • Loading branch information
Eslam-Nawara authored Dec 16, 2024
2 parents aac7301 + 4c02a35 commit af90a4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
18 changes: 8 additions & 10 deletions monitoring-bot/internal/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import (
"github.com/cosmos/go-bip39"
"github.com/rs/zerolog/log"
client "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
)

type address string
type network string
type (
address string
network string
)

type config struct {
testMnemonic string `env:"TESTNET_MNEMONIC"`
Expand Down Expand Up @@ -364,7 +367,8 @@ func (m *Monitor) systemVersion(ctx context.Context) (map[network]version, map[n

for _, NodeID := range randomNodes {
log.Debug().Msgf("check node %d", NodeID)
ver, working, failed, err := m.checkNodeSystemVersion(ctx, NodeID, network)
ver, working, failed, err := m.checkNodeSystemVersion(ctx, con, NodeID, network)

failedNodes[network] = append(failedNodes[network], failed...)
if err != nil {
log.Error().Err(err).Msgf("check node %d failed", NodeID)
Expand All @@ -379,18 +383,12 @@ func (m *Monitor) systemVersion(ctx context.Context) (map[network]version, map[n
return versions, workingNodes, failedNodes
}

func (m *Monitor) checkNodeSystemVersion(ctx context.Context, NodeID uint32, net network) (version, []uint32, []uint32, error) {
func (m *Monitor) checkNodeSystemVersion(ctx context.Context, con *substrate.Substrate, NodeID uint32, net network) (version, []uint32, []uint32, error) {
const cmd = "zos.system.version"
var ver version
var workingNodes []uint32
var failedNodes []uint32

con, err := m.managers[net].Substrate()
if err != nil {
return version{}, []uint32{}, []uint32{}, fmt.Errorf("substrate connection for %v network failed with error: %w", NodeID, err)
}
defer con.Close()

node, err := con.GetNode(NodeID)
if err != nil {
failedNodes = append(failedNodes, NodeID)
Expand Down
6 changes: 0 additions & 6 deletions rmb-sdk-go/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@ func NewPeer(

if !bytes.Equal(twin.E2EKey, publicKey) || twin.Relay == nil || joinURLs != *twin.Relay {
log.Info().Str("Relay url/s", joinURLs).Msg("twin relay/public key didn't match, updating on chain ...")
subConn, err := subManager.Substrate()
if err != nil {
return nil, errors.Wrap(err, "could not start substrate connection")
}
defer subConn.Close()

if _, err = subConn.UpdateTwin(identity, joinURLs, publicKey); err != nil {
return nil, errors.Wrap(err, "could not update twin relay information")
}
Expand Down

0 comments on commit af90a4a

Please # to comment.