From 9cdca1d3d6d162387d68f90f8b837e38b366e705 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 5 Oct 2023 14:27:59 -0400 Subject: [PATCH] Use the newly stabilized div_ceil Sets a msrv of 1.73.0. --- coins/bitcoin/src/wallet/send.rs | 2 +- coins/monero/src/wallet/seed/polyseed.rs | 3 +-- crypto/transcript/src/lib.rs | 2 +- processor/src/multisigs/mod.rs | 10 +--------- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/coins/bitcoin/src/wallet/send.rs b/coins/bitcoin/src/wallet/send.rs index 7dde21867..066ae5579 100644 --- a/coins/bitcoin/src/wallet/send.rs +++ b/coins/bitcoin/src/wallet/send.rs @@ -197,7 +197,7 @@ impl SignableTransaction { // multiplied by DEFAULT_BYTES_PER_SIGOP (20) // We only use 1 signature per input, and our inputs have a weight exceeding 20 // Accordingly, our inputs' weight will always be greater than the cost of the signature ops - let vsize = (weight + 3) / 4; + let vsize = weight.div_ceil(4); // Technically, if there isn't change, this TX may still pay enough of a fee to pass the // minimum fee. Such edge cases aren't worth programming when they go against intent, as the // specified fee rate is too low to be valid diff --git a/coins/monero/src/wallet/seed/polyseed.rs b/coins/monero/src/wallet/seed/polyseed.rs index 4b38fd83a..b9833297c 100644 --- a/coins/monero/src/wallet/seed/polyseed.rs +++ b/coins/monero/src/wallet/seed/polyseed.rs @@ -50,8 +50,7 @@ fn birthday_decode(birthday: u16) -> u64 { const SECRET_BITS: usize = 150; const BITS_PER_BYTE: usize = 8; -// ceildiv of SECRET_BITS by BITS_PER_BYTE -const SECRET_SIZE: usize = (SECRET_BITS + BITS_PER_BYTE - 1) / BITS_PER_BYTE; // 19 +const SECRET_SIZE: usize = SECRET_BITS.div_ceil(BITS_PER_BYTE); // 19 const CLEAR_BITS: usize = (SECRET_SIZE * BITS_PER_BYTE) - SECRET_BITS; // 2 // Polyseed calls this CLEAR_MASK and has a very complicated formula for this fundamental diff --git a/crypto/transcript/src/lib.rs b/crypto/transcript/src/lib.rs index 1f386d269..66d5d7cfb 100644 --- a/crypto/transcript/src/lib.rs +++ b/crypto/transcript/src/lib.rs @@ -149,7 +149,7 @@ where // block_size returns the block_size in bytes // Use a ceil div in case the block size isn't evenly divisible by our word size - let words = (D::block_size() + (WORD_SIZE - 1)) / WORD_SIZE; + let words = D::block_size().div_ceil(WORD_SIZE); for _ in 0 .. (2 * words) { self.0.update([255; WORD_SIZE]); } diff --git a/processor/src/multisigs/mod.rs b/processor/src/multisigs/mod.rs index 968e094c9..a6838fd5a 100644 --- a/processor/src/multisigs/mod.rs +++ b/processor/src/multisigs/mod.rs @@ -229,14 +229,6 @@ impl MultisigManager { } fn current_rotation_step(&self, block_number: usize) -> RotationStep { - fn ceil_div(num: usize, denom: usize) -> usize { - let res = num / denom; - if (res * denom) == num { - return res; - } - res + 1 - } - let Some(new) = self.new.as_ref() else { return RotationStep::UseExisting }; // Period numbering here has no meaning other than these the time values useful here, and the @@ -250,7 +242,7 @@ impl MultisigManager { // N::CONFIRMATIONS + 10 minutes let period_1_start = new.activation_block + N::CONFIRMATIONS + - ceil_div(10 * 60, N::ESTIMATED_BLOCK_TIME_IN_SECONDS); + (10usize * 60).div_ceil(N::ESTIMATED_BLOCK_TIME_IN_SECONDS); // N::CONFIRMATIONS let period_2_start = period_1_start + N::CONFIRMATIONS;