From 9a785f9638b1521880e1e637a2845cc1117c2d1d Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 12 Apr 2019 21:52:32 +0000 Subject: [PATCH 1/3] [consensus] add set consensus ID function Signed-off-by: Leo Chen --- consensus/consensus.go | 5 +++++ consensus/consensus_test.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/consensus/consensus.go b/consensus/consensus.go index ba8c0a7ff..9248c7b16 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -231,6 +231,11 @@ func New(host p2p.Host, ShardID uint32, leader p2p.Peer, blsPriKey *bls.SecretKe return &consensus, nil } +// SetConsensusID set the consensusID to the height of the blockchain +func (consensus *Consensus) SetConsensusID(height uint32) { + consensus.consensusID = height +} + // RegisterPRndChannel registers the channel for receiving randomness preimage from DRG protocol func (consensus *Consensus) RegisterPRndChannel(pRndChannel chan []byte) { consensus.PRndChannel = pRndChannel diff --git a/consensus/consensus_test.go b/consensus/consensus_test.go index cff152fe3..d8d4c8973 100644 --- a/consensus/consensus_test.go +++ b/consensus/consensus_test.go @@ -117,3 +117,22 @@ func TestSignAndMarshalConsensusMessage(t *testing.T) { t.Error("No signature is signed on the consensus message.") } } + +func TestSetConsensusID(t *testing.T) { + leader := p2p.Peer{IP: "127.0.0.1", Port: "9902"} + priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902") + host, err := p2pimpl.NewHost(&leader, priKey) + if err != nil { + t.Fatalf("newhost failure: %v", err) + } + consensus, err := New(host, 0, leader, bls.RandPrivateKey()) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } + + height := uint32(1000) + consensus.SetConsensusID(height) + if consensus.consensusID != height { + t.Errorf("Cannot set consensus ID. Got: %v, Expected: %v", consensus.consensusID, height) + } +} From 67688fc1dd386f61c367ce5c7e5923838f9e7dc5 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 12 Apr 2019 22:06:02 +0000 Subject: [PATCH 2/3] [consensus] set init consensus ID Signed-off-by: Leo Chen --- cmd/harmony/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 9a7cef20e..ab86ce3b4 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -266,6 +266,12 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen // This needs to be executed after consensus and drand are setup currentNode.InitGenesisShardState() + // Set the consensus ID to be the current block number + height := currentNode.Blockchain().CurrentBlock().NumberU64() + + consensus.SetConsensusID(uint32(height)) + utils.GetLogInstance().Info("Init Blockchain", "height", height) + // Assign closure functions to the consensus object consensus.BlockVerifier = currentNode.VerifyNewBlock consensus.OnConsensusDone = currentNode.PostConsensusProcessing From 0ff3c9ae0a7186f0c608443253234d75624d59f0 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 12 Apr 2019 15:12:20 -0700 Subject: [PATCH 3/3] [build] set GO111MODULE in deploy.sh Signed-off-by: Leo Chen --- test/deploy.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/deploy.sh b/test/deploy.sh index 7b54d16bc..d0b11352f 100755 --- a/test/deploy.sh +++ b/test/deploy.sh @@ -8,6 +8,8 @@ USER=$(whoami) set -x set -eo pipefail +export GO111MODULE=on + function check_result() { find $log_folder -name leader-*.log > $log_folder/all-leaders.txt find $log_folder -name validator-*.log > $log_folder/all-validators.txt