change shardId to shardID, and ShardId to ShardID

pull/75/head
Minh Doan 6 years ago
parent cefdaad930
commit 7513a79c32
  1. 12
      blockchain/block.go
  2. 12
      blockchain/blockchain.go
  3. 12
      blockchain/transaction.go
  4. 4
      blockchain/utxopool.go
  5. 22
      client/btctxgen/main.go
  6. 28
      client/client.go
  7. 8
      client/config/config.go
  8. 62
      client/txgen/main.go
  9. 10
      client/wallet/main.go
  10. 2
      deploy.sh
  11. 2
      deploy_btctx.sh
  12. 6
      node/node_handler.go
  13. 7
      proto/client/client.go
  14. 2
      run_experiment.sh
  15. 2
      utils/distribution_config.go

@ -20,7 +20,7 @@ type Block struct {
NumTransactions int32
TransactionIds [][32]byte
Transactions []*Transaction // Transactions.
ShardId uint32
ShardID uint32
Hash [32]byte
MerkleRootData []byte
State *State // If present, this block is state block.
@ -106,29 +106,29 @@ func (b *Block) CalculateBlockHash() []byte {
b.generateMerkleRootData()
hashes = append(hashes, b.MerkleRootData)
hashes = append(hashes, utils.ConvertFixedDataIntoByteArray(b.ShardId))
hashes = append(hashes, utils.ConvertFixedDataIntoByteArray(b.ShardID))
blockHash = sha256.Sum256(bytes.Join(hashes, []byte{}))
return blockHash[:]
}
// NewBlock creates and returns a new block.
func NewBlock(transactions []*Transaction, prevBlockHash [32]byte, shardId uint32) *Block {
func NewBlock(transactions []*Transaction, prevBlockHash [32]byte, shardID uint32) *Block {
numTxs := int32(len(transactions))
var txIds [][32]byte
for _, tx := range transactions {
txIds = append(txIds, tx.ID)
}
block := &Block{Timestamp: time.Now().Unix(), PrevBlockHash: prevBlockHash, NumTransactions: numTxs, TransactionIds: txIds, Transactions: transactions, ShardId: shardId, Hash: [32]byte{}}
block := &Block{Timestamp: time.Now().Unix(), PrevBlockHash: prevBlockHash, NumTransactions: numTxs, TransactionIds: txIds, Transactions: transactions, ShardID: shardID, Hash: [32]byte{}}
copy(block.Hash[:], block.CalculateBlockHash()[:])
return block
}
// NewGenesisBlock creates and returns genesis Block.
func NewGenesisBlock(coinbase *Transaction, shardId uint32) *Block {
return NewBlock([]*Transaction{coinbase}, [32]byte{}, shardId)
func NewGenesisBlock(coinbase *Transaction, shardID uint32) *Block {
return NewBlock([]*Transaction{coinbase}, [32]byte{}, shardID)
}
// NewStateBlock creates and returns a state Block based on utxo pool.

@ -192,10 +192,10 @@ func (bc *Blockchain) NewUTXOTransaction(priKey kyber.Scalar, from, to [20]byte,
// AddNewUserTransfer creates a new transaction and a block of that transaction.
// Mostly used for testing.
func (bc *Blockchain) AddNewUserTransfer(utxoPool *UTXOPool, priKey kyber.Scalar, from, to [20]byte, amount int, shardId uint32) bool {
tx := bc.NewUTXOTransaction(priKey, from, to, amount, shardId)
func (bc *Blockchain) AddNewUserTransfer(utxoPool *UTXOPool, priKey kyber.Scalar, from, to [20]byte, amount int, shardID uint32) bool {
tx := bc.NewUTXOTransaction(priKey, from, to, amount, shardID)
if tx != nil {
newBlock := NewBlock([]*Transaction{tx}, bc.Blocks[len(bc.Blocks)-1].Hash, shardId)
newBlock := NewBlock([]*Transaction{tx}, bc.Blocks[len(bc.Blocks)-1].Hash, shardID)
if bc.VerifyNewBlockAndUpdate(utxoPool, newBlock) {
return true
}
@ -222,11 +222,11 @@ func (bc *Blockchain) VerifyNewBlockAndUpdate(utxopool *UTXOPool, block *Block)
// CreateBlockchain creates a new blockchain DB
// TODO(minhdoan): This func is not used, consider to remove.
func CreateBlockchain(address [20]byte, shardId uint32) *Blockchain {
func CreateBlockchain(address [20]byte, shardID uint32) *Blockchain {
// TODO: We assume we have not created any blockchain before.
// In current bitcoin, we can check if we created a blockchain before accessing local db.
cbtx := NewCoinbaseTX(address, genesisCoinbaseData, shardId)
genesis := NewGenesisBlock(cbtx, shardId)
cbtx := NewCoinbaseTX(address, genesisCoinbaseData, shardID)
genesis := NewGenesisBlock(cbtx, shardID)
bc := Blockchain{[]*Block{genesis}}

@ -129,14 +129,14 @@ func (tx *Transaction) Sign(priKey kyber.Scalar) error {
// IsCrossShard returns if the transaction is a cross transation.
func (tx *Transaction) IsCrossShard() bool {
shardIds := make(map[uint32]bool)
shardIDs := make(map[uint32]bool)
for _, value := range tx.TxInput {
shardIds[value.ShardID] = true
shardIDs[value.ShardID] = true
}
for _, value := range tx.TxOutput {
shardIds[value.ShardID] = true
shardIDs[value.ShardID] = true
}
return len(shardIds) > 1
return len(shardIDs) > 1
}
// GetContentToVerify gets content to verify.
@ -170,7 +170,7 @@ func (txInput *TXInput) String() string {
res := fmt.Sprintf("TxID: %v, ", hex.EncodeToString(txInput.PreviousOutPoint.TxID[:]))
res += fmt.Sprintf("TxOutputIndex: %v, ", txInput.PreviousOutPoint.Index)
res += fmt.Sprintf("Address: %v, ", txInput.Address)
res += fmt.Sprintf("ShardId: %v", txInput.ShardID)
res += fmt.Sprintf("ShardID: %v", txInput.ShardID)
return res
}
@ -178,7 +178,7 @@ func (txInput *TXInput) String() string {
func (txOutput *TXOutput) String() string {
res := fmt.Sprintf("Amount: %v, ", txOutput.Amount)
res += fmt.Sprintf("Address: %v", txOutput.Address)
res += fmt.Sprintf("ShardId: %v", txOutput.ShardID)
res += fmt.Sprintf("ShardID: %v", txOutput.ShardID)
return res
}

@ -388,7 +388,7 @@ func (utxoPool *UTXOPool) VerifyAndUpdate(transactions []*Transaction) bool {
// CreateUTXOPoolFromGenesisBlock a Utxo pool from a genesis block.
func CreateUTXOPoolFromGenesisBlock(block *Block) *UTXOPool {
shardId := block.ShardId
shardID := block.ShardID
var utxoPool UTXOPool
utxoPool.UtxoMap = make(UtxoMap)
utxoPool.LockedUtxoMap = make(UtxoMap)
@ -407,7 +407,7 @@ func CreateUTXOPoolFromGenesisBlock(block *Block) *UTXOPool {
utxoPool.UtxoMap[out.Address][txID][uint32(index)] = out.Amount
}
}
utxoPool.ShardID = shardId
utxoPool.ShardID = shardID
return &utxoPool
}

@ -169,20 +169,20 @@ LOOP:
return txs, crossTxs
}
func initClient(clientNode *node.Node, clientPort string, shardIdLeaderMap *map[uint32]p2p.Peer, nodes *[]*node.Node) {
func initClient(clientNode *node.Node, clientPort string, shardIDLeaderMap *map[uint32]p2p.Peer, nodes *[]*node.Node) {
if clientPort == "" {
return
}
clientNode.Client = client.NewClient(shardIdLeaderMap)
clientNode.Client = client.NewClient(shardIDLeaderMap)
// This func is used to update the client's utxopool when new blocks are received from the leaders
updateBlocksFunc := func(blocks []*blockchain.Block) {
log.Debug("Received new block from leader", "len", len(blocks))
for _, block := range blocks {
for _, node := range *nodes {
if node.Consensus.ShardID == block.ShardId {
log.Debug("Adding block from leader", "shardId", block.ShardId)
if node.Consensus.ShardID == block.ShardID {
log.Debug("Adding block from leader", "shardID", block.ShardID)
// Add it to blockchain
utxoPoolMutex.Lock()
node.AddNewBlock(block)
@ -210,10 +210,10 @@ func main() {
// Read the configs
config := client_config.NewConfig()
config.ReadConfigFile(*configFile)
shardIdLeaderMap := config.GetShardIdToLeaderMap()
shardIDLeaderMap := config.GetShardIDToLeaderMap()
// Do cross shard tx if there are more than one shard
setting.crossShard = len(shardIdLeaderMap) > 1
setting.crossShard = len(shardIDLeaderMap) > 1
setting.maxNumTxsPerBatch = *maxNumTxsPerBatch
// TODO(Richard): refactor this chuck to a single method
@ -233,7 +233,7 @@ func main() {
currentInt = 1 // start from address 1
// Nodes containing utxopools to mirror the shards' data in the network
nodes := []*node.Node{}
for shardID, _ := range shardIdLeaderMap {
for shardID, _ := range shardIDLeaderMap {
node := node.New(&consensus.Consensus{ShardID: shardID}, nil)
// Assign many fake addresses so we have enough address to play with at first
node.AddTestingAddresses(10000)
@ -245,21 +245,21 @@ func main() {
consensusObj := consensus.NewConsensus("0", clientPort, "0", nil, p2p.Peer{})
clientNode := node.New(consensusObj, nil)
initClient(clientNode, clientPort, &shardIdLeaderMap, &nodes)
initClient(clientNode, clientPort, &shardIDLeaderMap, &nodes)
// Transaction generation process
time.Sleep(3 * time.Second) // wait for nodes to be ready
leaders := []p2p.Peer{}
for _, leader := range shardIdLeaderMap {
for _, leader := range shardIDLeaderMap {
leaders = append(leaders, leader)
}
for true {
allCrossTxs := []*blockchain.Transaction{}
// Generate simulated transactions
for shardId, leader := range shardIdLeaderMap {
txs, crossTxs := generateSimulatedTransactions(int(shardId), nodes)
for shardID, leader := range shardIDLeaderMap {
txs, crossTxs := generateSimulatedTransactions(int(shardID), nodes)
allCrossTxs = append(allCrossTxs, crossTxs...)
log.Debug("[Generator] Sending single-shard txs ...", "leader", leader, "numTxs", len(txs), "numCrossTxs", len(crossTxs), "block height", iter.GetBlockIndex())

@ -110,16 +110,16 @@ func (client *Client) handleProofOfLockMessage(proofs *[]blockchain.CrossShardTx
func (client *Client) handleFetchUtxoResponseMessage(utxoResponse client_proto.FetchUtxoResponseMessage) {
client.ShardUtxoMapMutex.Lock()
defer client.ShardUtxoMapMutex.Unlock()
_, ok := client.ShardUtxoMap[utxoResponse.ShardId]
_, ok := client.ShardUtxoMap[utxoResponse.ShardID]
if ok {
return
}
client.ShardUtxoMap[utxoResponse.ShardId] = utxoResponse.UtxoMap
client.ShardUtxoMap[utxoResponse.ShardID] = utxoResponse.UtxoMap
}
func (client *Client) sendCrossShardTxUnlockMessage(txsToSend []*blockchain.Transaction) {
for shardId, txs := range BuildOutputShardTransactionMap(txsToSend) {
p2p.SendMessage((*client.Leaders)[shardId], node.ConstructUnlockToCommitOrAbortMessage(txs))
for shardID, txs := range BuildOutputShardTransactionMap(txsToSend) {
p2p.SendMessage((*client.Leaders)[shardID], node.ConstructUnlockToCommitOrAbortMessage(txs))
}
}
@ -139,27 +139,27 @@ func BuildOutputShardTransactionMap(txs []*blockchain.Transaction) map[uint32][]
// Put txs into corresponding output shards
for _, crossTx := range txs {
for curShardId, _ := range GetOutputShardIdsOfCrossShardTx(crossTx) {
txsShardMap[curShardId] = append(txsShardMap[curShardId], crossTx)
for curShardID, _ := range GetOutputShardIDsOfCrossShardTx(crossTx) {
txsShardMap[curShardID] = append(txsShardMap[curShardID], crossTx)
}
}
return txsShardMap
}
func GetInputShardIdsOfCrossShardTx(crossTx *blockchain.Transaction) map[uint32]bool {
shardIds := map[uint32]bool{}
func GetInputShardIDsOfCrossShardTx(crossTx *blockchain.Transaction) map[uint32]bool {
shardIDs := map[uint32]bool{}
for _, txInput := range crossTx.TxInput {
shardIds[txInput.ShardID] = true
shardIDs[txInput.ShardID] = true
}
return shardIds
return shardIDs
}
func GetOutputShardIdsOfCrossShardTx(crossTx *blockchain.Transaction) map[uint32]bool {
shardIds := map[uint32]bool{}
func GetOutputShardIDsOfCrossShardTx(crossTx *blockchain.Transaction) map[uint32]bool {
shardIDs := map[uint32]bool{}
for _, txOutput := range crossTx.TxOutput {
shardIds[txOutput.ShardID] = true
shardIDs[txOutput.ShardID] = true
}
return shardIds
return shardIDs
}
func (client *Client) GetLeaders() []p2p.Peer {

@ -40,19 +40,19 @@ func (config *Config) GetValidators() []p2p.Peer {
}
// Gets all the leader peers and corresponding shard Ids
func (config *Config) GetShardIdToLeaderMap() map[uint32]p2p.Peer {
shardIdLeaderMap := map[uint32]p2p.Peer{}
func (config *Config) GetShardIDToLeaderMap() map[uint32]p2p.Peer {
shardIDLeaderMap := map[uint32]p2p.Peer{}
for _, entry := range config.config {
if entry.Role == "leader" {
val, err := strconv.Atoi(entry.ShardID)
if err == nil {
shardIdLeaderMap[uint32(val)] = p2p.Peer{Ip: entry.IP, Port: entry.Port}
shardIDLeaderMap[uint32(val)] = p2p.Peer{Ip: entry.IP, Port: entry.Port}
} else {
log.Print("[Generator] Error parsing the shard Id ", entry.ShardID)
}
}
}
return shardIdLeaderMap
return shardIDLeaderMap
}
func (config *Config) GetClientPeer() *p2p.Peer {

@ -75,7 +75,7 @@ type TxInfo struct {
// Returns:
// all single-shard txs
// all cross-shard txs
func generateSimulatedTransactions(subsetId, numSubset int, shardId int, dataNodes []*node.Node) ([]*blockchain.Transaction, []*blockchain.Transaction) {
func generateSimulatedTransactions(subsetId, numSubset int, shardID int, dataNodes []*node.Node) ([]*blockchain.Transaction, []*blockchain.Transaction) {
/*
UTXO map structure:
address - [
@ -91,13 +91,13 @@ func generateSimulatedTransactions(subsetId, numSubset int, shardId int, dataNod
*/
txInfo := TxInfo{}
txInfo.shardID = shardId
txInfo.shardID = shardID
txInfo.dataNodes = dataNodes
txInfo.txCount = 0
UTXOLOOP:
// Loop over all addresses
for address, txMap := range dataNodes[shardId].UtxoPool.UtxoMap {
for address, txMap := range dataNodes[shardID].UtxoPool.UtxoMap {
if int(binary.BigEndian.Uint32(address[:]))%numSubset == subsetId%numSubset { // Work on one subset of utxo at a time
txInfo.address = address
// Loop over all txIds for the address
@ -139,23 +139,23 @@ UTXOLOOP:
}
}
}
log.Info("UTXO CLIENT", "numUtxo", dataNodes[shardId].UtxoPool.CountNumOfUtxos(), "shardId", shardId)
log.Info("UTXO CLIENT", "numUtxo", dataNodes[shardID].UtxoPool.CountNumOfUtxos(), "shardID", shardID)
log.Debug("[Generator] generated transations", "single-shard", len(txInfo.txs), "cross-shard", len(txInfo.crossTxs))
return txInfo.txs, txInfo.crossTxs
}
func generateCrossShardTx(txInfo *TxInfo) {
nodeShardID := txInfo.dataNodes[txInfo.shardID].Consensus.ShardID
crossShardId := nodeShardID
crossShardID := nodeShardID
// a random shard to spend money to
for true {
crossShardId = uint32(rand.Intn(len(txInfo.dataNodes)))
if crossShardId != nodeShardID {
crossShardID = uint32(rand.Intn(len(txInfo.dataNodes)))
if crossShardID != nodeShardID {
break
}
}
//crossShardNode := txInfo.dataNodes[crossShardId]
//crossShardNode := txInfo.dataNodes[crossShardID]
//crossShardUtxosMap := crossShardNode.UtxoPool.UtxoMap[txInfo.address]
//
//// Get the cross shard utxo from another shard
@ -173,7 +173,7 @@ func generateCrossShardTx(txInfo *TxInfo) {
//
// for crossShardIndex, crossShardValue := range crossShardUtxos {
// crossUtxoValue = crossShardValue
// crossTxin = blockchain.NewTXInput(blockchain.NewOutPoint(&crossTxId, crossShardIndex), txInfo.address, crossShardId)
// crossTxin = blockchain.NewTXInput(blockchain.NewOutPoint(&crossTxId, crossShardIndex), txInfo.address, crossShardID)
// break
// }
// if crossTxin != nil {
@ -191,13 +191,13 @@ func generateCrossShardTx(txInfo *TxInfo) {
//}
// 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: crossShardId}
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}
// crossTxout := blockchain.TXOutput{Amount: crossUtxoValue, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: crossShardID}
// txOutputs = append(txOutputs, crossTxout)
//}
@ -267,11 +267,11 @@ func main() {
// Read the configs
config := client_config.NewConfig()
config.ReadConfigFile(*configFile)
shardIdLeaderMap := config.GetShardIdToLeaderMap()
shardIDLeaderMap := config.GetShardIDToLeaderMap()
setting.numOfAddress = 10000
// Do cross shard tx if there are more than one shard
setting.crossShard = len(shardIdLeaderMap) > 1
setting.crossShard = len(shardIDLeaderMap) > 1
setting.maxNumTxsPerBatch = *maxNumTxsPerBatch
setting.crossShardRatio = *crossShardRatio
@ -286,8 +286,8 @@ func main() {
// Nodes containing utxopools to mirror the shards' data in the network
nodes := []*node.Node{}
for shardId, _ := range shardIdLeaderMap {
node := node.New(&consensus.Consensus{ShardID: shardId}, nil)
for shardID, _ := range shardIDLeaderMap {
node := node.New(&consensus.Consensus{ShardID: shardID}, nil)
// Assign many fake addresses so we have enough address to play with at first
node.AddTestingAddresses(setting.numOfAddress)
nodes = append(nodes, node)
@ -299,15 +299,15 @@ func main() {
clientNode := node.New(consensusObj, nil)
if clientPort != "" {
clientNode.Client = client.NewClient(&shardIdLeaderMap)
clientNode.Client = client.NewClient(&shardIDLeaderMap)
// This func is used to update the client's utxopool when new blocks are received from the leaders
updateBlocksFunc := func(blocks []*blockchain.Block) {
log.Debug("Received new block from leader", "len", len(blocks))
for _, block := range blocks {
for _, node := range nodes {
if node.Consensus.ShardID == block.ShardId {
log.Debug("Adding block from leader", "shardId", block.ShardId)
if node.Consensus.ShardID == block.ShardID {
log.Debug("Adding block from leader", "shardID", block.ShardID)
// Add it to blockchain
node.AddNewBlock(block)
utxoPoolMutex.Lock()
@ -341,16 +341,16 @@ func main() {
log.Debug("Generator timer ended.", "duration", (int(t.Sub(start))), "startTime", start, "totalTime", totalTime)
break
}
shardIdTxsMap := make(map[uint32][]*blockchain.Transaction)
shardIDTxsMap := make(map[uint32][]*blockchain.Transaction)
lock := sync.Mutex{}
var wg sync.WaitGroup
wg.Add(len(shardIdLeaderMap))
wg.Add(len(shardIDLeaderMap))
utxoPoolMutex.Lock()
log.Warn("STARTING TX GEN", "gomaxprocs", runtime.GOMAXPROCS(0))
for shardId, _ := range shardIdLeaderMap { // Generate simulated transactions
go func(shardId uint32) {
txs, crossTxs := generateSimulatedTransactions(subsetCounter, *numSubset, int(shardId), nodes)
for shardID, _ := range shardIDLeaderMap { // Generate simulated transactions
go func(shardID uint32) {
txs, crossTxs := generateSimulatedTransactions(subsetCounter, *numSubset, int(shardID), nodes)
// Put cross shard tx into a pending list waiting for proofs from leaders
if clientPort != "" {
@ -363,24 +363,24 @@ func main() {
lock.Lock()
// Put txs into corresponding shards
shardIdTxsMap[shardId] = append(shardIdTxsMap[shardId], txs...)
shardIDTxsMap[shardID] = append(shardIDTxsMap[shardID], txs...)
for _, crossTx := range crossTxs {
for curShardId, _ := range client.GetInputShardIdsOfCrossShardTx(crossTx) {
shardIdTxsMap[curShardId] = append(shardIdTxsMap[curShardId], crossTx)
for curShardID, _ := range client.GetInputShardIDsOfCrossShardTx(crossTx) {
shardIDTxsMap[curShardID] = append(shardIDTxsMap[curShardID], crossTx)
}
}
lock.Unlock()
wg.Done()
}(shardId)
}(shardID)
}
wg.Wait()
utxoPoolMutex.Unlock()
lock.Lock()
for shardId, txs := range shardIdTxsMap { // Send the txs to corresponding shards
go func(shardId uint32, txs []*blockchain.Transaction) {
SendTxsToLeader(shardIdLeaderMap[shardId], txs)
}(shardId, txs)
for shardID, txs := range shardIDTxsMap { // Send the txs to corresponding shards
go func(shardID uint32, txs []*blockchain.Transaction) {
SendTxsToLeader(shardIDLeaderMap[shardID], txs)
}(shardID, txs)
}
lock.Unlock()

@ -173,7 +173,7 @@ func main() {
cummulativeBalance := 0
txInputs := []blockchain.TXInput{}
LOOP:
for shardId, utxoMap := range shardUtxoMap {
for shardID, utxoMap := range shardUtxoMap {
for txId, vout2AmountMap := range utxoMap[senderAddressBytes] {
txIdBytes, err := utils.Get32BytesFromString(txId)
if err != nil {
@ -182,7 +182,7 @@ func main() {
}
for voutIndex, utxoAmount := range vout2AmountMap {
cummulativeBalance += utxoAmount
txIn := blockchain.NewTXInput(blockchain.NewOutPoint(&txIdBytes, voutIndex), senderAddressBytes, shardId)
txIn := blockchain.NewTXInput(blockchain.NewOutPoint(&txIdBytes, voutIndex), senderAddressBytes, shardID)
txInputs = append(txInputs, *txIn)
if cummulativeBalance >= amount {
break LOOP
@ -221,7 +221,7 @@ func main() {
}
}
func getShardIdToLeaderMap() map[uint32]p2p.Peer {
func getShardIDToLeaderMap() map[uint32]p2p.Peer {
// TODO(ricl): Later use data.harmony.one for API.
str, _ := client.DownloadUrlAsString("https://s3-us-west-2.amazonaws.com/unique-bucket-bin/leaders.txt")
lines := strings.Split(str, "\n")
@ -250,10 +250,10 @@ func CreateWalletServerNode() *node.Node {
var clientPeer *p2p.Peer
if true {
configr.ReadConfigFile("local_config2.txt")
shardIDLeaderMap = configr.GetShardIdToLeaderMap()
shardIDLeaderMap = configr.GetShardIDToLeaderMap()
clientPeer = configr.GetClientPeer()
} else {
shardIDLeaderMap = getShardIdToLeaderMap()
shardIDLeaderMap = getShardIDToLeaderMap()
clientPeer = &p2p.Peer{Port: "127.0.0.1", Ip: "1234"}
}
walletNode := node.New(nil, nil)

@ -46,7 +46,7 @@ mkdir -p $log_folder
# Start nodes
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardId <<< $line
IFS=' ' read ip port mode shardID <<< $line
#echo $ip $port $mode
if [ "$mode" != "client" ]; then
if [ -z "$db_supported" ]; then

@ -18,7 +18,7 @@ mkdir -p $log_folder
# Start nodes
config=$1
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardId <<< $line
IFS=' ' read ip port mode shardID <<< $line
#echo $ip $port $mode
if [ "$mode" != "client" ]; then
./bin/benchmark -ip $ip -port $port -config_file $config -log_folder $log_folder&

@ -424,8 +424,8 @@ func (node *Node) UpdateUtxoAndState(newBlock *blockchain.Block) {
// Clear transaction-in-Consensus list
node.transactionInConsensus = []*blockchain.Transaction{}
if node.Consensus.IsLeader {
node.log.Info("TX in New BLOCK", "num", len(newBlock.Transactions), "ShardId", node.UtxoPool.ShardID, "IsStateBlock", newBlock.IsStateBlock())
node.log.Info("LEADER CURRENT UTXO", "num", node.UtxoPool.CountNumOfUtxos(), "ShardId", node.UtxoPool.ShardID)
node.log.Info("LEADER LOCKED UTXO", "num", node.UtxoPool.CountNumOfLockedUtxos(), "ShardId", node.UtxoPool.ShardID)
node.log.Info("TX in New BLOCK", "num", len(newBlock.Transactions), "ShardID", node.UtxoPool.ShardID, "IsStateBlock", newBlock.IsStateBlock())
node.log.Info("LEADER CURRENT UTXO", "num", node.UtxoPool.CountNumOfUtxos(), "ShardID", node.UtxoPool.ShardID)
node.log.Info("LEADER LOCKED UTXO", "num", node.UtxoPool.CountNumOfLockedUtxos(), "ShardID", node.UtxoPool.ShardID)
}
}

@ -3,6 +3,7 @@ package client
import (
"bytes"
"encoding/gob"
"github.com/simple-rules/harmony-benchmark/blockchain"
"github.com/simple-rules/harmony-benchmark/proto"
)
@ -25,7 +26,7 @@ const (
type FetchUtxoResponseMessage struct {
UtxoMap blockchain.UtxoMap
ShardId uint32
ShardID uint32
}
// [leader] Constructs the proof of accept or reject message that will be sent to client
@ -40,12 +41,12 @@ func ConstructProofOfAcceptOrRejectMessage(proofs []blockchain.CrossShardTxProof
}
// Constructs the response message to fetch utxo message
func ConstructFetchUtxoResponseMessage(utxoMap *blockchain.UtxoMap, shardId uint32) []byte {
func ConstructFetchUtxoResponseMessage(utxoMap *blockchain.UtxoMap, shardID uint32) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(proto.CLIENT)})
byteBuffer.WriteByte(byte(TRANSACTION))
byteBuffer.WriteByte(byte(UTXO_RESPONSE))
encoder := gob.NewEncoder(byteBuffer)
encoder.Encode(FetchUtxoResponseMessage{*utxoMap, shardId})
encoder.Encode(FetchUtxoResponseMessage{*utxoMap, shardID})
return byteBuffer.Bytes()
}

@ -14,7 +14,7 @@ mkdir -p $log_folder
# For each of the nodes, start soldier
config=distribution_config.txt
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardId <<< $line
IFS=' ' read ip port mode shardID <<< $line
#echo $ip $port $mode
./soldier -ip $ip -port $port&
done < $config

@ -31,7 +31,7 @@ func NewDistributionConfig() *DistributionConfig {
}
// Gets all the leader peers and corresponding shard Ids
func (config *DistributionConfig) GetLeadersAndShardIds() ([]p2p.Peer, []uint32) {
func (config *DistributionConfig) GetLeadersAndShardIDs() ([]p2p.Peer, []uint32) {
var peerList []p2p.Peer
var shardIDs []uint32
for _, entry := range config.config {

Loading…
Cancel
Save