|
|
|
@ -155,6 +155,21 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
isValidCrossShard := true |
|
|
|
|
if isCrossShard { |
|
|
|
|
// Check whether for this shard this cross transaction is valid or not.
|
|
|
|
|
for _, in := range tx.TxInput { |
|
|
|
|
// Only check the input for my own shard.
|
|
|
|
|
if in.ShardId != utxoPool.ShardId { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
inTxID := hex.EncodeToString(in.TxID[:]) |
|
|
|
|
if _, ok := utxoPool.UtxoMap[in.Address][inTxID][in.TxOutputIndex]; !ok { |
|
|
|
|
isValidCrossShard = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
utxoPool.mutex.Lock() |
|
|
|
|
defer utxoPool.mutex.Unlock() |
|
|
|
|
if utxoPool != nil { |
|
|
|
@ -162,6 +177,7 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
|
|
|
|
|
|
// Remove
|
|
|
|
|
if !isUnlockTx { |
|
|
|
|
if isValidCrossShard { |
|
|
|
|
for _, in := range tx.TxInput { |
|
|
|
|
// Only check the input for my own shard.
|
|
|
|
|
if in.ShardId != utxoPool.ShardId { |
|
|
|
@ -186,10 +202,12 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Update
|
|
|
|
|
if !isCrossShard || isUnlockTx { |
|
|
|
|
if !unlockToCommit { |
|
|
|
|
if isValidCrossShard { |
|
|
|
|
// unlock-to-abort, bring back (unlock) the utxo input
|
|
|
|
|
for _, in := range tx.TxInput { |
|
|
|
|
// Only unlock the input for my own shard.
|
|
|
|
@ -211,6 +229,7 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
|
|
|
|
|
|
utxoPool.DeleteOneLockedUtxo(in.Address, inTxID, in.TxOutputIndex) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// normal utxo output update
|
|
|
|
|
for index, out := range tx.TxOutput { |
|
|
|
@ -237,16 +256,9 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
|
// VerifyOneTransactionAndUpdate verifies and update a valid transaction.
|
|
|
|
|
// Return false if the transaction is not valid.
|
|
|
|
|
func (utxoPool *UTXOPool) VerifyOneTransactionAndUpdate(tx *Transaction) bool { |
|
|
|
|
if valid, crossShard := utxoPool.VerifyOneTransaction(tx, nil); valid { |
|
|
|
|
if valid, _ := utxoPool.VerifyOneTransaction(tx, nil); valid { |
|
|
|
|
utxoPool.UpdateOneTransaction(tx) |
|
|
|
|
if crossShard { |
|
|
|
|
// TODO: send proof-of-accceptance
|
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} else if crossShard { |
|
|
|
|
if crossShard { |
|
|
|
|
// TODO: send proof-of-rejection
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|