HyperspaceApp / Hyperspace

Daemon for a blockchain-based storage marketplace
https://hspace.app
MIT License
15 stars 10 forks source link

checkOutput: Throw an error on old spent outputs #35

Open Numerio opened 6 years ago

Numerio commented 6 years ago

Should be the adequate fix for the problem.

huetsch commented 6 years ago

Having reviewed this more, here is the situation they were trying to catch. A wallet spends an output and so the output is present in the spentOutputs database. However, typically, after being spent, the transaction containing the output is confirmed and the wallet will delete the spendable output from the wallet database in updateConfirmedSet. They are trying to handle the situation where a transaction never gets confirmed but has been marked as spent, so they allow us to respend it.

A better solution is to disallow all spent outputs. When each new block comes in, the wallet should:

a) see if we have really old spent outputs that never showed up on the chain and unspend them and b) see if anyone else spent one of our outputs (another wallet using the same seed) and if so, mark the output as spent.

Let's redesign this solution a bit instead of using an ugly hack when we're trying to spend.