Closed Jerick26 closed 5 years ago
Is not allowed to transfer token concurrently just as transfer box?
Is not allowed to transfer token concurrently just as transfer box?
Yes, you are allowed, just like box.
You are sending token transfer txs back to back. This error can only happen when you try to send a tx, but the previous tx has not been accepted into mempool. So the utxos u get back still contain ones the previous tx spends. I'm guessing this happens rarely, e.g., when the node is under heavy load. I tried transferring tokens back to back locally, and never had this issue, probably because it's not heavily loaded.
Two solutions:
newTx, err := client.CreateTokenTransferTx(conn, fromAddress, targets,
AddrToAcc[fromAddr].PublicKey(), txHash, 0, AddrToAcc[fromAddr])
if err != nil {
// ----> Do NOT panic here
logger.Panic(err)
}
for j := 0; j < partLen && start+j < times; j++ {
amount := base + uint64(rand.Int63n(int64(base)))
logger.Debugf("sender %s transfer %d token to receiver %s", sender,
amount, receiver)
transferToken(sender, receiver, amount, issueTx, peerAddr)
// ---> WAIT till the tx made into mempool
atomic.AddUint64(&t.txCnt, 1)
atomic.AddUint64(&txAmount, amount)
}
I prefer solution 1. And the above applies to box transfer as well.
Now I do it via a new method to send batch transactions, no error and in a high speed to send transaction which is used in tx tests.
code: