Fixed block checking code. Optimized build.rs.

This commit is contained in:
Revertron
2021-04-19 15:31:05 +02:00
parent 9ca952ee67
commit 078781a6da
3 changed files with 17 additions and 5 deletions
+13 -3
View File
@@ -1,12 +1,17 @@
extern crate winres; extern crate winres;
use std::fs::File; use std::fs::File;
use std::fs::read_to_string;
use std::path::Path; use std::path::Path;
use std::io::Write; use std::io::Write;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha2::Sha256; use crypto::sha2::Sha256;
const IANA_FILE: &'static str = "iana-tlds.txt";
const IANA_HASHES: &'static str = "iana-hashes.txt";
const IANA_ZONES_URL: &'static str = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt";
fn main() { fn main() {
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
let mut res = winres::WindowsResource::new(); let mut res = winres::WindowsResource::new();
@@ -14,13 +19,18 @@ fn main() {
res.compile().unwrap(); res.compile().unwrap();
} }
download_iana_zones("iana-tlds.txt", "iana-hashes.txt"); download_iana_zones(IANA_FILE, IANA_HASHES);
} }
fn download_iana_zones(zones_name: &str, hashes_name: &str) { fn download_iana_zones(zones_name: &str, hashes_name: &str) {
let response = minreq::get("https://data.iana.org/TLD/tlds-alpha-by-domain.txt").send().expect("Could not make request!"); let response = match read_to_string(Path::new(IANA_FILE)) {
Ok(string) => { string }
Err(_) => {
let response = minreq::get(IANA_ZONES_URL).send().expect("Could not make request!");
response.as_str().expect("Response is not a valid UTF-8!").to_lowercase()
}
};
let response = response.as_str().expect("Response is not a valid UTF-8!").to_lowercase();
let list: Vec<_> = response.split("\n").collect(); let list: Vec<_> = response.split("\n").collect();
let mut zones = String::new(); let mut zones = String::new();
let mut hashes = String::new(); let mut hashes = String::new();
+3 -1
View File
@@ -754,8 +754,10 @@ impl Chain {
Twin Twin
}; };
} }
} else if block.prev_block_hash != last_block.hash {
warn!("Ignoring block with wrong previous hash:\n{:?}", &block);
return Bad;
} }
} }
} }
+1 -1
View File
@@ -509,7 +509,7 @@ fn process_new_block(context: Arc<Mutex<Context>>, peers: &mut Peers, token: &To
BlockQuality::Future => { debug!("Ignoring future block {}", block.index); } BlockQuality::Future => { debug!("Ignoring future block {}", block.index); }
BlockQuality::Bad => { BlockQuality::Bad => {
// TODO save bad public keys to banned table // TODO save bad public keys to banned table
debug!("Ignoring bad block {} with hash {:?}", block.index, block.hash); debug!("Ignoring bad block {} with hash {:?} from {}", block.index, block.hash, peer.get_addr());
let height = context.chain.height(); let height = context.chain.height();
context.chain.update_max_height(height); context.chain.update_max_height(height);
context.bus.post(crate::event::Event::SyncFinished); context.bus.post(crate::event::Event::SyncFinished);