Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out phantom txs from test_observer::parse_transaction fn #5635

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading