use core::fmt;
use hashes::{sha256d, Hash, HashEngine};
use io::{Read, Write};
use super::Weight;
use crate::blockdata::script;
use crate::blockdata::transaction::{Transaction, Txid, Wtxid};
use crate::consensus::{encode, Decodable, Encodable, Params};
use crate::internal_macros::{impl_consensus_encoding, impl_hashencode};
use crate::pow::{CompactTarget, Target, Work};
use crate::prelude::*;
use crate::{merkle_tree, VarInt};
hashes::hash_newtype! {
pub struct BlockHash(sha256d::Hash);
pub struct TxMerkleNode(sha256d::Hash);
pub struct WitnessMerkleNode(sha256d::Hash);
pub struct WitnessCommitment(sha256d::Hash);
}
impl_hashencode!(BlockHash);
impl_hashencode!(TxMerkleNode);
impl_hashencode!(WitnessMerkleNode);
impl From<Txid> for TxMerkleNode {
fn from(txid: Txid) -> Self { Self::from_byte_array(txid.to_byte_array()) }
}
impl From<Wtxid> for WitnessMerkleNode {
fn from(wtxid: Wtxid) -> Self { Self::from_byte_array(wtxid.to_byte_array()) }
}
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Header {
pub version: Version,
pub prev_blockhash: BlockHash,
pub merkle_root: TxMerkleNode,
pub time: u32,
pub bits: CompactTarget,
pub nonce: u32,
}
impl_consensus_encoding!(Header, version, prev_blockhash, merkle_root, time, bits, nonce);
impl Header {
pub const SIZE: usize = 4 + 32 + 32 + 4 + 4 + 4; pub fn block_hash(&self) -> BlockHash {
let mut engine = BlockHash::engine();
self.consensus_encode(&mut engine).expect("engines don't error");
BlockHash::from_engine(engine)
}
pub fn target(&self) -> Target { self.bits.into() }
pub fn difficulty(&self, params: impl AsRef<Params>) -> u128 {
self.target().difficulty(params)
}
pub fn difficulty_float(&self) -> f64 { self.target().difficulty_float() }
pub fn validate_pow(&self, required_target: Target) -> Result<BlockHash, ValidationError> {
let target = self.target();
if target != required_target {
return Err(ValidationError::BadTarget);
}
let block_hash = self.block_hash();
if target.is_met_by(block_hash) {
Ok(block_hash)
} else {
Err(ValidationError::BadProofOfWork)
}
}
pub fn work(&self) -> Work { self.target().to_work() }
}
impl fmt::Debug for Header {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Header")
.field("block_hash", &self.block_hash())
.field("version", &self.version)
.field("prev_blockhash", &self.prev_blockhash)
.field("merkle_root", &self.merkle_root)
.field("time", &self.time)
.field("bits", &self.bits)
.field("nonce", &self.nonce)
.finish()
}
}
#[derive(Copy, PartialEq, Eq, Clone, Debug, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Version(i32);
impl Version {
pub const ONE: Self = Self(1);
pub const TWO: Self = Self(2);
pub const NO_SOFT_FORK_SIGNALLING: Self = Self(Self::USE_VERSION_BITS as i32);
const VERSION_BITS_MASK: u32 = 0x1FFF_FFFF;
const USE_VERSION_BITS: u32 = 0x2000_0000;
#[inline]
pub const fn from_consensus(v: i32) -> Self { Version(v) }
pub fn to_consensus(self) -> i32 { self.0 }
pub fn is_signalling_soft_fork(&self, bit: u8) -> bool {
if bit > 28 {
return false;
}
if (self.0 as u32) & !Self::VERSION_BITS_MASK != Self::USE_VERSION_BITS {
return false;
}
(self.0 as u32 & Self::VERSION_BITS_MASK) & (1 << bit) > 0
}
}
impl Default for Version {
fn default() -> Version { Self::NO_SOFT_FORK_SIGNALLING }
}
impl Encodable for Version {
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
self.0.consensus_encode(w)
}
}
impl Decodable for Version {
fn consensus_decode<R: Read + ?Sized>(r: &mut R) -> Result<Self, encode::Error> {
Decodable::consensus_decode(r).map(Version)
}
}
#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Block {
pub header: Header,
pub txdata: Vec<Transaction>,
}
impl_consensus_encoding!(Block, header, txdata);
impl Block {
pub fn block_hash(&self) -> BlockHash { self.header.block_hash() }
pub fn check_merkle_root(&self) -> bool {
match self.compute_merkle_root() {
Some(merkle_root) => self.header.merkle_root == merkle_root,
None => false,
}
}
pub fn check_witness_commitment(&self) -> bool {
const MAGIC: [u8; 6] = [0x6a, 0x24, 0xaa, 0x21, 0xa9, 0xed];
if self.txdata.iter().all(|t| t.input.iter().all(|i| i.witness.is_empty())) {
return true;
}
if self.txdata.is_empty() {
return false;
}
let coinbase = &self.txdata[0];
if !coinbase.is_coinbase() {
return false;
}
if let Some(pos) = coinbase
.output
.iter()
.rposition(|o| o.script_pubkey.len() >= 38 && o.script_pubkey.as_bytes()[0..6] == MAGIC)
{
let commitment = WitnessCommitment::from_slice(
&coinbase.output[pos].script_pubkey.as_bytes()[6..38],
)
.unwrap();
let witness_vec: Vec<_> = coinbase.input[0].witness.iter().collect();
if witness_vec.len() == 1 && witness_vec[0].len() == 32 {
if let Some(witness_root) = self.witness_root() {
return commitment
== Self::compute_witness_commitment(&witness_root, witness_vec[0]);
}
}
}
false
}
pub fn compute_merkle_root(&self) -> Option<TxMerkleNode> {
let hashes = self.txdata.iter().map(|obj| obj.compute_txid().to_raw_hash());
merkle_tree::calculate_root(hashes).map(|h| h.into())
}
pub fn compute_witness_commitment(
witness_root: &WitnessMerkleNode,
witness_reserved_value: &[u8],
) -> WitnessCommitment {
let mut encoder = WitnessCommitment::engine();
witness_root.consensus_encode(&mut encoder).expect("engines don't error");
encoder.input(witness_reserved_value);
WitnessCommitment::from_engine(encoder)
}
pub fn witness_root(&self) -> Option<WitnessMerkleNode> {
let hashes = self.txdata.iter().enumerate().map(|(i, t)| {
if i == 0 {
Wtxid::all_zeros().to_raw_hash()
} else {
t.compute_wtxid().to_raw_hash()
}
});
merkle_tree::calculate_root(hashes).map(|h| h.into())
}
pub fn weight(&self) -> Weight {
let wu = self.base_size() * 3 + self.total_size();
Weight::from_wu_usize(wu)
}
fn base_size(&self) -> usize {
let mut size = Header::SIZE;
size += VarInt::from(self.txdata.len()).size();
size += self.txdata.iter().map(|tx| tx.base_size()).sum::<usize>();
size
}
pub fn total_size(&self) -> usize {
let mut size = Header::SIZE;
size += VarInt::from(self.txdata.len()).size();
size += self.txdata.iter().map(|tx| tx.total_size()).sum::<usize>();
size
}
pub fn coinbase(&self) -> Option<&Transaction> { self.txdata.first() }
pub fn bip34_block_height(&self) -> Result<u64, Bip34Error> {
if self.header.version < Version::TWO {
return Err(Bip34Error::Unsupported);
}
let cb = self.coinbase().ok_or(Bip34Error::NotPresent)?;
let input = cb.input.first().ok_or(Bip34Error::NotPresent)?;
let push = input.script_sig.instructions_minimal().next().ok_or(Bip34Error::NotPresent)?;
match push.map_err(|_| Bip34Error::NotPresent)? {
script::Instruction::PushBytes(b) => {
let h = script::read_scriptint(b.as_bytes())
.map_err(|_e| Bip34Error::UnexpectedPush(b.as_bytes().to_vec()))?;
if h < 0 {
Err(Bip34Error::NegativeHeight)
} else {
Ok(h as u64)
}
}
_ => Err(Bip34Error::NotPresent),
}
}
}
impl From<Header> for BlockHash {
fn from(header: Header) -> BlockHash { header.block_hash() }
}
impl From<&Header> for BlockHash {
fn from(header: &Header) -> BlockHash { header.block_hash() }
}
impl From<Block> for BlockHash {
fn from(block: Block) -> BlockHash { block.block_hash() }
}
impl From<&Block> for BlockHash {
fn from(block: &Block) -> BlockHash { block.block_hash() }
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Bip34Error {
Unsupported,
NotPresent,
UnexpectedPush(Vec<u8>),
NegativeHeight,
}
internals::impl_from_infallible!(Bip34Error);
impl fmt::Display for Bip34Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Bip34Error::*;
match *self {
Unsupported => write!(f, "block doesn't support BIP34"),
NotPresent => write!(f, "BIP34 push not present in block's coinbase"),
UnexpectedPush(ref p) => {
write!(f, "unexpected byte push of > 8 bytes: {:?}", p)
}
NegativeHeight => write!(f, "negative BIP34 height"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Bip34Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use Bip34Error::*;
match *self {
Unsupported | NotPresent | UnexpectedPush(_) | NegativeHeight => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ValidationError {
BadProofOfWork,
BadTarget,
}
internals::impl_from_infallible!(ValidationError);
impl fmt::Display for ValidationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ValidationError::*;
match *self {
BadProofOfWork => f.write_str("block target correct but not attained"),
BadTarget => f.write_str("block target incorrect"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ValidationError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use self::ValidationError::*;
match *self {
BadProofOfWork | BadTarget => None,
}
}
}
#[cfg(test)]
mod tests {
use hex::{test_hex_unwrap as hex, FromHex};
use super::*;
use crate::consensus::encode::{deserialize, serialize};
use crate::Network;
#[test]
fn test_coinbase_and_bip34() {
const BLOCK_HEX: &str = "0200000035ab154183570282ce9afc0b494c9fc6a3cfea05aa8c1add2ecc56490000000038ba3d78e4500a5a7570dbe61960398add4410d278b21cd9708e6d9743f374d544fc055227f1001c29c1ea3b0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3703a08601000427f1001c046a510100522cfabe6d6d0000000000000000000068692066726f6d20706f6f6c7365727665726aac1eeeed88ffffffff0100f2052a010000001976a914912e2b234f941f30b18afbb4fa46171214bf66c888ac00000000";
let block: Block = deserialize(&hex!(BLOCK_HEX)).unwrap();
let cb_txid = "d574f343976d8e70d91cb278d21044dd8a396019e6db70755a0a50e4783dba38";
assert_eq!(block.coinbase().unwrap().compute_txid().to_string(), cb_txid);
assert_eq!(block.bip34_block_height(), Ok(100_000));
const BAD_HEX: &str = "0200000035ab154183570282ce9afc0b494c9fc6a3cfea05aa8c1add2ecc56490000000038ba3d78e4500a5a7570dbe61960398add4410d278b21cd9708e6d9743f374d544fc055227f1001c29c1ea3b0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3d09a08601112233445566000427f1001c046a510100522cfabe6d6d0000000000000000000068692066726f6d20706f6f6c7365727665726aac1eeeed88ffffffff0100f2052a010000001976a914912e2b234f941f30b18afbb4fa46171214bf66c888ac00000000";
let bad: Block = deserialize(&hex!(BAD_HEX)).unwrap();
let push = Vec::<u8>::from_hex("a08601112233445566").unwrap();
assert_eq!(bad.bip34_block_height(), Err(super::Bip34Error::UnexpectedPush(push)));
}
#[test]
fn block_test() {
let params = Params::new(Network::Bitcoin);
let some_block = hex!("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac00000000");
let cutoff_block = hex!("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d026e04ffffffff0100f2052a0100000043410446ef0102d1ec5240f0d061a4246c1bdef63fc3dbab7733052fbbf0ecd8f41fc26bf049ebb4f9527f374280259e7cfa99c48b0e3f39c51347a19a5819651503a5ac00000000010000000321f75f3139a013f50f315b23b0c9a2b6eac31e2bec98e5891c924664889942260000000049483045022100cb2c6b346a978ab8c61b18b5e9397755cbd17d6eb2fe0083ef32e067fa6c785a02206ce44e613f31d9a6b0517e46f3db1576e9812cc98d159bfdaf759a5014081b5c01ffffffff79cda0945903627c3da1f85fc95d0b8ee3e76ae0cfdc9a65d09744b1f8fc85430000000049483045022047957cdd957cfd0becd642f6b84d82f49b6cb4c51a91f49246908af7c3cfdf4a022100e96b46621f1bffcf5ea5982f88cef651e9354f5791602369bf5a82a6cd61a62501fffffffffe09f5fe3ffbf5ee97a54eb5e5069e9da6b4856ee86fc52938c2f979b0f38e82000000004847304402204165be9a4cbab8049e1af9723b96199bfd3e85f44c6b4c0177e3962686b26073022028f638da23fc003760861ad481ead4099312c60030d4cb57820ce4d33812a5ce01ffffffff01009d966b01000000434104ea1feff861b51fe3f5f8a3b12d0f4712db80e919548a80839fc47c6a21e66d957e9c5d8cd108c7a2d2324bad71f9904ac0ae7336507d785b17a2c115e427a32fac");
let prevhash = hex!("4ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000");
let merkle = hex!("bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914c");
let work = Work::from(0x100010001_u128);
let decode: Result<Block, _> = deserialize(&some_block);
let bad_decode: Result<Block, _> = deserialize(&cutoff_block);
assert!(decode.is_ok());
assert!(bad_decode.is_err());
let real_decode = decode.unwrap();
assert_eq!(real_decode.header.version, Version(1));
assert_eq!(serialize(&real_decode.header.prev_blockhash), prevhash);
assert_eq!(real_decode.header.merkle_root, real_decode.compute_merkle_root().unwrap());
assert_eq!(serialize(&real_decode.header.merkle_root), merkle);
assert_eq!(real_decode.header.time, 1231965655);
assert_eq!(real_decode.header.bits, CompactTarget::from_consensus(486604799));
assert_eq!(real_decode.header.nonce, 2067413810);
assert_eq!(real_decode.header.work(), work);
assert_eq!(
real_decode.header.validate_pow(real_decode.header.target()).unwrap(),
real_decode.block_hash()
);
assert_eq!(real_decode.header.difficulty(¶ms), 1);
assert_eq!(real_decode.header.difficulty_float(), 1.0);
assert_eq!(real_decode.total_size(), some_block.len());
assert_eq!(real_decode.base_size(), some_block.len());
assert_eq!(
real_decode.weight(),
Weight::from_non_witness_data_size(some_block.len() as u64)
);
assert!(real_decode.check_witness_commitment());
assert_eq!(serialize(&real_decode), some_block);
}
#[test]
fn segwit_block_test() {
let params = Params::new(Network::Testnet);
let segwit_block = include_bytes!("../../tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw").to_vec();
let decode: Result<Block, _> = deserialize(&segwit_block);
let prevhash = hex!("2aa2f2ca794ccbd40c16e2f3333f6b8b683f9e7179b2c4d74906000000000000");
let merkle = hex!("10bc26e70a2f672ad420a6153dd0c28b40a6002c55531bfc99bf8994a8e8f67e");
let work = Work::from(0x257c3becdacc64_u64);
assert!(decode.is_ok());
let real_decode = decode.unwrap();
assert_eq!(real_decode.header.version, Version(Version::USE_VERSION_BITS as i32)); assert_eq!(serialize(&real_decode.header.prev_blockhash), prevhash);
assert_eq!(serialize(&real_decode.header.merkle_root), merkle);
assert_eq!(real_decode.header.merkle_root, real_decode.compute_merkle_root().unwrap());
assert_eq!(real_decode.header.time, 1472004949);
assert_eq!(real_decode.header.bits, CompactTarget::from_consensus(0x1a06d450));
assert_eq!(real_decode.header.nonce, 1879759182);
assert_eq!(real_decode.header.work(), work);
assert_eq!(
real_decode.header.validate_pow(real_decode.header.target()).unwrap(),
real_decode.block_hash()
);
assert_eq!(real_decode.header.difficulty(¶ms), 2456598);
assert_eq!(real_decode.header.difficulty_float(), 2456598.4399242126);
assert_eq!(real_decode.total_size(), segwit_block.len());
assert_eq!(real_decode.base_size(), 4283);
assert_eq!(real_decode.weight(), Weight::from_wu(17168));
assert!(real_decode.check_witness_commitment());
assert_eq!(serialize(&real_decode), segwit_block);
}
#[test]
fn block_version_test() {
let block = hex!("ffffff7f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
let decode: Result<Block, _> = deserialize(&block);
assert!(decode.is_ok());
let real_decode = decode.unwrap();
assert_eq!(real_decode.header.version, Version(2147483647));
let block2 = hex!("000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
let decode2: Result<Block, _> = deserialize(&block2);
assert!(decode2.is_ok());
let real_decode2 = decode2.unwrap();
assert_eq!(real_decode2.header.version, Version(-2147483648));
}
#[test]
fn validate_pow_test() {
let some_header = hex!("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b");
let some_header: Header =
deserialize(&some_header).expect("Can't deserialize correct block header");
assert_eq!(
some_header.validate_pow(some_header.target()).unwrap(),
some_header.block_hash()
);
match some_header.validate_pow(Target::ZERO) {
Err(ValidationError::BadTarget) => (),
_ => panic!("unexpected result from validate_pow"),
}
let mut invalid_header: Header = some_header;
invalid_header.version.0 += 1;
match invalid_header.validate_pow(invalid_header.target()) {
Err(ValidationError::BadProofOfWork) => (),
_ => panic!("unexpected result from validate_pow"),
}
}
#[test]
fn compact_roundrtip_test() {
let some_header = hex!("010000004ddccd549d28f385ab457e98d1b11ce80bfea2c5ab93015ade4973e400000000bf4473e53794beae34e64fccc471dace6ae544180816f89591894e0f417a914cd74d6e49ffff001d323b3a7b");
let header: Header =
deserialize(&some_header).expect("Can't deserialize correct block header");
assert_eq!(header.bits, header.target().to_compact_lossy());
}
#[test]
fn soft_fork_signalling() {
for i in 0..31 {
let version_int = (0x20000000u32 ^ 1 << i) as i32;
let version = Version(version_int);
if i < 29 {
assert!(version.is_signalling_soft_fork(i));
} else {
assert!(!version.is_signalling_soft_fork(i));
}
}
let segwit_signal = Version(0x20000000 ^ 1 << 1);
assert!(!segwit_signal.is_signalling_soft_fork(0));
assert!(segwit_signal.is_signalling_soft_fork(1));
assert!(!segwit_signal.is_signalling_soft_fork(2));
}
}
#[cfg(bench)]
mod benches {
use io::sink;
use test::{black_box, Bencher};
use super::Block;
use crate::consensus::{deserialize, Decodable, Encodable};
#[bench]
pub fn bench_stream_reader(bh: &mut Bencher) {
let big_block = include_bytes!("../../tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw");
assert_eq!(big_block.len(), 1_381_836);
let big_block = black_box(big_block);
bh.iter(|| {
let mut reader = &big_block[..];
let block = Block::consensus_decode(&mut reader).unwrap();
black_box(&block);
});
}
#[bench]
pub fn bench_block_serialize(bh: &mut Bencher) {
let raw_block = include_bytes!("../../tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw");
let block: Block = deserialize(&raw_block[..]).unwrap();
let mut data = Vec::with_capacity(raw_block.len());
bh.iter(|| {
let result = block.consensus_encode(&mut data);
black_box(&result);
data.clear();
});
}
#[bench]
pub fn bench_block_serialize_logic(bh: &mut Bencher) {
let raw_block = include_bytes!("../../tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw");
let block: Block = deserialize(&raw_block[..]).unwrap();
bh.iter(|| {
let size = block.consensus_encode(&mut sink());
black_box(&size);
});
}
#[bench]
pub fn bench_block_deserialize(bh: &mut Bencher) {
let raw_block = include_bytes!("../../tests/data/mainnet_block_000000000000000000000c835b2adcaedc20fdf6ee440009c249452c726dafae.raw");
bh.iter(|| {
let block: Block = deserialize(&raw_block[..]).unwrap();
black_box(&block);
});
}
}