@@ -20,6 +20,7 @@ package release
2020//go:generate abigen --sol ./contract.sol --pkg release --out ./contract.go
2121
2222import (
23+ "context"
2324 "fmt"
2425 "strings"
2526 "time"
@@ -33,7 +34,6 @@ import (
3334 "github.com/ethereum/go-ethereum/node"
3435 "github.com/ethereum/go-ethereum/p2p"
3536 "github.com/ethereum/go-ethereum/rpc"
36- "golang.org/x/net/context"
3737)
3838
3939// Interval to check for new releases
@@ -116,47 +116,49 @@ func (r *ReleaseService) checker() {
116116
117117 for {
118118 select {
119- // If the time arrived, check for a new release
120119 case <- timer .C :
121120 // Rechedule the timer before continuing
122121 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 ()
157123 case errc := <- r .quit :
158124 errc <- nil
159125 return
160126 }
161127 }
162128}
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