From b3b6a24317351e085dccfb13e7c8327e842cc239 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 16 Jan 2015 01:06:15 -0800 Subject: [PATCH] fix validator_set add() bug --- state/validator_set.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/state/validator_set.go b/state/validator_set.go index 9db6f8bcc..50f76f423 100644 --- a/state/validator_set.go +++ b/state/validator_set.go @@ -144,8 +144,10 @@ func (valSet *ValidatorSet) Add(val *Validator) (added bool) { } else if bytes.Compare(valSet.Validators[idx].Address, val.Address) == 0 { return false } else { - newValidators := append(valSet.Validators[:idx], val) - newValidators = append(newValidators, valSet.Validators[idx:]...) + newValidators := make([]*Validator, len(valSet.Validators)+1) + copy(newValidators[:idx], valSet.Validators[:idx]) + newValidators[idx] = val + copy(newValidators[idx+1:], valSet.Validators[idx:]) valSet.Validators = newValidators // Invalidate cache valSet.proposer = nil