From 41921b9b4de41d5f306fdb335e6f9dd2d3beacd3 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 19 Dec 2024 12:33:30 -0700 Subject: [PATCH] fix: include block height in phantom tx memo for unique txids --- stackslib/src/chainstate/nakamoto/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stackslib/src/chainstate/nakamoto/mod.rs b/stackslib/src/chainstate/nakamoto/mod.rs index 7be4b2d89b..0694edf7a0 100644 --- a/stackslib/src/chainstate/nakamoto/mod.rs +++ b/stackslib/src/chainstate/nakamoto/mod.rs @@ -2156,6 +2156,7 @@ impl NakamotoChainState { Self::generate_phantom_unlock_tx( phantom_unlock_events, &stacks_chain_state.config(), + next_ready_block.header.chain_length, ) { tx_receipts.push(unlock_receipt); @@ -4920,6 +4921,7 @@ impl NakamotoChainState { fn generate_phantom_unlock_tx( events: Vec, config: &ChainstateConfig, + stacks_block_height: u64, ) -> Option { if events.is_empty() { return None; @@ -4930,6 +4932,16 @@ impl NakamotoChainState { } else { TransactionVersion::Testnet }; + + // Make the txid unique -- the phantom tx payload should include something block-specific otherwise + // they will always have the same txid. In this case we use the block height in the memo. This also + // happens to give some indication of the purpose of this phantom tx, for anyone looking. + let memo = TokenTransferMemo({ + let str = format!("Block {} token unlocks", stacks_block_height); + let mut buf = [0u8; 34]; + buf[..str.len().min(34)].copy_from_slice(&str.as_bytes()[..]); + buf + }); let boot_code_address = boot_code_addr(config.mainnet); let boot_code_auth = boot_code_tx_auth(boot_code_address.clone()); let unlock_tx = StacksTransaction::new( @@ -4938,7 +4950,7 @@ impl NakamotoChainState { TransactionPayload::TokenTransfer( PrincipalData::Standard(boot_code_address.into()), 0, - TokenTransferMemo([0u8; 34]), + memo, ), ); let unlock_receipt = StacksTransactionReceipt::from_stx_transfer(