build: bump the CRC crate from 1.x to 3.x (#930)

This commit is contained in:
Frank Dai
2023-01-20 18:55:24 -08:00
committed by GitHub
parent c41bdd9cbf
commit 3f7744398b
2 changed files with 10 additions and 4 deletions

View File

@@ -39,7 +39,7 @@ secp256k1 = { version = "0.24.2", default-features = false, features = [
] }
# used for forkid
crc = "1"
crc = "3"
# misc
bytes = "1.2"

View File

@@ -4,7 +4,7 @@
#![deny(missing_docs)]
use crate::{BlockNumber, H256};
use crc::crc32;
use crc::*;
use reth_codecs::derive_arbitrary;
use reth_rlp::*;
use serde::{Deserialize, Serialize};
@@ -15,6 +15,8 @@ use std::{
};
use thiserror::Error;
const CRC_32_IEEE: Crc<u32> = Crc::<u32>::new(&CRC_32_ISO_HDLC);
/// `CRC32` hash of all previous forks starting from genesis block.
#[derive_arbitrary(rlp)]
#[derive(
@@ -39,14 +41,18 @@ impl fmt::Debug for ForkHash {
impl From<H256> for ForkHash {
fn from(genesis: H256) -> Self {
Self(crc32::checksum_ieee(&genesis[..]).to_be_bytes())
Self(CRC_32_IEEE.checksum(&genesis[..]).to_be_bytes())
}
}
impl AddAssign<BlockNumber> for ForkHash {
fn add_assign(&mut self, block: BlockNumber) {
let blob = block.to_be_bytes();
self.0 = crc32::update(u32::from_be_bytes(self.0), &crc32::IEEE_TABLE, &blob).to_be_bytes();
let digest = CRC_32_IEEE.digest_with_initial(u32::from_be_bytes(self.0));
let value = digest.finalize();
let mut digest = CRC_32_IEEE.digest_with_initial(value);
digest.update(&blob);
self.0 = digest.finalize().to_be_bytes();
}
}