From c78f6a191437d47f28f979dbb546f620c25a2331 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Fri, 4 Jan 2019 16:03:21 -0800 Subject: [PATCH] More comments and code fixes --- api/proto/node/node.go | 7 ------- cmd/client/txgen/main.go | 26 ++++++++++++-------------- consensus/consensus_engine.go | 2 ++ node/node_handler.go | 4 +--- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/api/proto/node/node.go b/api/proto/node/node.go index a9abbfcc0..2c7b34120 100644 --- a/api/proto/node/node.go +++ b/api/proto/node/node.go @@ -10,7 +10,6 @@ import ( "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/api/proto" - "github.com/harmony-one/harmony/p2p" ) // MessageType is to indicate the specific type of message under Node category @@ -74,12 +73,6 @@ const ( STOP ControlMessageType = iota ) -// FetchUtxoMessage is the wrapper struct FetchUtxoMessage sent from client wallet. -type FetchUtxoMessage struct { - Addresses [][20]byte - Sender p2p.Peer -} - // SerializeBlockchainSyncMessage serializes BlockchainSyncMessage. func SerializeBlockchainSyncMessage(blockchainSyncMessage *BlockchainSyncMessage) []byte { var result bytes.Buffer diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index ff85dd133..9514c502c 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -23,11 +23,11 @@ import ( ) var ( - version string - builtBy string - builtAt string - commit string - utxoPoolMutex sync.Mutex + version string + builtBy string + builtAt string + commit string + stateMutex sync.Mutex ) func printVersion(me string) { @@ -93,7 +93,7 @@ func main() { ) log.Root().SetHandler(h) - // Nodes containing utxopools to mirror the shards' data in the network + // Nodes containing blockchain data to mirror the shards' data in the network nodes := []*node.Node{} for shardID := range shardIDLeaderMap { _, pubKey := utils.GenKey(clientPeer.IP, clientPeer.Port) @@ -110,15 +110,15 @@ func main() { clientNode := node.New(host, consensusObj, nil) clientNode.Client = client.NewClient(clientNode.GetHost(), &shardIDLeaderMap) - // This func is used to update the client's utxopool when new blocks are received from the leaders readySignal := make(chan uint32) go func() { for i := range shardIDLeaderMap { readySignal <- i } }() + // This func is used to update the client's blockchain when new blocks are received from the leaders updateBlocksFunc := func(blocks []*types.Block) { - log.Info("RECEIVED BLOCK", "block", blocks) + log.Info("[Txgen] Received new block", "block", blocks) for _, block := range blocks { for _, node := range nodes { shardID := block.ShardID() @@ -128,9 +128,9 @@ func main() { log.Info("Current Block", "hash", node.Blockchain().CurrentBlock().Hash().Hex()) log.Info("Adding block from leader", "txNum", len(block.Transactions()), "shardID", shardID, "preHash", block.ParentHash().Hex()) node.AddNewBlock(block) - utxoPoolMutex.Lock() + stateMutex.Lock() node.Worker.UpdateCurrent() - utxoPoolMutex.Unlock() + stateMutex.Unlock() readySignal <- shardID } else { continue @@ -168,17 +168,15 @@ func main() { shardIDTxsMap := make(map[uint32]types.Transactions) lock := sync.Mutex{} - utxoPoolMutex.Lock() + stateMutex.Lock() log.Warn("STARTING TX GEN", "gomaxprocs", runtime.GOMAXPROCS(0)) txs, _ := txgen.GenerateSimulatedTransactionsAccount(int(shardID), nodes, setting) - // TODO: Put cross shard tx into a pending list waiting for proofs from leaders - lock.Lock() // Put txs into corresponding shards shardIDTxsMap[shardID] = append(shardIDTxsMap[shardID], txs...) lock.Unlock() - utxoPoolMutex.Unlock() + stateMutex.Unlock() lock.Lock() for shardID, txs := range shardIDTxsMap { // Send the txs to corresponding shards diff --git a/consensus/consensus_engine.go b/consensus/consensus_engine.go index a20b1f848..771f494a4 100644 --- a/consensus/consensus_engine.go +++ b/consensus/consensus_engine.go @@ -9,6 +9,7 @@ import ( // ChainReader defines a small collection of methods needed to access the local // blockchain during header and/or uncle verification. +// Note this reader interface is still in process of being integrated with the BFT consensus. type ChainReader interface { // Config retrieves the blockchain's chain configuration. Config() *params.ChainConfig @@ -30,6 +31,7 @@ type ChainReader interface { } // Engine is an algorithm agnostic consensus engine. +// Note this engine interface is still in process of being integrated with the BFT consensus. type Engine interface { // Author retrieves the Harmony address of the account that validated the given // block. diff --git a/node/node_handler.go b/node/node_handler.go index bf055dab1..cd632075d 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -27,7 +27,7 @@ const ( // MaybeBroadcastAsValidator returns if the node is a validator node. func (node *Node) MaybeBroadcastAsValidator(content []byte) { - // TODO: this is tree broadcasting. this needs to be removed later. Actually the whole logic needs to be replaced by p2p. + // TODO: this is tree-based broadcasting. this needs to be replaced by p2p gossiping. if node.SelfPeer.ValidatorID > 0 && node.SelfPeer.ValidatorID <= host.MaxBroadCast { go host.BroadcastMessageFromValidator(node.host, node.SelfPeer, node.Consensus.GetValidatorPeers(), content) } @@ -75,8 +75,6 @@ func (node *Node) StreamHandler(s p2p.Stream) { switch messageType { case proto_identity.Register: fmt.Println("received a identity message") - // TODO(ak): fix it. - // node.processPOWMessage(msgPayload) node.log.Info("NET: received message: IDENTITY/REGISTER") default: node.log.Error("Announce message should be sent to IdentityChain")