@@ -20,6 +20,7 @@ package release
20
20
//go:generate abigen --sol ./contract.sol --pkg release --out ./contract.go
21
21
22
22
import (
23
+ "context"
23
24
"fmt"
24
25
"strings"
25
26
"time"
@@ -33,7 +34,6 @@ import (
33
34
"github.com/ethereum/go-ethereum/node"
34
35
"github.com/ethereum/go-ethereum/p2p"
35
36
"github.com/ethereum/go-ethereum/rpc"
36
- "golang.org/x/net/context"
37
37
)
38
38
39
39
// Interval to check for new releases
@@ -116,47 +116,49 @@ func (r *ReleaseService) checker() {
116
116
117
117
for {
118
118
select {
119
- // If the time arrived, check for a new release
120
119
case <- timer .C :
121
120
// Rechedule the timer before continuing
122
121
timer .Reset (releaseRecheckInterval )
123
-
124
- // Retrieve the current version, and handle missing contracts gracefully
125
- ctx , _ := context .WithTimeout (context .Background (), time .Second * 5 )
126
- opts := & bind.CallOpts {Context : ctx }
127
- version , err := r .oracle .CurrentVersion (opts )
128
- if err != nil {
129
- if err == bind .ErrNoCode {
130
- log .Debug ("Release oracle not found" , "contract" , r .config .Oracle )
131
- continue
132
- }
133
- log .Error ("Failed to retrieve current release" , "err" , err )
134
- continue
135
- }
136
- // Version was successfully retrieved, notify if newer than ours
137
- if version .Major > r .config .Major ||
138
- (version .Major == r .config .Major && version .Minor > r .config .Minor ) ||
139
- (version .Major == r .config .Major && version .Minor == r .config .Minor && version .Patch > r .config .Patch ) {
140
-
141
- warning := fmt .Sprintf ("Client v%d.%d.%d-%x seems older than the latest upstream release v%d.%d.%d-%x" ,
142
- r .config .Major , r .config .Minor , r .config .Patch , r .config .Commit [:4 ], version .Major , version .Minor , version .Patch , version .Commit [:4 ])
143
- howtofix := fmt .Sprintf ("Please check https://github.com/ethereum/go-ethereum/releases for new releases" )
144
- separator := strings .Repeat ("-" , len (warning ))
145
-
146
- log .Warn (separator )
147
- log .Warn (warning )
148
- log .Warn (howtofix )
149
- log .Warn (separator )
150
- } else {
151
- log .Debug ("Client seems up to date with upstream" ,
152
- "local" , fmt .Sprintf ("v%d.%d.%d-%x" , r .config .Major , r .config .Minor , r .config .Patch , r .config .Commit [:4 ]),
153
- "upstream" , fmt .Sprintf ("v%d.%d.%d-%x" , version .Major , version .Minor , version .Patch , version .Commit [:4 ]))
154
- }
155
-
156
- // If termination was requested, return
122
+ r .checkVersion ()
157
123
case errc := <- r .quit :
158
124
errc <- nil
159
125
return
160
126
}
161
127
}
162
128
}
129
+
130
+ func (r * ReleaseService ) checkVersion () {
131
+ // Retrieve the current version, and handle missing contracts gracefully
132
+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 )
133
+ opts := & bind.CallOpts {Context : ctx }
134
+ defer cancel ()
135
+
136
+ version , err := r .oracle .CurrentVersion (opts )
137
+ if err != nil {
138
+ if err == bind .ErrNoCode {
139
+ log .Debug ("Release oracle not found" , "contract" , r .config .Oracle )
140
+ } else {
141
+ log .Error ("Failed to retrieve current release" , "err" , err )
142
+ }
143
+ return
144
+ }
145
+ // Version was successfully retrieved, notify if newer than ours
146
+ if version .Major > r .config .Major ||
147
+ (version .Major == r .config .Major && version .Minor > r .config .Minor ) ||
148
+ (version .Major == r .config .Major && version .Minor == r .config .Minor && version .Patch > r .config .Patch ) {
149
+
150
+ warning := fmt .Sprintf ("Client v%d.%d.%d-%x seems older than the latest upstream release v%d.%d.%d-%x" ,
151
+ r .config .Major , r .config .Minor , r .config .Patch , r .config .Commit [:4 ], version .Major , version .Minor , version .Patch , version .Commit [:4 ])
152
+ howtofix := fmt .Sprintf ("Please check https://github.com/ethereum/go-ethereum/releases for new releases" )
153
+ separator := strings .Repeat ("-" , len (warning ))
154
+
155
+ log .Warn (separator )
156
+ log .Warn (warning )
157
+ log .Warn (howtofix )
158
+ log .Warn (separator )
159
+ } else {
160
+ log .Debug ("Client seems up to date with upstream" ,
161
+ "local" , fmt .Sprintf ("v%d.%d.%d-%x" , r .config .Major , r .config .Minor , r .config .Patch , r .config .Commit [:4 ]),
162
+ "upstream" , fmt .Sprintf ("v%d.%d.%d-%x" , version .Major , version .Minor , version .Patch , version .Commit [:4 ]))
163
+ }
164
+ }
0 commit comments