Added some checks for "Yggdrasil only" zones.
This commit is contained in:
+18
-2
@@ -8,7 +8,7 @@ use chrono::Utc;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use sqlite::{Connection, State, Statement};
|
||||
|
||||
use crate::{Block, Bytes, Keystore, Transaction, check_domain, get_domain_zone};
|
||||
use crate::{Block, Bytes, Keystore, Transaction, check_domain, get_domain_zone, is_yggdrasil_record};
|
||||
use crate::commons::constants::*;
|
||||
use crate::blockchain::types::{BlockQuality, MineResult, Options};
|
||||
use crate::blockchain::types::BlockQuality::*;
|
||||
@@ -558,7 +558,7 @@ impl Chain {
|
||||
}
|
||||
if let Some(transaction) = &block.transaction {
|
||||
// TODO check for zone transaction
|
||||
if !self.is_id_available(&transaction.identity, &block.pub_key, false) {
|
||||
if !self.is_id_available(&transaction.identity, &block.pub_key, false) || !self.is_id_available(&transaction.identity, &block.pub_key, true) {
|
||||
warn!("Block {:?} is trying to spoof an identity!", &block);
|
||||
return Bad;
|
||||
}
|
||||
@@ -569,6 +569,22 @@ impl Chain {
|
||||
return Bad;
|
||||
}
|
||||
}
|
||||
// Check if yggdrasil only quality of zone is not violated
|
||||
if let Some(block_data) = transaction.get_domain_data() {
|
||||
let zones = self.get_zones();
|
||||
for z in &zones {
|
||||
if z.name == block_data.zone {
|
||||
if z.yggdrasil {
|
||||
for record in &block_data.records {
|
||||
if !is_yggdrasil_record(record) {
|
||||
warn!("Someone mined domain with clearnet records for Yggdrasil only zone!");
|
||||
return Bad;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
match &self.last_block {
|
||||
None => {
|
||||
|
||||
@@ -58,7 +58,8 @@ pub fn same_hash(left: &[u8], right: &[u8]) -> bool {
|
||||
result
|
||||
}
|
||||
|
||||
/// Returns hash difficulty
|
||||
/// Returns hash difficulty (sum of zeroes from start and end)
|
||||
#[inline]
|
||||
pub fn hash_difficulty(hash: &[u8]) -> u32 {
|
||||
let bytes: [u8; 8] = hash[..8].try_into().unwrap();
|
||||
let int_start = u64::from_be_bytes(bytes);
|
||||
@@ -67,12 +68,16 @@ pub fn hash_difficulty(hash: &[u8]) -> u32 {
|
||||
int_start.leading_zeros() + int_end.trailing_zeros()
|
||||
}
|
||||
|
||||
/// Returns hash difficulty for keys (only from the start)
|
||||
#[inline]
|
||||
pub fn hash_difficulty_key(hash: &[u8]) -> u32 {
|
||||
let bytes: [u8; 8] = hash[..8].try_into().unwrap();
|
||||
let int = u64::from_be_bytes(bytes);
|
||||
int.leading_zeros()
|
||||
}
|
||||
|
||||
/// Hashes data by Sha256 algorithm
|
||||
#[inline]
|
||||
pub fn hash_sha256(data: &[u8]) -> Vec<u8> {
|
||||
let mut digest = Sha256::default();
|
||||
digest.update(data.as_ref());
|
||||
|
||||
@@ -53,6 +53,16 @@ impl Transaction {
|
||||
let confirmation = hash_identity(&domain, Some(&self.pub_key));
|
||||
self.identity.eq(&hash) && self.confirmation.eq(&confirmation)
|
||||
}
|
||||
|
||||
/// Returns [DomainData] from this transaction if it has it
|
||||
pub fn get_domain_data(&self) -> Option<DomainData> {
|
||||
if self.class == "domain" {
|
||||
if let Ok(data) = serde_json::from_str::<DomainData>(&self.data) {
|
||||
return Some(data)
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Transaction {
|
||||
|
||||
Reference in New Issue
Block a user