Added Limited Confidence to work with forks.
This commit is contained in:
+11
-5
@@ -748,21 +748,27 @@ impl Chain {
|
|||||||
return Bad;
|
return Bad;
|
||||||
}
|
}
|
||||||
if !check_block_hash(block) {
|
if !check_block_hash(block) {
|
||||||
warn!("Block {:?} has wrong hash! Ignoring!", &block);
|
warn!("Ignoring block with wrong hash:\n{:?}", &block);
|
||||||
return Bad;
|
return Bad;
|
||||||
}
|
}
|
||||||
if !check_block_signature(&block) {
|
if !check_block_signature(&block) {
|
||||||
warn!("Block {:?} has wrong signature! Ignoring!", &block);
|
warn!("Ignoring block with wrong signature:\n{:?}", &block);
|
||||||
return Bad;
|
return Bad;
|
||||||
}
|
}
|
||||||
if let Some(prev_block) = self.get_block(block.index - 1) {
|
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) {
|
if block.prev_block_hash.ne(&prev_block.hash) {
|
||||||
warn!("Ignoring block with wrong previous hash:\n{:?}", &block);
|
if block.index < self.get_height() - LIMITED_CONFIDENCE_DEPTH {
|
||||||
return Rewind;
|
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 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");
|
warn!("Ignoring excess zone block");
|
||||||
return Bad;
|
return Bad;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
/// 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;
|
pub const BLOCK_SIGNERS_TIME: i64 = 1800;
|
||||||
|
|
||||||
/// PoS signers, that sign blocks when chosen signers didn't sign
|
/// Limited Confidence depth
|
||||||
pub const BLOCK_POS_SIGNERS: u64 = 1000;
|
/// 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
|
/// We start mining signing blocks after random delay, this is the max delay
|
||||||
pub const BLOCK_SIGNERS_START_RANDOM: i64 = 180;
|
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 NEW_DOMAINS_INTERVAL: i64 = 86400; // One day in seconds
|
||||||
pub const DOMAIN_LIFETIME: i64 = 86400 * 365; // One year
|
pub const DOMAIN_LIFETIME: i64 = 86400 * 365; // One year
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user