Added Limited Confidence to work with forks.

This commit is contained in:
Revertron
2021-04-30 12:27:24 +02:00
parent eb6d6d3690
commit f5423f8463
2 changed files with 17 additions and 7 deletions
+11 -5
View File
@@ -748,21 +748,27 @@ impl Chain {
return Bad;
}
if !check_block_hash(block) {
warn!("Block {:?} has wrong hash! Ignoring!", &block);
warn!("Ignoring block with wrong hash:\n{:?}", &block);
return Bad;
}
if !check_block_signature(&block) {
warn!("Block {:?} has wrong signature! Ignoring!", &block);
warn!("Ignoring block with wrong signature:\n{:?}", &block);
return Bad;
}
if let Some(prev_block) = self.get_block(block.index - 1) {
// https://en.bitcoinwiki.org/wiki/Limited_Confidence_Proof-of-Activity
if block.prev_block_hash.ne(&prev_block.hash) {
warn!("Ignoring block with wrong previous hash:\n{:?}", &block);
return Rewind;
if block.index < self.get_height() - LIMITED_CONFIDENCE_DEPTH {
warn!("Ignoring block from shorter chain:\n{:?}", &block);
return Bad;
} else {
warn!("Rewinding chain of block with wrong previous hash:\n{:?}", &block);
return Rewind;
}
}
}
if matches!(Transaction::get_type(&block.transaction), TransactionType::Zone) {
if self.get_zones().len() >= 10 {
if self.get_zones().len() >= MAXIMUM_ZONES {
warn!("Ignoring excess zone block");
return Bad;
}
+6 -2
View File
@@ -20,12 +20,16 @@ pub const BLOCK_SIGNERS_MIN: u64 = 4;
/// Signers have 30 minutes to sign, after that time any owner of first 1000 block can add needed signature
pub const BLOCK_SIGNERS_TIME: i64 = 1800;
/// PoS signers, that sign blocks when chosen signers didn't sign
pub const BLOCK_POS_SIGNERS: u64 = 1000;
/// Limited Confidence depth
/// https://en.bitcoinwiki.org/wiki/Limited_Confidence_Proof-of-Activity
pub const LIMITED_CONFIDENCE_DEPTH: u64 = 4;
/// We start mining signing blocks after random delay, this is the max delay
pub const BLOCK_SIGNERS_START_RANDOM: i64 = 180;
/// Maximum zones in blockchain
pub const MAXIMUM_ZONES: usize = 10;
pub const NEW_DOMAINS_INTERVAL: i64 = 86400; // One day in seconds
pub const DOMAIN_LIFETIME: i64 = 86400 * 365; // One year