Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace deprecated bigint with uint #1874

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ arrayref = "0.3.5"
bincode = "1.1.4"
log = "0.4"
blake2 = "^0.8.0"
bigint = "^4.4.1"
uint = { version = "0.8", default-features = false }
ttl_cache = "0.5.1"
tokio = { version="^0.2", features = ["blocking", "time"] }
futures = {version = "^0.3.1", features = ["async-await"] }
Expand Down
5 changes: 5 additions & 0 deletions base_layer/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ pub mod transactions;
// Re-export the crypto crate to make exposing traits etc easier for clients of this crate
pub use crypto::tari_utilities;
pub use tari_crypto as crypto;

uint::construct_uint! {
/// 256-bit unsigned integer.
pub(crate) struct U256(4);
}
5 changes: 2 additions & 3 deletions base_layer/core/src/proof_of_work/blake_pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use crate::{blocks::BlockHeader, proof_of_work::Difficulty};
use bigint::uint::U256;
use crate::{blocks::BlockHeader, proof_of_work::Difficulty, U256};
use blake2::Blake2b;
use digest::Digest;
use tari_crypto::{common::Blake256, tari_utilities::Hashable};
Expand All @@ -43,7 +42,7 @@ pub fn blake_difficulty_with_hash(header: &BlockHeader) -> (Difficulty, Vec<u8>)
let hash = Blake256::digest(&hash).to_vec();
let scalar = U256::from_big_endian(&hash); // Big endian so the hash has leading zeroes
let result = MAX_TARGET / scalar;
let difficulty = u64::from(result).into();
let difficulty = result.low_u64().into();
(difficulty, hash)
}

Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/proof_of_work/monero_rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
use crate::{
blocks::BlockHeader,
proof_of_work::{monero_rx::MergeMineError::HashingError, Difficulty},
U256,
};
use bigint::uint::U256;
use derive_error::Error;
use monero::blockdata::{block::BlockHeader as MoneroBlockHeader, Transaction as MoneroTransaction};
#[cfg(feature = "monero_merge_mining")]
Expand Down Expand Up @@ -94,7 +94,7 @@ fn monero_difficulty_calculation(header: &BlockHeader) -> Result<Difficulty, Mer
let hash = vm.calculate_hash(&input)?;
let scalar = U256::from_big_endian(&hash); // Big endian so the hash has leading zeroes
let result = MAX_TARGET / scalar;
let difficulty = u64::from(result).into();
let difficulty = result.low_u64().into();
Ok(difficulty)
}
#[cfg(not(feature = "monero_merge_mining"))]
Expand Down