Просмотр исходного кода

blockchain/monero: cleanup chore

skoupidi 8 месяцев назад
Родитель
Сommit
b93b0dde30

+ 2 - 2
bin/darkfid/src/rpc_xmr.rs

@@ -29,12 +29,12 @@ use darkfi::{
         },
         HeaderHash,
     },
-    util::encoding::base64,
     rpc::jsonrpc::{ErrorCode, ErrorCode::InvalidParams, JsonError, JsonResponse, JsonResult},
+    util::encoding::base64,
     validator::consensus::Proposal,
 };
-use darkfi_serial::serialize_async;
 use darkfi_sdk::crypto::PublicKey;
+use darkfi_serial::serialize_async;
 use hex::FromHex;
 use tinyjson::JsonValue;
 use tracing::{error, info};

+ 23 - 27
src/blockchain/header_store.rs

@@ -33,7 +33,10 @@ use sled_overlay::{
 
 use crate::{util::time::Timestamp, Error, Result};
 
-use super::{monero::{extract_aux_merkle_root, MoneroPowData}, SledDbOverlayPtr};
+use super::{
+    monero::{extract_aux_merkle_root, MoneroPowData},
+    SledDbOverlayPtr,
+};
 
 /// Struct representing the Proof of Work used in a block.
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
@@ -155,32 +158,25 @@ impl Header {
 
     /// Validate PowData from the header.
     pub fn validate_powdata(&self) -> bool {
-		match &self.pow_data {
-			// For native DarkFi PoW, this is handled so we just return `true`.
-			PowData::DarkFi => true,
-			// For Monero PoW, we have to check a few things.
-			PowData::Monero(powdata) => {
-				if !powdata.is_coinbase_valid_merkle_root() {
-					return false
-				}
-
-				// Verify that MoneroPowData correctly corresponds to this header.
-				let aux_hash = monero::Hash::from(self.template_hash().inner());
-				let Ok(merkle_root) = extract_aux_merkle_root(&powdata.coinbase_tx_extra) else {
-					return false
-				};
-
-				let Some(merkle_root) = merkle_root else {
-					return false
-				};
-
-				if powdata.aux_chain_merkle_proof.calculate_root(&aux_hash) != merkle_root {
-					return false
-				}
-
-				true
-			}
-		}
+        match &self.pow_data {
+            // For native DarkFi PoW, this is handled so we just return `true`.
+            PowData::DarkFi => true,
+            // For Monero PoW, we have to check a few things.
+            PowData::Monero(powdata) => {
+                if !powdata.is_coinbase_valid_merkle_root() {
+                    return false
+                }
+
+                // Verify that MoneroPowData correctly corresponds to this header.
+                let Ok(Some(merkle_root)) = extract_aux_merkle_root(&powdata.coinbase_tx_extra)
+                else {
+                    return false
+                };
+
+                let aux_hash = monero::Hash::from(self.template_hash().inner());
+                powdata.aux_chain_merkle_proof.calculate_root(&aux_hash) == merkle_root
+            }
+        }
     }
 }
 

+ 1 - 2
src/blockchain/monero/merkle_proof.rs

@@ -351,8 +351,7 @@ mod tests {
     fn test_big_proof_construction() {
         // 65536 txs is beyond what is reasonable to fit in a block
         let mut thread_rng = rand::thread_rng();
-        let tx_hashes = iter::repeat(())
-            .take(0x10000)
+        let tx_hashes = iter::repeat_n((), 0x10000)
             .map(|_| {
                 let mut buf = [0u8; 32];
                 thread_rng.fill_bytes(&mut buf[..]);

+ 1 - 3
src/blockchain/monero/mod.rs

@@ -433,17 +433,15 @@ fn parse_extra_field_truncate_on_error(raw_extra_field: &RawExtraField) -> Extra
     }
 }
 
-
 /// Extract the Monero block hash from the coinbase transaction's extra field
 pub fn extract_aux_merkle_root_from_block(monero: &monero::Block) -> Result<Option<monero::Hash>> {
     extract_aux_merkle_root(&monero.miner_tx.prefix.extra)
 }
 
-
 /// Extract the Monero block hash from the coinbase transaction's extra field
 pub fn extract_aux_merkle_root(extra_field: &RawExtraField) -> Result<Option<monero::Hash>> {
     let extra_field = parse_extra_field_truncate_on_error(extra_field);
-	// Only one merge mining tag is allowed
+    // Only one merge mining tag is allowed
     let merge_mining_hashes: Vec<monero::Hash> = extra_field
         .0
         .iter()