blockchain_go
blockchain_go copied to clipboard
How to make transaction id unique?
I'm reading part 4, and I think if txid
is not unique for this tutorial. Txid
should be unique for blockchain. Otherwise, you can't lookup each transaction by txid
.
The logic to generate txid
. It generates the same id for newly mined coin
:
https://github.com/Jeiwan/blockchain_go/blob/e17722eb18caa7618dee298da677a9f5667a0513/transaction.go#L64-L72
the FindUnspentTransactions would go wrong:
https://github.com/Jeiwan/blockchain_go/blob/e17722eb18caa7618dee298da677a9f5667a0513/blockchain.go#L78-L82
for example, could you mine 2 new coins with duplicated txid
by calling NewCoinbaseTX("same_miner", "")
Then one coin could be used and the other is not. The above FindUnspentTransactions
logic can't distinguish those 2 coins.
Even if you add rand
in part 6, it still has a chance of colliding.
https://github.com/Jeiwan/blockchain_go/blob/0538111918aad7d18f2b71b19f8ad0dec186e6db/transaction.go#L174-L188
Any suggestion to make sure that the txid
is unique?
您好,邮件已查收。Anmi、