Skip to content

Commit

Permalink
fix: redundant code reverted, quiet parameter removed
Browse files Browse the repository at this point in the history
  • Loading branch information
fess-v committed Apr 10, 2024
1 parent ac057ca commit 72507cc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 42 deletions.
17 changes: 8 additions & 9 deletions stackslib/src/chainstate/nakamoto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3357,13 +3357,12 @@ impl StacksMessageCodec for NakamotoBlock {
}

fn consensus_deserialize<R: std::io::Read>(fd: &mut R) -> Result<Self, CodecError> {
let header: NakamotoBlockHeader = read_next(fd)?;

let txs: Vec<StacksTransaction> = {
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) {
Expand Down
43 changes: 12 additions & 31 deletions stackslib/src/chainstate/stacks/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -853,8 +836,7 @@ impl StacksMessageCodec for StacksMicroblock {
let header: StacksMicroblockHeader = read_next(fd)?;
let txs: Vec<StacksTransaction> = {
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 {
Expand Down Expand Up @@ -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,
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
));
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/stacks/db/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 72507cc

Please sign in to comment.