From 33d987759992755680bf570ad6ff7e2115856bb0 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 11 Jul 2016 21:45:08 -0400 Subject: [PATCH] consensus: hvs.Reset(height, valSet) --- consensus/height_vote_set.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/consensus/height_vote_set.go b/consensus/height_vote_set.go index 93fa94e86..583ef3f6f 100644 --- a/consensus/height_vote_set.go +++ b/consensus/height_vote_set.go @@ -38,18 +38,28 @@ type HeightVoteSet struct { func NewHeightVoteSet(chainID string, height int, valSet *types.ValidatorSet) *HeightVoteSet { hvs := &HeightVoteSet{ - chainID: chainID, - height: height, - valSet: valSet, - roundVoteSets: make(map[int]RoundVoteSet), - peerCatchupRounds: make(map[string]int), + chainID: chainID, } + hvs.Reset(height, valSet) + return hvs +} + +func (hvs *HeightVoteSet) Reset(height int, valSet *types.ValidatorSet) { + hvs.mtx.Lock() + defer hvs.mtx.Unlock() + + hvs.height = height + hvs.valSet = valSet + hvs.roundVoteSets = make(map[int]RoundVoteSet) + hvs.peerCatchupRounds = make(map[string]int) + hvs.addRound(0) hvs.round = 0 - return hvs } func (hvs *HeightVoteSet) Height() int { + hvs.mtx.Lock() + defer hvs.mtx.Unlock() return hvs.height }