Skip to content

Commit 7ab5633

Browse files
committed
Merge #260: Add '()' annotation and error handling to submit_header
d3a047e Add '()' annotation and error handling to submit_header (GideonBature) Pull request description: This is a patch for [PR #259](#259) that adds a `let _: () = ...` annotation and an `.expect("submitheader")` call to the integration test for `submit_header`. The `.expect()` call is necessary to extract the `()` value from the result returned by `submit_header`, making the test both explicit and consistent with the other null-returning client function tests. Also, Introduced a for loop to increment the header’s nonce until the PoW is valid. This ensures the header meets Bitcoin’s difficulty target before calling `submit_header`. ACKs for top commit: jamillambert: ACK d3a047e tcharding: ACK d3a047e Tree-SHA512: 18d02f72acdde75e293d5e9ea61bbad1841909d3ff09e63219e9fbd85dfa5af1c7a048645bb3111928ac4f4811c41337ea5f674e64528b2f4d01a9f40738f40e
2 parents b2b7c22 + d3a047e commit 7ab5633

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

integration_test/tests/mining.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,12 @@ fn mining__submit_header() {
221221
let best_block = node.client.get_best_block_hash().expect("getbestblockhash").into_model().unwrap().0;
222222
let mut header = node.client.get_block_header(&best_block).expect("getblockheader").into_model().unwrap().0;
223223

224-
// Change the nonce to ensure the header is different from the current tip.
225-
header.nonce = header.nonce.wrapping_add(1);
224+
for _ in 1..=u32::MAX {
225+
header.nonce = header.nonce.wrapping_add(1);
226+
if header.validate_pow(header.target()).is_ok() {
227+
break;
228+
}
229+
}
226230

227-
let _ = node.client.submit_header(&header);
231+
let _: () = node.client.submit_header(&header).expect("submitheader");
228232
}

0 commit comments

Comments
 (0)