From 65b91c08ce8e0e3b79a863612cdec37969442e33 Mon Sep 17 00:00:00 2001 From: Stanimal Date: Thu, 1 Jul 2021 16:15:56 +0400 Subject: [PATCH] [chore, testnet-reset] Remove unimplemented Blake pow algo variant Remove unimplemented PowAlgo::Blake variant. This is a DB and network breaking change. --- applications/tari_app_grpc/proto/types.proto | 5 ++--- .../tari_base_node/src/command_handler.rs | 2 +- .../base_node/sync/block_sync/synchronizer.rs | 2 +- base_layer/core/src/blocks/genesis_block.rs | 6 +++--- .../core/src/chain_storage/accumulated_data.rs | 18 +++++++++--------- .../src/chain_storage/target_difficulties.rs | 4 ---- .../src/consensus/chain_strength_comparer.rs | 4 ++-- .../core/src/proof_of_work/proof_of_work.rs | 3 +-- .../proof_of_work/proof_of_work_algorithm.rs | 6 ++---- base_layer/core/src/proto/block.proto | 2 +- base_layer/core/src/proto/block.rs | 4 ++-- base_layer/core/src/validation/helpers.rs | 3 +-- .../core/tests/helpers/block_builders.rs | 4 ++-- integration_tests/helpers/baseNodeClient.js | 2 +- 14 files changed, 28 insertions(+), 37 deletions(-) diff --git a/applications/tari_app_grpc/proto/types.proto b/applications/tari_app_grpc/proto/types.proto index c0a40deee7..a387d730af 100644 --- a/applications/tari_app_grpc/proto/types.proto +++ b/applications/tari_app_grpc/proto/types.proto @@ -71,7 +71,7 @@ message ProofOfWork { // 1 = Blake uint64 pow_algo = 1; // uint64 accumulated_monero_difficulty = 2; -// uint64 accumulated_blake_difficulty = 3; +// uint64 accumulated_sha_difficulty = 3; bytes pow_data = 4; // uint64 target_difficulty = 5; } @@ -80,8 +80,7 @@ message ProofOfWork { message PowAlgo { enum PowAlgos { POW_ALGOS_MONERO = 0; - POW_ALGOS_BLAKE = 1; - POW_ALGOS_SHA3 = 2; + POW_ALGOS_SHA3 = 1; } PowAlgos pow_algo = 1; } diff --git a/applications/tari_base_node/src/command_handler.rs b/applications/tari_base_node/src/command_handler.rs index 03f5557356..7be48fce86 100644 --- a/applications/tari_base_node/src/command_handler.rs +++ b/applications/tari_base_node/src/command_handler.rs @@ -958,7 +958,7 @@ impl CommandHandler { .consensus_constants(height) .get_difficulty_max_block_interval(pow_algo), ); - let acc_sha3 = header.accumulated_data().accumulated_blake_difficulty; + let acc_sha3 = header.accumulated_data().accumulated_sha_difficulty; let acc_monero = header.accumulated_data().accumulated_monero_difficulty; writeln!( diff --git a/base_layer/core/src/base_node/sync/block_sync/synchronizer.rs b/base_layer/core/src/base_node/sync/block_sync/synchronizer.rs index 2eb369fa3e..51497c9598 100644 --- a/base_layer/core/src/base_node/sync/block_sync/synchronizer.rs +++ b/base_layer/core/src/base_node/sync/block_sync/synchronizer.rs @@ -230,7 +230,7 @@ impl BlockSynchronizer { .total_accumulated_difficulty .to_formatted_string(&Locale::en), block.accumulated_data().accumulated_monero_difficulty, - block.accumulated_data().accumulated_blake_difficulty, + block.accumulated_data().accumulated_sha_difficulty, ); current_block = Some(block); } diff --git a/base_layer/core/src/blocks/genesis_block.rs b/base_layer/core/src/blocks/genesis_block.rs index ec93403053..8114b2e422 100644 --- a/base_layer/core/src/blocks/genesis_block.rs +++ b/base_layer/core/src/blocks/genesis_block.rs @@ -79,7 +79,7 @@ pub fn get_stibbons_genesis_block() -> ChainBlock { achieved_difficulty: 1.into(), total_accumulated_difficulty: 1, accumulated_monero_difficulty: 1.into(), - accumulated_blake_difficulty: 1.into(), + accumulated_sha_difficulty: 1.into(), target_difficulty: 1.into(), }; // NOTE: Panic is impossible, accumulated_data is created from the block @@ -118,7 +118,7 @@ pub fn get_weatherwax_genesis_block() -> ChainBlock { achieved_difficulty: 1.into(), total_accumulated_difficulty: 1, accumulated_monero_difficulty: 1.into(), - accumulated_blake_difficulty: 1.into(), + accumulated_sha_difficulty: 1.into(), target_difficulty: 1.into(), }; ChainBlock::try_construct(Arc::new(block), accumulated_data).unwrap() @@ -291,7 +291,7 @@ pub fn get_ridcully_genesis_block() -> ChainBlock { achieved_difficulty: 1.into(), total_accumulated_difficulty: 1, accumulated_monero_difficulty: 1.into(), - accumulated_blake_difficulty: 1.into(), + accumulated_sha_difficulty: 1.into(), target_difficulty: 1.into(), }; // NOTE: Panic is impossible, accumulated_data hash is set from block diff --git a/base_layer/core/src/chain_storage/accumulated_data.rs b/base_layer/core/src/chain_storage/accumulated_data.rs index 43a30fd427..f04770e379 100644 --- a/base_layer/core/src/chain_storage/accumulated_data.rs +++ b/base_layer/core/src/chain_storage/accumulated_data.rs @@ -239,12 +239,11 @@ impl BlockHeaderAccumulatedDataBuilder<'_> { let (monero_diff, blake_diff) = match achieved_target.pow_algo() { PowAlgorithm::Monero => ( previous_accum.accumulated_monero_difficulty + achieved_target.achieved(), - previous_accum.accumulated_blake_difficulty, + previous_accum.accumulated_sha_difficulty, ), - PowAlgorithm::Blake => unimplemented!(), PowAlgorithm::Sha3 => ( previous_accum.accumulated_monero_difficulty, - previous_accum.accumulated_blake_difficulty + achieved_target.achieved(), + previous_accum.accumulated_sha_difficulty + achieved_target.achieved(), ), }; @@ -259,7 +258,7 @@ impl BlockHeaderAccumulatedDataBuilder<'_> { achieved_difficulty: achieved_target.achieved(), total_accumulated_difficulty: monero_diff.as_u64() as u128 * blake_diff.as_u64() as u128, accumulated_monero_difficulty: monero_diff, - accumulated_blake_difficulty: blake_diff, + accumulated_sha_difficulty: blake_diff, target_difficulty: achieved_target.target(), }; trace!( @@ -267,7 +266,7 @@ impl BlockHeaderAccumulatedDataBuilder<'_> { "Calculated: Tot_acc_diff {}, Monero {}, SHA3 {}", result.total_accumulated_difficulty.to_formatted_string(&Locale::en), result.accumulated_monero_difficulty, - result.accumulated_blake_difficulty, + result.accumulated_sha_difficulty, ); Ok(result) } @@ -280,11 +279,12 @@ pub struct BlockHeaderAccumulatedData { pub total_kernel_offset: BlindingFactor, pub achieved_difficulty: Difficulty, pub total_accumulated_difficulty: u128, - /// The total accumulated difficulty for each proof of work algorithms for all blocks since Genesis, + /// The total accumulated difficulty for monero proof of work for all blocks since Genesis, /// but not including this block, tracked separately. pub accumulated_monero_difficulty: Difficulty, - // TODO: Rename #testnetreset - pub accumulated_blake_difficulty: Difficulty, + /// The total accumulated difficulty for SHA3 proof of work for all blocks since Genesis, + /// but not including this block, tracked separately. + pub accumulated_sha_difficulty: Difficulty, /// The target difficulty for solving the current block using the specified proof of work algorithm. pub target_difficulty: Difficulty, } @@ -305,7 +305,7 @@ impl Display for BlockHeaderAccumulatedData { "Accumulated monero difficulty: {}", self.accumulated_monero_difficulty )?; - writeln!(f, "Accumulated sha3 difficulty: {}", self.accumulated_blake_difficulty)?; + writeln!(f, "Accumulated sha3 difficulty: {}", self.accumulated_sha_difficulty)?; writeln!(f, "Target difficulty: {}", self.target_difficulty)?; Ok(()) } diff --git a/base_layer/core/src/chain_storage/target_difficulties.rs b/base_layer/core/src/chain_storage/target_difficulties.rs index b4c64c36c0..86be7a685a 100644 --- a/base_layer/core/src/chain_storage/target_difficulties.rs +++ b/base_layer/core/src/chain_storage/target_difficulties.rs @@ -62,8 +62,6 @@ impl TargetDifficulties { use PowAlgorithm::*; match algo { Monero => &self.monero, - // TODO: remove - Blake => unimplemented!(), Sha3 => &self.sha3, } } @@ -72,8 +70,6 @@ impl TargetDifficulties { use PowAlgorithm::*; match algo { Monero => &mut self.monero, - // TODO: remove - Blake => unimplemented!(), Sha3 => &mut self.sha3, } } diff --git a/base_layer/core/src/consensus/chain_strength_comparer.rs b/base_layer/core/src/consensus/chain_strength_comparer.rs index 89b73daa7b..54b5e4ae75 100644 --- a/base_layer/core/src/consensus/chain_strength_comparer.rs +++ b/base_layer/core/src/consensus/chain_strength_comparer.rs @@ -58,8 +58,8 @@ pub struct Sha3DifficultyComparer {} impl ChainStrengthComparer for Sha3DifficultyComparer { fn compare(&self, a: &ChainHeader, b: &ChainHeader) -> Ordering { a.accumulated_data() - .accumulated_blake_difficulty - .cmp(&b.accumulated_data().accumulated_blake_difficulty) + .accumulated_sha_difficulty + .cmp(&b.accumulated_data().accumulated_sha_difficulty) } } diff --git a/base_layer/core/src/proof_of_work/proof_of_work.rs b/base_layer/core/src/proof_of_work/proof_of_work.rs index cb291e0331..1753723fa3 100644 --- a/base_layer/core/src/proof_of_work/proof_of_work.rs +++ b/base_layer/core/src/proof_of_work/proof_of_work.rs @@ -73,7 +73,6 @@ impl Display for PowAlgorithm { fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { let algo = match self { PowAlgorithm::Monero => "Monero", - PowAlgorithm::Blake => "Blake", PowAlgorithm::Sha3 => "Sha3", }; fmt.write_str(&algo.to_string()) @@ -104,6 +103,6 @@ mod test { pow_algo: PowAlgorithm::Sha3, ..Default::default() }; - assert_eq!(pow.to_bytes(), vec![2]); + assert_eq!(pow.to_bytes(), vec![1]); } } diff --git a/base_layer/core/src/proof_of_work/proof_of_work_algorithm.rs b/base_layer/core/src/proof_of_work/proof_of_work_algorithm.rs index dd13b53c85..a56bd11d0b 100644 --- a/base_layer/core/src/proof_of_work/proof_of_work_algorithm.rs +++ b/base_layer/core/src/proof_of_work/proof_of_work_algorithm.rs @@ -26,9 +26,7 @@ use std::convert::TryFrom; #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Hash, Eq)] pub enum PowAlgorithm { Monero = 0, - // TODO: remove #testnetreset - Blake = 1, - Sha3 = 2, + Sha3 = 1, } impl PowAlgorithm { @@ -51,7 +49,7 @@ impl TryFrom for PowAlgorithm { fn try_from(v: u64) -> Result { match v { 0 => Ok(PowAlgorithm::Monero), - 2 => Ok(PowAlgorithm::Sha3), + 1 => Ok(PowAlgorithm::Sha3), _ => Err("Invalid PoWAlgorithm".into()), } } diff --git a/base_layer/core/src/proto/block.proto b/base_layer/core/src/proto/block.proto index a61f46347f..ae6df42fd5 100644 --- a/base_layer/core/src/proto/block.proto +++ b/base_layer/core/src/proto/block.proto @@ -80,7 +80,7 @@ message HistoricalBlock { message BlockHeaderAccumulatedData { uint64 achieved_difficulty = 1; uint64 accumulated_monero_difficulty = 2; - uint64 accumulated_blake_difficulty = 3; + uint64 accumulated_sha_difficulty = 3; uint64 target_difficulty = 4; bytes total_kernel_offset = 5; bytes hash = 6; diff --git a/base_layer/core/src/proto/block.rs b/base_layer/core/src/proto/block.rs index ea6fe0f270..4c433c33cc 100644 --- a/base_layer/core/src/proto/block.rs +++ b/base_layer/core/src/proto/block.rs @@ -113,7 +113,7 @@ impl From for proto::BlockHeaderAccumulatedData { Self { achieved_difficulty: source.achieved_difficulty.into(), accumulated_monero_difficulty: source.accumulated_monero_difficulty.into(), - accumulated_blake_difficulty: source.accumulated_blake_difficulty.into(), + accumulated_sha_difficulty: source.accumulated_sha_difficulty.into(), target_difficulty: source.target_difficulty.into(), total_kernel_offset: source.total_kernel_offset.to_vec(), hash: source.hash, @@ -135,7 +135,7 @@ impl TryFrom for BlockHeaderAccumulatedData { achieved_difficulty: source.achieved_difficulty.into(), total_accumulated_difficulty: accumulated_difficulty, accumulated_monero_difficulty: source.accumulated_monero_difficulty.into(), - accumulated_blake_difficulty: source.accumulated_blake_difficulty.into(), + accumulated_sha_difficulty: source.accumulated_sha_difficulty.into(), target_difficulty: source.target_difficulty.into(), total_kernel_offset: BlindingFactor::from_bytes(source.total_kernel_offset.as_slice()) .map_err(|err| format!("Invalid value for total_kernel_offset: {}", err))?, diff --git a/base_layer/core/src/validation/helpers.rs b/base_layer/core/src/validation/helpers.rs index b05e9adbd3..e6405a04d2 100644 --- a/base_layer/core/src/validation/helpers.rs +++ b/base_layer/core/src/validation/helpers.rs @@ -139,7 +139,7 @@ pub fn check_pow_data( Ok(()) }, - Blake | Sha3 => { + Sha3 => { if !block_header.pow.pow_data.is_empty() { return Err(ValidationError::CustomError( "Proof of work data must be empty for Sha3 blocks".to_string(), @@ -157,7 +157,6 @@ pub fn check_target_difficulty( ) -> Result { let achieved = match block_header.pow_algo() { PowAlgorithm::Monero => monero_difficulty(block_header, randomx_factory)?, - PowAlgorithm::Blake => unimplemented!(), PowAlgorithm::Sha3 => sha3_difficulty(block_header), }; diff --git a/base_layer/core/tests/helpers/block_builders.rs b/base_layer/core/tests/helpers/block_builders.rs index 462c8dad2f..ddef703e11 100644 --- a/base_layer/core/tests/helpers/block_builders.rs +++ b/base_layer/core/tests/helpers/block_builders.rs @@ -190,7 +190,7 @@ pub fn create_genesis_block_with_coinbase_value( achieved_difficulty: 1.into(), total_accumulated_difficulty: 1, accumulated_monero_difficulty: 1.into(), - accumulated_blake_difficulty: 1.into(), + accumulated_sha_difficulty: 1.into(), target_difficulty: 1.into(), }) .unwrap(), @@ -227,7 +227,7 @@ pub fn create_genesis_block_with_utxos( achieved_difficulty: 1.into(), total_accumulated_difficulty: 1, accumulated_monero_difficulty: 1.into(), - accumulated_blake_difficulty: 1.into(), + accumulated_sha_difficulty: 1.into(), target_difficulty: 1.into(), }) .unwrap(), diff --git a/integration_tests/helpers/baseNodeClient.js b/integration_tests/helpers/baseNodeClient.js index 04d1ffd44c..1221d260da 100644 --- a/integration_tests/helpers/baseNodeClient.js +++ b/integration_tests/helpers/baseNodeClient.js @@ -372,7 +372,7 @@ class BaseNodeClient { toLittleEndian(parseInt(header.pow.accumulated_monero_difficulty), 64) ); hash.update( - toLittleEndian(parseInt(header.pow.accumulated_blake_difficulty), 64) + toLittleEndian(parseInt(header.pow.accumulated_sha_difficulty), 64) ); hash.update(header.pow.pow_data); const first_round = hash.digest();