Clean up some getblocktemplate difficulty code and tests

This commit is contained in:
teor 2023-01-05 16:42:12 +10:00
parent 07e3f55b6e
commit cd1ee735cc
4 changed files with 12 additions and 11 deletions

View File

@ -106,6 +106,7 @@ pub async fn test_responses<State, ReadState>(
let fake_cur_time = DateTime32::from(1654008617); let fake_cur_time = DateTime32::from(1654008617);
// nu5 block time + 123 // nu5 block time + 123
let fake_max_time = DateTime32::from(1654008728); let fake_max_time = DateTime32::from(1654008728);
let fake_difficulty = CompactDifficulty::from(ExpandedDifficulty::from(U256::one()));
let (mock_chain_tip, mock_chain_tip_sender) = MockChainTip::new(); let (mock_chain_tip, mock_chain_tip_sender) = MockChainTip::new();
mock_chain_tip_sender.send_best_tip_height(fake_tip_height); mock_chain_tip_sender.send_best_tip_height(fake_tip_height);
@ -181,7 +182,7 @@ pub async fn test_responses<State, ReadState>(
.expect_request_that(|req| matches!(req, ReadRequest::ChainInfo)) .expect_request_that(|req| matches!(req, ReadRequest::ChainInfo))
.await .await
.respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo { .respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo {
expected_difficulty: CompactDifficulty::from(ExpandedDifficulty::from(U256::one())), expected_difficulty: fake_difficulty,
tip_height: fake_tip_height, tip_height: fake_tip_height,
tip_hash: fake_tip_hash, tip_hash: fake_tip_hash,
cur_time: fake_cur_time, cur_time: fake_cur_time,
@ -235,7 +236,7 @@ pub async fn test_responses<State, ReadState>(
.expect_request_that(|req| matches!(req, ReadRequest::ChainInfo)) .expect_request_that(|req| matches!(req, ReadRequest::ChainInfo))
.await .await
.respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo { .respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo {
expected_difficulty: CompactDifficulty::from(ExpandedDifficulty::from(U256::one())), expected_difficulty: fake_difficulty,
tip_height: fake_tip_height, tip_height: fake_tip_height,
tip_hash: fake_tip_hash, tip_hash: fake_tip_hash,
cur_time: fake_cur_time, cur_time: fake_cur_time,

View File

@ -953,6 +953,7 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
let fake_cur_time = DateTime32::from(1654008617); let fake_cur_time = DateTime32::from(1654008617);
// nu5 block time + 123 // nu5 block time + 123
let fake_max_time = DateTime32::from(1654008728); let fake_max_time = DateTime32::from(1654008728);
let fake_difficulty = CompactDifficulty::from(ExpandedDifficulty::from(U256::one()));
let (mock_chain_tip, mock_chain_tip_sender) = MockChainTip::new(); let (mock_chain_tip, mock_chain_tip_sender) = MockChainTip::new();
mock_chain_tip_sender.send_best_tip_height(fake_tip_height); mock_chain_tip_sender.send_best_tip_height(fake_tip_height);
@ -976,7 +977,7 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
.expect_request_that(|req| matches!(req, ReadRequest::ChainInfo)) .expect_request_that(|req| matches!(req, ReadRequest::ChainInfo))
.await .await
.respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo { .respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo {
expected_difficulty: CompactDifficulty::from(ExpandedDifficulty::from(U256::one())), expected_difficulty: fake_difficulty,
tip_height: fake_tip_height, tip_height: fake_tip_height,
tip_hash: fake_tip_hash, tip_hash: fake_tip_hash,
cur_time: fake_cur_time, cur_time: fake_cur_time,

View File

@ -166,16 +166,14 @@ pub struct GetBlockTemplateChainInfo {
/// Depends on the `tip_hash`. /// Depends on the `tip_hash`.
pub history_tree: Arc<zebra_chain::history_tree::HistoryTree>, pub history_tree: Arc<zebra_chain::history_tree::HistoryTree>,
// Data derived from the state tip and recent blocks.
//
/// The expected difficulty of the candidate block.
/// Depends on the `tip_hash`.
pub expected_difficulty: CompactDifficulty,
// Data derived from the state tip and recent blocks, and the current local clock. // Data derived from the state tip and recent blocks, and the current local clock.
// //
/// The expected difficulty of the candidate block.
/// Depends on the `tip_hash`, and the local clock on testnet.
pub expected_difficulty: CompactDifficulty,
/// The current system time, adjusted to fit within `min_time` and `max_time`. /// The current system time, adjusted to fit within `min_time` and `max_time`.
/// Depends on the local clock and the `tip_hash`. /// Always depends on the local clock and the `tip_hash`.
pub cur_time: DateTime32, pub cur_time: DateTime32,
/// The mininimum time the miner can use in this block. /// The mininimum time the miner can use in this block.

View File

@ -227,12 +227,13 @@ fn difficulty_time_and_history_tree(
network, network,
relevant_data.iter().cloned(), relevant_data.iter().cloned(),
); );
let expected_difficulty = difficulty_adjustment.expected_difficulty_threshold();
let mut result = GetBlockTemplateChainInfo { let mut result = GetBlockTemplateChainInfo {
tip_hash, tip_hash,
tip_height, tip_height,
history_tree, history_tree,
expected_difficulty: difficulty_adjustment.expected_difficulty_threshold(), expected_difficulty,
cur_time, cur_time,
min_time, min_time,
max_time, max_time,