-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
send_only_node_lifecycle.go
67 lines (62 loc) · 1.61 KB
/
send_only_node_lifecycle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package client
import (
"fmt"
"time"
"github.com/smartcontractkit/chainlink/v2/common/internal/utils"
)
// verifyLoop may only be triggered once, on Start, if initial chain ID check
// fails.
//
// It will continue checking until success and then exit permanently.
func (s *sendOnlyNode[CHAIN_ID, RPC]) verifyLoop() {
defer s.wg.Done()
ctx, cancel := s.chStop.NewCtx()
defer cancel()
backoff := utils.NewRedialBackoff()
for {
select {
case <-ctx.Done():
return
case <-time.After(backoff.Duration()):
}
chainID, err := s.rpc.ChainID(ctx)
if err != nil {
ok := s.IfStarted(func() {
if changed := s.setState(nodeStateUnreachable); changed {
promPoolRPCNodeTransitionsToUnreachable.WithLabelValues(s.chainID.String(), s.name).Inc()
}
})
if !ok {
return
}
s.log.Errorw(fmt.Sprintf("Verify failed: %v", err), "err", err)
continue
} else if chainID.String() != s.chainID.String() {
ok := s.IfStarted(func() {
if changed := s.setState(nodeStateInvalidChainID); changed {
promPoolRPCNodeTransitionsToInvalidChainID.WithLabelValues(s.chainID.String(), s.name).Inc()
}
})
if !ok {
return
}
s.log.Errorf(
"sendonly rpc ChainID doesn't match local chain ID: RPC ID=%s, local ID=%s, node name=%s",
chainID.String(),
s.chainID.String(),
s.name,
)
continue
}
ok := s.IfStarted(func() {
if changed := s.setState(nodeStateAlive); changed {
promPoolRPCNodeTransitionsToAlive.WithLabelValues(s.chainID.String(), s.name).Inc()
}
})
if !ok {
return
}
s.log.Infow("Sendonly RPC Node is online", "nodeState", s.state)
return
}
}