-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
send_only_node_lifecycle.go
67 lines (62 loc) · 1.63 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 (
"context"
"fmt"
"time"
"github.com/smartcontractkit/chainlink/v2/core/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) verifyLoop() {
defer s.wg.Done()
backoff := utils.NewRedialBackoff()
for {
select {
case <-time.After(backoff.Duration()):
chainID, err := s.sender.ChainID(context.Background())
if err != nil {
ok := s.IfStarted(func() {
if changed := s.setState(NodeStateUnreachable); changed {
promEVMPoolRPCNodeTransitionsToUnreachable.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.Cmp(s.chainID) != 0 {
ok := s.IfStarted(func() {
if changed := s.setState(NodeStateInvalidChainID); changed {
promEVMPoolRPCNodeTransitionsToInvalidChainID.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
} else {
ok := s.IfStarted(func() {
if changed := s.setState(NodeStateAlive); changed {
promEVMPoolRPCNodeTransitionsToAlive.WithLabelValues(s.chainID.String(), s.name).Inc()
}
})
if !ok {
return
}
s.log.Infow("Sendonly RPC Node is online", "nodeState", s.state)
return
}
case <-s.chStop:
return
}
}
}