diff --git a/src/blockchain/chain.rs b/src/blockchain/chain.rs index 6a915b6..fd0cef0 100644 --- a/src/blockchain/chain.rs +++ b/src/blockchain/chain.rs @@ -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; } diff --git a/src/commons/constants.rs b/src/commons/constants.rs index 02234bc..86aca44 100644 --- a/src/commons/constants.rs +++ b/src/commons/constants.rs @@ -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