Skip to content

Commit c64b79a

Browse files
authored
fix: base node panic (#7074)
Description --- Fix potential panic in base node <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved the calculation method for estimated hash rates of different proof-of-work algorithms, ensuring more accurate and reliable network state reporting. - **Chores** - Updated mainnet configuration to adjust the expected block target times for multiple proof-of-work algorithms. - Refined pre-mine token maturity schedules and spendable supply expectations in tests to reflect updated block boundaries. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 3cc9f8a commit c64b79a

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

applications/minotari_node/src/grpc/base_node_grpc_server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
426426
obscure_error_if_true(report_error_flag, Status::internal(e.to_string()))
427427
})?;
428428
let target_time = constants.pow_target_block_interval(PowAlgorithm::Sha3x);
429-
let estimated_hash_rate = target_difficulty.as_u64() / target_time;
429+
let estimated_hash_rate = target_difficulty.as_u64().saturating_sub(target_time);
430430
self.data_cache
431431
.set_sha3x_estimated_hash_rate(estimated_hash_rate, *metadata.best_block_hash())
432432
.await;
@@ -452,7 +452,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
452452
obscure_error_if_true(report_error_flag, Status::internal(e.to_string()))
453453
})?;
454454
let target_time = constants.pow_target_block_interval(PowAlgorithm::RandomXM);
455-
let estimated_hash_rate = target_difficulty.as_u64() / target_time;
455+
let estimated_hash_rate = target_difficulty.as_u64().saturating_sub(target_time);
456456
self.data_cache
457457
.set_monero_randomx_estimated_hash_rate(estimated_hash_rate, *metadata.best_block_hash())
458458
.await;
@@ -479,7 +479,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
479479
obscure_error_if_true(report_error_flag, Status::internal(e.to_string()))
480480
})?;
481481
let target_time = constants.pow_target_block_interval(PowAlgorithm::RandomXT);
482-
let estimated_hash_rate = target_difficulty.as_u64() / target_time;
482+
let estimated_hash_rate = target_difficulty.as_u64().saturating_sub(target_time);
483483
self.data_cache
484484
.set_tari_randomx_estimated_hash_rate(estimated_hash_rate, *metadata.best_block_hash())
485485
.await;

base_layer/core/src/blocks/pre_mine/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,8 +1473,8 @@ mod test {
14731473
// Initial maturity schedule up to 3 weeks ( | height | (maturity) |):
14741474
// | 0 -> 5040 - 1 | (720) |
14751475
// | 5040 -> 10080 - 1 | (540) |
1476-
// | 10080 -> 15120 - 1 | (360) |
1477-
// | 15120 -> | (180) |
1476+
// | 10080 -> 15000 - 1 | (360) |
1477+
// | 15000 -> | (180) |
14781478

14791479
let network = Network::MainNet;
14801480
let consensus_manager = ConsensusManager::builder(network)
@@ -1510,14 +1510,14 @@ mod test {
15101510
898513007030503,
15111511
),
15121512
// Within 4th tranche
1513-
(maturity_tranches[3].effective_from_height, 960614382886959),
1513+
(maturity_tranches[3].effective_from_height, 958961532039375),
15141514
(
15151515
maturity_tranches[3].effective_from_height + maturity_tranches[2].maturity / 2,
1516-
963093332298424,
1516+
961440742937559,
15171517
),
15181518
(
15191519
maturity_tranches[3].effective_from_height + maturity_tranches[2].maturity,
1520-
968050054592502,
1520+
966397988109264,
15211521
),
15221522
// Within pre-mine maturity range 1
15231523
(180 * BLOCKS_PER_DAY, 2573982676047120),

base_layer/core/src/consensus/consensus_constants.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ impl ConsensusConstants {
696696
consensus_constants
697697
}
698698

699-
// These values are mainly place holder till the final decision has been made about their values.
700699
pub fn mainnet() -> Vec<Self> {
701700
let difficulty_block_window = 90;
702701
let mut algos = HashMap::new();
@@ -759,17 +758,17 @@ impl ConsensusConstants {
759758
algos.insert(PowAlgorithm::Sha3x, PowAlgorithmConstants {
760759
min_difficulty: Difficulty::from_u64(150_000_000_000).expect("valid difficulty"),
761760
max_difficulty: Difficulty::max(),
762-
target_time: 360,
761+
target_time: 240,
763762
});
764763
algos.insert(PowAlgorithm::RandomXM, PowAlgorithmConstants {
765764
min_difficulty: Difficulty::from_u64(1_200_000).expect("valid difficulty"),
766765
max_difficulty: Difficulty::max(),
767-
target_time: 360,
766+
target_time: 480,
768767
});
769768
algos.insert(PowAlgorithm::RandomXT, PowAlgorithmConstants {
770769
min_difficulty: Difficulty::from_u64(1_200_000).expect("valid difficulty"),
771770
max_difficulty: Difficulty::max(),
772-
target_time: 360,
771+
target_time: 480,
773772
});
774773
con_4.blockchain_version = 1;
775774
con_4.valid_blockchain_version_range = 1..=1;

0 commit comments

Comments
 (0)