From 6b3083a6d224d0aeb659f45bb6fd41ed8bfcd0ad Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Wed, 19 Sep 2018 15:07:49 -0700 Subject: [PATCH] Make cross-shard tx 2 times more complex than single shard tx --- client/txgen/main.go | 66 ++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/client/txgen/main.go b/client/txgen/main.go index 1920631d1..b709419d7 100644 --- a/client/txgen/main.go +++ b/client/txgen/main.go @@ -155,51 +155,51 @@ func generateCrossShardTx(txInfo *TxInfo) { } } - crossShardNode := txInfo.dataNodes[crossShardId] - crossShardUtxosMap := crossShardNode.UtxoPool.UtxoMap[txInfo.address] - - // Get the cross shard utxo from another shard - var crossTxin *blockchain.TXInput - crossUtxoValue := 0 - // Loop over utxos for the same address from the other shard and use the first utxo as the second cross tx input - for crossTxIdStr, crossShardUtxos := range crossShardUtxosMap { - // Parse TxId - id, err := hex.DecodeString(crossTxIdStr) - if err != nil { - continue - } - crossTxId := [32]byte{} - copy(crossTxId[:], id[:]) - - for crossShardIndex, crossShardValue := range crossShardUtxos { - crossUtxoValue = crossShardValue - crossTxin = blockchain.NewTXInput(blockchain.NewOutPoint(&crossTxId, crossShardIndex), txInfo.address, crossShardId) - break - } - if crossTxin != nil { - break - } - } + //crossShardNode := txInfo.dataNodes[crossShardId] + //crossShardUtxosMap := crossShardNode.UtxoPool.UtxoMap[txInfo.address] + // + //// Get the cross shard utxo from another shard + //var crossTxin *blockchain.TXInput + //crossUtxoValue := 0 + //// Loop over utxos for the same address from the other shard and use the first utxo as the second cross tx input + //for crossTxIdStr, crossShardUtxos := range crossShardUtxosMap { + // // Parse TxId + // id, err := hex.DecodeString(crossTxIdStr) + // if err != nil { + // continue + // } + // crossTxId := [32]byte{} + // copy(crossTxId[:], id[:]) + // + // for crossShardIndex, crossShardValue := range crossShardUtxos { + // crossUtxoValue = crossShardValue + // crossTxin = blockchain.NewTXInput(blockchain.NewOutPoint(&crossTxId, crossShardIndex), txInfo.address, crossShardId) + // break + // } + // if crossTxin != nil { + // break + // } + //} // Add the utxo from current shard txIn := blockchain.NewTXInput(blockchain.NewOutPoint(&txInfo.id, txInfo.index), txInfo.address, nodeShardID) txInputs := []blockchain.TXInput{*txIn} // Add the utxo from the other shard, if any - if crossTxin != nil { // This means the ratio of cross shard tx could be lower than 1/3 - txInputs = append(txInputs, *crossTxin) - } + //if crossTxin != nil { // This means the ratio of cross shard tx could be lower than 1/3 + // txInputs = append(txInputs, *crossTxin) + //} // Spend the utxo from the current shard to a random address in [0 - N) - txout := blockchain.TXOutput{Amount: txInfo.value, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: nodeShardID} + txout := blockchain.TXOutput{Amount: txInfo.value, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: crossShardId} txOutputs := []blockchain.TXOutput{txout} // Spend the utxo from the other shard, if any, to a random address in [0 - N) - if crossTxin != nil { - crossTxout := blockchain.TXOutput{Amount: crossUtxoValue, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: crossShardId} - txOutputs = append(txOutputs, crossTxout) - } + //if crossTxin != nil { + // crossTxout := blockchain.TXOutput{Amount: crossUtxoValue, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: crossShardId} + // txOutputs = append(txOutputs, crossTxout) + //} // Construct the new transaction tx := blockchain.Transaction{ID: [32]byte{}, TxInput: txInputs, TxOutput: txOutputs, Proofs: nil}