fix some send message failure

Signed-off-by: Leo Chen <leo@harmony.one>
pull/304/head
Leo Chen 6 years ago
parent 85baa93be2
commit 8edebd2250
  1. 3
      .gitignore
  2. 3
      internal/beaconchain/libs/beaconchain.go
  3. 5
      internal/newnode/newnode.go
  4. 1
      p2p/host/hostv2/hostv2.go
  5. 4
      test/configs/local_config1.txt
  6. 29
      test/deploy.sh

3
.gitignore vendored

@ -44,3 +44,6 @@ tmp_log
# beacon chain data # beacon chain data
bc_config.json bc_config.json
# leveldb local storage
db/

@ -139,6 +139,9 @@ func (bc *BeaconChain) RespondRandomness(Node *node.Info) {
msg := bcconn.SerializeRandomInfo(response) msg := bcconn.SerializeRandomInfo(response)
msgToSend := proto_identity.ConstructIdentityMessage(proto_identity.Acknowledge, msg) msgToSend := proto_identity.ConstructIdentityMessage(proto_identity.Acknowledge, msg)
bc.log.Info("Sent Out Msg", "# Nodes", response.NumberOfNodesAdded) bc.log.Info("Sent Out Msg", "# Nodes", response.NumberOfNodesAdded)
for i, n := range response.Leaders {
bc.log.Info("Sent Out Msg", "leader", i, "nodeInfo", n.PeerID)
}
host.SendMessage(bc.host, bc.Peer, msgToSend, nil) host.SendMessage(bc.host, bc.Peer, msgToSend, nil)
bc.state = RandomInfoSent bc.state = RandomInfoSent
} }

@ -46,9 +46,10 @@ func New(ip string, port string) *NewNode {
node.PubK = pubKey node.PubK = pubKey
node.priK = priKey node.priK = priKey
node.Self = p2p.Peer{IP: ip, Port: port, PubKey: pubKey, ValidatorID: -1} node.Self = p2p.Peer{IP: ip, Port: port, PubKey: pubKey, ValidatorID: -1}
node.log = log.New() node.log = utils.GetLogInstance()
node.SetInfo = make(chan bool) node.SetInfo = make(chan bool)
node.host, err = p2pimpl.NewHost(&node.Self) node.host, err = p2pimpl.NewHost(&node.Self)
node.log.Info("NewNode New", "Self", node.Self)
if err != nil { if err != nil {
node.log.Error("failed to create new host", "msg", err) node.log.Error("failed to create new host", "msg", err)
return nil return nil
@ -80,7 +81,7 @@ func (node *NewNode) requestBeaconChain(BCPeer p2p.Peer) (err error) {
if err != nil { if err != nil {
node.log.Error("Could not Marshall public key into binary") node.log.Error("Could not Marshall public key into binary")
} }
nodeInfo := &proto_node.Info{IP: node.Self.IP, Port: node.Self.Port, PubKey: pubk, PeerID: node.host.GetID()} nodeInfo := &proto_node.Info{IP: node.Self.IP, Port: node.Self.Port, PubKey: pubk, PeerID: node.Self.PeerID}
msg := bcconn.SerializeNodeInfo(nodeInfo) msg := bcconn.SerializeNodeInfo(nodeInfo)
msgToSend := proto_identity.ConstructIdentityMessage(proto_identity.Register, msg) msgToSend := proto_identity.ConstructIdentityMessage(proto_identity.Register, msg)
gotShardInfo := false gotShardInfo := false

@ -114,7 +114,6 @@ func (host *HostV2) SendMessage(p p2p.Peer, message []byte) error {
return err return err
} }
defer s.Close()
s.Write(message) s.Write(message)
return nil return nil

@ -1,5 +1,5 @@
127.0.0.1 9000 leader 0 127.0.0.1 9000 leader 0
127.0.0.1 9001 validator 0 127.0.0.1 9001 leader 0
127.0.0.1 9002 validator 0 127.0.0.1 9002 validator 0
127.0.0.1 9003 validator 0 127.0.0.1 9003 validator 0
127.0.0.1 9004 validator 0 127.0.0.1 9004 validator 0
@ -9,4 +9,6 @@
127.0.0.1 9008 validator 0 127.0.0.1 9008 validator 0
127.0.0.1 9009 validator 0 127.0.0.1 9009 validator 0
127.0.0.1 9010 validator 0 127.0.0.1 9010 validator 0
127.0.0.1 9011 validator 0
127.0.0.1 9012 validator 0
127.0.0.1 19999 client 0 127.0.0.1 19999 client 0

@ -133,14 +133,19 @@ if [ -n "$MA" ]; then
HMY_OPT="-bc_addr $MA" HMY_OPT="-bc_addr $MA"
fi fi
NUM_NN=0
# Start nodes # Start nodes
while IFS='' read -r line || [[ -n "$line" ]]; do 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" == "leader" || "$mode" == "validator" ]]; then if [[ "$mode" == "leader" || "$mode" == "validator" ]]; then
$DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT 2>&1 | tee -a $LOG_FILE & $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT 2>&1 | tee -a $LOG_FILE &
sleep 0.5 sleep 0.5
fi fi
if [[ "$mode" == "newnode" && "$SYNC" == "true" ]]; then
(( NUM_NN += 35 ))
(sleep $NUM_NN; $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT 2>&1 | tee -a $LOG_FILE ) &
fi
done < $config done < $config
# Emulate node offline # Emulate node offline
@ -149,29 +154,17 @@ if [ "$SYNC" == "false" ]; then
fi fi
if [ "$TXGEN" == "true" ]; then if [ "$TXGEN" == "true" ]; then
echo "launching txgen ..." echo "launching txgen ... wait"
sleep 2
line=$(grep client $config) line=$(grep client $config)
IFS=' ' read ip port mode shardID <<< $line IFS=' ' read ip port mode shardID <<< $line
if [ "$mode" == "client" ]; then if [ "$mode" == "client" ]; then
$DRYRUN $ROOT/bin/txgen -log_folder $log_folder -duration $DURATION -ip $ip -port $port $HMY_OPT 2>&1 | tee -a $LOG_FILE & $DRYRUN $ROOT/bin/txgen -log_folder $log_folder -duration $DURATION -ip $ip -port $port $HMY_OPT 2>&1 | tee -a $LOG_FILE
fi
fi
# sleep enough time before consensus reached then add new node for state syncing
if [ "$SYNC" == "true" ]; then
sleep 45
echo "launching new node..."
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardID <<< $line
echo launching newnode $ip $port $mode
if [ "$mode" == "newnode" ]; then
$DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT 2>&1 | tee -a $LOG_FILE &
sleep 25
fi fi
done < $config
fi fi
wait # save bc_config.json
cp -f bc_config.json $log_folder
cleanup cleanup
check_result check_result

Loading…
Cancel
Save