Skip to content

Commit 5f33fd9

Browse files
authored
Merge pull request #5635 from stacks-network/fix/check-nakamoto-empty-block-heuristics
Filter out phantom txs from test_observer::parse_transaction fn
2 parents 41c74fa + 5e31343 commit 5f33fd9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

stackslib/src/chainstate/stacks/transaction.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use crate::chainstate::stacks::{TransactionPayloadID, *};
3434
use crate::codec::Error as CodecError;
3535
use crate::core::*;
3636
use crate::net::Error as net_error;
37+
use crate::util_lib::boot::boot_code_addr;
3738

3839
impl StacksMessageCodec for TransactionContractCall {
3940
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
@@ -1031,6 +1032,16 @@ impl StacksTransaction {
10311032
_ => false,
10321033
}
10331034
}
1035+
1036+
/// Is this a phantom transaction?
1037+
pub fn is_phantom(&self) -> bool {
1038+
let boot_address = boot_code_addr(self.is_mainnet()).into();
1039+
if let TransactionPayload::TokenTransfer(address, amount, _) = &self.payload {
1040+
*address == boot_address && *amount == 0
1041+
} else {
1042+
false
1043+
}
1044+
}
10341045
}
10351046

10361047
impl StacksTransactionSigner {

testnet/stacks-node/src/tests/neon_integrations.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ pub mod test_observer {
578578
PROPOSAL_RESPONSES.lock().unwrap().clear();
579579
}
580580

581-
/// Parse the StacksTransactions from a block (does not include burn ops)
581+
/// Parse the StacksTransactions from a block (does not include burn ops or phantom txs)
582582
/// panics on any failures to parse
583583
pub fn parse_transactions(block: &serde_json::Value) -> Vec<StacksTransaction> {
584584
block
@@ -588,15 +588,20 @@ pub mod test_observer {
588588
.unwrap()
589589
.iter()
590590
.filter_map(|tx_json| {
591+
// Filter out burn ops
591592
if let Some(burnchain_op_val) = tx_json.get("burnchain_op") {
592593
if !burnchain_op_val.is_null() {
593594
return None;
594595
}
595596
}
597+
// Filter out phantom txs
596598
let tx_hex = tx_json.get("raw_tx").unwrap().as_str().unwrap();
597599
let tx_bytes = hex_bytes(&tx_hex[2..]).unwrap();
598600
let tx =
599601
StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap();
602+
if tx.is_phantom() {
603+
return None;
604+
}
600605
Some(tx)
601606
})
602607
.collect()

0 commit comments

Comments
 (0)