wallet/wallet: remove invalid transactions when broadcast fails #597
In this commit, we rework how
We do this in order to be able to reuse the new publishTransaction method within other parts of the wallet in order to consolidate all error string-matching within one place.
In this commit, we rework how publishTransaction works in order to correctly handle removing invalid transactions from the wallet's unconfirmed transaction store. This is crucial as otherwise, invalid transactions can remain within the wallet and be used for further transactions, causing a chain of inaccurate transactions. publishTransaction will now only return an error if the transaction fails to be broadcast and it has not been previously seen in the mempool/chain. This is intended in order to provide an easier API to callers. Any other errors when broadcasting the transaction will cause it to be removed from the wallet's unconfirmed transaction store to ensure it maintains an accurate view of the chain.
By doing this, we defer all error string-matching to happen within publishTransaction, which allows us to simplify some of the existing logic and maintain consistency.
Roasbeef left a comment
Nice work tracking this down! My only gripe is that I'd like to be able to test this more extensively, but doing so would require a more integrated testing harness for the wallet. However, we might be able to create something minimal using the existing