threefoldtecharchive / rivine

Blockchain technology for creating custom chains.
Apache License 2.0
22 stars 12 forks source link

consensus conflict: transaction spends a nonexisting coin output #454

Open robvanmieghem opened 6 years ago

robvanmieghem commented 6 years ago
./tfchainc  wallet send coins 01ffffbd36a9d6c995a82c8e34d53cf9cbb13b2c55bed3fcc0020d9c0ff682cd8d45d2f41acbeb 1000
Succesfully sent coins as transaction 34ecaeb49be54ea5be239901d0cdbe2d8c576fdcb9e8fcc3fb18fccdfe2d57ce
Sent 1000 TFT to 01ffffbd36a9d6c995a82c8e34d53cf9cbb13b2c55bed3fcc0020d9c0ff682cd8d45d2f41acbeb (using ConditionType 1)
MacBook-Pro-783:tfchainc rob$ ./tfchainc  wallet send coins 01ffffbd36a9d6c995a82c8e34d53cf9cbb13b2c55bed3fcc0020d9c0ff682cd8d45d2f41acbeb 1000
Could not send coins: HTTP 500 error: error after call to /wallet/coins: consensus conflict: transaction spends a nonexisting coin output
MacBook-Pro-783:tfchainc rob$ ./tfchainc  wallet send coins 01ffffbd36a9d6c995a82c8e34d53cf9cbb13b2c55bed3fcc0020d9c0ff682cd8d45d2f41acbeb 1000
Could not send coins: HTTP 500 error: error after call to /wallet/coins: consensus conflict: transaction spends a nonexisting coin output

git describe v1.1.0

GlenDC commented 6 years ago

That error can only be returned in case it tries to spend a coin output that could no longer be found in the consensus set. Meaning that it never existed, or more likely that it was already spend. So the bug is probably in the wallet module, which somehow tries (or tried) to spend a coin output that was already spend.

It doesn't help that we do not log the coin output ID and that kind of information in case of such an error though. For now going to read through that logic, to see if I can spot something weird just by reading.

GlenDC commented 6 years ago

The TxBuilder (which is what you use when sending that command) has 3 properties it uses of the wallet, that are relevant to how it auto-funds the coins you are about to send:

Fairly sure (2) is the reason why you are getting this error. But need to understand that part a bit more, as that code was originally from Sia, and it's been a while since I saw it.

GlenDC commented 6 years ago

Didn't state it explicitly, but (1) coinOutputs is fine as is. A coin output (diff) is reverted not only when the block that added the coin output is reverted, but also when it is used as a coin input. And thus, that mapping of the Wallet will be up to date with the available.

Stating this explicitly, I wonder even more what the purpose of (2) spentOutputs is for confirmed outputs.

GlenDC commented 6 years ago

Fairly sure (2) is the reason why you are getting this error. But need to understand that part a bit more, as that code was originally from Sia, and it's been a while since I saw it.

Nevermind, looking further into this, I do not think it can be your issue. It only is used to ensure we do not spend an output too quickly again. However as the outputs can only come from the unspent coin outputs and unconfirmed txs, and the wallet of @robvanmieghem had no unconfirmed txs, it cannot have caused an issue in any way.

GlenDC commented 6 years ago

I am stuck, however quoting myself from earlier:

That error can only be returned in case it tries to spend a coin output that could no longer be found in the consensus set. Meaning that it never existed, or more likely that it was already spend.

There are 2 possibilities as I see it:

Going to add a log statement, so that we can know what coin output is being spend while this happens. This way we at least have more of an idea to know where to start looking, in case it happens.

GlenDC commented 6 years ago

Rivine has the extra logging info, and tfchain has latest master of rivine as well. When you encounter this error again @robvanmieghem:

I'll assume you try with a tfchain CLI client on testnet, but if not, please do tell me as well.