|
|
@ -57,13 +57,13 @@ func (utxoPool *UTXOPool) VerifyOneTransaction(tx *Transaction, spentTXOs *map[s |
|
|
|
// Calculate the sum of TxInput
|
|
|
|
// Calculate the sum of TxInput
|
|
|
|
for _, in := range tx.TxInput { |
|
|
|
for _, in := range tx.TxInput { |
|
|
|
// Only check the input for my own shard.
|
|
|
|
// Only check the input for my own shard.
|
|
|
|
if in.ShardId != utxoPool.ShardId { |
|
|
|
if in.ShardID != utxoPool.ShardId { |
|
|
|
crossShard = true |
|
|
|
crossShard = true |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inTxID := hex.EncodeToString(in.TxID[:]) |
|
|
|
inTxID := hex.EncodeToString(in.PreviousOutPoint.Hash[:]) |
|
|
|
index := in.TxOutputIndex |
|
|
|
index := in.PreviousOutPoint.Index |
|
|
|
// Check if the transaction with the addres is spent or not.
|
|
|
|
// Check if the transaction with the addres is spent or not.
|
|
|
|
if val, ok := (*spentTXOs)[in.Address][inTxID][index]; ok { |
|
|
|
if val, ok := (*spentTXOs)[in.Address][inTxID][index]; ok { |
|
|
|
if val { |
|
|
|
if val { |
|
|
@ -150,7 +150,7 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
isCrossShard := false |
|
|
|
isCrossShard := false |
|
|
|
// check whether it's a cross shard tx.
|
|
|
|
// check whether it's a cross shard tx.
|
|
|
|
for _, in := range tx.TxInput { |
|
|
|
for _, in := range tx.TxInput { |
|
|
|
if in.ShardId != utxoPool.ShardId { |
|
|
|
if in.ShardID != utxoPool.ShardId { |
|
|
|
isCrossShard = true |
|
|
|
isCrossShard = true |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
@ -161,11 +161,11 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
// Check whether for this shard this cross transaction is valid or not.
|
|
|
|
// Check whether for this shard this cross transaction is valid or not.
|
|
|
|
for _, in := range tx.TxInput { |
|
|
|
for _, in := range tx.TxInput { |
|
|
|
// Only check the input for my own shard.
|
|
|
|
// Only check the input for my own shard.
|
|
|
|
if in.ShardId != utxoPool.ShardId { |
|
|
|
if in.ShardID != utxoPool.ShardId { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
inTxID := hex.EncodeToString(in.TxID[:]) |
|
|
|
inTxID := hex.EncodeToString(in.PreviousOutPoint.Hash[:]) |
|
|
|
if _, ok := utxoPool.UtxoMap[in.Address][inTxID][in.TxOutputIndex]; !ok { |
|
|
|
if _, ok := utxoPool.UtxoMap[in.Address][inTxID][in.PreviousOutPoint.Index]; !ok { |
|
|
|
isValidCrossShard = false |
|
|
|
isValidCrossShard = false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -181,17 +181,17 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
if isValidCrossShard { |
|
|
|
if isValidCrossShard { |
|
|
|
for _, in := range tx.TxInput { |
|
|
|
for _, in := range tx.TxInput { |
|
|
|
// Only check the input for my own shard.
|
|
|
|
// Only check the input for my own shard.
|
|
|
|
if in.ShardId != utxoPool.ShardId { |
|
|
|
if in.ShardID != utxoPool.ShardId { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NOTE: for the locking phase of cross tx, the utxo is simply removed from the pool.
|
|
|
|
// NOTE: for the locking phase of cross tx, the utxo is simply removed from the pool.
|
|
|
|
inTxID := hex.EncodeToString(in.TxID[:]) |
|
|
|
inTxID := hex.EncodeToString(in.PreviousOutPoint.Hash[:]) |
|
|
|
value := utxoPool.UtxoMap[in.Address][inTxID][in.TxOutputIndex] |
|
|
|
value := utxoPool.UtxoMap[in.Address][inTxID][in.PreviousOutPoint.Index] |
|
|
|
utxoPool.DeleteOneUtxo(in.Address, inTxID, in.TxOutputIndex) |
|
|
|
utxoPool.DeleteOneUtxo(in.Address, inTxID, in.PreviousOutPoint.Index) |
|
|
|
if isCrossShard { |
|
|
|
if isCrossShard { |
|
|
|
// put the delete (locked) utxo into a separate locked utxo pool
|
|
|
|
// put the delete (locked) utxo into a separate locked utxo pool
|
|
|
|
inTxID := hex.EncodeToString(in.TxID[:]) |
|
|
|
inTxID := hex.EncodeToString(in.PreviousOutPoint.Hash[:]) |
|
|
|
if _, ok := utxoPool.LockedUtxoMap[in.Address]; !ok { |
|
|
|
if _, ok := utxoPool.LockedUtxoMap[in.Address]; !ok { |
|
|
|
utxoPool.LockedUtxoMap[in.Address] = make(map[string]map[int]int) |
|
|
|
utxoPool.LockedUtxoMap[in.Address] = make(map[string]map[int]int) |
|
|
|
utxoPool.LockedUtxoMap[in.Address][inTxID] = make(map[int]int) |
|
|
|
utxoPool.LockedUtxoMap[in.Address][inTxID] = make(map[int]int) |
|
|
@ -199,7 +199,7 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
if _, ok := utxoPool.LockedUtxoMap[in.Address][inTxID]; !ok { |
|
|
|
if _, ok := utxoPool.LockedUtxoMap[in.Address][inTxID]; !ok { |
|
|
|
utxoPool.LockedUtxoMap[in.Address][inTxID] = make(map[int]int) |
|
|
|
utxoPool.LockedUtxoMap[in.Address][inTxID] = make(map[int]int) |
|
|
|
} |
|
|
|
} |
|
|
|
utxoPool.LockedUtxoMap[in.Address][inTxID][in.TxOutputIndex] = value |
|
|
|
utxoPool.LockedUtxoMap[in.Address][inTxID][in.PreviousOutPoint.Index] = value |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -212,12 +212,12 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
// unlock-to-abort, bring back (unlock) the utxo input
|
|
|
|
// unlock-to-abort, bring back (unlock) the utxo input
|
|
|
|
for _, in := range tx.TxInput { |
|
|
|
for _, in := range tx.TxInput { |
|
|
|
// Only unlock the input for my own shard.
|
|
|
|
// Only unlock the input for my own shard.
|
|
|
|
if in.ShardId != utxoPool.ShardId { |
|
|
|
if in.ShardID != utxoPool.ShardId { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Simply bring back the locked (removed) utxo
|
|
|
|
// Simply bring back the locked (removed) utxo
|
|
|
|
inTxID := hex.EncodeToString(in.TxID[:]) |
|
|
|
inTxID := hex.EncodeToString(in.PreviousOutPoint.Hash[:]) |
|
|
|
if _, ok := utxoPool.UtxoMap[in.Address]; !ok { |
|
|
|
if _, ok := utxoPool.UtxoMap[in.Address]; !ok { |
|
|
|
utxoPool.UtxoMap[in.Address] = make(map[string]map[int]int) |
|
|
|
utxoPool.UtxoMap[in.Address] = make(map[string]map[int]int) |
|
|
|
utxoPool.UtxoMap[in.Address][inTxID] = make(map[int]int) |
|
|
|
utxoPool.UtxoMap[in.Address][inTxID] = make(map[int]int) |
|
|
@ -225,10 +225,10 @@ func (utxoPool *UTXOPool) UpdateOneTransaction(tx *Transaction) { |
|
|
|
if _, ok := utxoPool.UtxoMap[in.Address][inTxID]; !ok { |
|
|
|
if _, ok := utxoPool.UtxoMap[in.Address][inTxID]; !ok { |
|
|
|
utxoPool.UtxoMap[in.Address][inTxID] = make(map[int]int) |
|
|
|
utxoPool.UtxoMap[in.Address][inTxID] = make(map[int]int) |
|
|
|
} |
|
|
|
} |
|
|
|
value := utxoPool.LockedUtxoMap[in.Address][inTxID][in.TxOutputIndex] |
|
|
|
value := utxoPool.LockedUtxoMap[in.Address][inTxID][in.PreviousOutPoint.Index] |
|
|
|
utxoPool.UtxoMap[in.Address][inTxID][in.TxOutputIndex] = value |
|
|
|
utxoPool.UtxoMap[in.Address][inTxID][in.PreviousOutPoint.Index] = value |
|
|
|
|
|
|
|
|
|
|
|
utxoPool.DeleteOneLockedUtxo(in.Address, inTxID, in.TxOutputIndex) |
|
|
|
utxoPool.DeleteOneLockedUtxo(in.Address, inTxID, in.PreviousOutPoint.Index) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -319,10 +319,10 @@ func (utxoPool *UTXOPool) SelectTransactionsForNewBlock(transactions []*Transact |
|
|
|
return selected, unselected, crossShardTxs |
|
|
|
return selected, unselected, crossShardTxs |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getShardTxInput(transaction *Transaction, shardId uint32) []TXInput { |
|
|
|
func getShardTxInput(transaction *Transaction, shardID uint32) []TXInput { |
|
|
|
result := []TXInput{} |
|
|
|
result := []TXInput{} |
|
|
|
for _, txInput := range transaction.TxInput { |
|
|
|
for _, txInput := range transaction.TxInput { |
|
|
|
if txInput.ShardId == shardId { |
|
|
|
if txInput.ShardID == shardID { |
|
|
|
result = append(result, txInput) |
|
|
|
result = append(result, txInput) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|