More comments and code fixes

pull/219/head
Rongjian Lan 6 years ago
parent 0af1abfeb6
commit c78f6a1914
  1. 7
      api/proto/node/node.go
  2. 26
      cmd/client/txgen/main.go
  3. 2
      consensus/consensus_engine.go
  4. 4
      node/node_handler.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

@ -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

@ -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.

@ -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")

Loading…
Cancel
Save