Merge pull request #717 from LeoHChen/set_init_consensus_id

Set init consensus ID
pull/727/head
Leo Chen 6 years ago committed by GitHub
commit 85b1f5001d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      cmd/harmony/main.go
  2. 5
      consensus/consensus.go
  3. 19
      consensus/consensus_test.go
  4. 2
      test/deploy.sh

@ -266,6 +266,12 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen
// This needs to be executed after consensus and drand are setup // This needs to be executed after consensus and drand are setup
currentNode.InitGenesisShardState() 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 // Assign closure functions to the consensus object
consensus.BlockVerifier = currentNode.VerifyNewBlock consensus.BlockVerifier = currentNode.VerifyNewBlock
consensus.OnConsensusDone = currentNode.PostConsensusProcessing consensus.OnConsensusDone = currentNode.PostConsensusProcessing

@ -231,6 +231,11 @@ func New(host p2p.Host, ShardID uint32, leader p2p.Peer, blsPriKey *bls.SecretKe
return &consensus, nil 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 // RegisterPRndChannel registers the channel for receiving randomness preimage from DRG protocol
func (consensus *Consensus) RegisterPRndChannel(pRndChannel chan []byte) { func (consensus *Consensus) RegisterPRndChannel(pRndChannel chan []byte) {
consensus.PRndChannel = pRndChannel consensus.PRndChannel = pRndChannel

@ -117,3 +117,22 @@ func TestSignAndMarshalConsensusMessage(t *testing.T) {
t.Error("No signature is signed on the consensus message.") 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)
}
}

@ -8,6 +8,8 @@ USER=$(whoami)
set -x set -x
set -eo pipefail set -eo pipefail
export GO111MODULE=on
function check_result() { function check_result() {
find $log_folder -name leader-*.log > $log_folder/all-leaders.txt find $log_folder -name leader-*.log > $log_folder/all-leaders.txt
find $log_folder -name validator-*.log > $log_folder/all-validators.txt find $log_folder -name validator-*.log > $log_folder/all-validators.txt

Loading…
Cancel
Save