diff --git a/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs b/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs index 5a6108bac..0c747de34 100644 --- a/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs +++ b/zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs @@ -106,6 +106,7 @@ pub async fn test_responses( let fake_cur_time = DateTime32::from(1654008617); // nu5 block time + 123 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(); mock_chain_tip_sender.send_best_tip_height(fake_tip_height); @@ -181,7 +182,7 @@ pub async fn test_responses( .expect_request_that(|req| matches!(req, ReadRequest::ChainInfo)) .await .respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo { - expected_difficulty: CompactDifficulty::from(ExpandedDifficulty::from(U256::one())), + expected_difficulty: fake_difficulty, tip_height: fake_tip_height, tip_hash: fake_tip_hash, cur_time: fake_cur_time, @@ -235,7 +236,7 @@ pub async fn test_responses( .expect_request_that(|req| matches!(req, ReadRequest::ChainInfo)) .await .respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo { - expected_difficulty: CompactDifficulty::from(ExpandedDifficulty::from(U256::one())), + expected_difficulty: fake_difficulty, tip_height: fake_tip_height, tip_hash: fake_tip_hash, cur_time: fake_cur_time, diff --git a/zebra-rpc/src/methods/tests/vectors.rs b/zebra-rpc/src/methods/tests/vectors.rs index a3615a7af..8b3b8475e 100644 --- a/zebra-rpc/src/methods/tests/vectors.rs +++ b/zebra-rpc/src/methods/tests/vectors.rs @@ -953,6 +953,7 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) { let fake_cur_time = DateTime32::from(1654008617); // nu5 block time + 123 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(); 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)) .await .respond(ReadResponse::ChainInfo(GetBlockTemplateChainInfo { - expected_difficulty: CompactDifficulty::from(ExpandedDifficulty::from(U256::one())), + expected_difficulty: fake_difficulty, tip_height: fake_tip_height, tip_hash: fake_tip_hash, cur_time: fake_cur_time, diff --git a/zebra-state/src/response.rs b/zebra-state/src/response.rs index 1d529c2b9..1ee264cb6 100644 --- a/zebra-state/src/response.rs +++ b/zebra-state/src/response.rs @@ -166,16 +166,14 @@ pub struct GetBlockTemplateChainInfo { /// Depends on the `tip_hash`. pub history_tree: Arc, - // 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. // + /// 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`. - /// Depends on the local clock and the `tip_hash`. + /// Always depends on the local clock and the `tip_hash`. pub cur_time: DateTime32, /// The mininimum time the miner can use in this block. diff --git a/zebra-state/src/service/read/difficulty.rs b/zebra-state/src/service/read/difficulty.rs index 3dd38f236..d66250338 100644 --- a/zebra-state/src/service/read/difficulty.rs +++ b/zebra-state/src/service/read/difficulty.rs @@ -227,12 +227,13 @@ fn difficulty_time_and_history_tree( network, relevant_data.iter().cloned(), ); + let expected_difficulty = difficulty_adjustment.expected_difficulty_threshold(); let mut result = GetBlockTemplateChainInfo { tip_hash, tip_height, history_tree, - expected_difficulty: difficulty_adjustment.expected_difficulty_threshold(), + expected_difficulty, cur_time, min_time, max_time,