@@ -18,6 +18,8 @@ use crate::node::MixNode;
18
18
use clap:: { App , Arg , ArgMatches } ;
19
19
use config:: NymConfig ;
20
20
use crypto:: asymmetric:: { encryption, identity} ;
21
+ use log:: * ;
22
+ use version_checker:: is_minor_version_compatible;
21
23
22
24
pub fn command_args < ' a , ' b > ( ) -> App < ' a , ' b > {
23
25
App :: new ( "run" )
@@ -127,17 +129,48 @@ fn load_sphinx_keys(pathfinder: &MixNodePathfinder) -> encryption::KeyPair {
127
129
sphinx_keypair
128
130
}
129
131
132
+ // this only checks compatibility between config the binary. It does not take into consideration
133
+ // network version. It might do so in the future.
134
+ fn version_check ( cfg : & Config ) -> bool {
135
+ let binary_version = env ! ( "CARGO_PKG_VERSION" ) ;
136
+ let config_version = cfg. get_version ( ) ;
137
+ if binary_version != config_version {
138
+ warn ! ( "The mixnode binary has different version than what is specified in config file! {} and {}" , binary_version, config_version) ;
139
+ if is_minor_version_compatible ( binary_version, config_version) {
140
+ info ! ( "but they are still semver compatible. However, consider running the `upgrade` command" ) ;
141
+ true
142
+ } else {
143
+ error ! ( "and they are semver incompatible! - please run the `upgrade` command before attempting `run` again" ) ;
144
+ false
145
+ }
146
+ } else {
147
+ true
148
+ }
149
+ }
150
+
130
151
pub fn execute ( matches : & ArgMatches ) {
131
152
let id = matches. value_of ( "id" ) . unwrap ( ) ;
132
153
133
154
println ! ( "Starting mixnode {}..." , id) ;
134
155
135
- let mut config =
136
- Config :: load_from_file ( matches. value_of ( "config" ) . map ( |path| path. into ( ) ) , Some ( id) )
137
- . expect ( "Failed to load config file" ) ;
156
+ let mut config = match Config :: load_from_file (
157
+ matches. value_of ( "config" ) . map ( |path| path. into ( ) ) ,
158
+ Some ( id) ,
159
+ ) {
160
+ Ok ( cfg) => cfg,
161
+ Err ( err) => {
162
+ error ! ( "Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})" , id, err) ;
163
+ return ;
164
+ }
165
+ } ;
138
166
139
167
config = override_config ( config, matches) ;
140
168
169
+ if !version_check ( & config) {
170
+ error ! ( "failed the local version check" ) ;
171
+ return ;
172
+ }
173
+
141
174
let pathfinder = MixNodePathfinder :: new_from_config ( & config) ;
142
175
let identity_keypair = load_identity_keys ( & pathfinder) ;
143
176
let sphinx_keypair = load_sphinx_keys ( & pathfinder) ;
0 commit comments