Stability fixes.

This commit is contained in:
Revertron committed 2023-03-18 18:07:30 +01:00
1 parent 167b6db426
commit 829ee753a0
2 files changed
+12 -5

No files matched your search

+8 -5
View File
@@ -254,19 +254,22 @@ impl Chain {
let index = block.index; let index = block.index;
let timestamp = block.timestamp; let timestamp = block.timestamp;
let owner = block.pub_key.clone(); let owner = block.pub_key.clone();
self.last_block = Some(block.clone());
if block.transaction.is_some() {
self.last_full_block = Some(block.clone());
}
let transaction = block.transaction.clone(); let transaction = block.transaction.clone();
if self.add_block_to_table(block).is_ok() { match self.add_block_to_table(block.clone()) {
Ok(_) => {
self.last_block = Some(block.clone());
if let Some(mut transaction) = transaction { if let Some(mut transaction) = transaction {
self.last_full_block = Some(block);
if transaction.signing.is_empty() { if transaction.signing.is_empty() {
transaction.signing = owner; transaction.signing = owner;
} }
self.add_transaction_to_table(index, timestamp, &transaction).expect("Error adding transaction"); self.add_transaction_to_table(index, timestamp, &transaction).expect("Error adding transaction");
} }
} }
Err(e) => {
warn!("Error adding block to table ({}): {:?}", e, &block);
}
}
} }
pub fn replace_block(&mut self, block: Block) -> sqlite::Result<()> { pub fn replace_block(&mut self, block: Block) -> sqlite::Result<()> {
+4
View File
@@ -288,9 +288,13 @@ impl Peers {
// If someone has more blocks we sync // If someone has more blocks we sync
if nodes >= MIN_CONNECTED_NODES_START_SYNC && height < max_height { if nodes >= MIN_CONNECTED_NODES_START_SYNC && height < max_height {
// Give some opportunity to get more peers instead of requests for blocks only
let request_blocks = nodes >= 10 || random::<bool>();
if request_blocks {
let count = min(max_height - height, nodes as u64); let count = min(max_height - height, nodes as u64);
self.ask_blocks_from_peers(registry, height, height + count, have_blocks); self.ask_blocks_from_peers(registry, height, height + count, have_blocks);
} }
}
// If someone has less blocks (we mined a new block) we send a ping with our height // If someone has less blocks (we mined a new block) we send a ping with our height
if self.need_behind_ping() { if self.need_behind_ping() {