Skip to content

Commit 6c3f3d1

Browse files
authored
Merge pull request #24 from EthanYuan/fix-calculate-next-target
fix: overflow in `calculate_next_target` to match Bitcoin Core
2 parents 1ccd114 + 2b8f96d commit 6c3f3d1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

verifier/src/utilities/bitcoin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ pub fn calculate_next_target(
2020
end_time: u32,
2121
flags: u8,
2222
) -> Target {
23-
let expected = DIFFCHANGE_TIMESPAN;
23+
let expected = DIFFCHANGE_TIMESPAN as i64;
2424
let actual = {
25-
let mut actual = end_time - start_time;
25+
let mut actual = (end_time as i64) - (start_time as i64);
2626
if actual < expected / 4 {
2727
actual = expected / 4;
2828
}
2929
if actual > expected * 4 {
3030
actual = expected * 4;
3131
}
32-
actual
32+
actual as u32
3333
};
3434

3535
let le_bytes = {

0 commit comments

Comments
 (0)