Increase verbosity, introduce DYNAMIC_GENESIS_TIMESTAMP and STATIC_GENESIS_TIMESTAMP

This commit is contained in:
Ludo Galabru
2020-05-26 15:37:03 -04:00
parent 1f00d6bb56
commit f2dedf7dbc

View File

@@ -47,12 +47,20 @@ async fn main() -> http_types::Result<()> {
Err(err) => err.duration(),
}.as_secs() as u64;
let genesis_timestamp = match std::env::var("NEON_GENESIS_TIMESTAMP") {
Ok(val) => match val.parse::<u64>() {
Ok(val) => val,
_ => config.neon.genesis_timestamp,
},
_ => config.neon.genesis_timestamp
let genesis_timestamp = if env::var("DYNAMIC_GENESIS_TIMESTAMP") == Ok("1".into()) {
println!("INFO: detected DYNAMIC_GENESIS_TIMESTAMP, will set the genesis timestamp to {}", now);
now.clone()
} else {
match std::env::var("STATIC_GENESIS_TIMESTAMP") {
Ok(val) => match val.parse::<u64>() {
Ok(val) => val,
Err(err) => {
println!("WARN: parsing STATIC_GENESIS_TIMESTAMP failed ({:?}), falling back on {}", err, config.neon.genesis_timestamp);
config.neon.genesis_timestamp
},
},
_ => config.neon.genesis_timestamp
}
};
let time_since_genesis = now - genesis_timestamp;
@@ -230,10 +238,28 @@ async fn generate_blocks(blocks_count: u64, address: String, config: &ConfigFile
let rpc_req = RPCRequest::generate_next_block_req(blocks_count, address);
let stream = TcpStream::connect(rpc_addr).await.unwrap();
let body = serde_json::to_vec(&rpc_req).unwrap();
let stream = match TcpStream::connect(rpc_addr).await {
Ok(stream) => stream,
Err(err) => {
println!("ERROR: connection failed - {:?}", err);
return
}
};
let body = match serde_json::to_vec(&rpc_req) {
Ok(body) => body,
Err(err) => {
println!("ERROR: serialization failed - {:?}", err);
return
}
};
let req = build_request(&config, body);
client::connect(stream.clone(), req).await.unwrap();
match client::connect(stream.clone(), req).await {
Ok(_) => {},
Err(err) => {
println!("ERROR: rpc invokation failed - {:?}", err);
return
}
};
}
fn build_request(config: &ConfigFile, body: Vec<u8>) -> Request {