Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: BradZimdack on November 15, 2012, 12:48:04 AM



Title: Cancel Invalid Raw Transaction
Post by: BradZimdack on November 15, 2012, 12:48:04 AM
Let's suppose I create, sign, and send a raw transaction but I fail to give it enough in fees to be relayed (let's say it's for a small amount that would require at least 0.0005).  This bad tx will now be stuck in my memory pool.  If I use the command "getrawmempool", I'll see the txid for my transaction that will never be relayed and my client will think the inputs for that transaction have been spent.  Basically, those inputs will be "stuck".  I won't even be able to make a new raw transaction that spends those same inputs with a higher fee because the client thinks they've been spent and it will reject any attempt to send a new raw tx that uses them.

Is there some way I can remove or cancel a poorly crafted raw transaction to unfreeze its inputs?


Title: Re: Cancel Invalid Raw Transaction
Post by: Stephen Gornick on November 15, 2012, 01:12:49 AM
Is there some way I can remove or cancel a poorly crafted raw transaction

You can perform wallet surgery to remove a transaction so that the client will not attempt to re-broadcast it.  Pywallet gives a delete transaction option.

to unfreeze its inputs?

If the transaction did get relayed by other nodes, your client will probably discover that transaction and thus those inputs will again be locked.  But eventually this transaction will get included in a block.

You can check Blockchain.info to see if your transaction was relayed to a node that they listen to.
 - http://www.Blockchain.info

There are free relay nodes which will relay your transaction regardless of whether or not a fee was paid.
 - https://en.bitcoin.it/wiki/Free_transaction_relay_policy

The right solution is the "child pays for parent", in which another transaction can be made (by the recipient of the transaction) and the fee paid in the second transaction will help cause the "parent" to be included in a block as well.  This is not yet available in a Bitcoin release.
 - https://github.com/bitcoin/bitcoin/pull/1647


Title: Re: Cancel Invalid Raw Transaction
Post by: DeathAndTaxes on November 15, 2012, 01:14:45 AM
Not easily.  You can use tool like pywallet to delete the "bad" tx.  If you are going to "play" around with raw tx I would recommend backing up your wallet frequently.   If you have a recent backup you can simply restore from a backup prior to when you added the defective tx to the memory pool.  WARNING: irrecoverable loss of funds could occur if you backup is old enough to not include all keys in your current keypool. Backup your current "broken" wallet before EITHER using pywallet tool or restoring from a previous backup.

To answer your next questions (I already know what it is ;) ...  Yes
"Shouldn't there be an easier way to cancel tx which haven't been included in a block?  At least for power users from the command-line?"


Title: Re: Cancel Invalid Raw Transaction
Post by: MoonShadow on November 15, 2012, 01:22:04 AM
If it was a valid transaction, then it will be relayed regardless of how much of a transaction fee you provided for it.  If it's invalid, you would have had to use some low level command tools to create it, because your client wouldn't do it.

Even if you sent it without any fee whatever, it will eventually make it into a block.

Time-locked (and thus retractable) transactions are part of the scripted transaction set, but are not presently honored by the network.  Those will come someday.


Title: Re: Cancel Invalid Raw Transaction
Post by: BradZimdack on November 15, 2012, 01:24:08 AM
Thanks.  I'll check out pywallet and hope to avoid situations like these.

(It looks like it's also possible to create stuck coins with a tx that accidentally tries to double spend an input.)


Title: Re: Cancel Invalid Raw Transaction
Post by: MoonShadow on November 15, 2012, 01:26:01 AM
Thanks.  I'll check out pywallet and hope to avoid situations like these.

(It looks like it's also possible to create stuck coins with a tx that accidentally tries to double spend an input.)

Ah, yeah.  That's one of those 'invalid' conditions I was talking about.  What were you doing, coding the transaction by hand?


Title: Re: Cancel Invalid Raw Transaction
Post by: BradZimdack on November 15, 2012, 01:43:15 AM
What were you doing, coding the transaction by hand?

Yes, I was.  I was using listunspent to find available inputs, then using those to create raw transactions.  Somehow, I was shown unspents that had actually been spent an hour earlier.  I think it may have been due to an odd combination of factors including switching out wallet files, a big time gap between blocks, and difficulty establishing more than 2-3 connections to other nodes.  I can't fully explain how it happened, but being blighted with a broken transaction appears to be my punishment.