mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-11 07:25:09 -05:00
build: bump the CRC crate from 1.x to 3.x (#930)
This commit is contained in:
@@ -39,7 +39,7 @@ secp256k1 = { version = "0.24.2", default-features = false, features = [
|
||||
] }
|
||||
|
||||
# used for forkid
|
||||
crc = "1"
|
||||
crc = "3"
|
||||
|
||||
# misc
|
||||
bytes = "1.2"
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user