Skip to content

Commit 9addd7e

Browse files
committed
fix: validate_transaction_static_epoch function added
1 parent 6766e65 commit 9addd7e

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

stackslib/src/chainstate/stacks/block.rs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -570,41 +570,52 @@ impl StacksBlock {
570570
epoch_id: StacksEpochId,
571571
) -> bool {
572572
for tx in txs.iter() {
573-
if let TransactionPayload::Coinbase(_, ref recipient_opt, ref proof_opt) = &tx.payload {
574-
if proof_opt.is_some() && epoch_id < StacksEpochId::Epoch30 {
575-
// not supported
576-
error!("Coinbase with VRF proof not supported before Stacks 3.0"; "txid" => %tx.txid());
577-
return false;
578-
}
579-
if proof_opt.is_none() && epoch_id >= StacksEpochId::Epoch30 {
580-
// not supported
581-
error!("Coinbase with VRF proof is required in Stacks 3.0 and later"; "txid" => %tx.txid());
582-
return false;
583-
}
584-
if recipient_opt.is_some() && epoch_id < StacksEpochId::Epoch21 {
585-
// not supported
586-
error!("Coinbase pay-to-alt-recipient not supported before Stacks 2.1"; "txid" => %tx.txid());
587-
return false;
588-
}
573+
if !StacksBlock::validate_transaction_static_epoch(tx, epoch_id) {
574+
return false;
589575
}
590-
if let TransactionPayload::SmartContract(_, ref version_opt) = &tx.payload {
591-
if version_opt.is_some() && epoch_id < StacksEpochId::Epoch21 {
592-
// not supported
593-
error!("Versioned smart contracts not supported before Stacks 2.1");
594-
return false;
595-
}
576+
}
577+
return true;
578+
}
579+
580+
/// Verify that one transaction is supported in the given epoch, as indicated by `epoch_id`
581+
pub fn validate_transaction_static_epoch(
582+
tx: &StacksTransaction,
583+
epoch_id: StacksEpochId,
584+
) -> bool {
585+
if let TransactionPayload::Coinbase(_, ref recipient_opt, ref proof_opt) = &tx.payload {
586+
if proof_opt.is_some() && epoch_id < StacksEpochId::Epoch30 {
587+
// not supported
588+
error!("Coinbase with VRF proof not supported before Stacks 3.0"; "txid" => %tx.txid());
589+
return false;
596590
}
597-
if let TransactionPayload::TenureChange(..) = &tx.payload {
598-
if epoch_id < StacksEpochId::Epoch30 {
599-
error!("TenureChange transaction not supported before Stacks 3.0"; "txid" => %tx.txid());
600-
return false;
601-
}
591+
if proof_opt.is_none() && epoch_id >= StacksEpochId::Epoch30 {
592+
// not supported
593+
error!("Coinbase with VRF proof is required in Stacks 3.0 and later"; "txid" => %tx.txid());
594+
return false;
602595
}
603-
if !tx.auth.is_supported_in_epoch(epoch_id) {
604-
error!("Authentication mode not supported in Epoch {epoch_id}");
596+
if recipient_opt.is_some() && epoch_id < StacksEpochId::Epoch21 {
597+
// not supported
598+
error!("Coinbase pay-to-alt-recipient not supported before Stacks 2.1"; "txid" => %tx.txid());
605599
return false;
606600
}
607601
}
602+
if let TransactionPayload::SmartContract(_, ref version_opt) = &tx.payload {
603+
if version_opt.is_some() && epoch_id < StacksEpochId::Epoch21 {
604+
// not supported
605+
error!("Versioned smart contracts not supported before Stacks 2.1");
606+
return false;
607+
}
608+
}
609+
if let TransactionPayload::TenureChange(..) = &tx.payload {
610+
if epoch_id < StacksEpochId::Epoch30 {
611+
error!("TenureChange transaction not supported before Stacks 3.0"; "txid" => %tx.txid());
612+
return false;
613+
}
614+
}
615+
if !tx.auth.is_supported_in_epoch(epoch_id) {
616+
error!("Authentication mode not supported in Epoch {epoch_id}");
617+
return false;
618+
}
608619
return true;
609620
}
610621

stackslib/src/chainstate/stacks/db/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6666,7 +6666,7 @@ impl StacksChainState {
66666666
}
66676667

66686668
// 4: check if transaction is valid in the current epoch
6669-
if !StacksBlock::validate_transactions_static_epoch(&[tx.clone()], epoch) {
6669+
if !StacksBlock::validate_transaction_static_epoch(tx, epoch) {
66706670
return Err(MemPoolRejection::Other(
66716671
"Transaction is not supported in this epoch".to_string(),
66726672
));

0 commit comments

Comments
 (0)