diff --git a/Cargo.lock b/Cargo.lock index 4c60e44..05a1bf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aead" version = "0.3.2" @@ -65,7 +67,7 @@ dependencies = [ [[package]] name = "alfis" -version = "0.6.4" +version = "0.6.5" dependencies = [ "base64", "bincode", diff --git a/Cargo.toml b/Cargo.toml index 5a7404e..7213dd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alfis" -version = "0.6.4" +version = "0.6.5" authors = ["Revertron "] edition = "2018" build = "build.rs" diff --git a/src/blockchain/chain.rs b/src/blockchain/chain.rs index 8cb2223..8bca584 100644 --- a/src/blockchain/chain.rs +++ b/src/blockchain/chain.rs @@ -785,7 +785,7 @@ impl Chain { SIGNER_DIFFICULTY } } - Some(t) => self.get_difficulty_for_transaction(&t) + Some(t) => self.get_difficulty_for_transaction(&t, block.index) }; if block.difficulty < difficulty { warn!("Block difficulty is lower than needed"); @@ -821,7 +821,7 @@ impl Chain { None => 0, Some(block) => block.index }; - // If this domain is available to this public key + // If this domain is not available to this public key if !self.is_id_available(current_height, &transaction.identity, &block.pub_key) { warn!("Block {:?} is trying to spoof an identity!", &block); return Bad; @@ -959,11 +959,16 @@ impl Chain { true } - fn get_difficulty_for_transaction(&self, transaction: &Transaction) -> u32 { + fn get_difficulty_for_transaction(&self, transaction: &Transaction, index: u64) -> u32 { match transaction.class.as_ref() { CLASS_DOMAIN => { + // If this domain is already in blockchain we approve slightly smaller difficulty + let discount = match self.is_domain_in_blockchain(index, &transaction.identity) { + true => { 1 } + false => { 0 } + }; return match serde_json::from_str::(&transaction.data) { - Ok(_) => DOMAIN_DIFFICULTY, + Ok(_) => DOMAIN_DIFFICULTY - discount, Err(_) => { warn!("Error parsing DomainData from {:?}", transaction); u32::MAX diff --git a/src/web_ui.rs b/src/web_ui.rs index af19dc9..118f2ab 100644 --- a/src/web_ui.rs +++ b/src/web_ui.rs @@ -560,7 +560,7 @@ fn format_event_now(kind: &str, message: &str) -> String { format!("addEvent('{}', '{}', '{}');", kind, time.format("%d.%m.%y %X"), message) } -fn create_domain(_context: Arc>, miner: Arc>, class: &str, name: &str, mut data: DomainData, difficulty: u32, keystore: &Keystore, signing: Bytes, encryption: Bytes) { +fn create_domain(context: Arc>, miner: Arc>, class: &str, name: &str, mut data: DomainData, difficulty: u32, keystore: &Keystore, signing: Bytes, encryption: Bytes) { let name = name.to_owned(); let encrypted = CryptoBox::encrypt(encryption.as_slice(), name.as_bytes()).expect("Error encrypting domain name!"); data.encrypted = Bytes::from_bytes(&encrypted); @@ -572,7 +572,15 @@ fn create_domain(_context: Arc>, miner: Arc>, class: (signing, encryption) }; let transaction = Transaction::from_str(name, class.to_owned(), data, signing, encryption); - let block = Block::new(Some(transaction), keystore.get_public(), Bytes::default(), difficulty); + // If this domain is already in blockchain we approve slightly smaller difficulty + let discount = { + let context = context.lock().unwrap(); + match context.chain.is_domain_in_blockchain(context.chain.get_height(), &transaction.identity) { + true => { 1 } + false => { 0 } + } + }; + let block = Block::new(Some(transaction), keystore.get_public(), Bytes::default(), difficulty - discount); miner.lock().unwrap().add_block(block, keystore.clone()); }