Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending transaction with mineNow = false. #32

Open
LeeDark opened this issue Apr 19, 2018 · 5 comments
Open

Sending transaction with mineNow = false. #32

LeeDark opened this issue Apr 19, 2018 · 5 comments

Comments

@LeeDark
Copy link

LeeDark commented Apr 19, 2018

If you try to send transaction with mineNow = false from same wallet (address) 2 times, you got 2 transactions with same transaction hash, because NewUTXOTransaction will create identical Transaction structs.
My solution works with adding some salt:

// Hash returns the hash of the Transaction
func (tx *Transaction) Hash() []byte {
	var hash [32]byte

	txCopy := *tx
	txCopy.ID = []byte{}

	salt := make([]byte, 32)
	_, err := io.ReadFull(rand.Reader, salt)
	if err != nil {
		fmt.Printf("ERROR: Creating salt failed: %s\n", err)
	}

	data := txCopy.Serialize()
	data = append(data, salt...)

	hash = sha256.Sum256(data)

	return hash[:]
}
@LeeDark
Copy link
Author

LeeDark commented Apr 19, 2018

Also this case creates block with 2 transactions (after I fixed Hash() function), but the second one didnt change Sender output Value.
For example Sender had 1000 coins, Receiver had 0 coins. After sending 100 coins two times first transaction will decrease Sender output Value to 900, and increase Receiver output Value to 100, and second transaction will decrease Sender output Value to 900, and increase Receiver output Value to 100, but must be like this: will decrease Sender output Value to 800, and increase Receiver output Value to 200.
Have you an idea how to fix it? I think it is MineBlock() function issue or handleTx() function issue.

@fe1t
Copy link

fe1t commented Apr 20, 2018

I'm stuck at this problem too.
If you manage to solve the problem, you can also fix this issue automatically #23.

@LeeDark
Copy link
Author

LeeDark commented Apr 23, 2018

@fe1t Yes, I will investigate the core of this problem. I did not fork this repo, I created my own repo based on this tutorial with my features. So perhaps, I will fork this repo and create PRs.

@LeeDark
Copy link
Author

LeeDark commented Apr 23, 2018

@fe1t I will add Timestamp field to Transaction. Then I will fix handleTx() in case if len(mempool) >= 2. I think that we should recheck transactions (txs) that were created before by some algorithm.

@LeeDark
Copy link
Author

LeeDark commented Apr 23, 2018

@fe1t Unfortunately this bug is huge, we should also fix Sign/Verify when rechecking transactions, also we cant Find or Verify transaction before adding block with them, because they are not present in the blockchain. So now I just fix len(mempool) >= 1, but it is workaround just for simple testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants