You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was able to reproduce the issue locally by altering the wallet.dat file specifically in the part that stores wallet transaction states.
To reproduce it on demand I created a patch that intentionally corrupted the wallet.dat file by randomly Serializing transactions as "Inactive" but they were confirmed:
diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h
index 29baf6695a..b3ff344ee1 100644
--- a/src/wallet/transaction.h
+++ b/src/wallet/transaction.h
@@ -300,12 +300,20 @@ public:
uint32_t dummy_int = 0; // Used to be fTimeReceivedIsTxTime
uint256 serializedHash = TxStateSerializedBlockHash(m_state);
int serializedIndex = TxStateSerializedIndex(m_state);
if (rand() % 5 == 0)
{
std::cout<< "[ljeffrey]: "<<"Corrupting state on transaction "<<tx->GetHash().ToString()<<std::endl;
// Sera que el problema es que no estoy revalidando aca la transaccion?
Init();
std::vector<uint256> dummy_vector1; // Used to be vMerkleBranch
The root issue is not in the abandonTransaction call itself but is that the wallet is blindly trusting the transactions status in the wallet.dat file, and it's not double checking them after recovering from a file. As conclusion, a carefully corrupted wallet.dat file can crash a bitcoin-core node. The wallet should rescan transactions and double-check them.
I will create a pr on this week trying to solve this problem
This appears to be caused by a very unlucky race that occurs during loading.
The crash requires an unclean shutdown and a parent transaction that ends up with an Inactive state, and a child that ends up with a Confirmed state. When the node restarts after the unclean shutdown, it's chainstate is behind where the wallet last recorded it's tip. As the wallet loads transactions, it will check to see whether Confirmed transactions are still confirmed according to the node's current chain state. If the confirming block is not yet in the chain, the transaction will be reset to Inactive. This is how the parent becomes Inactive.
As the wallet continues loading, the chain is also advancing. The issue is that when the wallet starts AttachChain, the chain may have advanced past the block confirming the parent transaction. When AttachChain finishes connecting the signals and doing rescans, it does so from the current tip at the time that AttachChain starts. When the child transaction is confirmed in a block that is processed after AttachChain, it's status becomes Confirmed. Crucially, some blocks that were reprocessed end up being missed, so the parent transaction's state is never corrected.
When abandontransaction is called on the parent transaction, it finds that it is allowed to be abandoned because it's state is Inactive. Since abandoning also abandons all of the children, it will attempt to abandon the child transaction, but then run into the assertion because the state of the child is Confirmed.
The solution is to fix this state updating during loading that is missing blocks. The assertion is correct as it enforces the invariants for abandoning transactions.
Unfortunately I don't know how to write a functional test that can exercise this case, and I don't think a unit test would be sufficient. I have some ideas on the fix though.
Activity
[-]wallet: Assertion `!wtx.isConfirmed()' failed[/-][+]wallet: Assertion `!wtx.isConfirmed()` failed[/+]wallet: fix abandon crash on inconsistent state
tony-ku commentedon Apr 19, 2026
Opened a fix in #35115.
Luquitasjeffrey commentedon Apr 21, 2026
I was able to reproduce the issue locally by altering the wallet.dat file specifically in the part that stores wallet transaction states.
To reproduce it on demand I created a patch that intentionally corrupted the wallet.dat file by randomly Serializing transactions as "Inactive" but they were confirmed:
diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h
index 29baf6695a..b3ff344ee1 100644
--- a/src/wallet/transaction.h
+++ b/src/wallet/transaction.h
@@ -300,12 +300,20 @@ public:
uint32_t dummy_int = 0; // Used to be fTimeReceivedIsTxTime
uint256 serializedHash = TxStateSerializedBlockHash(m_state);
int serializedIndex = TxStateSerializedIndex(m_state);
}
template
void Unserialize(Stream& s)
{
The root issue is not in the abandonTransaction call itself but is that the wallet is blindly trusting the transactions status in the wallet.dat file, and it's not double checking them after recovering from a file. As conclusion, a carefully corrupted wallet.dat file can crash a bitcoin-core node. The wallet should rescan transactions and double-check them.
I will create a pr on this week trying to solve this problem
Luquitasjeffrey commentedon Apr 22, 2026
I was able to create an unit test that reproduces the bug without touching the wallet internal state, it touches only the wallet database.
Currently working on this branch: https://github.com/Luquitasjeffrey/bitcoin/tree/issue34599
achow101 commentedon May 14, 2026
This appears to be caused by a very unlucky race that occurs during loading.
The crash requires an unclean shutdown and a parent transaction that ends up with an Inactive state, and a child that ends up with a Confirmed state. When the node restarts after the unclean shutdown, it's chainstate is behind where the wallet last recorded it's tip. As the wallet loads transactions, it will check to see whether Confirmed transactions are still confirmed according to the node's current chain state. If the confirming block is not yet in the chain, the transaction will be reset to Inactive. This is how the parent becomes Inactive.
As the wallet continues loading, the chain is also advancing. The issue is that when the wallet starts
AttachChain, the chain may have advanced past the block confirming the parent transaction. WhenAttachChainfinishes connecting the signals and doing rescans, it does so from the current tip at the time thatAttachChainstarts. When the child transaction is confirmed in a block that is processed afterAttachChain, it's status becomes Confirmed. Crucially, some blocks that were reprocessed end up being missed, so the parent transaction's state is never corrected.When
abandontransactionis called on the parent transaction, it finds that it is allowed to be abandoned because it's state is Inactive. Since abandoning also abandons all of the children, it will attempt to abandon the child transaction, but then run into the assertion because the state of the child is Confirmed.The solution is to fix this state updating during loading that is missing blocks. The assertion is correct as it enforces the invariants for abandoning transactions.
Unfortunately I don't know how to write a functional test that can exercise this case, and I don't think a unit test would be sufficient. I have some ideas on the fix though.
Edit: I have a test
achow101 commentedon May 15, 2026
#35294 should be the fix. @dergoegge can you try that in antithesis?
dergoegge commentedon May 18, 2026
Yes, but I'll wait for the CI to be green first