diff --git a/stackslib/src/chainstate/nakamoto/mod.rs b/stackslib/src/chainstate/nakamoto/mod.rs index 6786151796..f0d2085cb4 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, write_next, Error as CodecError, StacksMessageCodec, - MAX_MESSAGE_LEN, MAX_PAYLOAD_LEN, + read_next, 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, @@ -1176,7 +1176,7 @@ impl NakamotoBlock { warn!("Not a well-formed tenure-extend block"); return false; } - if !StacksBlock::validate_transactions_static_epoch(&self.txs, epoch_id, false) { + if !StacksBlock::validate_transactions_static_epoch(&self.txs, epoch_id) { return false; } return true; @@ -3357,13 +3357,12 @@ impl StacksMessageCodec for NakamotoBlock { } fn consensus_deserialize(fd: &mut R) -> Result { - let header: NakamotoBlockHeader = read_next(fd)?; - - let txs: Vec = { + let (header, txs) = { 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(&mut bound_read, u32::MAX) - }?; + let header: NakamotoBlockHeader = read_next(&mut bound_read)?; + let txs: Vec<_> = read_next(&mut bound_read)?; + (header, txs) + }; // all transactions are unique if !StacksBlock::validate_transactions_unique(&txs) { diff --git a/stackslib/src/chainstate/stacks/block.rs b/stackslib/src/chainstate/stacks/block.rs index 872e4fe9d2..6126dfcfc4 100644 --- a/stackslib/src/chainstate/stacks/block.rs +++ b/stackslib/src/chainstate/stacks/block.rs @@ -568,46 +568,35 @@ impl StacksBlock { pub fn validate_transactions_static_epoch( txs: &[StacksTransaction], epoch_id: StacksEpochId, - quiet: bool, ) -> bool { for tx in txs.iter() { if let TransactionPayload::Coinbase(_, ref recipient_opt, ref proof_opt) = &tx.payload { if proof_opt.is_some() && epoch_id < StacksEpochId::Epoch30 { // not supported - if !quiet { - error!("Coinbase with VRF proof not supported before Stacks 3.0"; "txid" => %tx.txid()); - } + error!("Coinbase with VRF proof not supported before Stacks 3.0"; "txid" => %tx.txid()); return false; } if proof_opt.is_none() && epoch_id >= StacksEpochId::Epoch30 { // not supported - if !quiet { - error!("Coinbase with VRF proof is required in Stacks 3.0 and later"; "txid" => %tx.txid()); - } + error!("Coinbase with VRF proof is required in Stacks 3.0 and later"; "txid" => %tx.txid()); return false; } if recipient_opt.is_some() && epoch_id < StacksEpochId::Epoch21 { // not supported - if !quiet { - error!("Coinbase pay-to-alt-recipient not supported before Stacks 2.1"; "txid" => %tx.txid()); - } + error!("Coinbase pay-to-alt-recipient not supported before Stacks 2.1"; "txid" => %tx.txid()); return false; } } if let TransactionPayload::SmartContract(_, ref version_opt) = &tx.payload { if version_opt.is_some() && epoch_id < StacksEpochId::Epoch21 { // not supported - if !quiet { - error!("Versioned smart contracts not supported before Stacks 2.1"); - } + error!("Versioned smart contracts not supported before Stacks 2.1"); return false; } } if let TransactionPayload::TenureChange(..) = &tx.payload { if epoch_id < StacksEpochId::Epoch30 { - if !quiet { - error!("TenureChange transaction not supported before Stacks 3.0"; "txid" => %tx.txid()); - } + error!("TenureChange transaction not supported before Stacks 3.0"; "txid" => %tx.txid()); return false; } } @@ -616,9 +605,7 @@ impl StacksBlock { match origin { TransactionSpendingCondition::OrderIndependentMultisig(..) => { if epoch_id < StacksEpochId::Epoch30 { - if !quiet { - error!("Order independent multisig transactions not supported before Stacks 3.0"); - } + error!("Order independent multisig transactions not supported before Stacks 3.0"); return false; } } @@ -627,9 +614,7 @@ impl StacksBlock { match sponsor { TransactionSpendingCondition::OrderIndependentMultisig(..) => { if epoch_id < StacksEpochId::Epoch30 { - if !quiet { - error!("Order independent multisig transactions not supported before Stacks 3.0"); - } + error!("Order independent multisig transactions not supported before Stacks 3.0"); return false; } } @@ -639,9 +624,7 @@ impl StacksBlock { TransactionAuth::Standard(ref origin) => match origin { TransactionSpendingCondition::OrderIndependentMultisig(..) => { if epoch_id < StacksEpochId::Epoch30 { - if !quiet { - error!("Order independent multisig transactions not supported before Stacks 3.0"); - } + error!("Order independent multisig transactions not supported before Stacks 3.0"); return false; } } @@ -674,7 +657,7 @@ impl StacksBlock { if !StacksBlock::validate_coinbase(&self.txs, true) { return false; } - if !StacksBlock::validate_transactions_static_epoch(&self.txs, epoch_id, false) { + if !StacksBlock::validate_transactions_static_epoch(&self.txs, epoch_id) { return false; } return true; @@ -853,8 +836,7 @@ impl StacksMessageCodec for StacksMicroblock { 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 Epoch25 - read_next_at_most(&mut bound_read, u32::MAX) + read_next(&mut bound_read) }?; if txs.len() == 0 { @@ -1802,16 +1784,15 @@ mod test { assert!(!StacksBlock::validate_transactions_static_epoch( &txs, epoch_id.clone(), - false, )); } else if deactivation_epoch_id.is_none() || deactivation_epoch_id.unwrap() > *epoch_id { assert!(StacksBlock::validate_transactions_static_epoch( - &txs, *epoch_id, false, + &txs, *epoch_id, )); } else { assert!(!StacksBlock::validate_transactions_static_epoch( - &txs, *epoch_id, false, + &txs, *epoch_id, )); } } diff --git a/stackslib/src/chainstate/stacks/db/blocks.rs b/stackslib/src/chainstate/stacks/db/blocks.rs index 5b6b9d6e91..792ca8edc7 100644 --- a/stackslib/src/chainstate/stacks/db/blocks.rs +++ b/stackslib/src/chainstate/stacks/db/blocks.rs @@ -6666,7 +6666,7 @@ impl StacksChainState { // 4: check if transaction is valid in the current epoch let epoch = clarity_connection.get_epoch().clone(); - if !StacksBlock::validate_transactions_static_epoch(&[tx.clone()], epoch, true) { + if !StacksBlock::validate_transactions_static_epoch(&[tx.clone()], epoch) { return Err(MemPoolRejection::Other( "Transaction is not supported in this epoch".to_string(), )); diff --git a/stackslib/src/chainstate/stacks/db/transactions.rs b/stackslib/src/chainstate/stacks/db/transactions.rs index cb2c569a2a..e8412f5060 100644 --- a/stackslib/src/chainstate/stacks/db/transactions.rs +++ b/stackslib/src/chainstate/stacks/db/transactions.rs @@ -1480,7 +1480,7 @@ impl StacksChainState { } } - if !StacksBlock::validate_transactions_static_epoch(&vec![tx.clone()], epoch, quiet) { + if !StacksBlock::validate_transactions_static_epoch(&vec![tx.clone()], epoch) { let msg = format!( "Invalid transaction {}: target epoch is not activated", tx.txid()