From 655bd9f73edc3c64d3bf4ce2df6d6e130be79e02 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Fri, 15 Mar 2019 22:27:54 -0700 Subject: [PATCH 01/17] Use genesis BLS key for beacon chain nodes --- cmd/client/txgen/main.go | 2 +- cmd/harmony/main.go | 15 ++++++-- consensus/consensus.go | 22 +++++------- consensus/consensus_leader.go | 2 +- consensus/consensus_leader_msg_test.go | 6 ++-- consensus/consensus_leader_test.go | 32 ++++++++++------- consensus/consensus_test.go | 12 ++++--- consensus/consensus_validator.go | 2 +- consensus/consensus_validator_msg_test.go | 6 ++-- consensus/consensus_validator_test.go | 23 +++++++----- core/blockchain.go | 17 ++++----- core/resharding.go | 15 +++++--- crypto/bls/bls.go | 7 ++++ node/contract_test.go | 2 +- node/node_handler.go | 44 ++++++++++++++++++++++- node/node_handler_test.go | 4 +-- node/node_test.go | 10 +++--- node/staking_test.go | 2 +- 18 files changed, 150 insertions(+), 73 deletions(-) diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index d392fcbf3..4454e16e3 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -118,7 +118,7 @@ func main() { } // Client/txgenerator server node setup - consensusObj := consensus.New(host, "0", nil, p2p.Peer{}) + consensusObj := consensus.New(host, "0", nil, p2p.Peer{}, nil) clientNode := node.New(host, consensusObj, nil) clientNode.Client = client.NewClient(clientNode.GetHost(), shardIDs) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 18e53a507..e18f9548a 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "github.com/harmony-one/bls/ffi/go/bls" "math/rand" "os" "path" @@ -124,11 +125,21 @@ func createGlobalConfig() *nodeconfig.ConfigType { // Key Setup ================= [Start] // Staking private key is the ecdsa key used for token related transaction signing (especially the staking txs). stakingPriKey := "" + consensusPriKey := &bls.SecretKey{} if *isBeacon { stakingPriKey = contract.InitialBeaconChainAccounts[*accountIndex].Private + err := consensusPriKey.DeserializeHexStr(contract.InitialBeaconChainBLSAccounts[*accountIndex].Private) + if err != nil { + panic(fmt.Errorf("generate key error")) + } } else { stakingPriKey = contract.NewNodeAccounts[*accountIndex].Private + // TODO: use user supplied key + consensusPriKey, _ = utils.GenKey(*ip, *port) } + consensusPriKey, _ = utils.GenKey(*ip, *port) + fmt.Println("TESTTEST") + fmt.Println(consensusPriKey.SerializeToHexStr()) nodeConfig.StakingPriKey = node.StoreStakingKeyFromFile(*stakingKeyFile, stakingPriKey) // P2p private key is used for secure message transfer between p2p nodes. @@ -138,7 +149,7 @@ func createGlobalConfig() *nodeconfig.ConfigType { } // Consensus keys are the BLS12-381 keys used to sign consensus messages - nodeConfig.ConsensusPriKey, nodeConfig.ConsensusPubKey = utils.GenKey(*ip, *port) + nodeConfig.ConsensusPriKey, nodeConfig.ConsensusPubKey = consensusPriKey, consensusPriKey.GetPublicKey() if nodeConfig.ConsensusPriKey == nil || nodeConfig.ConsensusPubKey == nil { panic(fmt.Errorf("generate key error")) } @@ -179,7 +190,7 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen // Consensus object. // TODO: consensus object shouldn't start here // TODO(minhdoan): During refactoring, found out that the peers list is actually empty. Need to clean up the logic of consensus later. - consensus := consensus.New(nodeConfig.Host, nodeConfig.ShardIDString, []p2p.Peer{}, nodeConfig.Leader) + consensus := consensus.New(nodeConfig.Host, nodeConfig.ShardIDString, []p2p.Peer{}, nodeConfig.Leader, nodeConfig.ConsensusPriKey) consensus.MinPeers = *minPeers // Current node. diff --git a/consensus/consensus.go b/consensus/consensus.go index a56921c7e..b9bafe7ea 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -4,7 +4,6 @@ package consensus // consensus import ( "bytes" "crypto/sha256" - "encoding/binary" "encoding/hex" "errors" "fmt" @@ -62,7 +61,7 @@ type Consensus struct { // private/public keys of current node priKey *bls.SecretKey - pubKey *bls.PublicKey + PubKey *bls.PublicKey // Whether I am leader. False means I am validator IsLeader bool @@ -170,7 +169,7 @@ func (consensus *Consensus) GetNextRnd() ([32]byte, [32]byte, error) { // New creates a new Consensus object // TODO: put shardId into chain reader's chain config -func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer) *Consensus { +func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer, blsPriKey *bls.SecretKey) *Consensus { consensus := Consensus{} consensus.host = host @@ -210,13 +209,10 @@ func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer) *Cons // TODO: populate Id derived from address consensus.nodeID = utils.GetUniqueIDFromPeer(selfPeer) - // Set private key for myself so that I can sign messages. - nodeIDBytes := make([]byte, 32) - binary.LittleEndian.PutUint32(nodeIDBytes, consensus.nodeID) - privateKey := bls.SecretKey{} - err := privateKey.SetLittleEndian(nodeIDBytes) - consensus.priKey = &privateKey - consensus.pubKey = privateKey.GetPublicKey() + if blsPriKey != nil { + consensus.priKey = blsPriKey + consensus.PubKey = blsPriKey.GetPublicKey() + } consensus.consensusID = 0 // or view Id in the original pbft paper @@ -242,7 +238,7 @@ func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer) *Cons consensus.uniqueIDInstance = utils.GetUniqueValidatorIDInstance() consensus.OfflinePeerList = make([]p2p.Peer, 0) - // consensus.Log.Info("New Consensus", "IP", ip, "Port", port, "NodeID", consensus.nodeID, "priKey", consensus.priKey, "pubKey", consensus.pubKey) + // consensus.Log.Info("New Consensus", "IP", ip, "Port", port, "NodeID", consensus.nodeID, "priKey", consensus.priKey, "PubKey", consensus.PubKey) return &consensus } @@ -404,8 +400,8 @@ func (consensus *Consensus) String() string { } else { duty = "VLD" // validator } - return fmt.Sprintf("[duty:%s, pubKey:%s, ShardID:%v, nodeID:%v, state:%s]", - duty, hex.EncodeToString(consensus.pubKey.Serialize()), consensus.ShardID, consensus.nodeID, consensus.state) + return fmt.Sprintf("[duty:%s, PubKey:%s, ShardID:%v, nodeID:%v, state:%s]", + duty, hex.EncodeToString(consensus.PubKey.Serialize()), consensus.ShardID, consensus.nodeID, consensus.state) } // AddPeers adds new peers into the validator map of the consensus diff --git a/consensus/consensus_leader.go b/consensus/consensus_leader.go index c0800fdcc..d403c8461 100644 --- a/consensus/consensus_leader.go +++ b/consensus/consensus_leader.go @@ -350,7 +350,7 @@ func (consensus *Consensus) reportMetrics(block types.Block) { txHashes = append(txHashes, hex.EncodeToString(txHash[:])) } metrics := map[string]interface{}{ - "key": hex.EncodeToString(consensus.pubKey.Serialize()), + "key": hex.EncodeToString(consensus.PubKey.Serialize()), "tps": tps, "txCount": numOfTxs, "nodeCount": len(consensus.PublicKeys) + 1, diff --git a/consensus/consensus_leader_msg_test.go b/consensus/consensus_leader_msg_test.go index 453024888..f27fc46dd 100644 --- a/consensus/consensus_leader_msg_test.go +++ b/consensus/consensus_leader_msg_test.go @@ -3,6 +3,8 @@ package consensus import ( "testing" + "github.com/harmony-one/harmony/crypto/bls" + protobuf "github.com/golang/protobuf/proto" "github.com/harmony-one/harmony/api/proto" msg_pb "github.com/harmony-one/harmony/api/proto/message" @@ -19,7 +21,7 @@ func TestConstructAnnounceMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := New(host, "0", []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) consensus.blockHash = [32]byte{} message := &msg_pb.Message{} @@ -45,7 +47,7 @@ func TestConstructPreparedMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := New(host, "0", []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) consensus.blockHash = [32]byte{} message := "test string" diff --git a/consensus/consensus_leader_test.go b/consensus/consensus_leader_test.go index 039688e6a..6543606c8 100644 --- a/consensus/consensus_leader_test.go +++ b/consensus/consensus_leader_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "github.com/harmony-one/bls/ffi/go/bls" + "github.com/ethereum/go-ethereum/rlp" "github.com/golang/mock/gomock" protobuf "github.com/golang/protobuf/proto" @@ -30,15 +32,17 @@ func TestProcessMessageLeaderPrepare(test *testing.T) { defer ctrl.Finish() leader := p2p.Peer{IP: ip, Port: "7777"} - _, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) + var priKey *bls.SecretKey + priKey, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) validators := make([]p2p.Peer, 3) hosts := make([]p2p.Host, 3) + validatorsPriKeys := [3]*bls.SecretKey{} for i := 0; i < 3; i++ { port := fmt.Sprintf("%d", 7788+i) validators[i] = p2p.Peer{IP: ip, Port: port, ValidatorID: i + 1} - _, validators[i].ConsensusPubKey = utils.GenKey(validators[i].IP, validators[i].Port) + validatorsPriKeys[i], validators[i].ConsensusPubKey = utils.GenKey(validators[i].IP, validators[i].Port) } m := mock_host.NewMockHost(ctrl) @@ -47,7 +51,7 @@ func TestProcessMessageLeaderPrepare(test *testing.T) { m.EXPECT().GetSelfPeer().Return(leader) m.EXPECT().SendMessageToGroups([]p2p.GroupID{p2p.GroupIDBeacon}, gomock.Any()) - consensusLeader := New(m, "0", validators, leader) + consensusLeader := New(m, "0", validators, leader, priKey) consensusLeader.blockHash = blockHash consensusValidators := make([]*Consensus, 3) @@ -59,7 +63,7 @@ func TestProcessMessageLeaderPrepare(test *testing.T) { } hosts[i] = host - consensusValidators[i] = New(hosts[i], "0", validators, leader) + consensusValidators[i] = New(hosts[i], "0", validators, leader, validatorsPriKeys[i]) consensusValidators[i].blockHash = blockHash msg := consensusValidators[i].constructPrepareMessage() msgPayload, _ := proto.GetConsensusMessagePayload(msg) @@ -76,15 +80,17 @@ func TestProcessMessageLeaderPrepareInvalidSignature(test *testing.T) { defer ctrl.Finish() leader := p2p.Peer{IP: ip, Port: "7777"} - _, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) + var priKey *bls.SecretKey + priKey, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) validators := make([]p2p.Peer, 3) hosts := make([]p2p.Host, 3) + validatorKeys := [3]*bls.SecretKey{} for i := 0; i < 3; i++ { port := fmt.Sprintf("%d", 7788+i) validators[i] = p2p.Peer{IP: ip, Port: port, ValidatorID: i + 1} - _, validators[i].ConsensusPubKey = utils.GenKey(validators[i].IP, validators[i].Port) + validatorKeys[i], validators[i].ConsensusPubKey = utils.GenKey(validators[i].IP, validators[i].Port) } m := mock_host.NewMockHost(ctrl) @@ -92,7 +98,7 @@ func TestProcessMessageLeaderPrepareInvalidSignature(test *testing.T) { // Anything else will fail. m.EXPECT().GetSelfPeer().Return(leader) - consensusLeader := New(m, "0", validators, leader) + consensusLeader := New(m, "0", validators, leader, priKey) consensusLeader.blockHash = blockHash consensusValidators := make([]*Consensus, 3) @@ -104,7 +110,7 @@ func TestProcessMessageLeaderPrepareInvalidSignature(test *testing.T) { } hosts[i] = host - consensusValidators[i] = New(hosts[i], "0", validators, leader) + consensusValidators[i] = New(hosts[i], "0", validators, leader, validatorKeys[i]) consensusValidators[i].blockHash = blockHash msgBytes := consensusValidators[i].constructPrepareMessage() msgPayload, _ := proto.GetConsensusMessagePayload(msgBytes) @@ -130,15 +136,17 @@ func TestProcessMessageLeaderCommit(test *testing.T) { defer ctrl.Finish() leader := p2p.Peer{IP: ip, Port: "8889"} - _, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) + var priKey *bls.SecretKey + priKey, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) validators := make([]p2p.Peer, 3) hosts := make([]p2p.Host, 3) + validatorKeys := [3]*bls.SecretKey{} for i := 0; i < 3; i++ { port := fmt.Sprintf("%d", 8788+i) validators[i] = p2p.Peer{IP: ip, Port: port, ValidatorID: i + 1} - _, validators[i].ConsensusPubKey = utils.GenKey(validators[i].IP, validators[i].Port) + validatorKeys[i], validators[i].ConsensusPubKey = utils.GenKey(validators[i].IP, validators[i].Port) } m := mock_host.NewMockHost(ctrl) @@ -156,7 +164,7 @@ func TestProcessMessageLeaderCommit(test *testing.T) { hosts[i] = host } - consensusLeader := New(m, "0", validators, leader) + consensusLeader := New(m, "0", validators, leader, priKey) consensusLeader.state = PreparedDone consensusLeader.blockHash = blockHash consensusLeader.OnConsensusDone = func(newBlock *types.Block) {} @@ -174,7 +182,7 @@ func TestProcessMessageLeaderCommit(test *testing.T) { <-consensusLeader.ReadySignal }() for i := 0; i < 3; i++ { - consensusValidators[i] = New(hosts[i], "0", validators, leader) + consensusValidators[i] = New(hosts[i], "0", validators, leader, validatorKeys[i]) consensusValidators[i].blockHash = blockHash payload := consensusValidators[i].constructCommitMessage(multiSigAndBitmap) msg, err := proto.GetConsensusMessagePayload(payload) diff --git a/consensus/consensus_test.go b/consensus/consensus_test.go index e9a4484ba..4a0ea949e 100644 --- a/consensus/consensus_test.go +++ b/consensus/consensus_test.go @@ -4,6 +4,8 @@ import ( "bytes" "testing" + "github.com/harmony-one/harmony/crypto/bls" + msg_pb "github.com/harmony-one/harmony/api/proto/message" "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/p2p" @@ -18,7 +20,7 @@ func TestNew(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := New(host, "0", []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) if consensus.consensusID != 0 { test.Errorf("Consensus Id is initialized to the wrong value: %d", consensus.consensusID) } @@ -54,7 +56,7 @@ func TestRemovePeers(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", peers, leader) + consensus := New(host, "0", peers, leader, nil) // consensus.DebugPrintPublicKeys() f := consensus.RemovePeers(peerRemove) @@ -72,7 +74,7 @@ func TestGetPeerFromID(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := New(host, "0", []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) leaderID := utils.GetUniqueIDFromIPPort(leader.IP, leader.Port) validatorID := utils.GetUniqueIDFromIPPort(validator.IP, validator.Port) l, _ := consensus.GetPeerFromID(leaderID) @@ -93,7 +95,7 @@ func TestPopulateMessageFields(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := New(host, "0", []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) consensus.consensusID = 2 consensus.blockHash = blockHash consensus.nodeID = 3 @@ -125,7 +127,7 @@ func TestSignAndMarshalConsensusMessage(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := New(host, "0", []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) consensus.consensusID = 2 consensus.blockHash = blockHash consensus.nodeID = 3 diff --git a/consensus/consensus_validator.go b/consensus/consensus_validator.go index d0fa20765..163347b6c 100644 --- a/consensus/consensus_validator.go +++ b/consensus/consensus_validator.go @@ -176,7 +176,7 @@ func (consensus *Consensus) processPreparedMessage(message *msg_pb.Message) { mask, err := bls_cosi.NewMask(consensus.PublicKeys, nil) mask.SetMask(bitmap) if !deserializedMultiSig.VerifyHash(mask.AggregatePublic, blockHash) || err != nil { - utils.GetLogInstance().Warn("Failed to verify the multi signature for prepare phase", "Error", err, "leader ID", leaderID) + utils.GetLogInstance().Warn("Failed to verify the multi signature for prepare phase", "Error", err, "leader ID", leaderID, "PubKeys", len(consensus.PublicKeys)) return } consensus.aggregatedPrepareSig = &deserializedMultiSig diff --git a/consensus/consensus_validator_msg_test.go b/consensus/consensus_validator_msg_test.go index 61c5c8710..4c45aaa40 100644 --- a/consensus/consensus_validator_msg_test.go +++ b/consensus/consensus_validator_msg_test.go @@ -3,6 +3,8 @@ package consensus import ( "testing" + "github.com/harmony-one/harmony/crypto/bls" + protobuf "github.com/golang/protobuf/proto" "github.com/harmony-one/harmony/api/proto" msg_pb "github.com/harmony-one/harmony/api/proto/message" @@ -19,7 +21,7 @@ func TestConstructPrepareMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := New(host, "0", []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) consensus.blockHash = [32]byte{} msgBytes := consensus.constructPrepareMessage() msgBytes, err = proto.GetConsensusMessagePayload(msgBytes) @@ -45,7 +47,7 @@ func TestConstructCommitMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := New(host, "0", []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) consensus.blockHash = [32]byte{} msg := consensus.constructCommitMessage([]byte("random string")) msg, err = proto.GetConsensusMessagePayload(msg) diff --git a/consensus/consensus_validator_test.go b/consensus/consensus_validator_test.go index fbf6818fe..c89558f1a 100644 --- a/consensus/consensus_validator_test.go +++ b/consensus/consensus_validator_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "github.com/harmony-one/bls/ffi/go/bls" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" @@ -53,7 +55,8 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) { defer ctrl.Finish() leader := p2p.Peer{IP: "127.0.0.1", Port: "9982"} - _, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) + var leaderPriKey *bls.SecretKey + leaderPriKey, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) validator1 := p2p.Peer{IP: "127.0.0.1", Port: "9984", ValidatorID: 1} _, validator1.ConsensusPubKey = utils.GenKey(validator1.IP, validator1.Port) @@ -73,7 +76,7 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensusLeader := New(host, "0", []p2p.Peer{validator1, validator2, validator3}, leader) + consensusLeader := New(host, "0", []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") @@ -91,7 +94,7 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) { test.Errorf("Failed to unmarshal message payload") } - consensusValidator1 := New(m, "0", []p2p.Peer{validator1, validator2, validator3}, leader) + consensusValidator1 := New(m, "0", []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) consensusValidator1.ChainReader = MockChainReader{} copy(consensusValidator1.blockHash[:], hashBytes[:]) @@ -107,7 +110,8 @@ func TestProcessMessageValidatorPrepared(test *testing.T) { defer ctrl.Finish() leader := p2p.Peer{IP: "127.0.0.1", Port: "7782"} - _, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) + var leaderPriKey *bls.SecretKey + leaderPriKey, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) validator1 := p2p.Peer{IP: "127.0.0.1", Port: "7784", ValidatorID: 1} _, validator1.ConsensusPubKey = utils.GenKey(validator1.IP, validator1.Port) @@ -127,7 +131,7 @@ func TestProcessMessageValidatorPrepared(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensusLeader := New(host, "0", []p2p.Peer{validator1, validator2, validator3}, leader) + consensusLeader := New(host, "0", []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") @@ -139,7 +143,7 @@ func TestProcessMessageValidatorPrepared(test *testing.T) { preparedMsg, _ := consensusLeader.constructPreparedMessage() - consensusValidator1 := New(m, "0", []p2p.Peer{validator1, validator2, validator3}, leader) + consensusValidator1 := New(m, "0", []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) consensusValidator1.ChainReader = MockChainReader{} // Get actual consensus messages. @@ -175,7 +179,8 @@ func TestProcessMessageValidatorCommitted(test *testing.T) { defer ctrl.Finish() leader := p2p.Peer{IP: "127.0.0.1", Port: "7782"} - _, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) + var leaderPriKey *bls.SecretKey + leaderPriKey, leader.ConsensusPubKey = utils.GenKey(leader.IP, leader.Port) validator1 := p2p.Peer{IP: "127.0.0.1", Port: "7784", ValidatorID: 1} _, validator1.ConsensusPubKey = utils.GenKey(validator1.IP, validator1.Port) @@ -196,7 +201,7 @@ func TestProcessMessageValidatorCommitted(test *testing.T) { test.Fatalf("newhost failure: %v", err) } message := &msg_pb.Message{} - consensusLeader := New(host, "0", []p2p.Peer{validator1, validator2, validator3}, leader) + consensusLeader := New(host, "0", []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") @@ -227,7 +232,7 @@ func TestProcessMessageValidatorCommitted(test *testing.T) { test.Errorf("Failed to get consensus message") } - consensusValidator1 := New(m, "0", []p2p.Peer{validator1, validator2, validator3}, leader) + consensusValidator1 := New(m, "0", []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) consensusValidator1.ChainReader = MockChainReader{} consensusValidator1.OnConsensusDone = func(newBlock *types.Block) {} diff --git a/core/blockchain.go b/core/blockchain.go index 0181dd392..492eeefb0 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1733,17 +1733,14 @@ func (bc *BlockChain) ValidateNewShardState(block *types.Block, stakeInfo *map[c } // StoreNewShardState insert new shard state into epoch block -func (bc *BlockChain) StoreNewShardState(block *types.Block, stakeInfo *map[common.Address]*structs.StakeInfo) { +func (bc *BlockChain) StoreNewShardState(block *types.Block, stakeInfo *map[common.Address]*structs.StakeInfo) types.ShardState { // write state into db. shardState := bc.GetNewShardState(block, stakeInfo) - if shardState == nil { - return - } - hash := block.Hash() - number := block.NumberU64() - rawdb.WriteShardState(bc.db, hash, number, shardState) - utils.GetLogInstance().Debug("[Resharding] Saved new shard state success", "shardStateHash", shardState.Hash()) - for _, c := range shardState { - utils.GetLogInstance().Debug("[Resharding] Shard Info", "shardID", c.ShardID, "NodeList", c.NodeList) + if shardState != nil { + hash := block.Hash() + number := block.NumberU64() + rawdb.WriteShardState(bc.db, hash, number, shardState) + utils.GetLogInstance().Debug("[Resharding] Saved new shard state success", "state", shardState) } + return shardState } diff --git a/core/resharding.go b/core/resharding.go index 26d7b256d..969e1703c 100644 --- a/core/resharding.go +++ b/core/resharding.go @@ -2,7 +2,6 @@ package core import ( "encoding/binary" - "encoding/hex" "math/rand" "sort" @@ -151,8 +150,10 @@ func CalculateNewShardState(bc *BlockChain, epoch uint64, stakeInfo *map[common. ss := GetShardingStateFromBlockChain(bc, epoch-1) if epoch == FirstEpoch { newNodes := []types.NodeID{} + for addr, stakeInfo := range *stakeInfo { - newNodes = append(newNodes, types.NodeID{addr.Hex(), hex.EncodeToString(stakeInfo.BlsAddress[:])}) + blsAddr := common.BytesToAddress(stakeInfo.BlsAddress[:]) + newNodes = append(newNodes, types.NodeID{addr.Hex(), blsAddr.Hex()}) } rand.Seed(int64(ss.rnd)) Shuffle(newNodes) @@ -191,7 +192,7 @@ func (ss *ShardingState) UpdateShardingState(stakeInfo *map[common.Address]*stru for addr, info := range *stakeInfo { _, ok := oldAddresses[addr.Hex()] if !ok { - newAddresses = append(newAddresses, types.NodeID{hex.EncodeToString(info.BlsAddress[:]), addr.Hex()}) + newAddresses = append(newAddresses, types.NodeID{common.BytesToAddress(info.BlsAddress[:]).Hex(), addr.Hex()}) } } return newAddresses @@ -208,9 +209,13 @@ func GetInitShardState() types.ShardState { priKey := bls.SecretKey{} priKey.SetHexString(contract.InitialBeaconChainBLSAccounts[j].Private) addrBytes := priKey.GetPublicKey().GetAddress() - blsAddr := hex.EncodeToString(addrBytes[:]) + blsAddr := common.BytesToAddress(addrBytes[:]).Hex() // TODO: directly read address for bls too - com.NodeList = append(com.NodeList, types.NodeID{blsAddr, contract.InitialBeaconChainAccounts[j].Address}) + curNodeID := types.NodeID{blsAddr, contract.InitialBeaconChainAccounts[j].Address} + if j == 0 { + com.Leader = curNodeID + } + com.NodeList = append(com.NodeList, curNodeID) } } shardState = append(shardState, com) diff --git a/crypto/bls/bls.go b/crypto/bls/bls.go index 273a2b1cd..18bc52137 100644 --- a/crypto/bls/bls.go +++ b/crypto/bls/bls.go @@ -11,6 +11,13 @@ func init() { bls.Init(bls.BLS12_381) } +// RandPrivateKey returns a random private key. +func RandPrivateKey() *bls.SecretKey { + sec := bls.SecretKey{} + sec.SetByCSPRNG() + return &sec +} + // AggregateSig aggregates all the BLS signature into a single multi-signature. func AggregateSig(sigs []*bls.Sign) *bls.Sign { var aggregatedSig bls.Sign diff --git a/node/contract_test.go b/node/contract_test.go index 70c0b637d..efdeb2946 100644 --- a/node/contract_test.go +++ b/node/contract_test.go @@ -18,7 +18,7 @@ func prepareNode(t *testing.T) *Node { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) return New(host, consensus, nil) } diff --git a/node/node_handler.go b/node/node_handler.go index dd10beaef..d1fde694f 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -3,9 +3,12 @@ package node import ( "bytes" "context" + "math" "os" "time" + "github.com/harmony-one/harmony/core" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" pb "github.com/golang/protobuf/proto" @@ -289,7 +292,46 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block) { utils.GetLogInstance().Info("Updating staking list") node.UpdateStakingList(node.QueryStakeInfo()) node.printStakingList() - node.blockchain.StoreNewShardState(newBlock, &node.CurrentStakes) + if core.IsEpochBlock(newBlock) { + shardState := node.blockchain.StoreNewShardState(newBlock, &node.CurrentStakes) + if shardState != nil { + myShard := uint32(math.MaxUint32) + isLeader := false + for _, shard := range shardState { + for _, nodeID := range shard.NodeList { + blsAddr := node.Consensus.PubKey.GetAddress() + blsAddrStr := common.BytesToAddress(blsAddr[:]).Hex() + if nodeID.BlsAddress == blsAddrStr { + myShard = shard.ShardID + isLeader = shard.Leader == nodeID + } + } + } + + if myShard != uint32(math.MaxUint32) { + aboutLeader := "" + if node.Consensus.IsLeader { + aboutLeader = "I am not leader anymore" + if isLeader { + aboutLeader = "I am still leader" + } + } else { + aboutLeader = "I am still validator" + if isLeader { + aboutLeader = "I become the leader" + } + } + if node.blockchain.ShardID() == myShard { + utils.GetLogInstance().Info("[Resharding] I stay at", "shardID", myShard, "leader") + } else { + utils.GetLogInstance().Info("[Resharding] I got resharded to", "shardID", myShard, "isLeader", isLeader) + } + utils.GetLogInstance().Info("[Resharding] " + aboutLeader) + } else { + utils.GetLogInstance().Info("[Resharding] Somehow I got kicked out") + } + } + } } // AddNewBlock is usedd to add new block into the blockchain. diff --git a/node/node_handler_test.go b/node/node_handler_test.go index deb6a10df..92a93bfac 100644 --- a/node/node_handler_test.go +++ b/node/node_handler_test.go @@ -18,7 +18,7 @@ func TestAddNewBlock(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) node := New(host, consensus, nil) selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock) @@ -41,7 +41,7 @@ func TestVerifyNewBlock(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) node := New(host, consensus, nil) selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock) diff --git a/node/node_test.go b/node/node_test.go index 276788cff..b9c96188b 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -26,7 +26,7 @@ func TestNewNode(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) node := New(host, consensus, nil) if node.Consensus == nil { t.Error("Consensus is not initialized for the node") @@ -51,7 +51,7 @@ func TestGetSyncingPeers(t *testing.T) { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) node := New(host, consensus, nil) peer := p2p.Peer{IP: "127.0.0.1", Port: "8000"} @@ -93,7 +93,7 @@ func TestAddPeers(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) dRand := drand.New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) node := New(host, consensus, nil) @@ -138,7 +138,7 @@ func TestAddBeaconPeer(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) dRand := drand.New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) node := New(host, consensus, nil) @@ -209,7 +209,7 @@ func TestPingPongHandler(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader}, leader, nil) node := New(host, consensus, nil) //go sendPingMessage(leader) go sendPongMessage(node, leader) diff --git a/node/staking_test.go b/node/staking_test.go index a380f7fcf..5c30732bd 100644 --- a/node/staking_test.go +++ b/node/staking_test.go @@ -31,7 +31,7 @@ func TestUpdateStakingList(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader) + consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) node := New(host, consensus, nil) for i := 0; i < 5; i++ { From 8800b5e171aaf7c9bc320bb0b82d9f01412c01ac Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Fri, 15 Mar 2019 23:29:07 -0700 Subject: [PATCH 02/17] Fix errors --- cmd/harmony/main.go | 16 +++++++++------- core/resharding.go | 4 ++-- drand/drand.go | 13 +++++-------- drand/drand_leader_msg_test.go | 6 ++++-- drand/drand_test.go | 20 +++++++++++--------- drand/drand_validator_msg_test.go | 6 ++++-- node/node_test.go | 4 ++-- 7 files changed, 37 insertions(+), 32 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index e18f9548a..b4f7609fa 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -3,13 +3,15 @@ package main import ( "flag" "fmt" - "github.com/harmony-one/bls/ffi/go/bls" "math/rand" "os" "path" "runtime" + "strconv" "time" + "github.com/harmony-one/bls/ffi/go/bls" + "github.com/harmony-one/harmony/internal/utils/contract" "github.com/ethereum/go-ethereum/ethdb" @@ -127,8 +129,11 @@ func createGlobalConfig() *nodeconfig.ConfigType { stakingPriKey := "" consensusPriKey := &bls.SecretKey{} if *isBeacon { - stakingPriKey = contract.InitialBeaconChainAccounts[*accountIndex].Private - err := consensusPriKey.DeserializeHexStr(contract.InitialBeaconChainBLSAccounts[*accountIndex].Private) + // TODO: use a better way to get the index for accounts. + portNum, _ := strconv.Atoi(*port) + index := portNum % 10 + stakingPriKey = contract.InitialBeaconChainAccounts[index].Private + err := consensusPriKey.SetHexString(contract.InitialBeaconChainBLSAccounts[index].Private) if err != nil { panic(fmt.Errorf("generate key error")) } @@ -137,9 +142,6 @@ func createGlobalConfig() *nodeconfig.ConfigType { // TODO: use user supplied key consensusPriKey, _ = utils.GenKey(*ip, *port) } - consensusPriKey, _ = utils.GenKey(*ip, *port) - fmt.Println("TESTTEST") - fmt.Println(consensusPriKey.SerializeToHexStr()) nodeConfig.StakingPriKey = node.StoreStakingKeyFromFile(*stakingKeyFile, stakingPriKey) // P2p private key is used for secure message transfer between p2p nodes. @@ -226,7 +228,7 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen // TODO: enable drand only for beacon chain // TODO: put this in a better place other than main. // TODO(minhdoan): During refactoring, found out that the peers list is actually empty. Need to clean up the logic of drand later. - dRand := drand.New(nodeConfig.Host, nodeConfig.ShardIDString, []p2p.Peer{}, nodeConfig.Leader, currentNode.ConfirmedBlockChannel, *isLeader) + dRand := drand.New(nodeConfig.Host, nodeConfig.ShardIDString, []p2p.Peer{}, nodeConfig.Leader, currentNode.ConfirmedBlockChannel, *isLeader, nodeConfig.ConsensusPriKey) currentNode.Consensus.RegisterPRndChannel(dRand.PRndChannel) currentNode.Consensus.RegisterRndChannel(dRand.RndChannel) currentNode.DRand = dRand diff --git a/core/resharding.go b/core/resharding.go index 969e1703c..29ef2bce6 100644 --- a/core/resharding.go +++ b/core/resharding.go @@ -192,7 +192,7 @@ func (ss *ShardingState) UpdateShardingState(stakeInfo *map[common.Address]*stru for addr, info := range *stakeInfo { _, ok := oldAddresses[addr.Hex()] if !ok { - newAddresses = append(newAddresses, types.NodeID{common.BytesToAddress(info.BlsAddress[:]).Hex(), addr.Hex()}) + newAddresses = append(newAddresses, types.NodeID{addr.Hex(), common.BytesToAddress(info.BlsAddress[:]).Hex()}) } } return newAddresses @@ -211,7 +211,7 @@ func GetInitShardState() types.ShardState { addrBytes := priKey.GetPublicKey().GetAddress() blsAddr := common.BytesToAddress(addrBytes[:]).Hex() // TODO: directly read address for bls too - curNodeID := types.NodeID{blsAddr, contract.InitialBeaconChainAccounts[j].Address} + curNodeID := types.NodeID{contract.InitialBeaconChainAccounts[j].Address, blsAddr} if j == 0 { com.Leader = curNodeID } diff --git a/drand/drand.go b/drand/drand.go index 11758026d..36fb7bd4d 100644 --- a/drand/drand.go +++ b/drand/drand.go @@ -2,7 +2,6 @@ package drand import ( "crypto/sha256" - "encoding/binary" "errors" "strconv" "sync" @@ -67,7 +66,7 @@ type DRand struct { } // New creates a new dRand object -func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer, confirmedBlockChannel chan *types.Block, isLeader bool) *DRand { +func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer, confirmedBlockChannel chan *types.Block, isLeader bool, blsPriKey *bls.SecretKey) *DRand { dRand := DRand{} dRand.host = host @@ -108,12 +107,10 @@ func New(host p2p.Host, ShardID string, peers []p2p.Peer, leader p2p.Peer, confi dRand.nodeID = utils.GetUniqueIDFromPeer(selfPeer) // Set private key for myself so that I can sign messages. - nodeIDBytes := make([]byte, 32) - binary.LittleEndian.PutUint32(nodeIDBytes, dRand.nodeID) - privateKey := bls.SecretKey{} - err := privateKey.SetLittleEndian(nodeIDBytes) - dRand.priKey = &privateKey - dRand.pubKey = privateKey.GetPublicKey() + if blsPriKey != nil { + dRand.priKey = blsPriKey + dRand.pubKey = blsPriKey.GetPublicKey() + } // VRF keys priKey, pubKey := p256.GenerateKey() diff --git a/drand/drand_leader_msg_test.go b/drand/drand_leader_msg_test.go index 1b90a9b6a..7f2ee0bee 100644 --- a/drand/drand_leader_msg_test.go +++ b/drand/drand_leader_msg_test.go @@ -3,6 +3,8 @@ package drand import ( "testing" + "github.com/harmony-one/harmony/crypto/bls" + protobuf "github.com/golang/protobuf/proto" "github.com/harmony-one/harmony/api/proto" msg_pb "github.com/harmony-one/harmony/api/proto/message" @@ -19,7 +21,7 @@ func TestConstructInitMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls.RandPrivateKey()) dRand.blockHash = [32]byte{} msg := dRand.constructInitMessage() @@ -41,7 +43,7 @@ func TestProcessCommitMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls.RandPrivateKey()) dRand.blockHash = [32]byte{} msg := dRand.constructCommitMessage([32]byte{}, []byte{}) diff --git a/drand/drand_test.go b/drand/drand_test.go index 705b46135..6bb82f2da 100644 --- a/drand/drand_test.go +++ b/drand/drand_test.go @@ -5,6 +5,8 @@ import ( "strings" "testing" + bls2 "github.com/harmony-one/harmony/crypto/bls" + "github.com/ethereum/go-ethereum/common" "github.com/harmony-one/bls/ffi/go/bls" msg_pb "github.com/harmony-one/harmony/api/proto/message" @@ -22,7 +24,7 @@ func TestNew(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) if !dRand.IsLeader { test.Error("dRand should belong to a leader") @@ -37,7 +39,7 @@ func TestGetValidatorPeers(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) if !dRand.IsLeader { test.Error("dRand should belong to a leader") @@ -58,7 +60,7 @@ func TestAddPeers(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) if !dRand.IsLeader { test.Error("dRand should belong to a leader") @@ -84,7 +86,7 @@ func TestGetValidatorByPeerId(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) if !dRand.IsLeader { test.Error("dRand should belong to a leader") @@ -111,7 +113,7 @@ func TestResetState(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) dRand.ResetState() } @@ -123,7 +125,7 @@ func TestSetLeaderPubKey(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) _, newPublicKey, _ := utils.GenKeyP2P("127.0.0.1", "9902") newPublicKeyBytes, _ := newPublicKey.Bytes() @@ -140,7 +142,7 @@ func TestUpdatePublicKeys(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) _, pubKey1 := utils.GenKey("127.0.0.1", "5555") _, pubKey2 := utils.GenKey("127.0.0.1", "6666") @@ -166,7 +168,7 @@ func TestVerifyMessageSig(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) message := &msg_pb.Message{ ReceiverType: msg_pb.ReceiverType_VALIDATOR, @@ -195,7 +197,7 @@ func TestVrf(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls2.RandPrivateKey()) tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), 0, big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11}) txs := []*types.Transaction{tx1} diff --git a/drand/drand_validator_msg_test.go b/drand/drand_validator_msg_test.go index cb9dd973f..815b7d19a 100644 --- a/drand/drand_validator_msg_test.go +++ b/drand/drand_validator_msg_test.go @@ -3,6 +3,8 @@ package drand import ( "testing" + "github.com/harmony-one/harmony/crypto/bls" + protobuf "github.com/golang/protobuf/proto" "github.com/harmony-one/harmony/api/proto" msg_pb "github.com/harmony-one/harmony/api/proto/message" @@ -19,7 +21,7 @@ func TestConstructCommitMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls.RandPrivateKey()) dRand.blockHash = [32]byte{} msg := dRand.constructCommitMessage([32]byte{}, []byte{}) msgPayload, _ := proto.GetDRandMessagePayload(msg) @@ -40,7 +42,7 @@ func TestProcessInitMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, bls.RandPrivateKey()) dRand.blockHash = [32]byte{} msg := dRand.constructInitMessage() diff --git a/node/node_test.go b/node/node_test.go index b9c96188b..0ab5e3531 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -94,7 +94,7 @@ func TestAddPeers(t *testing.T) { t.Fatalf("newhost failure: %v", err) } consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) - dRand := drand.New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := drand.New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, nil) node := New(host, consensus, nil) node.DRand = dRand @@ -139,7 +139,7 @@ func TestAddBeaconPeer(t *testing.T) { t.Fatalf("newhost failure: %v", err) } consensus := consensus.New(host, "0", []p2p.Peer{leader, validator}, leader, nil) - dRand := drand.New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true) + dRand := drand.New(host, "0", []p2p.Peer{leader, validator}, leader, nil, true, nil) node := New(host, consensus, nil) node.DRand = dRand From 4eb5cc4c27cfffb7a568bc3e0b40f1e0d96230be Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sat, 16 Mar 2019 15:01:49 +0000 Subject: [PATCH 03/17] [gomod] update bls to v0.0.1 version bls v0.0.1 has the fix of the following PR. https://github.com/harmony-one/bls/pull/1 Signed-off-by: Leo Chen --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 44d9233ca..2a9eb8936 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/golang/mock v1.2.0 github.com/golang/protobuf v1.3.0 github.com/gorilla/mux v1.7.0 - github.com/harmony-one/bls v0.0.0-20190309234102-1bd75ac96c09 + github.com/harmony-one/bls v0.0.1 github.com/hashicorp/golang-lru v0.5.1 github.com/ipfs/go-datastore v3.2.0+incompatible github.com/libp2p/go-libp2p v0.0.2 From 93acc5e934a82fef4d6c7d43820265d46fe11527 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 12:23:47 -0700 Subject: [PATCH 04/17] Turn module mode on --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 89651aeb1..d61ac6909 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ go: - stable go_import_path: github.com/harmony-one/harmony install: - - env GO111MODULE=on + - export GO111MODULE=on - export GOPATH=$HOME/gopath - export CGO_CPPFLAGS="-I$GOPATH/src/github.com/harmony-one/bls/include -I$GOPATH/src/github.com/harmony-one/mcl/include" - export CGO_LDFLAGS="-L$GOPATH/src/github.com/harmony-one/bls/lib -L$GOPATH/src/github.com/harmony-one/mcl/lib" From fe9c55c94c4c1e03b48ae5898793d10146bab7d7 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 12:27:32 -0700 Subject: [PATCH 05/17] Unvendor now that module mode is on --- .gitmodules | 7 ------- vendor/github.com/ethereum/go-ethereum | 1 - vendor/github.com/libp2p/go-libp2p-kad-dht | 1 - 3 files changed, 9 deletions(-) delete mode 160000 vendor/github.com/ethereum/go-ethereum delete mode 160000 vendor/github.com/libp2p/go-libp2p-kad-dht diff --git a/.gitmodules b/.gitmodules index ad2702ed2..e69de29bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +0,0 @@ -[submodule "vendor/github.com/ethereum/go-ethereum"] - path = vendor/github.com/ethereum/go-ethereum - url = https://github.com/harmony-one/go-ethereum - branch = master -[submodule "vendor/github.com/libp2p/go-libp2p-kad-dht"] - path = vendor/github.com/libp2p/go-libp2p-kad-dht - url = https://github.com/libp2p/go-libp2p-kad-dht diff --git a/vendor/github.com/ethereum/go-ethereum b/vendor/github.com/ethereum/go-ethereum deleted file mode 160000 index 38cce9ac3..000000000 --- a/vendor/github.com/ethereum/go-ethereum +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 38cce9ac333d674616047be14c270d7cfbd43641 diff --git a/vendor/github.com/libp2p/go-libp2p-kad-dht b/vendor/github.com/libp2p/go-libp2p-kad-dht deleted file mode 160000 index 838d43da0..000000000 --- a/vendor/github.com/libp2p/go-libp2p-kad-dht +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 838d43da02fc33899794e1c63fe4bd4d0bfd749a From 7714bae1a1b447028cd2a2a8ccd4dd3daf7f60d4 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 12:32:53 -0700 Subject: [PATCH 06/17] =?UTF-8?q?go-datastore=20v3.2.0=20=E2=86=92=20v0.0.?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v3.2.0 is now prefixed with gx/. --- go.mod | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 2a9eb8936..657b966cb 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/mux v1.7.0 github.com/harmony-one/bls v0.0.1 github.com/hashicorp/golang-lru v0.5.1 - github.com/ipfs/go-datastore v3.2.0+incompatible + github.com/ipfs/go-datastore v0.0.1 github.com/libp2p/go-libp2p v0.0.2 github.com/libp2p/go-libp2p-crypto v0.0.1 github.com/libp2p/go-libp2p-discovery v0.0.1 @@ -31,5 +31,4 @@ require ( github.com/shirou/gopsutil v2.18.12+incompatible golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 google.golang.org/grpc v1.19.0 - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) From 937b372cd9743e3a1909c883aaf1380b626f4877 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 12:37:31 -0700 Subject: [PATCH 07/17] go mod tidy --- go.mod | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/go.mod b/go.mod index 657b966cb..49c78b5d2 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,16 @@ module github.com/harmony-one/harmony go 1.12 require ( + github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect github.com/Workiva/go-datastructures v1.0.50 github.com/allegro/bigcache v1.2.0 // indirect github.com/aristanetworks/goarista v0.0.0-20190308231643-e9fb69a13f45 // indirect + github.com/cespare/cp v1.1.1 // indirect github.com/deckarep/golang-set v1.7.1 // indirect + github.com/edsrzf/mmap-go v1.0.0 // indirect github.com/ethereum/go-ethereum v1.8.23 + github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a // indirect + github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/golang/mock v1.2.0 github.com/golang/protobuf v1.3.0 @@ -15,6 +20,8 @@ require ( github.com/harmony-one/bls v0.0.1 github.com/hashicorp/golang-lru v0.5.1 github.com/ipfs/go-datastore v0.0.1 + github.com/ipfs/go-log v0.0.1 + github.com/karalabe/hid v0.0.0-20181128192157-d815e0c1a2e2 // indirect github.com/libp2p/go-libp2p v0.0.2 github.com/libp2p/go-libp2p-crypto v0.0.1 github.com/libp2p/go-libp2p-discovery v0.0.1 @@ -28,7 +35,14 @@ require ( github.com/multiformats/go-multiaddr-net v0.0.1 github.com/pborman/uuid v1.2.0 // indirect github.com/rjeczalik/notify v0.9.2 // indirect + github.com/rs/cors v1.6.0 // indirect github.com/shirou/gopsutil v2.18.12+incompatible + github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect + github.com/stretchr/testify v1.3.0 + github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 google.golang.org/grpc v1.19.0 + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 + gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect + gopkg.in/urfave/cli.v1 v1.20.0 // indirect ) From 5d99b22d30dd27d763915dafc25eeaae9cd6dcd9 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 12:54:14 -0700 Subject: [PATCH 08/17] Make go generate verbose --- scripts/gogenerate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gogenerate.sh b/scripts/gogenerate.sh index 5ac4c3ebd..9adb847d0 100755 --- a/scripts/gogenerate.sh +++ b/scripts/gogenerate.sh @@ -6,4 +6,4 @@ case "${0}" in *) progdir=.;; esac git grep -l '^//go:generate ' -- '*.go' | \ - "${progdir}/xargs_by_dir.sh" go generate + "${progdir}/xargs_by_dir.sh" go generate -v -x From 36e794564a2c26dfcfa79a2b5e164b6cf5c69b86 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 12:56:53 -0700 Subject: [PATCH 09/17] Move go test to the end because it takes longest --- scripts/travis_checker.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index d4702bd45..245a2f89c 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -16,15 +16,6 @@ tmpdir=$(mktemp -d) . "${progdir}/setup_bls_build_flags.sh" -echo "Running go test..." -if go test -v -count=1 ./... -then - echo "go test succeeded." -else - echo "go test FAILED!" - ok=false -fi - echo "Running golint..." golint_output="${tmpdir}/golint_output.txt" if "${progdir}/golint.sh" -set_exit_status > "${golint_output}" 2>&1 @@ -74,6 +65,15 @@ else ok=false fi +echo "Running go test..." +if go test -v -count=1 ./... +then + echo "go test succeeded." +else + echo "go test FAILED!" + ok=false +fi + if ! ${ok} then echo "Some checks failed; see output above." From bf662ff159efd906162055f614d4040f04cc777d Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 13:02:54 -0700 Subject: [PATCH 10/17] Check if go.mod dependencies have changed This is to see if manual tool installation upgraded any dependencies. --- scripts/travis_checker.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 245a2f89c..792570d80 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -1,6 +1,6 @@ #!/bin/bash -unset -v ok tmpdir goimports_output golint_output progdir +unset -v ok tmpdir gomod_diff_output goimports_output golint_output progdir ok=true case "${0}" in @@ -16,6 +16,19 @@ tmpdir=$(mktemp -d) . "${progdir}/setup_bls_build_flags.sh" +echo "Checking go.mod..." +gomod_diff_output="${tmpdir}/gomod.diff" +if git diff --exit-code -- go.mod > "${gomod_diff_output}" +then + echo "go.mod stayed the same as in the repository." +else + echo "go.mod has changed from the repository version!" + "${progdir}/print_file.sh" "${gomod_diff_output}" "go.mod diff" + "${progdir}/print_file.sh" go.mod "go.mod changed contents" + #ok=false + echo "Not treating this as an error, but consider updating go.mod!" +fi + echo "Running golint..." golint_output="${tmpdir}/golint_output.txt" if "${progdir}/golint.sh" -set_exit_status > "${golint_output}" 2>&1 From b64d7a44121a51468e606deba59b935e4c1f78e7 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 13:07:05 -0700 Subject: [PATCH 11/17] =?UTF-8?q?=E2=80=9Cgo=20get:=20-t=20flag=20is=20a?= =?UTF-8?q?=20no-op=20when=20using=20modules=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d61ac6909..e660ee286 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ install: - cd bls - make - cd ../harmony - - go get -t -v ./... + - go get -v ./... - go get -u golang.org/x/lint/golint - go get -u golang.org/x/tools/cmd/goimports - go get gopkg.in/check.v1 From da3c93fb58371b5355923ede044ab0ad398d15e6 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 13:11:59 -0700 Subject: [PATCH 12/17] Temporarily disable gencodec gencodec fails spectacularly and colorfully in various places; see https://travis-ci.org/harmony-ek/harmony/builds/507288316 for one. Local builds run into a bunch of other issues as well. --- core/genesis.go | 4 ++-- core/types/log.go | 2 +- core/types/receipt.go | 2 +- core/types/transaction.go | 2 +- core/vm/logger.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 65aade753..7527cec6e 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -37,8 +37,8 @@ import ( "github.com/harmony-one/harmony/internal/utils" ) -//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go -//go:generate gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go +// no go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go +// no go:generate gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go var errGenesisNoConfig = errors.New("genesis has no chain configuration") diff --git a/core/types/log.go b/core/types/log.go index 717cd2e5a..6142a1656 100644 --- a/core/types/log.go +++ b/core/types/log.go @@ -24,7 +24,7 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) -//go:generate gencodec -type Log -field-override logMarshaling -out gen_log_json.go +// no go:generate gencodec -type Log -field-override logMarshaling -out gen_log_json.go // Log represents a contract log event. These events are generated by the LOG opcode and // stored/indexed by the node. diff --git a/core/types/receipt.go b/core/types/receipt.go index 3d1fc95aa..aee69a66f 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -27,7 +27,7 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) -//go:generate gencodec -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go +// no go:generate gencodec -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go var ( receiptStatusFailedRLP = []byte{} diff --git a/core/types/transaction.go b/core/types/transaction.go index e220abfca..e7bf4174c 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -29,7 +29,7 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) -//go:generate gencodec -type txdata -field-override txdataMarshaling -out gen_tx_json.go +// no go:generate gencodec -type txdata -field-override txdataMarshaling -out gen_tx_json.go // Errors constants for Transaction. var ( diff --git a/core/vm/logger.go b/core/vm/logger.go index 1733bf270..ebeea4c53 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -51,7 +51,7 @@ type LogConfig struct { Limit int // maximum length of output, but zero means unlimited } -//go:generate gencodec -type StructLog -field-override structLogMarshaling -out gen_structlog.go +// no go:generate gencodec -type StructLog -field-override structLogMarshaling -out gen_structlog.go // StructLog is emitted to the EVM each cycle and lists information about the current internal state // prior to the execution of the statement. From 9d6ea5f13721e7ca64d05d19c1890d4059f81718 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 13:25:27 -0700 Subject: [PATCH 13/17] Move go build -v ./... to the script stage Install stage (where it was previously found), by convention, is used for installing tools and dependencies only. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e660ee286..a874c41de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,8 @@ install: - go get github.com/golang/protobuf/protoc-gen-go - ./scripts/install_protoc.sh -V 3.6.1 - ./scripts/travis_checker.sh - - go build -v ./... script: + - go build -v ./... - ./scripts/travis_checker.sh notifications: slack: harmonyone:gggCd1QQopsQAW8JYgBWiH7M From e3bd479aa4d2272ae85d0812a3fbbfd7ab87c3c0 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 13:26:52 -0700 Subject: [PATCH 14/17] Do not run Travis checker twice Really. Makes no sense to do so. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a874c41de..a9380b7ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,6 @@ install: - go get github.com/golang/mock/mockgen - go get github.com/golang/protobuf/protoc-gen-go - ./scripts/install_protoc.sh -V 3.6.1 - - ./scripts/travis_checker.sh script: - go build -v ./... - ./scripts/travis_checker.sh From 31be7f063244ca81481591aecc3b54939ad6243b Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 15:14:18 -0700 Subject: [PATCH 15/17] Make go build verbose --- scripts/go_executable_build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/go_executable_build.sh b/scripts/go_executable_build.sh index d4bc031ad..ffe2d076c 100755 --- a/scripts/go_executable_build.sh +++ b/scripts/go_executable_build.sh @@ -89,7 +89,7 @@ function build_only if [[ -z "$build" || "$bin" == "$build" ]]; then rm -f $BINDIR/$bin echo "building ${SRC[$bin]}" - env GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE ${SRC[$bin]} + env GOOS=$GOOS GOARCH=$GOARCH go build -v -x -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE ${SRC[$bin]} if [ "$(uname -s)" == "Linux" ]; then $BINDIR/$bin -version fi From a6ed72800bcd3552432ad8eb21667b6f40c9cbdc Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 16 Mar 2019 15:06:12 -0700 Subject: [PATCH 16/17] GO111MODULE does not belong here; remove --- scripts/go_executable_build.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/go_executable_build.sh b/scripts/go_executable_build.sh index ffe2d076c..e2fb4fba4 100755 --- a/scripts/go_executable_build.sh +++ b/scripts/go_executable_build.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -export GO111MODULE=on - declare -A SRC SRC[harmony]=cmd/harmony/main.go SRC[txgen]=cmd/client/txgen/main.go From d2f2a44ec338421af6f5ea79d0dfa8a141c66588 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 18 Mar 2019 14:05:21 -0700 Subject: [PATCH 17/17] Add more new nodes in deploy_newnode.sh --- test/deploy_newnode.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/deploy_newnode.sh b/test/deploy_newnode.sh index 3e031653c..d3cb386d0 100755 --- a/test/deploy_newnode.sh +++ b/test/deploy_newnode.sh @@ -119,8 +119,9 @@ HMY_OPT= HMY_OPT2= HMY_OPT3= -for i in {0..4} +for i in 0{1..9} {10..99} do echo "launching new node $i ..." - ($DRYRUN $ROOT/bin/harmony -ip 127.0.0.1 -port 910$i -log_folder $log_folder -is_newnode $DB -account_index $i -min_peers $MIN $HMY_OPT $HMY_OPT2 $HMY_OPT3 -key /tmp/127.0.0.1-910$i.key 2>&1 | tee -a $LOG_FILE ) & + ($DRYRUN $ROOT/bin/harmony -ip 127.0.0.1 -port 91$i -log_folder $log_folder -is_newnode $DB -account_index $i -min_peers $MIN $HMY_OPT $HMY_OPT2 $HMY_OPT3 -key /tmp/127.0.0.1-91$i.key 2>&1 | tee -a $LOG_FILE ) & + sleep 3 done