Speedup initial blockchain receiving.

This commit is contained in:
Revertron
2021-02-22 12:49:36 +01:00
parent ecb58b9984
commit 803b70fc25
4 changed files with 46 additions and 4 deletions
+9
View File
@@ -65,6 +65,15 @@ impl Blockchain {
}
pub fn add_block(&mut self, block: Block) -> Result<(), &str> {
match &self.last_block {
None => {}
Some(last_block) => {
if last_block.index >= block.index && last_block.hash == block.hash {
info!("Ignoring block {}, we already have it", block.index);
return Err("Already have that block");
}
}
}
if !self.check_block(&block, &self.last_block) {
warn!("Bad block found, ignoring:\n{:?}", &block);
return Err("Bad block found, ignoring");