From 7b4794db06525d254bf6cff1c1dbb8e4e46eb3c5 Mon Sep 17 00:00:00 2001 From: Jeff Bencin Date: Wed, 3 Apr 2024 23:35:48 -0400 Subject: [PATCH] chore: Remove `DeserializeWithEpoch` trait --- libsigner/src/messages.rs | 8 +- stacks-common/src/codec/mod.rs | 69 ----- stackslib/src/blockstack_cli.rs | 16 +- stackslib/src/chainstate/nakamoto/mod.rs | 15 +- .../src/chainstate/nakamoto/staging_blocks.rs | 14 +- .../src/chainstate/nakamoto/tests/mod.rs | 7 +- stackslib/src/chainstate/stacks/block.rs | 103 +------ stackslib/src/chainstate/stacks/db/blocks.rs | 39 +-- .../src/chainstate/stacks/transaction.rs | 40 +-- stackslib/src/core/mempool.rs | 27 +- stackslib/src/main.rs | 39 +-- stackslib/src/net/api/getblock.rs | 9 +- stackslib/src/net/api/getblock_v3.rs | 7 +- stackslib/src/net/api/gettenure.rs | 5 +- stackslib/src/net/api/postblock.rs | 21 +- stackslib/src/net/api/posttransaction.rs | 29 +- stackslib/src/net/api/tests/getblock.rs | 13 +- stackslib/src/net/api/tests/getblock_v3.rs | 8 +- stackslib/src/net/api/tests/gettenure.rs | 5 +- stackslib/src/net/codec.rs | 58 +--- testnet/stacks-node/src/node.rs | 2 +- testnet/stacks-node/src/tests/epoch_205.rs | 19 +- testnet/stacks-node/src/tests/epoch_21.rs | 41 +-- testnet/stacks-node/src/tests/epoch_22.rs | 15 +- testnet/stacks-node/src/tests/epoch_23.rs | 8 +- testnet/stacks-node/src/tests/epoch_24.rs | 8 +- testnet/stacks-node/src/tests/integrations.rs | 47 +-- testnet/stacks-node/src/tests/mempool.rs | 184 ++++-------- testnet/stacks-node/src/tests/mod.rs | 6 +- .../src/tests/neon_integrations.rs | 277 +++++------------- 30 files changed, 254 insertions(+), 885 deletions(-) diff --git a/libsigner/src/messages.rs b/libsigner/src/messages.rs index 86752135e5..6f644b9ef6 100644 --- a/libsigner/src/messages.rs +++ b/libsigner/src/messages.rs @@ -43,8 +43,8 @@ use clarity::vm::types::QualifiedContractIdentifier; use hashbrown::{HashMap, HashSet}; use serde::{Deserialize, Serialize}; use stacks_common::codec::{ - read_next, read_next_at_most, read_next_at_most_with_epoch, read_next_exact, write_next, - Error as CodecError, StacksMessageCodec, MAX_MESSAGE_LEN, + read_next, read_next_at_most, read_next_exact, write_next, Error as CodecError, + StacksMessageCodec, MAX_MESSAGE_LEN, }; use stacks_common::types::StacksEpochId; use stacks_common::util::hash::Sha512Trunc256Sum; @@ -366,7 +366,7 @@ impl StacksMessageCodec for SignerMessage { // I don't think these messages are stored on the blockchain, so `StacksEpochId::latest()` should be fine let transactions: Vec = { let mut bound_read = BoundReader::from_reader(fd, MAX_MESSAGE_LEN as u64); - read_next_at_most_with_epoch(&mut bound_read, u32::MAX, StacksEpochId::latest()) + read_next_at_most(&mut bound_read, u32::MAX) }?; SignerMessage::Transactions(transactions) } @@ -1224,7 +1224,7 @@ impl StacksMessageCodec for RejectCode { // I don't think these messages are stored on the blockchain, so `StacksEpochId::latest()` should be fine let transactions: Vec = { let mut bound_read = BoundReader::from_reader(fd, MAX_MESSAGE_LEN as u64); - read_next_at_most_with_epoch(&mut bound_read, u32::MAX, StacksEpochId::latest()) + read_next_at_most(&mut bound_read, u32::MAX) }?; RejectCode::MissingTransactions(transactions) } diff --git a/stacks-common/src/codec/mod.rs b/stacks-common/src/codec/mod.rs index 1cf30146f1..aa09348b0f 100644 --- a/stacks-common/src/codec/mod.rs +++ b/stacks-common/src/codec/mod.rs @@ -87,15 +87,6 @@ pub trait StacksMessageCodec { } } -pub trait DeserializeWithEpoch { - fn consensus_deserialize_with_epoch( - fd: &mut R, - epoch_id: StacksEpochId, - ) -> Result - where - Self: Sized; -} - // impl_byte_array_message_codec!(MARFValue, 40); impl_byte_array_message_codec!(SortitionId, 32); @@ -193,66 +184,6 @@ pub fn read_next_exact( read_next_vec::(fd, num_items, 0) } -pub fn read_next_with_epoch( - fd: &mut R, - epoch_id: StacksEpochId, -) -> Result { - let item: T = T::consensus_deserialize_with_epoch(fd, epoch_id)?; - Ok(item) -} - -fn read_next_vec_with_epoch( - fd: &mut R, - num_items: u32, - max_items: u32, - epoch_id: StacksEpochId, -) -> Result, Error> { - let len = u32::consensus_deserialize(fd)?; - - if max_items > 0 { - if len > max_items { - // too many items - return Err(Error::DeserializeError(format!( - "Array has too many items ({} > {}", - len, max_items - ))); - } - } else { - if len != num_items { - // inexact item count - return Err(Error::DeserializeError(format!( - "Array has incorrect number of items ({} != {})", - len, num_items - ))); - } - } - - if (mem::size_of::() as u128) * (len as u128) > MAX_MESSAGE_LEN as u128 { - return Err(Error::DeserializeError(format!( - "Message occupies too many bytes (tried to allocate {}*{}={})", - mem::size_of::() as u128, - len, - (mem::size_of::() as u128) * (len as u128) - ))); - } - - let mut ret = Vec::with_capacity(len as usize); - for _i in 0..len { - let next_item = T::consensus_deserialize_with_epoch(fd, epoch_id)?; - ret.push(next_item); - } - - Ok(ret) -} - -pub fn read_next_at_most_with_epoch( - fd: &mut R, - max_items: u32, - epoch_id: StacksEpochId, -) -> Result, Error> { - read_next_vec_with_epoch::(fd, 0, max_items, epoch_id) -} - impl StacksMessageCodec for Vec where T: StacksMessageCodec + Sized, diff --git a/stackslib/src/blockstack_cli.rs b/stackslib/src/blockstack_cli.rs index 2df300a90c..a4f679ac6a 100644 --- a/stackslib/src/blockstack_cli.rs +++ b/stackslib/src/blockstack_cli.rs @@ -46,7 +46,7 @@ use clarity::vm::errors::{Error as ClarityError, RuntimeErrorType}; use clarity::vm::types::PrincipalData; use clarity::vm::{ClarityName, ClarityVersion, ContractName, Value}; use stacks_common::address::{b58, AddressHashMode}; -use stacks_common::codec::{DeserializeWithEpoch, Error as CodecError, StacksMessageCodec}; +use stacks_common::codec::{Error as CodecError, StacksMessageCodec}; use stacks_common::types::chainstate::StacksAddress; use stacks_common::types::StacksEpochId; use stacks_common::util::hash::{hex_bytes, to_hex}; @@ -315,10 +315,8 @@ fn sign_transaction_single_sig_standard( transaction: &str, secret_key: &StacksPrivateKey, ) -> Result { - let transaction = StacksTransaction::consensus_deserialize_with_epoch( - &mut io::Cursor::new(&hex_bytes(transaction)?), - StacksEpochId::latest(), - )?; + let transaction = + StacksTransaction::consensus_deserialize(&mut io::Cursor::new(&hex_bytes(transaction)?))?; let mut tx_signer = StacksTransactionSigner::new(&transaction); tx_signer.sign_origin(secret_key)?; @@ -665,10 +663,7 @@ fn decode_transaction(args: &[String], _version: TransactionVersion) -> Result Ok(serde_json::to_string(&tx).expect("Failed to serialize transaction to JSON")), Err(e) => { let mut ret = String::new(); @@ -744,8 +739,7 @@ fn decode_block(args: &[String], _version: TransactionVersion) -> Result Ok(serde_json::to_string(&block).expect("Failed to serialize block to JSON")), Err(e) => { let mut ret = String::new(); diff --git a/stackslib/src/chainstate/nakamoto/mod.rs b/stackslib/src/chainstate/nakamoto/mod.rs index 82905d3265..5d5010ca1c 100644 --- a/stackslib/src/chainstate/nakamoto/mod.rs +++ b/stackslib/src/chainstate/nakamoto/mod.rs @@ -32,8 +32,8 @@ use rusqlite::{params, Connection, OpenFlags, OptionalExtension, ToSql, NO_PARAM use sha2::{Digest as Sha2Digest, Sha512_256}; use stacks_common::bitvec::BitVec; use stacks_common::codec::{ - read_next, read_next_at_most_with_epoch, write_next, DeserializeWithEpoch, Error as CodecError, - StacksMessageCodec, MAX_MESSAGE_LEN, MAX_PAYLOAD_LEN, + read_next, read_next_at_most, write_next, Error as CodecError, StacksMessageCodec, + MAX_MESSAGE_LEN, MAX_PAYLOAD_LEN, }; use stacks_common::consts::{ FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, MINER_REWARD_MATURITY, @@ -3351,21 +3351,12 @@ impl StacksMessageCodec for NakamotoBlock { } fn consensus_deserialize(fd: &mut R) -> Result { - panic!("NakamotoBlock should be deserialized with consensus_deserialize_with_epoch instead") - } -} - -impl DeserializeWithEpoch for NakamotoBlock { - fn consensus_deserialize_with_epoch( - fd: &mut R, - epoch_id: StacksEpochId, - ) -> Result { let header: NakamotoBlockHeader = read_next(fd)?; let txs: Vec = { let mut bound_read = BoundReader::from_reader(fd, u64::from(MAX_MESSAGE_LEN)); // The latest epoch where StacksMicroblock exist is Epoch25 - read_next_at_most_with_epoch(&mut bound_read, u32::MAX, epoch_id) + read_next_at_most(&mut bound_read, u32::MAX) }?; // all transactions are unique diff --git a/stackslib/src/chainstate/nakamoto/staging_blocks.rs b/stackslib/src/chainstate/nakamoto/staging_blocks.rs index 6f11d73694..3e637af21f 100644 --- a/stackslib/src/chainstate/nakamoto/staging_blocks.rs +++ b/stackslib/src/chainstate/nakamoto/staging_blocks.rs @@ -31,7 +31,7 @@ use crate::chainstate::nakamoto::{NakamotoBlock, NakamotoChainState}; use crate::chainstate::stacks::db::StacksChainState; use crate::chainstate::stacks::index::marf::MarfConnection; use crate::chainstate::stacks::{Error as ChainstateError, StacksBlock, StacksBlockHeader}; -use crate::stacks_common::codec::{DeserializeWithEpoch, StacksMessageCodec}; +use crate::stacks_common::codec::StacksMessageCodec; use crate::stacks_common::types::StacksEpochId; use crate::util_lib::db::{ query_int, query_row, query_row_panic, query_rows, sqlite_open, tx_begin_immediate, u64_to_sql, @@ -218,10 +218,7 @@ impl<'a> NakamotoStagingBlocksConnRef<'a> { let Some(block_bytes) = data else { return Ok(None); }; - let block = NakamotoBlock::consensus_deserialize_with_epoch( - &mut block_bytes.as_slice(), - StacksEpochId::latest(), - )?; + let block = NakamotoBlock::consensus_deserialize(&mut block_bytes.as_slice())?; if &block.header.consensus_hash != consensus_hash { error!( "Staging DB corruption: expected {}, got {}", @@ -258,10 +255,7 @@ impl<'a> NakamotoStagingBlocksConnRef<'a> { let Some(block_bytes) = res else { return Ok(None); }; - let block = NakamotoBlock::consensus_deserialize_with_epoch( - &mut block_bytes.as_slice(), - StacksEpochId::latest(), - )?; + let block = NakamotoBlock::consensus_deserialize(&mut block_bytes.as_slice())?; if &block.header.block_id() != index_block_hash { error!( "Staging DB corruption: expected {}, got {}", @@ -311,7 +305,7 @@ impl<'a> NakamotoStagingBlocksConnRef<'a> { self .query_row_and_then(query, NO_PARAMS, |row| { let data: Vec = row.get("data")?; - let block = NakamotoBlock::consensus_deserialize_with_epoch(&mut data.as_slice(), StacksEpochId::latest())?; + let block = NakamotoBlock::consensus_deserialize(&mut data.as_slice())?; Ok(Some(( block, u64::try_from(data.len()).expect("FATAL: block is bigger than a u64"), diff --git a/stackslib/src/chainstate/nakamoto/tests/mod.rs b/stackslib/src/chainstate/nakamoto/tests/mod.rs index acc8965c85..9844fa7b74 100644 --- a/stackslib/src/chainstate/nakamoto/tests/mod.rs +++ b/stackslib/src/chainstate/nakamoto/tests/mod.rs @@ -27,7 +27,7 @@ use rand::{thread_rng, RngCore}; use rusqlite::{Connection, ToSql}; use stacks_common::address::AddressHashMode; use stacks_common::bitvec::BitVec; -use stacks_common::codec::{DeserializeWithEpoch, StacksMessageCodec}; +use stacks_common::codec::StacksMessageCodec; use stacks_common::consts::{ CHAIN_ID_MAINNET, CHAIN_ID_TESTNET, FIRST_BURNCHAIN_CONSENSUS_HASH, FIRST_STACKS_BLOCK_HASH, }; @@ -101,10 +101,7 @@ impl<'a> NakamotoStagingBlocksConnRef<'a> { let block_data: Vec> = query_rows(self, qry, args)?; let mut blocks = Vec::with_capacity(block_data.len()); for data in block_data.into_iter() { - let block = NakamotoBlock::consensus_deserialize_with_epoch( - &mut data.as_slice(), - StacksEpochId::latest(), - )?; + let block = NakamotoBlock::consensus_deserialize(&mut data.as_slice())?; blocks.push(block); } Ok(blocks) diff --git a/stackslib/src/chainstate/stacks/block.rs b/stackslib/src/chainstate/stacks/block.rs index 911ab07b6d..674dbc66d6 100644 --- a/stackslib/src/chainstate/stacks/block.rs +++ b/stackslib/src/chainstate/stacks/block.rs @@ -21,8 +21,8 @@ use std::io::{Read, Write}; use sha2::{Digest, Sha512_256}; use stacks_common::codec::{ - read_next, read_next_at_most_with_epoch, write_next, DeserializeWithEpoch, - Error as codec_error, StacksMessageCodec, MAX_MESSAGE_LEN, + read_next, read_next_at_most, write_next, Error as codec_error, StacksMessageCodec, + MAX_MESSAGE_LEN, }; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, StacksBlockId, StacksWorkScore, TrieHash, VRFSeed, @@ -312,22 +312,13 @@ impl StacksMessageCodec for StacksBlock { Ok(()) } - fn consensus_deserialize(_fd: &mut R) -> Result { - panic!("StacksBlock should be deserialized with consensus_deserialize_with_epoch instead") - } -} - -impl DeserializeWithEpoch for StacksBlock { - fn consensus_deserialize_with_epoch( - fd: &mut R, - epoch_id: StacksEpochId, - ) -> Result { + fn consensus_deserialize(fd: &mut R) -> Result { // NOTE: don't worry about size clamps here; do that when receiving the data from the peer // network. This code assumes that the block will be small enough. let header: StacksBlockHeader = read_next(fd)?; let txs: Vec = { let mut bound_read = BoundReader::from_reader(fd, MAX_MESSAGE_LEN as u64); - read_next_at_most_with_epoch(&mut bound_read, u32::MAX, epoch_id) + read_next_at_most(&mut bound_read, u32::MAX) }?; // there must be at least one transaction (the coinbase) @@ -859,65 +850,7 @@ impl StacksMessageCodec for StacksMicroblock { let txs: Vec = { let mut bound_read = BoundReader::from_reader(fd, MAX_MESSAGE_LEN as u64); // The latest epoch where StacksMicroblock exist is Epoch25 - read_next_at_most_with_epoch(&mut bound_read, u32::MAX, StacksEpochId::Epoch25) - }?; - - if txs.len() == 0 { - warn!("Invalid microblock: zero transactions"); - return Err(codec_error::DeserializeError( - "Invalid microblock: zero transactions".to_string(), - )); - } - - if !StacksBlock::validate_transactions_unique(&txs) { - warn!("Invalid microblock: duplicate transaction"); - return Err(codec_error::DeserializeError( - "Invalid microblock: duplicate transaction".to_string(), - )); - } - - if !StacksBlock::validate_anchor_mode(&txs, false) { - warn!("Invalid microblock: found on-chain-only transaction"); - return Err(codec_error::DeserializeError( - "Invalid microblock: found on-chain-only transaction".to_string(), - )); - } - - // header and transactions must be consistent - let txid_vecs = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); - - let merkle_tree = MerkleTree::::new(&txid_vecs); - let tx_merkle_root = merkle_tree.root(); - - if tx_merkle_root != header.tx_merkle_root { - return Err(codec_error::DeserializeError( - "Invalid microblock: tx Merkle root mismatch".to_string(), - )); - } - - if !StacksBlock::validate_coinbase(&txs, false) { - warn!("Invalid microblock: found coinbase transaction"); - return Err(codec_error::DeserializeError( - "Invalid microblock: found coinbase transaction".to_string(), - )); - } - - Ok(StacksMicroblock { header, txs }) - } -} - -// This implementation is used for testing purposes, StacksMicroblock won't be used in Epoch 3.0 -impl DeserializeWithEpoch for StacksMicroblock { - fn consensus_deserialize_with_epoch( - fd: &mut R, - epoch_id: StacksEpochId, - ) -> Result { - // NOTE: maximum size must be checked elsewhere! - let header: StacksMicroblockHeader = read_next(fd)?; - let txs: Vec = { - let mut bound_read = BoundReader::from_reader(fd, MAX_MESSAGE_LEN as u64); - // The latest epoch where StacksMicroblock exist is Epoch24 - read_next_at_most_with_epoch(&mut bound_read, u32::MAX, epoch_id) + read_next_at_most(&mut bound_read, u32::MAX) }?; if txs.len() == 0 { @@ -1227,11 +1160,7 @@ mod test { block_bytes.len(), block.txs.len() ); - check_codec_and_corruption_with_epoch::( - &block, - &block_bytes, - StacksEpochId::latest(), - ); + check_codec_and_corruption::(&block, &block_bytes); } #[test] @@ -1314,11 +1243,7 @@ mod test { txs: txs, }; - check_codec_and_corruption_with_epoch::( - &mblock, - &block_bytes, - StacksEpochId::latest(), - ); + check_codec_and_corruption::(&mblock, &block_bytes); } } @@ -1910,25 +1835,19 @@ mod test { let mut bytes: Vec = vec![]; tx.consensus_serialize(&mut bytes).unwrap(); - StacksTransaction::consensus_deserialize_with_epoch(&mut &bytes[..], *epoch_id) - .unwrap(); + StacksTransaction::consensus_deserialize(&mut &bytes[..]).unwrap(); } - StacksBlock::consensus_deserialize_with_epoch(&mut &bytes[..], *epoch_id).unwrap(); + StacksBlock::consensus_deserialize(&mut &bytes[..]).unwrap(); } else { for tx in txs.iter() { let mut bytes: Vec = vec![]; tx.consensus_serialize(&mut bytes).unwrap(); - let _ = StacksTransaction::consensus_deserialize_with_epoch( - &mut &bytes[..], - *epoch_id, - ) - .unwrap_err(); + let _ = StacksTransaction::consensus_deserialize(&mut &bytes[..]).unwrap_err(); } - let _ = StacksBlock::consensus_deserialize_with_epoch(&mut &bytes[..], *epoch_id) - .unwrap_err(); + let _ = StacksBlock::consensus_deserialize(&mut &bytes[..]).unwrap_err(); assert!(!StacksBlock::validate_transactions_static_epoch( &txs, *epoch_id, false, diff --git a/stackslib/src/chainstate/stacks/db/blocks.rs b/stackslib/src/chainstate/stacks/db/blocks.rs index 1f6ac10e69..31680023bd 100644 --- a/stackslib/src/chainstate/stacks/db/blocks.rs +++ b/stackslib/src/chainstate/stacks/db/blocks.rs @@ -38,7 +38,7 @@ use rusqlite::{Connection, DatabaseName, Error as sqlite_error, OptionalExtensio use serde::Serialize; use serde_json::json; use stacks_common::bitvec::BitVec; -use stacks_common::codec::{read_next, write_next, DeserializeWithEpoch, MAX_MESSAGE_LEN}; +use stacks_common::codec::{read_next, write_next, MAX_MESSAGE_LEN}; use stacks_common::types::chainstate::{ BurnchainHeaderHash, SortitionId, StacksAddress, StacksBlockId, }; @@ -560,28 +560,6 @@ impl StacksChainState { Ok(inst) } - pub fn consensus_load_with_epoch( - path: &str, - epoch_id: StacksEpochId, - ) -> Result { - let mut fd = fs::OpenOptions::new() - .read(true) - .write(false) - .open(path) - .map_err(|e| { - if e.kind() == io::ErrorKind::NotFound { - Error::DBError(db_error::NotFoundError) - } else { - Error::DBError(db_error::IOError(e)) - } - })?; - - let mut bound_reader = BoundReader::from_reader(&mut fd, MAX_MESSAGE_LEN as u64); - let inst = T::consensus_deserialize_with_epoch(&mut bound_reader, epoch_id) - .map_err(Error::CodecError)?; - Ok(inst) - } - /// Do we have a stored a block in the chunk store? /// Will be true even if it's invalid. pub fn has_block_indexed( @@ -871,8 +849,7 @@ impl StacksChainState { return Ok(None); } - let block: StacksBlock = - StacksChainState::consensus_load_with_epoch(&block_path, epoch_id)?; + let block: StacksBlock = StacksChainState::consensus_load(&block_path)?; Ok(Some(block)) } @@ -1077,10 +1054,7 @@ impl StacksChainState { return Ok(None); } - match StacksBlock::consensus_deserialize_with_epoch( - &mut &staging_block.block_data[..], - StacksEpochId::Epoch25, - ) { + match StacksBlock::consensus_deserialize(&mut &staging_block.block_data[..]) { Ok(block) => Ok(Some(block)), Err(e) => Err(Error::CodecError(e)), } @@ -6002,11 +5976,8 @@ impl StacksChainState { epoch_id: StacksEpochId, ) -> Result { let block = { - StacksBlock::consensus_deserialize_with_epoch( - &mut &next_staging_block.block_data[..], - epoch_id, - ) - .map_err(Error::CodecError)? + StacksBlock::consensus_deserialize(&mut &next_staging_block.block_data[..]) + .map_err(Error::CodecError)? }; let block_hash = block.block_hash(); diff --git a/stackslib/src/chainstate/stacks/transaction.rs b/stackslib/src/chainstate/stacks/transaction.rs index 9d94addf42..e904ded73a 100644 --- a/stackslib/src/chainstate/stacks/transaction.rs +++ b/stackslib/src/chainstate/stacks/transaction.rs @@ -22,9 +22,7 @@ use clarity::vm::representations::{ClarityName, ContractName}; use clarity::vm::types::serialization::SerializationError as clarity_serialization_error; use clarity::vm::types::{QualifiedContractIdentifier, StandardPrincipalData}; use clarity::vm::{ClarityVersion, SymbolicExpression, SymbolicExpressionType, Value}; -use stacks_common::codec::{ - read_next, write_next, DeserializeWithEpoch, Error as codec_error, StacksMessageCodec, -}; +use stacks_common::codec::{read_next, write_next, Error as codec_error, StacksMessageCodec}; use stacks_common::types::chainstate::StacksAddress; use stacks_common::types::StacksPublicKeyBuffer; use stacks_common::util::hash::{to_hex, MerkleHashFunc, MerkleTree, Sha512Trunc256Sum}; @@ -613,7 +611,6 @@ impl StacksTransaction { pub fn consensus_deserialize_with_len( fd: &mut R, - epoch_id: StacksEpochId, ) -> Result<(StacksTransaction, u64), codec_error> { let mut bound_read = BoundReader::from_reader(fd, MAX_TRANSACTION_LEN.into()); let fd = &mut bound_read; @@ -699,13 +696,6 @@ impl StacksTransaction { payload, }; - if !StacksBlock::validate_transactions_static_epoch(&[tx.clone()], epoch_id, false) { - warn!("Invalid tx: target epoch is not activated"); - return Err(codec_error::DeserializeError( - "Failed to parse transaction: target epoch is not activated".to_string(), - )); - } - Ok((tx, fd.num_read())) } @@ -742,17 +732,8 @@ impl StacksMessageCodec for StacksTransaction { Ok(()) } - fn consensus_deserialize(_fd: &mut R) -> Result { - panic!("StacksTransaction should be deserialized with consensus_deserialize_with_epoch instead") - } -} - -impl DeserializeWithEpoch for StacksTransaction { - fn consensus_deserialize_with_epoch( - fd: &mut R, - epoch_id: StacksEpochId, - ) -> Result { - StacksTransaction::consensus_deserialize_with_len(fd, epoch_id).map(|(result, _)| result) + fn consensus_deserialize(fd: &mut R) -> Result { + StacksTransaction::consensus_deserialize_with_len(fd).map(|(result, _)| result) } } @@ -1360,9 +1341,7 @@ mod test { StacksPublicKey as PubKey, C32_ADDRESS_VERSION_MAINNET_MULTISIG, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, *, *, }; - use crate::net::codec::test::{ - check_codec_and_corruption, check_codec_and_corruption_with_epoch, - }; + use crate::net::codec::test::check_codec_and_corruption; use crate::net::codec::*; use crate::net::*; @@ -1974,10 +1953,7 @@ mod test { // test_debug!("mutate byte {}", &i); let mut cursor = io::Cursor::new(&tx_bytes); let mut reader = LogReader::from_reader(&mut cursor); - match StacksTransaction::consensus_deserialize_with_epoch( - &mut reader, - StacksEpochId::latest(), - ) { + match StacksTransaction::consensus_deserialize(&mut reader) { Ok(corrupt_tx) => { let mut corrupt_tx_bytes = vec![]; corrupt_tx @@ -3907,11 +3883,7 @@ mod test { test_debug!("---------"); test_debug!("text tx bytes:\n{}", &to_hex(&tx_bytes)); - check_codec_and_corruption_with_epoch::( - &tx, - &tx_bytes, - StacksEpochId::latest(), - ); + check_codec_and_corruption::(&tx, &tx_bytes); } } diff --git a/stackslib/src/core/mempool.rs b/stackslib/src/core/mempool.rs index 312623ac1c..4987786d85 100644 --- a/stackslib/src/core/mempool.rs +++ b/stackslib/src/core/mempool.rs @@ -34,8 +34,7 @@ use rusqlite::{ }; use siphasher::sip::SipHasher; // this is SipHash-2-4 use stacks_common::codec::{ - read_next, read_next_with_epoch, write_next, DeserializeWithEpoch, Error as codec_error, - StacksMessageCodec, MAX_MESSAGE_LEN, + read_next, write_next, Error as codec_error, StacksMessageCodec, MAX_MESSAGE_LEN, }; use stacks_common::types::chainstate::{BlockHeaderHash, StacksAddress, StacksBlockId}; use stacks_common::util::hash::{to_hex, Sha512Trunc256Sum}; @@ -237,8 +236,7 @@ pub fn decode_tx_stream_with_epoch( loop { let pos = retry_reader.position(); - let next_msg: Result = - read_next_with_epoch(&mut retry_reader, epoch_id); + let next_msg: Result = read_next(&mut retry_reader); match next_msg { Ok(tx) => { if expect_eof { @@ -598,11 +596,8 @@ impl FromRow for MemPoolTxInfo { fn from_row<'a>(row: &'a Row) -> Result { let md = MemPoolTxMetadata::from_row(row)?; let tx_bytes: Vec = row.get_unwrap("tx"); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .map_err(|_e| db_error::ParseError)?; + let tx = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]) + .map_err(|_e| db_error::ParseError)?; if tx.txid() != md.txid { return Err(db_error::ParseError); @@ -2461,11 +2456,8 @@ impl MemPoolDB { block_limit: &ExecutionCost, stacks_epoch_id: &StacksEpochId, ) -> Result<(), MemPoolRejection> { - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .map_err(MemPoolRejection::DeserializationFailure)?; + let tx = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]) + .map_err(MemPoolRejection::DeserializationFailure)?; if self.is_tx_blacklisted(&tx.txid())? { // don't re-store this transaction @@ -2829,11 +2821,8 @@ impl MemPoolDB { } let tx_bytes: Vec = row.get_unwrap("tx"); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .map_err(|_e| db_error::ParseError)?; + let tx = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]) + .map_err(|_e| db_error::ParseError)?; test_debug!("Returning txid {}", &txid); ret.push(tx); diff --git a/stackslib/src/main.rs b/stackslib/src/main.rs index 7aebe72ea0..e7f9ee9d84 100644 --- a/stackslib/src/main.rs +++ b/stackslib/src/main.rs @@ -76,7 +76,7 @@ use libstackerdb::StackerDBChunkData; use rusqlite::types::ToSql; use rusqlite::{Connection, OpenFlags}; use serde_json::{json, Value}; -use stacks_common::codec::{read_next, DeserializeWithEpoch, StacksMessageCodec}; +use stacks_common::codec::{read_next, StacksMessageCodec}; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, PoxId, StacksAddress, StacksBlockId, }; @@ -197,7 +197,7 @@ fn main() { let mut debug_cursor = LogReader::from_reader(&mut cursor); let epoch_id = parse_input_epoch(3); - let tx = StacksTransaction::consensus_deserialize_with_epoch(&mut debug_cursor, epoch_id) + let tx = StacksTransaction::consensus_deserialize(&mut debug_cursor) .map_err(|e| { eprintln!("Failed to decode transaction: {:?}", &e); eprintln!("Bytes consumed:"); @@ -226,15 +226,12 @@ fn main() { fs::read(block_path).unwrap_or_else(|_| panic!("Failed to open {block_path}")); let epoch_id = parse_input_epoch(3); - let block = StacksBlock::consensus_deserialize_with_epoch( - &mut io::Cursor::new(&block_data), - epoch_id, - ) - .map_err(|_e| { - eprintln!("Failed to decode block"); - process::exit(1); - }) - .unwrap(); + let block = StacksBlock::consensus_deserialize(&mut io::Cursor::new(&block_data)) + .map_err(|_e| { + eprintln!("Failed to decode block"); + process::exit(1); + }) + .unwrap(); println!("{:#?}", &block); process::exit(0); @@ -300,15 +297,13 @@ fn main() { let epoch_id = parse_input_epoch(4); - let block = StacksBlock::consensus_deserialize_with_epoch( - &mut io::Cursor::new(&block_info.block_data), - epoch_id, - ) - .map_err(|_e| { - eprintln!("Failed to decode block"); - process::exit(1); - }) - .unwrap(); + let block = + StacksBlock::consensus_deserialize(&mut io::Cursor::new(&block_info.block_data)) + .map_err(|_e| { + eprintln!("Failed to decode block"); + process::exit(1); + }) + .unwrap(); let microblocks = StacksChainState::find_parent_microblock_stream(chainstate.db(), &block_info) @@ -1460,9 +1455,7 @@ simulating a miner. let raw_tx_hex = item.as_str().unwrap(); let raw_tx_bytes = hex_bytes(&raw_tx_hex[2..]).unwrap(); let mut cursor = io::Cursor::new(&raw_tx_bytes); - let raw_tx = - StacksTransaction::consensus_deserialize_with_epoch(&mut cursor, epoch_id) - .unwrap(); + let raw_tx = StacksTransaction::consensus_deserialize(&mut cursor).unwrap(); if found_block_height { if submit_tx_count >= mine_max_txns { info!("Reached mine_max_txns {}", submit_tx_count); diff --git a/stackslib/src/net/api/getblock.rs b/stackslib/src/net/api/getblock.rs index 287c0563bf..406cd67bc3 100644 --- a/stackslib/src/net/api/getblock.rs +++ b/stackslib/src/net/api/getblock.rs @@ -20,7 +20,7 @@ use std::{fs, io}; use regex::{Captures, Regex}; use serde::de::Error as de_Error; -use stacks_common::codec::{DeserializeWithEpoch, StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; use stacks_common::types::chainstate::StacksBlockId; use stacks_common::types::net::PeerHost; use stacks_common::types::StacksEpochId; @@ -303,10 +303,7 @@ impl StacksHttpResponse { // contents will be raw bytes let block_bytes: Vec = contents.try_into()?; - let block = StacksBlock::consensus_deserialize_with_epoch( - &mut &block_bytes[..], - StacksEpochId::Epoch25, - )?; + let block = StacksBlock::consensus_deserialize(&mut &block_bytes[..])?; Ok(block) } @@ -318,7 +315,7 @@ impl StacksHttpResponse { // contents will be raw bytes let block_bytes: Vec = contents.try_into()?; - let block = StacksBlock::consensus_deserialize_with_epoch(&mut &block_bytes[..], epoch_id)?; + let block = StacksBlock::consensus_deserialize(&mut &block_bytes[..])?; Ok(block) } diff --git a/stackslib/src/net/api/getblock_v3.rs b/stackslib/src/net/api/getblock_v3.rs index ab359f8ecb..344aa6d746 100644 --- a/stackslib/src/net/api/getblock_v3.rs +++ b/stackslib/src/net/api/getblock_v3.rs @@ -20,7 +20,7 @@ use std::{fs, io}; use regex::{Captures, Regex}; use rusqlite::Connection; use serde::de::Error as de_Error; -use stacks_common::codec::{DeserializeWithEpoch, StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; use stacks_common::types::chainstate::{ConsensusHash, StacksBlockId}; use stacks_common::types::net::PeerHost; use stacks_common::types::StacksEpochId; @@ -318,10 +318,7 @@ impl StacksHttpResponse { // contents will be raw bytes let block_bytes: Vec = contents.try_into()?; - let block = NakamotoBlock::consensus_deserialize_with_epoch( - &mut &block_bytes[..], - StacksEpochId::latest(), - )?; + let block = NakamotoBlock::consensus_deserialize(&mut &block_bytes[..])?; Ok(block) } diff --git a/stackslib/src/net/api/gettenure.rs b/stackslib/src/net/api/gettenure.rs index 17bd3b8a73..4bd1d362f5 100644 --- a/stackslib/src/net/api/gettenure.rs +++ b/stackslib/src/net/api/gettenure.rs @@ -19,7 +19,7 @@ use std::{fs, io}; use regex::{Captures, Regex}; use serde::de::Error as de_Error; -use stacks_common::codec::{DeserializeWithEpoch, StacksMessageCodec, MAX_MESSAGE_LEN}; +use stacks_common::codec::{StacksMessageCodec, MAX_MESSAGE_LEN}; use stacks_common::types::chainstate::{ConsensusHash, StacksBlockId}; use stacks_common::types::net::PeerHost; use stacks_common::types::StacksEpochId; @@ -356,8 +356,7 @@ impl StacksHttpResponse { let mut blocks = vec![]; while ptr.len() > 0 { - let block = - NakamotoBlock::consensus_deserialize_with_epoch(ptr, StacksEpochId::latest())?; + let block = NakamotoBlock::consensus_deserialize(ptr)?; blocks.push(block); } diff --git a/stackslib/src/net/api/postblock.rs b/stackslib/src/net/api/postblock.rs index 155c39ed4c..bf0b010879 100644 --- a/stackslib/src/net/api/postblock.rs +++ b/stackslib/src/net/api/postblock.rs @@ -18,7 +18,7 @@ use std::io::{Read, Write}; use clarity::vm::costs::ExecutionCost; use regex::{Captures, Regex}; -use stacks_common::codec::{DeserializeWithEpoch, Error as CodecError, MAX_PAYLOAD_LEN}; +use stacks_common::codec::{Error as CodecError, StacksMessageCodec, MAX_PAYLOAD_LEN}; use stacks_common::types::chainstate::{ BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; @@ -74,18 +74,13 @@ impl RPCPostBlockRequestHandler { /// Decode a bare block from the body fn parse_postblock_octets(mut body: &[u8]) -> Result { - let block = - StacksBlock::consensus_deserialize_with_epoch(&mut body, StacksEpochId::Epoch25) - .map_err(|e| { - if let CodecError::DeserializeError(msg) = e { - Error::DecodeError(format!( - "Failed to deserialize posted transaction: {}", - msg - )) - } else { - e.into() - } - })?; + let block = StacksBlock::consensus_deserialize(&mut body).map_err(|e| { + if let CodecError::DeserializeError(msg) = e { + Error::DecodeError(format!("Failed to deserialize posted transaction: {}", msg)) + } else { + e.into() + } + })?; Ok(block) } } diff --git a/stackslib/src/net/api/posttransaction.rs b/stackslib/src/net/api/posttransaction.rs index c68027b1ae..3e6cea3038 100644 --- a/stackslib/src/net/api/posttransaction.rs +++ b/stackslib/src/net/api/posttransaction.rs @@ -18,9 +18,7 @@ use std::io::{Read, Write}; use clarity::vm::costs::ExecutionCost; use regex::{Captures, Regex}; -use stacks_common::codec::{ - DeserializeWithEpoch, Error as CodecError, StacksMessageCodec, MAX_PAYLOAD_LEN, -}; +use stacks_common::codec::{Error as CodecError, StacksMessageCodec, MAX_PAYLOAD_LEN}; use stacks_common::types::chainstate::{ BlockHeaderHash, ConsensusHash, StacksBlockId, StacksPublicKey, }; @@ -70,18 +68,13 @@ impl RPCPostTransactionRequestHandler { /// Decode a bare transaction from the body fn parse_posttransaction_octets(mut body: &[u8]) -> Result { - let tx = - StacksTransaction::consensus_deserialize_with_epoch(&mut body, StacksEpochId::latest()) - .map_err(|e| { - if let CodecError::DeserializeError(msg) = e { - Error::DecodeError(format!( - "Failed to deserialize posted transaction: {}", - msg - )) - } else { - e.into() - } - })?; + let tx = StacksTransaction::consensus_deserialize(&mut body).map_err(|e| { + if let CodecError::DeserializeError(msg) = e { + Error::DecodeError(format!("Failed to deserialize posted transaction: {}", msg)) + } else { + e.into() + } + })?; Ok(tx) } @@ -95,11 +88,7 @@ impl RPCPostTransactionRequestHandler { let tx = { let tx_bytes = hex_bytes(&body.tx) .map_err(|_e| Error::DecodeError("Failed to parse tx".into()))?; - StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .map_err(|e| { + StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).map_err(|e| { if let CodecError::DeserializeError(msg) = e { Error::DecodeError(format!("Failed to deserialize posted transaction: {}", msg)) } else { diff --git a/stackslib/src/net/api/tests/getblock.rs b/stackslib/src/net/api/tests/getblock.rs index 9dce17b252..54eb79e7b5 100644 --- a/stackslib/src/net/api/tests/getblock.rs +++ b/stackslib/src/net/api/tests/getblock.rs @@ -18,7 +18,6 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; use clarity::vm::{ClarityName, ContractName}; -use stacks_common::codec::DeserializeWithEpoch; use stacks_common::types::chainstate::{ ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, }; @@ -161,11 +160,7 @@ fn test_stream_blocks() { } // should decode back into the block - let staging_block = StacksBlock::consensus_deserialize_with_epoch( - &mut &all_block_bytes[..], - StacksEpochId::Epoch25, - ) - .unwrap(); + let staging_block = StacksBlock::consensus_deserialize(&mut &all_block_bytes[..]).unwrap(); assert_eq!(staging_block, block); // accept it @@ -190,10 +185,6 @@ fn test_stream_blocks() { } // should decode back into the block - let staging_block = StacksBlock::consensus_deserialize_with_epoch( - &mut &all_block_bytes[..], - StacksEpochId::Epoch25, - ) - .unwrap(); + let staging_block = StacksBlock::consensus_deserialize(&mut &all_block_bytes[..]).unwrap(); assert_eq!(staging_block, block); } diff --git a/stackslib/src/net/api/tests/getblock_v3.rs b/stackslib/src/net/api/tests/getblock_v3.rs index b24a81f815..4bd22f65f1 100644 --- a/stackslib/src/net/api/tests/getblock_v3.rs +++ b/stackslib/src/net/api/tests/getblock_v3.rs @@ -18,7 +18,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; use clarity::vm::{ClarityName, ContractName}; -use stacks_common::codec::{DeserializeWithEpoch, StacksMessageCodec}; +use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::{ ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, }; @@ -183,10 +183,6 @@ fn test_stream_nakamoto_blocks() { all_block_bytes.append(&mut next_bytes); } - let staging_block = NakamotoBlock::consensus_deserialize_with_epoch( - &mut &all_block_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let staging_block = NakamotoBlock::consensus_deserialize(&mut &all_block_bytes[..]).unwrap(); assert_eq!(staging_block.header.block_id(), nakamoto_tip_block_id); } diff --git a/stackslib/src/net/api/tests/gettenure.rs b/stackslib/src/net/api/tests/gettenure.rs index 1b3a280510..c7dcd9f3ea 100644 --- a/stackslib/src/net/api/tests/gettenure.rs +++ b/stackslib/src/net/api/tests/gettenure.rs @@ -18,7 +18,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions}; use clarity::vm::{ClarityName, ContractName}; -use stacks_common::codec::{DeserializeWithEpoch, StacksMessageCodec}; +use stacks_common::codec::StacksMessageCodec; use stacks_common::types::chainstate::{ ConsensusHash, StacksAddress, StacksBlockId, StacksPrivateKey, }; @@ -192,8 +192,7 @@ fn test_stream_nakamoto_tenure() { let ptr = &mut all_block_bytes.as_slice(); let mut blocks = vec![]; while ptr.len() > 0 { - let block = - NakamotoBlock::consensus_deserialize_with_epoch(ptr, StacksEpochId::latest()).unwrap(); + let block = NakamotoBlock::consensus_deserialize(ptr).unwrap(); blocks.push(block); } diff --git a/stackslib/src/net/codec.rs b/stackslib/src/net/codec.rs index 802b355fb6..fa1c588695 100644 --- a/stackslib/src/net/codec.rs +++ b/stackslib/src/net/codec.rs @@ -1554,7 +1554,7 @@ impl ProtocolFamily for StacksP2P { #[cfg(test)] pub mod test { use stacks_common::bitvec::BitVec; - use stacks_common::codec::{DeserializeWithEpoch, NEIGHBOR_ADDRESS_ENCODED_SIZE}; + use stacks_common::codec::NEIGHBOR_ADDRESS_ENCODED_SIZE; use stacks_common::types::StacksEpochId; use stacks_common::util::hash::hex_bytes; use stacks_common::util::secp256k1::*; @@ -1668,62 +1668,6 @@ pub mod test { } } - pub fn check_codec_and_corruption_with_epoch< - T: StacksMessageCodec + fmt::Debug + Clone + PartialEq + DeserializeWithEpoch, - >( - obj: &T, - bytes: &Vec, - epoch_id: StacksEpochId, - ) -> () { - // obj should serialize to bytes - let mut write_buf: Vec = Vec::with_capacity(bytes.len()); - obj.consensus_serialize(&mut write_buf).unwrap(); - assert_eq!(write_buf, *bytes); - - // bytes should deserialize to obj - let read_buf: Vec = write_buf.clone(); - let res = T::consensus_deserialize_with_epoch(&mut &read_buf[..], epoch_id); - match res { - Ok(out) => { - assert_eq!(out, *obj); - } - Err(e) => { - test_debug!("\nFailed to parse to {:?}: {:?}", obj, bytes); - test_debug!("error: {:?}", &e); - assert!(false); - } - } - - // short message shouldn't parse, but should EOF - if write_buf.len() > 0 { - let mut short_buf = write_buf.clone(); - let short_len = short_buf.len() - 1; - short_buf.truncate(short_len); - - let underflow_res = T::consensus_deserialize_with_epoch(&mut &short_buf[..], epoch_id); - match underflow_res { - Ok(oops) => { - test_debug!( - "\nMissing Underflow: Parsed {:?}\nFrom {:?}\n", - &oops, - &write_buf[0..short_len].to_vec() - ); - } - Err(codec_error::ReadError(io_error)) => match io_error.kind() { - io::ErrorKind::UnexpectedEof => {} - _ => { - test_debug!("Got unexpected I/O error: {:?}", &io_error); - assert!(false); - } - }, - Err(e) => { - test_debug!("Got unexpected Net error: {:?}", &e); - assert!(false); - } - }; - } - } - #[test] fn codec_primitive_types() { check_codec_and_corruption::(&0x01, &vec![0x01]); diff --git a/testnet/stacks-node/src/node.rs b/testnet/stacks-node/src/node.rs index 118db772ec..77117a6822 100644 --- a/testnet/stacks-node/src/node.rs +++ b/testnet/stacks-node/src/node.rs @@ -921,7 +921,7 @@ impl Node { &metadata.anchored_header.block_hash(), ) .unwrap(); - StacksChainState::consensus_load_with_epoch(&block_path, stacks_epoch.epoch_id).unwrap() + StacksChainState::consensus_load(&block_path).unwrap() }; let chain_tip = ChainTip { diff --git a/testnet/stacks-node/src/tests/epoch_205.rs b/testnet/stacks-node/src/tests/epoch_205.rs index 252c2981f1..05bdcea419 100644 --- a/testnet/stacks-node/src/tests/epoch_205.rs +++ b/testnet/stacks-node/src/tests/epoch_205.rs @@ -18,7 +18,6 @@ use stacks::core::{ StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, }; -use stacks_common::codec::DeserializeWithEpoch; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, StacksAddress, VRFSeed, }; @@ -231,11 +230,7 @@ fn test_exact_block_costs() { .filter_map(|tx| { let raw_tx = tx.get("raw_tx").unwrap().as_str().unwrap(); let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::Epoch2_05, - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::ContractCall(ref cc) = &parsed.payload { if cc.function_name.as_str() == "db-get2" { Some(parsed) @@ -425,11 +420,7 @@ fn test_dynamic_db_method_costs() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::Epoch2_05, - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::ContractCall(ref cc) = parsed.payload { assert_eq!( @@ -1172,11 +1163,7 @@ fn bigger_microblock_streams_in_2_05() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::Epoch2_05, - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(tsc, ..) = parsed.payload { if tsc.name.to_string().find("costs-2").is_some() { in_205 = true; diff --git a/testnet/stacks-node/src/tests/epoch_21.rs b/testnet/stacks-node/src/tests/epoch_21.rs index f1cc653e0a..14db80f0b1 100644 --- a/testnet/stacks-node/src/tests/epoch_21.rs +++ b/testnet/stacks-node/src/tests/epoch_21.rs @@ -26,7 +26,6 @@ use stacks::clarity_cli::vm_execute as execute; use stacks::core; use stacks::core::BURNCHAIN_TX_SEARCH_WINDOW; use stacks::util_lib::boot::boot_code_id; -use stacks_common::codec::DeserializeWithEpoch; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, VRFSeed, }; @@ -385,10 +384,9 @@ fn transition_adds_burn_block_height() { ); submit_tx(&http_origin, &tx); - let cc_txid = - StacksTransaction::consensus_deserialize_with_epoch(&mut &tx[..], StacksEpochId::Epoch21) - .unwrap() - .txid(); + let cc_txid = StacksTransaction::consensus_deserialize(&mut &tx[..]) + .unwrap() + .txid(); // mine it next_block_and_wait(&mut btc_regtest_controller, &blocks_processed); @@ -407,11 +405,7 @@ fn transition_adds_burn_block_height() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::Epoch21, - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if parsed.txid() == cc_txid { // check events for this block for event in events.iter() { @@ -1227,12 +1221,9 @@ fn transition_adds_get_pox_addr_recipients() { "test-get-pox-addrs", &[Value::UInt((stack_sort_height).into())], ); - let cc_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &cc_tx[..], - StacksEpochId::Epoch21, - ) - .unwrap() - .txid(); + let cc_txid = StacksTransaction::consensus_deserialize(&mut &cc_tx[..]) + .unwrap() + .txid(); submit_tx(&http_origin, &cc_tx); next_block_and_wait(&mut btc_regtest_controller, &blocks_processed); @@ -1251,11 +1242,7 @@ fn transition_adds_get_pox_addr_recipients() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::Epoch21, - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if parsed.txid() == cc_txid { // check events for this block for (_i, event) in events.iter().enumerate() { @@ -1985,11 +1972,7 @@ fn transition_empty_blocks() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::Epoch21, - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(tsc, ..) = parsed.payload { if tsc.name == "pox-2".into() { have_pox2 = true; @@ -4910,11 +4893,7 @@ fn trait_invocation_cross_epoch() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::Epoch21, - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if interesting_txids.contains(&parsed.txid().to_string()) { eprintln!( "{} => {}", diff --git a/testnet/stacks-node/src/tests/epoch_22.rs b/testnet/stacks-node/src/tests/epoch_22.rs index 1e52921848..4e387d6304 100644 --- a/testnet/stacks-node/src/tests/epoch_22.rs +++ b/testnet/stacks-node/src/tests/epoch_22.rs @@ -11,7 +11,6 @@ use stacks::clarity_cli::vm_execute as execute; use stacks::core; use stacks::core::STACKS_EPOCH_MAX; use stacks::util_lib::boot::boot_code_id; -use stacks_common::codec::DeserializeWithEpoch; use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; use stacks_common::types::PrivateKey; use stacks_common::util::hash::Hash160; @@ -541,11 +540,8 @@ fn disable_pox() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch22, - ) - .unwrap(); + let parsed = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let tx_sender = PrincipalData::from(parsed.auth.origin().address_testnet()); if &tx_sender == &spender_addr && parsed.auth.get_origin_nonce() == aborted_increase_nonce @@ -1201,11 +1197,8 @@ fn pox_2_unlock_all() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch22, - ) - .unwrap(); + let parsed = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let tx_sender = PrincipalData::from(parsed.auth.origin().address_testnet()); if &tx_sender == &spender_addr && parsed.auth.get_origin_nonce() == nonce_of_2_2_unlock_ht_call diff --git a/testnet/stacks-node/src/tests/epoch_23.rs b/testnet/stacks-node/src/tests/epoch_23.rs index 6f1ef70ba7..470eda9672 100644 --- a/testnet/stacks-node/src/tests/epoch_23.rs +++ b/testnet/stacks-node/src/tests/epoch_23.rs @@ -20,7 +20,6 @@ use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; use stacks::burnchains::{Burnchain, PoxConstants}; use stacks::core; use stacks::core::STACKS_EPOCH_MAX; -use stacks_common::codec::DeserializeWithEpoch; use stacks_common::util::sleep_ms; use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; @@ -509,11 +508,8 @@ fn trait_invocation_behavior() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch23, - ) - .unwrap(); + let parsed = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let tx_sender = PrincipalData::from(parsed.auth.origin().address_testnet()); if &tx_sender == &spender_addr { let contract_call = match &parsed.payload { diff --git a/testnet/stacks-node/src/tests/epoch_24.rs b/testnet/stacks-node/src/tests/epoch_24.rs index b4e30da04c..d98178f946 100644 --- a/testnet/stacks-node/src/tests/epoch_24.rs +++ b/testnet/stacks-node/src/tests/epoch_24.rs @@ -28,7 +28,6 @@ use stacks::chainstate::stacks::{Error, StacksTransaction, TransactionPayload}; use stacks::clarity_cli::vm_execute as execute; use stacks::core; use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_TESTNET_SINGLESIG}; -use stacks_common::codec::DeserializeWithEpoch; use stacks_common::consts::STACKS_EPOCH_MAX; use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, StacksPrivateKey}; use stacks_common::types::{Address, StacksEpochId}; @@ -645,11 +644,8 @@ fn fix_to_pox_contract() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch24, - ) - .unwrap(); + let parsed = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let tx_sender = PrincipalData::from(parsed.auth.origin().address_testnet()); if &tx_sender == &spender_addr && (parsed.auth.get_origin_nonce() == aborted_increase_nonce_2_2 diff --git a/testnet/stacks-node/src/tests/integrations.rs b/testnet/stacks-node/src/tests/integrations.rs index b13f6351b3..a0fa7408f4 100644 --- a/testnet/stacks-node/src/tests/integrations.rs +++ b/testnet/stacks-node/src/tests/integrations.rs @@ -22,7 +22,7 @@ use stacks::chainstate::stacks::{ TransactionContractCall, TransactionPayload, }; use stacks::clarity_vm::clarity::ClarityConnection; -use stacks::codec::{DeserializeWithEpoch, StacksMessageCodec}; +use stacks::codec::StacksMessageCodec; use stacks::core::mempool::MAXIMUM_MEMPOOL_TX_CHAINING; use stacks::core::{ StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, @@ -832,7 +832,7 @@ fn integration_test_get_info() { let tx_xfer_invalid = make_stacks_transfer(&spender_sk, (round + 30).into(), 200, // bad nonce &StacksAddress::from_string(ADDR_4).unwrap().into(), 456); - let tx_xfer_invalid_tx = StacksTransaction::consensus_deserialize_with_epoch(&mut &tx_xfer_invalid[..], StacksEpochId::latest()).unwrap(); + let tx_xfer_invalid_tx = StacksTransaction::consensus_deserialize(&mut &tx_xfer_invalid[..]).unwrap(); let res = client.post(&path) .header("Content-Type", "application/octet-stream") @@ -1197,11 +1197,9 @@ fn contract_stx_transfer() { &contract_identifier.clone().into(), 1000, ); - let xfer_to_contract = StacksTransaction::consensus_deserialize_with_epoch( - &mut &xfer_to_contract[..], - StacksEpochId::latest(), - ) - .unwrap(); + let xfer_to_contract = + StacksTransaction::consensus_deserialize(&mut &xfer_to_contract[..]) + .unwrap(); tenure .mem_pool .submit( @@ -1219,11 +1217,8 @@ fn contract_stx_transfer() { // this one should fail because the nonce is already in the mempool let xfer_to_contract = make_stacks_transfer(&sk_3, 3, 190, &contract_identifier.clone().into(), 1000); - let xfer_to_contract = StacksTransaction::consensus_deserialize_with_epoch( - &mut &xfer_to_contract[..], - StacksEpochId::latest(), - ) - .unwrap(); + let xfer_to_contract = + StacksTransaction::consensus_deserialize(&mut &xfer_to_contract[..]).unwrap(); match tenure .mem_pool .submit( @@ -2184,11 +2179,8 @@ fn mempool_errors() { &send_to, 456, ); - let tx_xfer_invalid_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_xfer_invalid[..], - StacksEpochId::latest(), - ) - .unwrap(); + let tx_xfer_invalid_tx = + StacksTransaction::consensus_deserialize(&mut &tx_xfer_invalid[..]).unwrap(); let res = client .post(&path) @@ -2228,11 +2220,8 @@ fn mempool_errors() { &send_to, 456, ); - let tx_xfer_invalid_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_xfer_invalid[..], - StacksEpochId::latest(), - ) - .unwrap(); + let tx_xfer_invalid_tx = + StacksTransaction::consensus_deserialize(&mut &tx_xfer_invalid[..]).unwrap(); let res = client .post(&path) @@ -2264,11 +2253,8 @@ fn mempool_errors() { &send_to, 456, ); - let tx_xfer_invalid_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_xfer_invalid[..], - StacksEpochId::latest(), - ) - .unwrap(); + let tx_xfer_invalid_tx = + StacksTransaction::consensus_deserialize(&mut &tx_xfer_invalid[..]).unwrap(); let res = client .post(&path) @@ -2311,11 +2297,8 @@ fn mempool_errors() { &send_to, 1000, ); - let tx_xfer_invalid_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_xfer_invalid[..], - StacksEpochId::latest(), - ) - .unwrap(); + let tx_xfer_invalid_tx = + StacksTransaction::consensus_deserialize(&mut &tx_xfer_invalid[..]).unwrap(); let res = client .post(&path) diff --git a/testnet/stacks-node/src/tests/mempool.rs b/testnet/stacks-node/src/tests/mempool.rs index 5d6ab19601..6221c6cf11 100644 --- a/testnet/stacks-node/src/tests/mempool.rs +++ b/testnet/stacks-node/src/tests/mempool.rs @@ -13,7 +13,7 @@ use stacks::chainstate::stacks::{ TransactionAnchorMode, TransactionAuth, TransactionPayload, TransactionSpendingCondition, TransactionVersion, C32_ADDRESS_VERSION_MAINNET_SINGLESIG, }; -use stacks::codec::{DeserializeWithEpoch, StacksMessageCodec}; +use stacks::codec::StacksMessageCodec; use stacks::core::mempool::MemPoolDB; use stacks::core::{StacksEpochId, CHAIN_ID_TESTNET}; use stacks::cost_estimates::metrics::UnitMetric; @@ -236,11 +236,8 @@ fn mempool_setup_chainstate() { // first a couple valid ones: let tx_bytes = make_contract_publish(&contract_sk, 5, 1000, "bar_contract", FOO_CONTRACT); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -260,11 +257,8 @@ fn mempool_setup_chainstate() { "bar", &[Value::UInt(1)], ); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -276,11 +270,8 @@ fn mempool_setup_chainstate() { .unwrap(); let tx_bytes = make_stacks_transfer(&contract_sk, 5, 200, &other_addr, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -293,11 +284,8 @@ fn mempool_setup_chainstate() { // bad signature let tx_bytes = make_bad_stacks_transfer(&contract_sk, 5, 200, &other_addr, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -338,11 +326,8 @@ fn mempool_setup_chainstate() { "bar", &[Value::UInt(1), Value::Int(2)], ); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -370,11 +355,8 @@ fn mempool_setup_chainstate() { .into(); let tx_bytes = make_stacks_transfer(&contract_sk, 5, 200, &bad_addr, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -392,11 +374,8 @@ fn mempool_setup_chainstate() { // bad fees let tx_bytes = make_stacks_transfer(&contract_sk, 5, 0, &other_addr, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -415,11 +394,8 @@ fn mempool_setup_chainstate() { // bad nonce let tx_bytes = make_stacks_transfer(&contract_sk, 0, 200, &other_addr, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -438,11 +414,8 @@ fn mempool_setup_chainstate() { // not enough funds let tx_bytes = make_stacks_transfer(&contract_sk, 5, 110000, &other_addr, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -462,11 +435,8 @@ fn mempool_setup_chainstate() { // sender == recipient let contract_princ = PrincipalData::from(contract_addr.clone()); let tx_bytes = make_stacks_transfer(&contract_sk, 5, 300, &contract_princ, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -488,11 +458,8 @@ fn mempool_setup_chainstate() { mainnet_recipient.version = C32_ADDRESS_VERSION_MAINNET_SINGLESIG; let mainnet_princ = mainnet_recipient.into(); let tx_bytes = make_stacks_transfer(&contract_sk, 5, 300, &mainnet_princ, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -524,11 +491,8 @@ fn mempool_setup_chainstate() { TransactionAnchorMode::OnChainOnly, TransactionVersion::Mainnet, ); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -547,11 +511,8 @@ fn mempool_setup_chainstate() { // send amount must be positive let tx_bytes = make_stacks_transfer(&contract_sk, 5, 300, &other_addr, 0); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -570,11 +531,8 @@ fn mempool_setup_chainstate() { // not enough funds let tx_bytes = make_stacks_transfer(&contract_sk, 5, 110000, &other_addr, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -592,11 +550,8 @@ fn mempool_setup_chainstate() { }); let tx_bytes = make_stacks_transfer(&contract_sk, 5, 99700, &other_addr, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -622,11 +577,8 @@ fn mempool_setup_chainstate() { "bar", &[Value::UInt(1)], ); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -652,11 +604,8 @@ fn mempool_setup_chainstate() { "foobar", &[Value::UInt(1)], ); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -682,11 +631,8 @@ fn mempool_setup_chainstate() { "bar", &[Value::UInt(1), Value::Int(2)], ); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -705,11 +651,8 @@ fn mempool_setup_chainstate() { let tx_bytes = make_contract_publish(&contract_sk, 5, 1000, "foo_contract", FOO_CONTRACT); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -743,11 +686,8 @@ fn mempool_setup_chainstate() { }; let tx_bytes = make_poison(&contract_sk, 5, 1000, microblock_1, microblock_2); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -777,11 +717,8 @@ fn mempool_setup_chainstate() { }; let tx_bytes = make_poison(&contract_sk, 5, 1000, microblock_1, microblock_2); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -814,11 +751,8 @@ fn mempool_setup_chainstate() { microblock_2.sign(&other_sk).unwrap(); let tx_bytes = make_poison(&contract_sk, 5, 1000, microblock_1, microblock_2); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -832,11 +766,8 @@ fn mempool_setup_chainstate() { assert!(matches!(e, MemPoolRejection::Other(_))); let tx_bytes = make_coinbase(&contract_sk, 5, 1000); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -893,11 +824,8 @@ fn mempool_setup_chainstate() { microblock_2.sign(&secret_key).unwrap(); let tx_bytes = make_poison(&contract_sk, 5, 1000, microblock_1, microblock_2); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -925,11 +853,8 @@ fn mempool_setup_chainstate() { "baz", &[Value::Principal(contract_principal)], ); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, @@ -955,11 +880,8 @@ fn mempool_setup_chainstate() { "baz", &[Value::Principal(contract_principal)], ); - let tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut tx_bytes.as_slice(), - StacksEpochId::Epoch25, - ) - .unwrap(); + let tx = + StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state .will_admit_mempool_tx( &NULL_BURN_STATE_DB, diff --git a/testnet/stacks-node/src/tests/mod.rs b/testnet/stacks-node/src/tests/mod.rs index 182eee6ec2..ddcbaf70f7 100644 --- a/testnet/stacks-node/src/tests/mod.rs +++ b/testnet/stacks-node/src/tests/mod.rs @@ -35,7 +35,7 @@ use stacks::chainstate::stacks::{ TransactionPostConditionMode, TransactionSmartContract, TransactionSpendingCondition, TransactionVersion, C32_ADDRESS_VERSION_TESTNET_SINGLESIG, }; -use stacks::codec::{DeserializeWithEpoch, StacksMessageCodec}; +use stacks::codec::StacksMessageCodec; use stacks::core::{StacksEpoch, StacksEpochExtension, StacksEpochId, CHAIN_ID_TESTNET}; use stacks::util_lib::strings::StacksString; use stacks_common::address::AddressHashMode; @@ -472,9 +472,7 @@ pub fn select_transactions_where( for tx in transactions.iter() { let raw_tx = tx.get("raw_tx").unwrap().as_str().unwrap(); let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = - StacksTransaction::consensus_deserialize_with_epoch(&mut &tx_bytes[..], epoch_id) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if test_fn(&parsed) { result.push(parsed); } diff --git a/testnet/stacks-node/src/tests/neon_integrations.rs b/testnet/stacks-node/src/tests/neon_integrations.rs index 1f2107fd01..b06f723dcf 100644 --- a/testnet/stacks-node/src/tests/neon_integrations.rs +++ b/testnet/stacks-node/src/tests/neon_integrations.rs @@ -36,7 +36,7 @@ use stacks::chainstate::stacks::{ StacksPublicKey, StacksTransaction, TransactionContractCall, TransactionPayload, }; use stacks::clarity_cli::vm_execute as execute; -use stacks::codec::{DeserializeWithEpoch, StacksMessageCodec}; +use stacks::codec::StacksMessageCodec; use stacks::core::mempool::MemPoolWalkTxTypes; use stacks::core::{ self, StacksEpoch, StacksEpochId, BLOCK_LIMIT_MAINNET_20, BLOCK_LIMIT_MAINNET_205, @@ -817,9 +817,7 @@ pub fn get_block(http_origin: &str, block_id: &StacksBlockId) -> Option = res.bytes().unwrap().to_vec(); - let block = - StacksBlock::consensus_deserialize_with_epoch(&mut &res[..], StacksEpochId::latest()) - .unwrap(); + let block = StacksBlock::consensus_deserialize(&mut &res[..]).unwrap(); Some(block) } else { None @@ -858,11 +856,7 @@ pub fn get_tip_anchored_block(conf: &Config) -> (ConsensusHash, StacksBlock) { let client = reqwest::blocking::Client::new(); let path = format!("{}/v2/blocks/{}", &http_origin, &stacks_id_tip); let block_bytes = client.get(&path).send().unwrap().bytes().unwrap(); - let block = StacksBlock::consensus_deserialize_with_epoch( - &mut block_bytes.as_ref(), - StacksEpochId::latest(), - ) - .unwrap(); + let block = StacksBlock::consensus_deserialize(&mut block_bytes.as_ref()).unwrap(); (stacks_tip_consensus_hash, block) } @@ -1419,11 +1413,7 @@ fn deep_contract() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = parsed.payload { included_smart_contract = true; } @@ -1636,11 +1626,7 @@ fn liquid_ustx_integration() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::ContractCall(contract_call) = parsed.payload { eprintln!("{}", contract_call.function_name.as_str()); if contract_call.function_name.as_str() == "execute" { @@ -3411,18 +3397,12 @@ fn microblock_fork_poison_integration_test() { let recipient = StacksAddress::from_string(ADDR_4).unwrap(); let unconfirmed_tx_bytes = make_stacks_transfer_mblock_only(&spender_sk, 0, 1000, &recipient.into(), 1000); - let unconfirmed_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &unconfirmed_tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let unconfirmed_tx = + StacksTransaction::consensus_deserialize(&mut &unconfirmed_tx_bytes[..]).unwrap(); let second_unconfirmed_tx_bytes = make_stacks_transfer_mblock_only(&second_spender_sk, 0, 1000, &recipient.into(), 1500); - let second_unconfirmed_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &second_unconfirmed_tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let second_unconfirmed_tx = + StacksTransaction::consensus_deserialize(&mut &second_unconfirmed_tx_bytes[..]).unwrap(); // TODO (hack) instantiate the sortdb in the burnchain let _ = btc_regtest_controller.sortdb_mut(); @@ -3537,11 +3517,7 @@ fn microblock_fork_poison_integration_test() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::PoisonMicroblock(..) = &parsed.payload { found = true; @@ -3679,18 +3655,12 @@ fn microblock_integration_test() { let recipient = StacksAddress::from_string(ADDR_4).unwrap(); let unconfirmed_tx_bytes = make_stacks_transfer_mblock_only(&spender_sk, 1, 1000, &recipient.into(), 1000); - let unconfirmed_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &unconfirmed_tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let unconfirmed_tx = + StacksTransaction::consensus_deserialize(&mut &unconfirmed_tx_bytes[..]).unwrap(); let second_unconfirmed_tx_bytes = make_stacks_transfer_mblock_only(&second_spender_sk, 0, 1000, &recipient.into(), 1500); - let second_unconfirmed_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &second_unconfirmed_tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let second_unconfirmed_tx = + StacksTransaction::consensus_deserialize(&mut &second_unconfirmed_tx_bytes[..]).unwrap(); // TODO (hack) instantiate the sortdb in the burnchain let _ = btc_regtest_controller.sortdb_mut(); @@ -4374,11 +4344,7 @@ fn size_check_integration_test() { "large-0", &giant_contract, ); - let parsed_tx = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed_tx = StacksTransaction::consensus_deserialize(&mut &tx[..]).unwrap(); debug!("Mine transaction {} in a microblock", &parsed_tx.txid()); tx } @@ -4680,11 +4646,7 @@ fn size_overflow_unconfirmed_microblocks_integration_test() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(tsc, ..) = parsed.payload { if tsc.name.to_string().find("large-").is_some() { num_big_anchored_txs += 1; @@ -4886,11 +4848,7 @@ fn size_overflow_unconfirmed_stream_microblocks_integration_test() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(tsc, ..) = parsed.payload { if tsc.name.to_string().find("small").is_some() { num_big_microblock_txs += 1; @@ -5065,11 +5023,7 @@ fn size_overflow_unconfirmed_invalid_stream_microblocks_integration_test() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(tsc, ..) = parsed.payload { if tsc.name.to_string().find("small").is_some() { num_big_microblock_txs += 1; @@ -5348,11 +5302,7 @@ fn runtime_overflow_unconfirmed_microblocks_integration_test() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); eprintln!("tx: {:?}", &parsed); if let TransactionPayload::SmartContract(tsc, ..) = parsed.payload { if tsc.name.to_string().find("large-").is_some() { @@ -5672,11 +5622,7 @@ fn cost_voting_integration() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::ContractCall(contract_call) = parsed.payload { eprintln!("{}", contract_call.function_name.as_str()); if contract_call.function_name.as_str() == "execute-2" { @@ -5725,11 +5671,7 @@ fn cost_voting_integration() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::ContractCall(contract_call) = parsed.payload { eprintln!("{}", contract_call.function_name.as_str()); if contract_call.function_name.as_str() == "confirm-miners" { @@ -5778,11 +5720,7 @@ fn cost_voting_integration() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::ContractCall(contract_call) = parsed.payload { eprintln!("{}", contract_call.function_name.as_str()); if contract_call.function_name.as_str() == "confirm-miners" { @@ -5827,11 +5765,7 @@ fn cost_voting_integration() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::ContractCall(contract_call) = parsed.payload { eprintln!("{}", contract_call.function_name.as_str()); if contract_call.function_name.as_str() == "execute-2" { @@ -7068,11 +7002,7 @@ fn pox_integration_test() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::ContractCall(contract_call) = parsed.payload { eprintln!("{}", contract_call.function_name.as_str()); if contract_call.function_name.as_str() == "stack-stx" { @@ -9198,16 +9128,8 @@ fn use_latest_tip_integration_test() { let publish_tx = make_contract_publish_microblock_only(&spender_sk, 1, 1000, "caller", caller_src); - let tx_1 = StacksTransaction::consensus_deserialize_with_epoch( - &mut &transfer_tx[..], - StacksEpochId::latest(), - ) - .unwrap(); - let tx_2 = StacksTransaction::consensus_deserialize_with_epoch( - &mut &publish_tx[..], - StacksEpochId::latest(), - ) - .unwrap(); + let tx_1 = StacksTransaction::consensus_deserialize(&mut &transfer_tx[..]).unwrap(); + let tx_2 = StacksTransaction::consensus_deserialize(&mut &publish_tx[..]).unwrap(); let vec_tx = vec![tx_1, tx_2]; let privk = find_microblock_privkey(&conf, &stacks_block.header.microblock_pubkey_hash, 1024).unwrap(); @@ -9554,12 +9476,9 @@ fn test_problematic_txs_are_not_stored() { "test-edge", &tx_edge_body, ); - let tx_edge_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_edge[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_edge_txid = StacksTransaction::consensus_deserialize(&mut &tx_edge[..]) + .unwrap() + .txid(); // something just over the limit of the expression depth let exceeds_repeat_factor = edge_repeat_factor + 1; @@ -9574,12 +9493,9 @@ fn test_problematic_txs_are_not_stored() { "test-exceeds", &tx_exceeds_body, ); - let tx_exceeds_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_exceeds[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_exceeds_txid = StacksTransaction::consensus_deserialize(&mut &tx_exceeds[..]) + .unwrap() + .txid(); // something stupidly high over the expression depth let high_repeat_factor = 128 * 1024; @@ -9594,12 +9510,9 @@ fn test_problematic_txs_are_not_stored() { "test-high", &tx_high_body, ); - let tx_high_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_high[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_high_txid = StacksTransaction::consensus_deserialize(&mut &tx_high[..]) + .unwrap() + .txid(); btc_regtest_controller.bootstrap_chain(201); @@ -9813,12 +9726,9 @@ fn test_problematic_blocks_are_not_mined() { "test-exceeds", &tx_exceeds_body, ); - let tx_exceeds_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_exceeds[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_exceeds_txid = StacksTransaction::consensus_deserialize(&mut &tx_exceeds[..]) + .unwrap() + .txid(); // something stupidly high over the expression depth let high_repeat_factor = 3200; @@ -9833,12 +9743,9 @@ fn test_problematic_blocks_are_not_mined() { "test-high", &tx_high_body, ); - let tx_high_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_high[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_high_txid = StacksTransaction::consensus_deserialize(&mut &tx_high[..]) + .unwrap() + .txid(); btc_regtest_controller.bootstrap_chain(201); @@ -9910,11 +9817,7 @@ fn test_problematic_blocks_are_not_mined() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = &parsed.payload { if parsed.txid() == tx_exceeds_txid { found = true; @@ -10011,11 +9914,7 @@ fn test_problematic_blocks_are_not_mined() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = &parsed.payload { assert!(parsed.txid() != tx_high_txid); } @@ -10185,12 +10084,9 @@ fn test_problematic_blocks_are_not_relayed_or_stored() { "test-exceeds", &tx_exceeds_body, ); - let tx_exceeds_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_exceeds[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_exceeds_txid = StacksTransaction::consensus_deserialize(&mut &tx_exceeds[..]) + .unwrap() + .txid(); let high_repeat_factor = 70; let tx_high_body_start = "{ a : ".repeat(high_repeat_factor as usize); @@ -10204,12 +10100,9 @@ fn test_problematic_blocks_are_not_relayed_or_stored() { "test-high", &tx_high_body, ); - let tx_high_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_high[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_high_txid = StacksTransaction::consensus_deserialize(&mut &tx_high[..]) + .unwrap() + .txid(); btc_regtest_controller.bootstrap_chain(201); @@ -10281,11 +10174,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = &parsed.payload { if parsed.txid() == tx_exceeds_txid { found = true; @@ -10411,11 +10300,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = &parsed.payload { if parsed.txid() == tx_high_txid { bad_block_height = Some(block.get("block_height").unwrap().as_u64().unwrap()); @@ -10598,12 +10483,9 @@ fn test_problematic_microblocks_are_not_mined() { "test-exceeds", &tx_exceeds_body, ); - let tx_exceeds_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_exceeds[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_exceeds_txid = StacksTransaction::consensus_deserialize(&mut &tx_exceeds[..]) + .unwrap() + .txid(); // something stupidly high over the expression depth let high_repeat_factor = @@ -10619,12 +10501,9 @@ fn test_problematic_microblocks_are_not_mined() { "test-high", &tx_high_body, ); - let tx_high_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_high[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_high_txid = StacksTransaction::consensus_deserialize(&mut &tx_high[..]) + .unwrap() + .txid(); btc_regtest_controller.bootstrap_chain(201); @@ -10703,11 +10582,7 @@ fn test_problematic_microblocks_are_not_mined() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = &parsed.payload { if parsed.txid() == tx_exceeds_txid { found = true; @@ -10816,11 +10691,7 @@ fn test_problematic_microblocks_are_not_mined() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = &parsed.payload { assert_ne!(parsed.txid(), tx_high_txid); } @@ -10998,12 +10869,9 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() { "test-exceeds", &tx_exceeds_body, ); - let tx_exceeds_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_exceeds[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_exceeds_txid = StacksTransaction::consensus_deserialize(&mut &tx_exceeds[..]) + .unwrap() + .txid(); // greatly exceeds AST depth, but is still mineable without a stack overflow let high_repeat_factor = @@ -11019,12 +10887,9 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() { "test-high", &tx_high_body, ); - let tx_high_txid = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_high[..], - StacksEpochId::latest(), - ) - .unwrap() - .txid(); + let tx_high_txid = StacksTransaction::consensus_deserialize(&mut &tx_high[..]) + .unwrap() + .txid(); btc_regtest_controller.bootstrap_chain(201); @@ -11099,11 +10964,7 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = &parsed.payload { if parsed.txid() == tx_exceeds_txid { found = true; @@ -11232,11 +11093,7 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() { continue; } let tx_bytes = hex_bytes(&raw_tx[2..]).unwrap(); - let parsed = StacksTransaction::consensus_deserialize_with_epoch( - &mut &tx_bytes[..], - StacksEpochId::latest(), - ) - .unwrap(); + let parsed = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap(); if let TransactionPayload::SmartContract(..) = &parsed.payload { if parsed.txid() == tx_high_txid { bad_block_id = {