Skip to content

Commit 41921b9

Browse files
committed
fix: include block height in phantom tx memo for unique txids
1 parent 29baa89 commit 41921b9

File tree

1 file changed

+13
-1
lines changed
  • stackslib/src/chainstate/nakamoto

1 file changed

+13
-1
lines changed

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,7 @@ impl NakamotoChainState {
21562156
Self::generate_phantom_unlock_tx(
21572157
phantom_unlock_events,
21582158
&stacks_chain_state.config(),
2159+
next_ready_block.header.chain_length,
21592160
)
21602161
{
21612162
tx_receipts.push(unlock_receipt);
@@ -4920,6 +4921,7 @@ impl NakamotoChainState {
49204921
fn generate_phantom_unlock_tx(
49214922
events: Vec<StacksTransactionEvent>,
49224923
config: &ChainstateConfig,
4924+
stacks_block_height: u64,
49234925
) -> Option<StacksTransactionReceipt> {
49244926
if events.is_empty() {
49254927
return None;
@@ -4930,6 +4932,16 @@ impl NakamotoChainState {
49304932
} else {
49314933
TransactionVersion::Testnet
49324934
};
4935+
4936+
// Make the txid unique -- the phantom tx payload should include something block-specific otherwise
4937+
// they will always have the same txid. In this case we use the block height in the memo. This also
4938+
// happens to give some indication of the purpose of this phantom tx, for anyone looking.
4939+
let memo = TokenTransferMemo({
4940+
let str = format!("Block {} token unlocks", stacks_block_height);
4941+
let mut buf = [0u8; 34];
4942+
buf[..str.len().min(34)].copy_from_slice(&str.as_bytes()[..]);
4943+
buf
4944+
});
49334945
let boot_code_address = boot_code_addr(config.mainnet);
49344946
let boot_code_auth = boot_code_tx_auth(boot_code_address.clone());
49354947
let unlock_tx = StacksTransaction::new(
@@ -4938,7 +4950,7 @@ impl NakamotoChainState {
49384950
TransactionPayload::TokenTransfer(
49394951
PrincipalData::Standard(boot_code_address.into()),
49404952
0,
4941-
TokenTransferMemo([0u8; 34]),
4953+
memo,
49424954
),
49434955
);
49444956
let unlock_receipt = StacksTransactionReceipt::from_stx_transfer(

0 commit comments

Comments
 (0)