Clean up some getblocktemplate difficulty code and tests
This commit is contained in:
parent
07e3f55b6e
commit
cd1ee735cc
|
@ -106,6 +106,7 @@ pub async fn test_responses<State, ReadState>(
|
|||
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<State, ReadState>(
|
|||
.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<State, ReadState>(
|
|||
.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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -166,16 +166,14 @@ pub struct GetBlockTemplateChainInfo {
|
|||
/// Depends on the `tip_hash`.
|
||||
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.
|
||||
//
|
||||
/// 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.
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue