Skip to content

Commit

Permalink
Merge pull request #5635 from stacks-network/fix/check-nakamoto-empty…
Browse files Browse the repository at this point in the history
…-block-heuristics

Filter out phantom txs from test_observer::parse_transaction fn
  • Loading branch information
jferrant authored Jan 3, 2025
2 parents 41c74fa + 5e31343 commit 5f33fd9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions stackslib/src/chainstate/stacks/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::chainstate::stacks::{TransactionPayloadID, *};
use crate::codec::Error as CodecError;
use crate::core::*;
use crate::net::Error as net_error;
use crate::util_lib::boot::boot_code_addr;

impl StacksMessageCodec for TransactionContractCall {
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
Expand Down Expand Up @@ -1031,6 +1032,16 @@ impl StacksTransaction {
_ => false,
}
}

/// Is this a phantom transaction?
pub fn is_phantom(&self) -> bool {
let boot_address = boot_code_addr(self.is_mainnet()).into();
if let TransactionPayload::TokenTransfer(address, amount, _) = &self.payload {
*address == boot_address && *amount == 0
} else {
false
}
}
}

impl StacksTransactionSigner {
Expand Down
7 changes: 6 additions & 1 deletion testnet/stacks-node/src/tests/neon_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ pub mod test_observer {
PROPOSAL_RESPONSES.lock().unwrap().clear();
}

/// Parse the StacksTransactions from a block (does not include burn ops)
/// Parse the StacksTransactions from a block (does not include burn ops or phantom txs)
/// panics on any failures to parse
pub fn parse_transactions(block: &serde_json::Value) -> Vec<StacksTransaction> {
block
Expand All @@ -588,15 +588,20 @@ pub mod test_observer {
.unwrap()
.iter()
.filter_map(|tx_json| {
// Filter out burn ops
if let Some(burnchain_op_val) = tx_json.get("burnchain_op") {
if !burnchain_op_val.is_null() {
return None;
}
}
// Filter out phantom txs
let tx_hex = tx_json.get("raw_tx").unwrap().as_str().unwrap();
let tx_bytes = hex_bytes(&tx_hex[2..]).unwrap();
let tx =
StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap();
if tx.is_phantom() {
return None;
}
Some(tx)
})
.collect()
Expand Down

0 comments on commit 5f33fd9

Please sign in to comment.