Two points for CWallet::CommitTransaction
:
-
The extra wtx lookup: As we are calling to
AddToWallet
first, which returns the recently added/updated wtx pointer, there is no need to look up the wtx again few lines later. We can just use it. -
The db write error:
AddToWallet
can only return a nullptr if the db write fails, which insideCommitTransaction
translates to an exception throw cause. We expect everywhere thatCommitTransaction
always succeed.
Extra note:
This finding generated another working path for me :)
It starts with the following question: why are we returning a nullptr from AddToWallet
if the db write failed without removing the recently added transaction from the wallet’s map?..
Can led to a wallet invalid state where the inputs of this new transaction are not marked dirty, while the transaction that spends them still exist on the in-memory wallet tx map.
– I’m writing it here to gather some feedback first and not forget it, will create a follow-up PR in the coming days 🚜 –